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 / I hate sprites!

Author
Message
MoNkEyMaN
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: United Kingdom
Posted: 4th Feb 2003 16:52
In my Pong game everything was working fine. Untill for some reason which i don't know the ball just vanished when i ran it. Now whenever it is run there is no ball. Please help me because i am really stuck with this. 8(
The code for the game is below:

MnKMaN
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Feb 2003 20:38
That didn't post right. Can you try again, or upload it to a website and post the link? Or alternatively, email it to me and I'll have a look.
MoNkEyMaN
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: United Kingdom
Posted: 4th Feb 2003 22:53
Oh, here it is again.

Hide Mouse
Sync On
Sync Rate 60

Load Music "Hidden Fury.mid",1
Loop Music 1
MainMenu:
Repeat
Set Text Size 50
Center Text 320,20, "PONG!"
Set Text Size 10
Center Text 320,300, "Type 1 and press enter for One Player!"
Center Text 320,315, "Type 2 and press enter for Two Player!"
Center Text 320,450, "Press Space to exit"
Set Cursor 320,240
Input choice
If choice = 1
Cls
Gosub OnePlayer
Endif

If choice = 2
Cls
Gosub TwoPlayer
Endif
If choice > 2
Center Text 320,255, "Press either 1 or 2!"
Gosub MainMenu
Endif

If choice <=0
Center Text 320,255, "Press either 1 or 2!"
Gosub MainMenu
Endif

Until choice = 1 Or 2

radius# = 3.0
score = 0
secondscore = 0
secondpspeed = 10
ballxpos = 320
ballypos = 240
ballyspeed = Rnd(4)
ballxspeed = 12

Oneplayer:
Do

Set Text Size 50
Center Text 320,20, "PONG!"
Set Text Size 10

Line 98,98,542,98
Line 542,98,542,382
Line 542,382,98,382
Line 98,382,98,98

Create bitmap 1,25,25

Line 1,1,1,21

Get Image 1,1,1,2,22

Set Current Bitmap 0

Sprite 1,xpos,ypos,1

ypos = MouseY()
xpos = 110

If ypos < 100 then ypos = 100
If ypos > 360 then ypos = 360

Create Bitmap 2,25,25

Circle 5,5,radius#

Get Image 2,1,1,10,10

Set Current Bitmap 0

Sprite 2,ballxpos,ballypos,2

ballxpos = ballxpos - ballxspeed
ballypos = ballypos + ballyspeed

If ballxpos > 534 then ballxspeed = ballxspeed * -1
If ballxpos < 100
ballxspeed = ballxspeed * -1

Endif
If ballypos < 97 then ballyspeed = ballyspeed * -1
If ballypos > 374 then ballyspeed = ballyspeed * -1

if ballxpos < xpos + 6 and ballxpos > xpos - 20 and ballypos < ypos + 20 and ballypos > ypos - 20
ballxspeed = ballxspeed * -1
score = score + 1
Endif


Text 0,0,"Score:"+str$(score)
If score >= 50
Cls
Delete Sprite 1
Delete Sprite 2
center text 320,240,"You win with "+str$(score)+" points!"
Wait 2000
Cls
Gosub MainMenu
Endif


If Spacekey()=1 then End
Center Text 320,450, "Press Space to Exit"
Center Text 320,390, "You need 50 points to win!!"
Center Text 320,435, "Press Shift to go back to Main Menu!"

If Shiftkey()=1
Cls
Delete Sprite 1
Delete Sprite 2
Gosub MainMenu
Endif

Sync
Loop

TwoPlayer:

secondxpos = 530
secondypos = 240

Do

Set Text Size 50
Center Text 320,20, "PONG!"
Set Text Size 10

Line 98,98,542,98
Line 542,98,542,382
Line 542,382,98,382
Line 98,382,98,98

Create bitmap 1,25,25

Line 1,1,1,21

Get Image 1,1,1,2,22

Set Current Bitmap 0

