Jump to content



2

detecting if a missile goes off the left or right edge


5 replies to this topic

#1 xucaen OFFLINE  

xucaen

    Star Raider

  • 94 posts
  • Looking for new owner for commodore 64
  • Location:Ma

Posted Mon Jul 10, 2006 2:33 PM

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.
  • use a playfield border on the left and right, and test for collision.
  • 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

#2 jbanes OFFLINE  

jbanes

    River Patroller

  • 3,074 posts
  • Coming soon to a natural satellite near you...

Posted Mon Jul 10, 2006 2:39 PM

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

#3 djmips OFFLINE  

djmips

    Dragonstomper

  • 591 posts
  • scrolling
  • Location:Seattle

Posted Mon Jul 10, 2006 3:29 PM

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.

#4 xucaen OFFLINE  

xucaen

    Star Raider

  • 94 posts
  • Looking for new owner for commodore 64
  • Location:Ma

Posted Tue Jul 11, 2006 11:32 AM

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

#5 jbanes OFFLINE  

jbanes

    River Patroller

  • 3,074 posts
  • Coming soon to a natural satellite near you...

Posted Tue Jul 11, 2006 11:58 AM

View Postxucaen, on Tue Jul 11, 2006 12:32 PM, said:

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.

#6 xucaen OFFLINE  

xucaen

    Star Raider

  • 94 posts
  • Looking for new owner for commodore 64
  • Location:Ma

Posted Tue Jul 11, 2006 2:21 PM

View Postjbanes, on Tue Jul 11, 2006 1:58 PM, said:

View Postxucaen, on Tue Jul 11, 2006 12:32 PM, said:

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.

:-o 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.

Attached File  player5.zip   3.17K   83 downloads


Jim




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users