Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Text isn't printing

Author
Message
LeeTC
18
Years of Service
User Offline
Joined: 20th Oct 2006
Location:
Posted: 23rd Oct 2006 23:31
Hi once more.

I'm trying to make a simple bouncy ball game. So far so good!

When the player's score reaches 500 I want the screen to clear and a few messages bob on the screen explaining they've completed the game.

I have an if statement at the end of the main do loop questioning whether the variable Score has reached 500, and if so, clear the screen and use the text command to display the end of game messages. However, in practice, no text appears! I've sat here for about an hour trying to figure this out but I'm totally clueless.

Here's the full game code. I've set the if statement to check if the Score's 100, just to make it easier to check if it works.

[CODE]
REMSTART
----------------------------------------------------------
Bouncy ball game
Mainly demonstrates the use of conditional logic
statements to detrmine the path of the ball object
----------------------------------------------------------
REMEND
SET DISPLAY MODE 1024,768,16
REM Create some variables
BallX = 320
BallY = 240
BallSize = 25
Border = 25
Score = 0
PositionX = mousex()
PositionY = mousey()
Click = 0
Difficulty = 0
CheatOn = 0

REM Introduce the game
print "Bouncy Ball"
print ""
print "Shoot the ball in the centre by clicking the mouse buttons."
print "The higher the level, the faster the ball (and the more central the target!)"
print ""
print "Press any key to begin"
print "Press Esc to exit at any time"
wait key
CLS

SYNC RATE 30

REM Bring up the level selection screen
while Difficulty = 0
print "Choose a difficulty level:"
print ""
print " 1 = Novice"
print " 2 = Standard"
print " 3 = Tricky"
print " 4 = Difficult"
print " 5 = Impossible"
print ""
print "Type the level number and press return."
input Difficulty
IF Difficulty = 84982
REM A little cheat sub-menu
CheatOn = 1
CLS
print "Congratulations, Mr. Cheater!"
print ""
print "Type in your new frame rate:"
input newsyncrate
SYNC RATE newsyncrate
Score = -500
Difficulty = 0
CLS
else
IF Difficulty > 5 or Difficulty < 1
CLS
print "You must select a level between one and five!"
wait 2000
CLS
Difficulty = 0
ENDIF
ENDIF
endwhile

REM Initialize the program
SYNC ON

REM Set the circle speed
SpeedX = 2 * Difficulty
SpeedY = 3 * Difficulty

REM Start the main loop
DO

REM Set the colour
colour1 = RGB(205,205,255)
colour2 = RGB(RND(255), RND(255), RND(255))
colour3 = RGB(255,0,0)
INK colour1, 0
REM Clear the screen
CLS

REM Draw the screen border
LINE 0, 0, 1023, 0
LINE 1023, 0, 1023, 767
LINE 1023, 767, 0, 767
LINE 0, 767, 0, 0

REM Move the ball
BallX = BallX + SpeedX * Difficulty
BallY = BallY + SpeedY * Difficulty

REM Print a scoreboard including the current
text 15,15,"SCORE: "+str$(Score)
text 15,30,"LEVEL: "+str$(Difficulty)
IF CheatOn = 1
INK colour3,0
text 15,45,"CHEAT MODE!"
ENDIF

REM Check conditions for the BallX
IF BallX > 1023 - Border
BallX = 1022 - Border
SpeedX = SpeedX*-1
ELSE
IF BallX < Border
BallX = Border + 1
SpeedX = SpeedX*-1
ENDIF
ENDIF

REM Check conditions for BallY
IF BallY > 767 - Border
BallY = 766 - Border
SpeedY = SpeedY*-1
ELSE
IF BallY < Border
BallY = Border + 1
SpeedY = SpeedY*-1
ENDIF
ENDIF

REM Draw the ball
INK colour2, 0
CIRCLE BallX, BallY, BallSize

REM If they're playing fair (or accessed the cheat menu), let 'em shoot
IF Click = 0 and mouseclick() = 1 or Click = 0 and mouseclick() = 2

IF BallY - BallSize/Difficulty < mousey() and BallY + BallSize/Difficulty > mousey()
IF BallX - BallSize/Difficulty < mousex() and BallX + BallSize/Difficulty > mousex()
Score = Score + 10
IF CheatOn = 0 then Click = 1 else Click = 0
ENDIF
ENDIF

ENDIF

REM If they're holding down the mouse button, don't let them shoot next time
REM (unless they accessed the cheat menu)
IF mouseclick() = 0 and CheatOn = 0 then Click = 0

REM Change the level if they get a decent score
IF Score = 100 and Difficulty = 1 then Difficulty = 2
IF Score = 200 and Difficulty = 2 then Difficulty = 3
IF Score = 300 and Difficulty = 3 then Difficulty = 4
IF Score = 400 and Difficulty = 4 then Difficulty = 5

REM If they get to 500, call it a day
IF Score = 100
CLS
wait 2000
text 15,15,"Wow... well done!"
wait 2000
CLS
text 15,15,"I couldn't even get past 210 "
wait 2000
CLS
text 15,15,"Anyway, have a rest. You deserve it."
wait 2000
CLS
text 15,15,"Goodbye."
wait 2000
CLS
text 15,30,"And thanks for playing!"
text 15,45,"-Lee"
text 15,60,""
wait 2000
END
ELSE
ENDIF

REM Check for escape
IF ESCAPEKEY() = 1 THEN END

REM Redraw the screen
SYNC
LOOP
[/CODE]

Any help would be greatly appreciated!

Cheers
Lee
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 24th Oct 2006 01:41
You need a "sync" before every "wait" to show the text. Also I noticed the text needs to be reset to white... I actually got that rare occasion when the color was totally black when the endgame messages were showing.

And you really should start indenting your code. It's much easier to read and debug... trust me you won't regret indenting code.

LeeTC
18
Years of Service
User Offline
Joined: 20th Oct 2006
Location:
Posted: 24th Oct 2006 12:50
Thank you very much Sir, that's worked a treat!

I'm still in the very early stages of learning so hopefully I'll get these sorta problems less and less.

Many thanks again.

(I did actually indent my code, the code tags just had paddy and forgot the formatting... honestly! )

Login to post a reply

Server time is: 2024-11-26 07:48:20
Your offset time is: 2024-11-26 07:48:20