Help me please!!

Advanced game related topics
robert1352
User
User
Posts: 34
Joined: Tue Mar 14, 2006 8:17 pm

Help me please!!

Post 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!!!
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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.
@}--`--,-- A rose by any other name ..
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
robert1352
User
User
Posts: 34
Joined: Tue Mar 14, 2006 8:17 pm

code snippet

Post 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
robert1352
User
User
Posts: 34
Joined: Tue Mar 14, 2006 8:17 pm

ok

Post by robert1352 »

The above is my code so far. Any suggegestions would be helpful.Thank you very much.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1286
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post 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. :)
Image Image
robert1352
User
User
Posts: 34
Joined: Tue Mar 14, 2006 8:17 pm

Thank you paul

Post 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!!
robert1352
User
User
Posts: 34
Joined: Tue Mar 14, 2006 8:17 pm

still need help

Post 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. :(
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post by dontmailme »

Yes!

Did you see Monjas Breakout ?

It will help you to learn :D

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

;)
Paid up PB User !
Post Reply