Jump to content

Moving a ball respecting collision with the Playfield


Recommended Posts

I'm setting up a labyrinth where the player (ball) must travel through a labyrinth, respecting the Playfield limit.


It is working, however, when it touches the Playfield, it stops when it should actually slide against the Playfield. 😔


Attached is the full source code, just put it in Batari and run it to identify what I said.


Could anyone give me an idea of how to change the source code to make the BALL slide on the playfield?


Below is a brief explanation of the code:

Depending on the movement of the Joystick, I will move the Ball to the desired destination and put 1 in a variable that moved to that side (for example, if it went DOWN, then d = 1). Then I will test the collision of the BALL with the PLAYFIELD, if it is true, I see which variable has the value 1 and return the BALL to the previous position.



 if collision(playfield,ball) && d = 1 then bally = bally - 1: d = 0
 if collision(playfield,ball) && r = 1 then ballx = ballx - 1: r = 0
 if collision(playfield,ball) && l = 1 then ballx = ballx + 1: l = 0
 if collision(playfield,ball) && u = 1 then bally = bally + 1: u = 0

 if joy0down  then bally = bally + 1: d = 1
 if joy0right then ballx = ballx + 1: r = 1
 if joy0left  then ballx = ballx - 1: l = 1
 if joy0up    then bally = bally - 1: u = 1


 goto loop




Edited by DevBR
Two uploaded files
Link to comment
Share on other sites

4 hours ago, Random Terrain said:

Remember that you can do just one "collision(playfield,ball)" check to save cycles.


Something like if !collision(playfield,ball) then goto _Skip_Collision_PF_Ball" then have your other checks sandwiched in there.

Hi Random Terrain,


Thank you very much for your tip. I did not know that.


I discovered that the collision does not change the value in the same cycle (frame) only when I started the Debug on Adventure on Stella emulator.


I appreciate your help!


Best Regards.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...