Jump to content
BenMcLean

Collision detection

Recommended Posts

I've been trying to build something with collision detection and I got the basic idea to store the sprite's current position in temporary variables, move the sprite to the place I want to check, and move it back to where I'd previously stored if there is a playfield obstacle in the way, while leaving the change permanently if it's clear. But for some reason, that basic concept doesn't seem to work. It gets stuck on the first obstacle encountered and cannot move anymore. Any idea why it's doing this? I'm guessing there's something about how sprite positions and/or the Atari's memory work that I'm not getting. A code example that produces this effect (which I've trimmed away most of the other stuff in my program) is attached. The score color changes if collision(player0, playfield) is true

 

default.bas

Edited by BenMcLean

Share this post


Link to post
Share on other sites

I assume you've constructed your algorithm with full knowledge that the collision registers for each sprite are set as they're drawn.

 

EDIT: Okay, having looked at your source... you didn't. You seem to be assuming that the collision registers magically get updated immediately. They don't. They get updated after drawscreen. So you need to put the "if collision" code at the top of the player movement routine, not the bottom, because its job is checking the result of the previous frame, not the current one.

 

At least, that's what I'm guessing is wrong. I haven't tested this theory, and I've never written any sprite manipulation code in bB.

Edited by ZylonBane
  • Like 1

Share this post


Link to post
Share on other sites

Here is one of the many ways you could do it:

 

cd_2014y_08m_22d_1525t.bas

 

 

But that's the old ugly sticky/bouncy method. I like the smooth method that includes pfread:

 

randomterrain.com/atari-2600-memories-batari-basic-commands.html#sprite_collision_example

Share this post


Link to post
Share on other sites

I assume you've constructed your algorithm with full knowledge that the collision registers for each sprite are set as they're drawn

No, I didn't know that. Thanks for telling me. Random Terrain's site should probably mention that right here. Edited by BenMcLean

Share this post


Link to post
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.

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