Sprite 1,xpos,ypos,1

Sprite 3,secondxpos,secondypos,1

if upkey()=1 then dec secondypos,secondpspeed
if downkey()=1 then inc secondypos,secondpspeed

ypos = MouseY()
xpos = 110

If ypos < 100 then ypos = 100
If ypos > 360 then ypos = 360

If secondypos < 100 then secondypos = 100
If secondypos > 360 then secondypos = 360

Create Bitmap 2,25,25

Circle 5,5,radius#

Get Image 2,1,1,10,10

Set Current Bitmap 0

Sprite 2,ballxpos,ballypos,2

ballxpos = ballxpos - ballxspeed
ballypos = ballypos + ballyspeed

If ballxpos > 534
ballxspeed = ballxspeed * -1
secondlives = secondlives - 1
Endif
If ballxpos < 100
ballxspeed = ballxspeed * -1
lives = lives - 1
Endif
If ballypos < 97 then ballyspeed = ballyspeed * -1
If ballypos > 374 then ballyspeed = ballyspeed * -1

If ballxpos < xpos + 6 and ballxpos > xpos - 20 and ballypos < ypos + 20 and ballypos > ypos - 20
ballxspeed = ballxspeed * -1
score = score + 1
Endif

If ballxpos > secondxpos - 12 and ballxpos < secondxpos + 20 and ballypos > secondypos - 20 and ballypos < secondypos + 20
ballxspeed = ballxspeed * -1
secondscore = secondscore + 1
Endif


If Spacekey()=1 then End
Center Text 320,450, "Press Space to Exit"
Center Text 320,390, "You need 50 points to win!!"
Center Text 320,435, "Press Shift to go back to Main Menu!"

Text 0,0,"Score:"+str$(score)
If score >= 50
Cls
Delete Sprite 1
Delete Sprite 2
Delete Sprite 3
center text 320,240,"Player 1 wins with "+str$(score)+" points!"
Wait 2000
Cls
Gosub MainMenu
Endif

Text 530,0,"Score:"+str$(secondscore)
If secondscore >= 50
Cls
Delete Sprite 1
Delete Sprite 2
Delete Sprite 3
center text 320,240,"Player 2 wins with "+str$(score)+" points!"
Wait 2000
Cls
Gosub MainMenu
Endif

If Shiftkey()=1
Cls
Delete Sprite 1
Delete Sprite 2
Delete Sprite 3
Gosub MainMenu
Endif

Sync
Loop

MnKMaN
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 5th Feb 2003 14:18
Great. I see several problems already. I'll download it when I get home later and have a play around with it for you.
MoNkEyMaN
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: United Kingdom
Posted: 5th Feb 2003 16:41
Thanks 8)

MnKMaN
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 5th Feb 2003 20:05
Here you go:



Your main problem was that the player and ball variables were not being initialised at the start of play.

A couple of points:
1) Indent It will make it far easier to follow the flow of your code.
2) Doing a gosub implies that you are going to return at some point - you were doing a gosub back to the main screen instead of just returning.
3) A lot of duplicate code - see if you can break out the common code into subroutines or functions.
4) You are recreating the game sprites every game loop - and that is slowing it down. Put this stuff into a subroutine and call it once at the start of your program.

Hope that's helped
MoNkEyMaN
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: United Kingdom
Posted: 6th Feb 2003 17:02
Thanks a lot! 8)
I can see where i went wrong now. 8)

MnKMaN
MoNkEyMaN
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: United Kingdom
Posted: 6th Feb 2003 17:08
Uhhhh, when i execute it there is only a blank screen and the menu only shows up when i exit the program (but then it only flashes)

MnKMaN
MoNkEyMaN
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: United Kingdom
Posted: 6th Feb 2003 17:44
Nm i managed to get it to work now 8).
Thanks. 8)

MnKMaN

Login to post a reply

Server time is: 2024-11-27 17:14:05
Your offset time is: 2024-11-27 17:14:05