Help me please!!
-
robert1352
- User

- Posts: 34
- Joined: Tue Mar 14, 2006 8:17 pm
Help me please!!
Hi all im trying to make my first pb game, a breakout clone you know were you hit the ball with the paddle and bounce it off some bricks.Anyway, im having a problem,I can get the ball to bounce off the paddle fine using the sprite pixel collision but when I try the same thing on the bricks the ball just travels right under them without a collision.I am perplexed
.Please send help!!!
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
-
robert1352
- User

- Posts: 34
- Joined: Tue Mar 14, 2006 8:17 pm
code snippet
Code: Select all
#screenwidth=1024
#screenheight=768
If InitSprite()=0 Or InitKeyboard()=0 Or InitMouse()=0 Or OpenScreen(#screenwidth,#screenheight,16,"Breakout game with a srtucture and list")=0
MessageRequester("Error!!","unable to initalize enviroment",#PB_MessageRequester_Ok)
End
EndIf
UsePNGImageDecoder()
LoadSprite(0,"bluebrick.png")
LoadSprite(1,"paddle2.png")
LoadSprite(3,"ball.png")
TransparentSpriteColor(0,255,255,255)
TransparentSpriteColor(1,255,255,255)
TransparentSpriteColor(3,255,255,255)
sprite_height=SpriteHeight(3)
sprite_width=SpriteWidth(3)
xdir = 1 ;0=left 1=right
ydir = 1 ;0=up 1=down
speed = 3
Repeat
ClearScreen(0,0,0)
;DisplayTransparentSprite(0,brickx,bricky)
DisplayTransparentSprite(1,inputx,700)
DisplayTransparentSprite(3,x,y)
ExamineMouse()
inputx = MouseX()
Gosub brick
If xdir = 0 ;if we are moving left subtract speed else we are going right so add speed
x = x - speed
Else
x = x + speed
EndIf
If x < 1
xdir = 1
EndIf
If x > #screenwidth-sprite_width
xdir = 0
EndIf
If ydir = 0
y = y - speed
Else
y = y + speed
EndIf
If y < 1
ydir = 1
EndIf
If y > #screenheight-sprite_height
ydir = 0
EndIf
If SpritePixelCollision(3,x,y,1,inputx,700)
ydir = 0
EndIf
If SpritePixelCollision(3,x,y,0,brickx,bricky)
ydir = 1
EndIf
StartDrawing(ScreenOutput())
StopDrawing()
FlipBuffers()
ExamineKeyboard()
Until KeyboardReleased(#PB_Key_All)
End
brick:
brickx=170
bricky=80
rowlength=0
bricknumber=0
If bricknumber = 0
;load up the bricks
For brick = 0 To 44
DisplayTransparentSprite(0,brickx,bricky)
brickx=brickx+65
rowlength = rowlength + 1
If rowlength = 9
bricky = bricky + 30
brickx = 170
rowlength = 0
bricknumber = bricknumber + 1
EndIf
Next
EndIf
Return-
robert1352
- User

- Posts: 34
- Joined: Tue Mar 14, 2006 8:17 pm
ok
The above is my code so far. Any suggegestions would be helpful.Thank you very much.
First you draw all your bricks (called using gosub) then you do a SpritePixelCollision against the last brick drawn (brickx,bricky)
The test needs to be with every brick drawn.
Feel free to look at the source code for PBPong on the PureProject website...
http://www.reelmedia.org/cgi-bin/PurePr ... mes&sub=2D
maybe it might help or give you some new ideas.
The test needs to be with every brick drawn.
Feel free to look at the source code for PBPong on the PureProject website...
http://www.reelmedia.org/cgi-bin/PurePr ... mes&sub=2D
maybe it might help or give you some new ideas.
-
robert1352
- User

- Posts: 34
- Joined: Tue Mar 14, 2006 8:17 pm
Thank you paul
Thank you very much Paul!! I thought that might be the problem but I guess I needed someone else to point it out to me!!! Again thanks!!
-
robert1352
- User

- Posts: 34
- Joined: Tue Mar 14, 2006 8:17 pm
still need help
could someone tell me if I should use a structure to text every brick for collisions? Im still trying to figure this out. 
-
dontmailme
- Enthusiast

- Posts: 537
- Joined: Wed Oct 29, 2003 10:35 am
Yes!
Did you see Monjas Breakout ?
It will help you to learn
http://www.purebasic.fr/english/viewtop ... t=breakout

Did you see Monjas Breakout ?
It will help you to learn
http://www.purebasic.fr/english/viewtop ... t=breakout
Paid up PB User !

