Computer Science Canada

text help

Author:  bgmrk [ Fri Apr 07, 2006 5:46 pm ]
Post subject:  text help

i am trying to make pong game..however when i am using the font.Draw it won't let me put an integar variable....does it only allow int? or is it just strings?

Here is my code..you'll c the error when u try to run it...
code:
setscreen ("graphics:500;500,nobuttonbar,nooffscreenonly")
%%%player
var boxx, width, score : int
var player : string
var chars : array char of boolean
boxx := maxx div 2 - 25
width := 50
%%ball
var x,y,dx,dy, radius : int
%board
var scorefont, playerfont,titlefont: int
titlefont:= Font.New ("Neuropol:24:Italic")
scorefont := Font.New ("Comic Sans MS:14:Bold")
playerfont := Font.New ("Baveuse:12")
%%program
loop
%put "Please enter your name: "..
%get player
cls
x:= maxx div 2
y := maxy div 2 - 50
dx := 1
dy := 1
radius := 5
score := 0
loop
%bord
drawbox (0,maxy - 50,maxx,0,black)
Font.Draw ("Pong",maxx div 2 - 50,maxy-24,titlefont,red)
Font.Draw ("Score:",50, maxy - 38, scorefont, green)
Font.Draw ("Player:",maxx - 175,maxy - 38,playerfont,blue)
Font.Draw (score, 100,maxy - 38, scorefont, green)
%ball
drawfilloval (x,y,radius,radius,black)

end loop
end loop


quick help would b very grateful

thanx

Author:  Cervantes [ Fri Apr 07, 2006 5:53 pm ]
Post subject: 

Font.Draw takes a number of parameters, the first of which is the text it wants to draw. The text is a string. It cannot be an integer.

To draw an integer, you have to convert it's value into a string. 5 would convert into "5". To do this, use the intstr function.

code:

var num := 5
Font.Draw (intstr (num), 100, 100, Font.New ("Times New Roman:12"), black)

Author:  bgmrk [ Fri Apr 07, 2006 6:27 pm ]
Post subject: 

thanks that helped...but i ran into another problem Smile

i don't want to use cls and draw everything over because that will take to long..so i figure why not draw a white box over where i want to refresh the screen however i'm not quite sure how to make it non flikery...any suggestions

code:

setscreen ("graphics:500;500,nobuttonbar,nooffscreenonly")
%%%player
var boxx, width, score : int
var player : string
var chars : array char of boolean
boxx := maxx div 2 - 25
width := 50
%%ball
var x,y,dx,dy, radius : int
%board
var scorefont, playerfont,titlefont: int
titlefont:= Font.New ("Neuropol:24:Italic")
scorefont := Font.New ("Comic Sans MS:14:Bold")
playerfont := Font.New ("Baveuse:12")
%%program
loop
put "Please enter your name: "..
loop
get player
if length (player) > 6 then
put "Please enter a name 6 letters or less"
end if
exit when length (player) <= 6
end loop
cls
x:= maxx div 2
y := maxy div 2 - 50
loop
randint (dx,-1,1)
randint (dy,-1,1)
if dx = 0 or dy = 0 then
randint (dx,-1,1)
randint (dy,-1,1)
end if
exit when dx not = 0 and dy not = 0
end loop
radius := 5
score := 0
Font.Draw ("Pong",maxx div 2 - 50,maxy-24,titlefont,red)
Font.Draw ("Score:",50, maxy - 38, scorefont, green)
Font.Draw ("Player:",maxx - 175,maxy - 38,playerfont,blue)
loop
%bord
drawbox (0,maxy - 50,maxx,0,black)
delay (3)
drawfillbox (3,maxy - 53,maxx - 3,3,white)
Font.Draw (intstr (score), 110,maxy - 38, scorefont, green)
Font.Draw (player,maxx - 95,maxy - 38,playerfont,blue)
drawfillbox (0,maxy - 50,maxx,0,white)
%ball
drawfilloval (x,y,radius,radius,black)
x := x + dx
y := y + dy
if x > maxx - radius - 2 or x < radius + 2 then
dx := -dx
end if
if y > maxx - 52 - radius or y < radius + 2then
dy := -dy
end if
View.Update
end loop
end loop

Author:  Cervantes [ Fri Apr 07, 2006 6:33 pm ]
Post subject: 

You'll want to be using View.Update.

bgmrk wrote:

code:

setscreen ("graphics:500;500,nobuttonbar,nooffscreenonly")


Why are you turning 'offscreenonly' mode off? It needs to be on for View.Update to work.

Author:  bgmrk [ Fri Apr 07, 2006 6:35 pm ]
Post subject: 

opps that was a stupid mistake....thanx..i may need more help so if i do..instead of jsut making a new topic..i'll just post it here Smile
thanx again

Author:  [Gandalf] [ Fri Apr 07, 2006 7:02 pm ]
Post subject: 

If you're only update one section of the screen, and speed is so important to you, you may also consider using View.UpdateArea(), which only updates a portion of the screen instead of the whole:
code:
View.UpdateArea (x1, y1, x2, y2)

Author:  bgmrk [ Fri Apr 07, 2006 8:03 pm ]
Post subject: 

oo good point i never thought of that....Smile Exclamation


: