Help please with text
Author |
Message |
Kingnoz
|
Posted: Fri May 23, 2003 3:58 pm Post subject: Help please with text |
|
|
The code is included below. the problem im having is that the put statements im using for when u lose a life will show up on the screen for a split second then disappear. the game then continues.
my question is how can i make it so that the text will stay up longer than that split second so that people playing will actually know how many lives they have.
i commented out the lines of code for the titlepage so u don't need the pic
code: |
colorback (black)
color (white)
cls
setscreen ("no cursor")
var x, y : int % x and y for the paddle
var xr, yr : int % x and y radius of the paddle
var b1, b2, r : int
var chars : array char of boolean
var nx, ny : int
%var titlepage : int
var lives : int
%titlepage := Pic.FileNew ("kingnoz.bmp")
b1 := 540 % x coordinate for ball - start position
b2 := 300 % y coordinate for ball /
r := 5 % radius for ball
x := 400 % x coordinate for paddle - start position
y := 80 % y coordinate for paddle /
xr := 430 % x radius for paddle
yr := 85 % y radius for paddle
nx := 4 % used to change direction
ny := -4 % used to change direction
lives := 3
%moves the ball and changes movement if it hits a wall
procedure ballmove
if b1 >= 585 or b1 <= 55 then
nx := nx * -1
end if
if b2 >= 345 or b2 <= 55 then
ny := ny * -1
end if
if x <= b1 and b1 <= xr and yr >= b2-r then
ny := ny * -1
end if
b1 += nx
b2 += ny
end ballmove
% MAIN LOOP
procedure main
loop
View.Set ("graphics:640;400,offscreenonly")
Input.KeyDown (chars)
ballmove
if chars (KEY_RIGHT_ARROW) and x + 30 < 590 then % move the paddle right
xr := xr + 5
x := x + 5
end if
if chars (KEY_LEFT_ARROW) and x > 50 then % move the paddle left
x := x - 5
xr := xr - 5
end if
if b2 <= 55 then
lives := lives - 1
b1 := 540
b2 := 300
nx := 4
ny := -4
setscreen ("no cursor")
locate(1,2)
put "Statistics for Kingnoz"
locate(2,2)
put "You have lost a life!!! You now have ", lives, " left."
end if
View.Update
delay (1)
cls
drawoval (b1, b2, r, r, white) %draw the ball
drawbox (50, 50, 590, 350, blue) %draw the game table border
drawfillbox (x, y, xr, yr, red) %draw the paddle
View.Update
exit when lives = 0
end loop
end main
%MAIN PROGRAM
loop
% shows title
%Pic.Draw (titlepage, maxx div 4, maxy div 4, picCopy)
%delay (3000)
%Pic.Free (titlepage)
main
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Fri May 23, 2003 4:21 pm Post subject: (No subject) |
|
|
because of the game structure, I think it would work best if you'll put a delay right after displaying the message.
put "you have whatever lifes left"
delay(1000)
...
This will also provide a pause to "prepare" to restart the game with another life. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Kingnoz
|
Posted: Fri May 23, 2003 4:37 pm Post subject: (No subject) |
|
|
i tried the delay after the lives left statement but what happens is it delays the time before the lives statement shows up |
|
|
|
|
|
Tony
|
Posted: Fri May 23, 2003 7:22 pm Post subject: (No subject) |
|
|
well your screen mode is still in "offscreenonly" mod, so you have to call a View.Update right before the delay
code: |
locate(1,2)
put "Statistics for Kingnoz"
locate(2,2)
put "You have lost a life!!! You now have ", lives, " left."
View.Update
delay(1000)
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Kingnoz
|
Posted: Fri May 23, 2003 8:13 pm Post subject: (No subject) |
|
|
i fixed it up a bit with help from my dad and it seems to work pretty good.
i tried another method
What do u think?
code: |
colorback (black)
color (white)
cls
setscreen ("graphics:vga,nocursor,offscreenonly")
var x, y : int % x and y for the paddle
var xr, yr : int % x and y radius of the paddle
var b1, b2, r : int
var chars : array char of boolean
var nx, ny : int
var titlepage : int
var lives : int
var response : string
%var name : string
var text : string
var text2 : string
%name := "Kingnoz"
%titlepage := Pic.FileNew ("kingnoz.bmp")
b1 := 540 % x coordinate for ball - start position
b2 := 300 % y coordinate for ball /
r := 5 % radius for ball
x := 400 % x coordinate for paddle - start position
y := 80 % y coordinate for paddle /
xr := 430 % x radius for paddle
yr := 85 % y radius for paddle
nx := 4 % used to change direction
ny := -4 % used to change direction
lives := 3
text := "Statistics for Kingnoz: Remaining lives ="
text2 := "Press 'c' then [ENTER] to continue play!!"
%moves the ball and changes movement if it hits a wall
procedure ballmove
if b1 >= 585 or b1 <= 55 then
nx := nx * -1
end if
if b2 >= 345 or b2 <= 55 then
ny := ny * -1
end if
if x <= b1 and b1 <= xr and yr >= b2 - r then
ny := ny * -1
end if
b1 += nx
b2 += ny
end ballmove
procedure TextDelay (text : string)
for i : 1 .. length (text)
color (yellow)
locate (1, i + 1)
put text (i), lives ..
locate (2, i + 1)
put text2 (i) ..
delay (50)
end for
end TextDelay
% MAIN LOOP
procedure main
loop
Input.KeyDown (chars)
ballmove
if chars (KEY_RIGHT_ARROW) and x + 30 < 590 then % move the paddle right
xr := xr + 5
x := x + 5
end if
if chars (KEY_LEFT_ARROW) and x > 50 then % move the paddle left
x := x - 5
xr := xr - 5
end if
if b2 <= 55 then
lives := lives - 1
b1 := 540
b2 := 300
nx := 4
ny := -4
loop
%cls
View.Update
setscreen ("nocursor")
TextDelay (text)
get response
exit when response = "c"
end loop
end if
View.Update
delay (1)
cls
drawoval (b1, b2, r, r, white) %draw the ball
drawbox (50, 50, 590, 350, blue) %draw the game table border
drawfillbox (x, y, xr, yr, red) %draw the paddle
exit when lives = 0
end loop
end main
%MAIN PROGRAM
loop
% shows title
%Pic.Draw (titlepage, maxx div 4, maxy div 4, picCopy)
%delay (3000)
%Pic.Free (titlepage)
main
end loop
|
|
|
|
|
|
|
Tony
|
Posted: Fri May 23, 2003 11:46 pm Post subject: (No subject) |
|
|
I think you should take a look at our more advanced textDelay procedure found in source code area... the one with two colors
also dont use Quote: press c then enter to continue crap. Like seriosly, you wouldn't want to do that... ether use a timer or hasch instead.
code: |
loop
exit when hasch
end loop
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Martin
|
Posted: Sat May 24, 2003 1:24 am Post subject: (No subject) |
|
|
Lol, I wish my parents could program. I think my parents think that turing is some kind of gourmet food. |
|
|
|
|
|
|
|