IGNORED

detecting if a missile goes off the left or right edge

Recommended Posts

Hi, I'm adding a missile to a demo I'm writing. Nothing fancy, I'm just trying to put it all together.

I'm trying to figure out the best way to tell if a missile goes off the left or right edge of the screen.

Top and bottom is easy, I just check my Y index for the missile.

But for left and right, I can think of only two possibilities.

1. use a playfield border on the left and right, and test for collision.
2. use the divide by 15 exact horizontal positioning and test the X index for the missile

Which would be the preferred way of doing this? Or is there a third way I didn't think of?

Thanks!

Jim

Share on other sites

3. Increment (or decrement) a counter with the amount moved immediately after you strobe the HMOVE?

Share on other sites

keep an xpos variable and an xvelocity variable. Test that xpos is on screen using single unsigned test ie if xpos>160 then then you're onscreen. If that test fails, check sign of xvelocity variable to see which side.

Share on other sites

Thanks guys, it sounds like based on these responses that I will need to track the X position using the divide by 15 trick. I guess it's time for me to dive in a figure it out.

Thanks!

Jim

Share on other sites

Thanks guys, it sounds like based on these responses that I will need to track the X position using the divide by 15 trick.

That is not quite what I said.

Listen, if you do a RESPx to position the sprite ONCE at the beginning of the game, you will know its starting position. Throw that position into a memory location. Now, everytime you strobe HMOVE, you only need to add the value of the HMOVE Counter to the memory location. In this way, you'll always be able to track the sprite or missile's location.

Share on other sites

Thanks guys, it sounds like based on these responses that I will need to track the X position using the divide by 15 trick.

That is not quite what I said.

Listen, if you do a RESPx to position the sprite ONCE at the beginning of the game, you will know its starting position. Throw that position into a memory location. Now, everytime you strobe HMOVE, you only need to add the value of the HMOVE Counter to the memory location. In this way, you'll always be able to track the sprite or missile's location.

DOH!

For some reason I had thought that wouldn't work. Ok, I'm with you now.

If I do

STA WSYNC

STA RESP0

Just before the game loop begins (so it only happens once) the sprite should be aligned with the left side of the screen. (when I try this it is not flush with the left edge as I had expected)

I set up my code to not do any HMOVE if my xpos is 0 or 160.

For example, lets say I HMOVE right by one clock #%11110000, then I would increment my xpos by 1. When xpos=160, then I should be at the right edge of the screen and I stop allowing any HMOVE in that direction. But for some reason it wraps back to the left side then stops. So my xpos is not at 160 when the sprite reaches the right edge of the screen. So here's what I ended up doing:

I start my xpos at #8, and moving right, I INC xpos until it reaches #152. This allows me to stop moving at what looks like the edge of the screen.

Obviously my counting is off.

Anyways, I'm attaching my source code in case anyone is interested in looking at it. It's messy, but it gets the job done. Once I get everything working the way I want it, then I'll go over it and streamline the code, but for now I'm just trying to get the basic concepts down.

player5.zip

Jim

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.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×