Page 1 of 1

Help me please!!

Posted: Sat May 06, 2006 4:08 pm
by robert1352
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 :cry: .Please send help!!!

Posted: Sat May 06, 2006 4:15 pm
by Dare2
Hi robert1352,

Welcome.

I am not good at this sort of thing, so I am unlikely to be able to help. But I can suggest you post a code snippet so the guru's can see how you're handling it. It's a bit awkward without.

Posted: Sat May 06, 2006 4:20 pm
by netmaestro
Create a sprite for the wall the right size and don't display it - just use it for collision tests assuming it were at the wall location.

code snippet

Posted: Sat May 06, 2006 4:35 pm
by robert1352

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

ok

Posted: Sat May 06, 2006 4:37 pm
by robert1352
The above is my code so far. Any suggegestions would be helpful.Thank you very much.

Posted: Sat May 06, 2006 8:17 pm
by Paul
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. :)

Thank you paul

Posted: Sat May 06, 2006 9:53 pm
by robert1352
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!!

still need help

Posted: Wed May 10, 2006 3:15 pm
by robert1352
could someone tell me if I should use a structure to text every brick for collisions? Im still trying to figure this out. :(

Posted: Thu May 11, 2006 4:21 pm
by dontmailme
Yes!

Did you see Monjas Breakout ?

It will help you to learn :D

http://www.purebasic.fr/english/viewtop ... t=breakout

;)