Breakout Problem?
Blitz3D Forums/Blitz3D Beginners Area/Breakout Problem?
| ||
hiya all, I have create some block on the screen but it showing just 1 block instead of 30 blocks on the screen here the code [BOX] AppTitle "BLOCKOUT VERSION 0.1 " Const ESCAPE=1 Type BALL Field X,Y,DX,DY End Type Global BALLOCK.BALL = New BALL Type BLOCK Field X,Y End Type Graphics 640,480,16,2 SetBuffer BackBuffer() HidePointer ; Loading Image Global BLOCK=LoadAnimImage("Block.png",30,10,0,2) Global BAT =LoadImage("BAT.png") Global BALL =LoadImage("BALL.png") Global BAT_X Global BAT_Y Global T ; Image Mask MaskImage BLOCK,255,0,255 MaskImage BALL ,255,0,255 MaskImage BAT ,255,0,255 ; Position the player BAT_X = 320 BAT_Y = 440 ; ball BALLOCK\x = 342 BALLOCK\y = 428 ; ball Speed BALLOCK\DX = 2 BALLOCK\DY = 2 Restore DATA_BLOCK For I=1 To 10 For J=1 To 3 Read DATA_BLOCK BALLOCK2.BLOCK = New BLOCK If DATA_BLOCK=0 Then Data_BLOCK=0 If DATA_BLOCK=1 Then Data_BLOCK=1 ; If DATA_BLOCK=2 Then Data_BLOCK=2 tempX=BALLOCK2\X+I*55 tempY=BALLOCK2\Y+J*60 Next Next While Not KeyDown (ESCAPE) For BALLOCK2.BLOCK = Each BLOCK DrawImage Block,BALLOCK2\X,BALLOCK2\X+J*60,DATA_BLOCK Next CONTROL_PLAYER COLISION RENDER Flip:Cls Wend .DATA_BLOCK Data 1,1,1,1,1,1,1,1,1,1 Data 1,1,1,1,1,1,1,1,1,1 Data 1,1,1,1,1,1,1,1,1,1 ;Data 2,2,2,2,2,2,2,2,2,2 Function CONTROL_PLAYER() If KeyDown(203) Then BAT_X=BAT_X-3 If KeyDown(205) Then BAT_X=BAT_X+3 If KeyDown(57) T=True EndIf End Function Function COLISION() If T=True ; BALL MOVEMENT BALLOCK\X=BALLOCK\X+BALLOCK\DX BALLOCK\Y=BALLOCK\Y+BALLOCK\DY ; @#!*IN COLISION If BALLOCK\X<=0 Or BALLOCK\X>=600 Then BALLOCK\DX=-BALLOCK\DX If BALLOCK\Y<=0 Then BALLOCK\DY=-BALLOCK\DY If BALLOCK\Y>=470 Then BALLOCK\DY=-BALLOCK\DY ; does it hit the BAT then send it home run If ImagesOverlap(BAT,BAT_X,BAT_Y,BALL,BALLOCK\x,BALLOCK\Y) BALLOCK\DY=-BALLOCK\DY EndIf ; Does it hit the Block then Delete them If ImagesOverlap(BALL,BALLOCK\x,BALLOCK\Y,Block,Block_X+I*55,J*60) ;Delete BALLOCK2 <<< PROBLEM EndIf Else If KeyDown(203) Then BALLOCK\DY=-BALLOCK\DY: BALLOCK\x=BALLOCK\x-3 If KeyDown(205) Then BALLOCK\DY=-BALLOCK\DY:: BALLOCK\x=BALLOCK\x+3 ; Stop the Ball moving off the Screen If BALLOCK\x=<24 Then BALLOCK\x=24 If BALLOCK\x=>608 Then BALLOCK\x=608 EndIf ; STOP THE BAT RUNNING OUT OF PLAYING AREA If BAT_X<=0 Then BAT_X=0 If BAT_X>585 Then BAT_X=585 End Function Function RENDER() DrawImage BALL,BALLOCK\x,BALLOCK\Y DrawImage BAT,BAT_X,BAT_Y End Function [/BOX] Can anyone point out what I am doing wrong? cheers |
| ||
Well I don't know why you are setting a varible to equal the value it already equals... Read DATA_BLOCK BALLOCK2.BLOCK = New BLOCK If DATA_BLOCK=0 Then Data_BLOCK=0 If DATA_BLOCK=1 Then Data_BLOCK=1 ; If DATA_BLOCK=2 Then Data_BLOCK=2 |
| ||
You don't set ballock\x or ballock\y anywhere. This is slightly better... Restore DATA_BLOCK For I=1 To 10 For J=1 To 3 Read DATA_BLOCK BALLOCK2.BLOCK = New BLOCK If DATA_BLOCK=0 Then Data_BLOCK=0 If DATA_BLOCK=1 Then Data_BLOCK=1 ; If DATA_BLOCK=2 Then Data_BLOCK=2 ;tempX=BALLOCK2\X+I*55 ;tempY=BALLOCK2\Y+J*60 ballock2\x=i*55 ballock2\y=j*60 Next Next In addition, you use ballock\x twice in your drawimage... While Not KeyDown (ESCAPE) For BALLOCK2.BLOCK = Each BLOCK DrawImage Block,BALLOCK2\X,BALLOCK2\X+J*60,DATA_BLOCK Next <edit> and what sswift said. You should have a 'Field Image' in your block type if you want to have different images |
| ||
Thanks....everythings is working fine but I having problem of delete the type when the ball hit the block |
| ||
it keep saying "cant Delete non-newtype" does anyone have clue? |
| ||
IT is ok now...I have done it and my next step is to make PARTICE EFFECT when the ball hit the block =) |
| ||
You're not doing your collision tests against a type instance...If ImagesOverlap(BALL,BALLOCK\x,BALLOCK\Y,Block,Block_X+I*55,J*60) You should be looping through each block type instance checking for overlap and, it it does, reverse the ball direction and delete the block type instance E.G. For all.block = Each block If ImagesOverlap(BALL,BALLOCK\x,BALLOCK\Y,Block,all\X,all\y) ballock\dx=-ballock\dx ballock\dy=-ballock\dy Delete all ;<<< PROBLEM EndIf Next In addition, I'm not sure what these lines are for either... ;If KeyDown(203) Then BALLOCK\DY=-BALLOCK\DY: BALLOCK\x=BALLOCK\x-3 ;If KeyDown(205) Then BALLOCK\DY=-BALLOCK\DY:: BALLOCK\x=BALLOCK\x+3 P.S. Use the <edit> key rather than multiple posts. |
| ||
THIS one is to control the ball at the start of the game before I press the spacebar and it is work very well ;If KeyDown(203) Then BALLOCK\DY=-BALLOCK\DY: BALLOCK\x=BALLOCK\x-3 ;If KeyDown(205) Then BALLOCK\DY=-BALLOCK\DY:: BALLOCK\x=BALLOCK\x+3 cheers |
| ||
You really shoudln't discuss problems you're having with your ballocks in public like this. :-) |
| ||
THIS one is to control the ball at the start of the game before I press the spacebar and it is work very well ;If KeyDown(203) Then BALLOCK\DY=-BALLOCK\DY: BALLOCK\x=BALLOCK\x-3 ;If KeyDown(205) Then BALLOCK\DY=-BALLOCK\DY:: BALLOCK\x=BALLOCK\x+3 cheers Really? Try pressing spacebar to release the ball and then, while the ball is moving upwards, move the bat using the cursors. Are you telling me your ball doesn't judder? I don't see a check to see if the ball has been released from 'spacebar' control either but you might have added it since. |