Jump to content
IGNORED

# 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.

Â

```loop

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

drawscreen

goto loop```

Â

Â

Edited by DevBR
Two uploaded files
##### Share on other sites

Hello, I discovered a way to make the movement I needed. I debugged the Adventure game and found that the movement occurred in 1 frame and the next two frames were collision tests. Thanks!

##### Share on other sites

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.

##### 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.

## 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.

Loading...
×
• ### Recently Browsing   0 members

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