+xucaen Posted July 10, 2006 Share Posted July 10, 2006 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 Quote Link to comment Share on other sites More sharing options...
jbanes Posted July 10, 2006 Share Posted July 10, 2006 3. Increment (or decrement) a counter with the amount moved immediately after you strobe the HMOVE? Quote Link to comment Share on other sites More sharing options...
djmips Posted July 10, 2006 Share Posted July 10, 2006 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. Quote Link to comment Share on other sites More sharing options...
+xucaen Posted July 11, 2006 Author Share Posted July 11, 2006 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 Quote Link to comment Share on other sites More sharing options...
jbanes Posted July 11, 2006 Share Posted July 11, 2006 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. Quote Link to comment Share on other sites More sharing options...
+xucaen Posted July 11, 2006 Author Share Posted July 11, 2006 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.