Computer Science Canada

Help with drawbox.... (i think thats the problem)

Author:  recneps [ Sat Dec 13, 2003 2:33 pm ]
Post subject:  Help with drawbox.... (i think thats the problem)

am i just a newbie or can drawbox not use variables instead of numbers??
im making a pong program and here it is...
code:

%position/direction variables
var x, y, dx, dy, score1, score2 : int
score1 := 0
score2 := 0
var midx : real := maxx * 0.5
var midy : real := maxy * 0.5
var p1x1, p1x2, p1y1, p1y2, p2x1, p2x2, p2y1, p2y2 : real
p1x1 := 0
p1x2 := 10
p1y1 := midy - 100
p1y2 := midy + 100
%clear screen
cls

%picture size
const pic_width := 10
const pic_height := 10

%set pos/dir variables
randint (x, 10, maxx - 10 - pic_width)
randint (y, 10, maxy - 10 - pic_height)
randint (dx, -3, 3)
randint (dy, -3, 3)

%smoother animation
setscreen ("offscreenonly")
%begin animation/gameplay
loop
    cls
    if x + dx < 0 or x + dx + pic_width > maxx then
        dx := -dx %Change x direction if bounce
    end if
    if y + dy < 0 or y + dy + pic_height > maxy then
        dy := -dy %change y direction if bounce
    end if
    x := x + dx %create the new positions
    y := y + dy %create the new positions
    drawoval (x, y, pic_width, pic_height, 7) %draw ball
    %drawbox (p1x1, p1y1, p1x2, p1y2, 7)
    View.Update %part of offscreenonly
    delay (7)
    exit when hasch
end loop

setscreen ("nooffscreenonly") %change screen back to normal

and it says error at
drawbox (p1x1, p1y1, p1x2, p1y2, 7)
"argument is wrong type". whats wrong with it? you can use viariables right?

Author:  AsianSensation [ Sat Dec 13, 2003 3:11 pm ]
Post subject: 

drawbox doesn't take real numbers as it's parameters, make sure that either those coordinates are integers, or use

code:
round


to round the real numbers into the closest integer, and then plug in the rounded value.

Author:  DanShadow [ Sat Dec 13, 2003 5:03 pm ]
Post subject: 

Hey AsianSensation...im having a problem that round could help with, could you private message me on how to use round in this situation:
code:

var hp,maxhp:int:=20
var hp_percent:real:=0
hp_percent:=(hp/maxhp)*100
put "HP: ",hp,"/",maxhp," [",hp_percent,"%]"


If you can, thanks!

Author:  recneps [ Sat Dec 13, 2003 7:33 pm ]
Post subject:  how does round work?

how does round work?
like
code:
round maxx/2
or what?[/code]

Author:  Tony [ Sat Dec 13, 2003 7:36 pm ]
Post subject: 

it's
code:

round ( real value or expression that returns a real value )


Note: if you use division in your expression, then it will always return a real value, even if numbers divide evenly.

Author:  DanShadow [ Sat Dec 13, 2003 8:30 pm ]
Post subject: 

Ah! I get it. So for me its like:
code:

round(hp_percent)

neat, tx

Author:  recneps [ Thu Dec 18, 2003 5:13 pm ]
Post subject:  thnx

thanks that good to know in future, but since the boards were down for a bit (?) i figured out i could use div to give me whole numbers only Smile


: