News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Help with Pong / Arkanoid the source code

Started by RaverDave, January 11, 2006, 10:33:33 PM

Previous topic - Next topic

kevin

#30
Examine this.  Try playing with the for next loop end counter.. try values from 1 to  3   -  it's set to 2 at the moment


a=10
print "Starting A="+Str$(a)

For lp=1 to 2
   a=a*-1
   print "The state of A Inside the loop ="+Str$(a)    
next

print "Final A="+Str$(a)

sync
waitkey


Notice how the number of loops affects the ultimate sign of the A variable.


Now relate this back the ball collision fragments of code...  

If the ball hits two blocks on the Right hand side say.

Then the loop runs down this right edge clearing each block.

Within the clear loop it flips the SIGN the speedX each loop...

 Obviously, if it clears two blocks, then the Xspeed sign will be flipped
and then flipped back..  Hence the logic error..  

 So, the balls speed only needs to be flipped when a collision registers, not during the block clearing loop itself.

RaverDave

#31
Finally!! I might have fixed it!!

ok i put for example the type looks like this:

ype tBall
   Status
   Xpos#,Ypos#
   Width,Height
   SpeedX#,SpeedY#
   newx#
   newy#
   speed#
   angle#
   hittop
   hitbottom
   hitside
Image
LifeTimer
FlashToggle
EndType
[QUOTE]



Now then when a impact occurs i set whatever to 1 like so:
[CODE]
If GetMapImpactLeft()
;   Print "Impact occured on the LEFT side"  
If (TileX-1)>-1
For  lp=TileY To (NewY+HEight-1)/TileHeight
 If PeekLevelTile(ThisMap,ThisLevel,TileX-1,lp)<>0
 hitdat(tilex-1,lp)=hitdat(tilex-1,lp)-1
  Inc score
; balls(thisball).speedx=balls(thisball).speedx *-1
 balls(thisball).hitside=1
    checked=0
    SetCursor 320,10
    If hitdat(tilex-1,lp)<=0
    PokeLevelTile ThisMap,ThisLevel,TileX-1,lp,0
     Dec tilenum
    EndIf
  If powerdat(tilex-1,lp)<>0
   s$="Wooohoooo!!!"
EndIf
  EndIf
Next
EndIf
EndIf


Ok then I check if its equal to 1 outside the for next loop of that functioon,near the bottom, like so:


If balls(thisball).hitside=1
balls(thisball).hitside=0

balls(thisball).speedx=balls(thisball).speedx *-1
EndIf
EndFunction

And then the speed is changed!
I do this for the tophit and bottomhit fileds aswell!

Maybe this works,it seems to work!

kevin

Bingo... in a round about kind of way..

or you could do this way


if GetMapImpactLeft()
;   Print "Impact occured on the LEFT side"  

; Do the Balls Rebound
 balls(thisball).speedx=balls(thisball).speedx *-1

; Now do the loop to clear the tiles
If (TileX-1)>-1
For  lp=TileY To (NewY+HEight-1)/TileHeight
If PeekLevelTile(ThisMap,ThisLevel,TileX-1,lp)<>0
hitdat(tilex-1,lp)=hitdat(tilex-1,lp)-1
 Inc score
   checked=0
   SetCursor 320,10
   If hitdat(tilex-1,lp)<=0
   PokeLevelTile ThisMap,ThisLevel,TileX-1,lp,0
    Dec tilenum
   EndIf
 If powerdat(tilex-1,lp)<>0
  s$="Wooohoooo!!!"
EndIf
 EndIf
Next
EndIf
EndIf


RaverDave

Oh my,thats cruelly shorter!
I feel inadequate!

RaverDave

maybe mine has the advantage of being more modular..lol

RaverDave

Oh NO!! It worked, then as I was admiring the balls rebounding,one of them stopped dead!lol,on a brick, it only moved again when another ball destroyed that brick..

RaverDave

I have implemented your way,cleaned the code up,now then very rarely it tends to bounce off a brick but not destroy the brick,I sometimes have to watch it for ages before this happens,to be sure! But yep its definately hapenning! Is this another simple logic over-sight?

RaverDave

Well, been working away at the code and the editor on and off all day, I implemented non destructable bricks, now this has shown a major snag in all this sytem, the ball on a given angle can get stuck in a rebound! But I think only if there is a 1 brick gap between the columns! So its gunna need careful planning or some hack to stop this

RaverDave

#38
Nah! It gets stuck in a rebound no matter what! I have presented a snapshot of an example of where it would get cought in a rebound loop! Its the area I have put a dimaond shape in black, not necessarily in this way does it loop but its typical example!
So the aim of the level would be to get to the top and destroy the only destructible bricks on that level (red and yellow) the white ones are not destructable

kevin

If it gets stuck at the screen edges, that's most probably caused by the edge flip not bothering to reposition the ball inside the egde, instead it just flips the speed.

 When the balls hits the edge (any of them)  it should be re position the bal inside the edge along the axis.  

Ie.

  If BallX >  RightEdge
      ; POsition ball so it can't cause a collision next frame
      BallX = RightEdge-BallWidth

     ; flip the speed
     BallSpeedX=BallSpeedX * -1
  endif

RaverDave

#40
well i tried it,eventually it got stuck again, after clearing the level 14 times though..  :/
I didnt mean it gets stuck stuck, it goes in a continues rebound loop! if you look at the snapshot closely you will see i have shown this with black lines(sorta middle left hand side) So I am saying the ball hits the side, then the bottom of a brick, rebounds to hit the side of the brick below that, rebounds to hit the top of the brick below that, then back to the side! In a diamond shape