I seem to have come to a pothole with this :/ It sometimes creates an endless loop, and it clearly doesn't check correctly. I'll have to try and fix this later, but if I can't get it, I'll post here. I think I'm still checking from the enemy rendering code :/
_player1537 wrote:
I seem to have come to a pothole with this :/ It sometimes creates an endless loop, and it clearly doesn't check correctly. I'll have to try and fix this later, but if I can't get it, I'll post here. I think I'm still checking from the enemy rendering code :/
Is it possible you're running into a stack level problem? Please feel free to post code for me/us to examine if you want. Smile
Haven't tested it yet, but figured I'd go ahead and post it to see if I need to totally redo my thinking on it. Testing it now btw

Edit: Didn't work, it just ran really slowly for a second, giving me enough time to exit with Clear. Any ideas? Btw, if you already saw that, my add statements were broken, fixing them now.

Edit2: Calc84 helped with a bunch of the code, and reminded me that I can do collision by subtracting the two widths of the sprites, and checking the absolute value of the two is greater than their combined total. Kinda like this: http://www.cemetech.net/forum/viewtopic.php?p=130182#130182

Edit3: Double check for Calc84 about seeing if I can reduce all my 16 bit register inc/dec into 8 bit inc/dec. I'll have to check if it stays in one 256 byte area and won't overflow.

Code:
CheckCollision:
   ld hl,BulletArray
   ld b,25
CheckCollisionLoop1:
   comparehl(BulletArray+50)
   ret z
   ld a,(hl)
   cp -1
   jr z,CheckCollisionSkipBullet
   ld c,a
   inc hl
   ex de,hl
   ld b,18
   ld hl,EnemyArray
CheckCollisionLoop2:
   ld a,(hl)
   and %00000011   ;Get the health of the enemy
   jr z,CheckCollisionSkipEnemy
   inc hl
   ld a,(hl)   ;A holds the Y position of the enemy, and C = Y position of bullet
   sub enemyBubble
   cp c
   jr nc,CheckCollisionSkipEnemy   ;If A > C, bullet is out of range, inc hl twice and djnz
   add a,enemyBubble*2
   cp c
   jr c,CheckCollisionSkipEnemy
   ex de,hl
   inc hl
   ld a,(hl)
   ld c,a      ;C has the X position of the next bullet
   ex de,hl
   inc hl
   ld a,(hl)    ;A has the X position of the next enemy
   sub enemyBubble
   cp c
   jr nc,CheckCollisionSkipEnemy2   ;If A > C, bullet is out of range, inc hl once, dec de, and djnz
   add a,enemyBubble*2
   cp c
   jr c,CheckCollisionSkipEnemy2   ;Else, a collision has occured!!!!  You can stop the bullet after this and continue with your bullet checking
   dec hl \ dec hl
   ld a,(hl)
   and %00000011
   dec a
   ld b,a
   ld a,(hl)
   and %11111100
   or b
   ld (hl),a
   ex de,hl
   dec hl
   ld a,-1
   ld (hl),a
   inc hl \ inc hl
   jr CheckCollisionLoop1
CheckCollisionSkipEnemy:
   inc hl
   inc hl
   djnz CheckCollisionLoop2
   ex de,hl
   inc hl
   inc hl
   jr CheckCollisionLoop1
CheckCollisionSkipEnemy2:
   inc hl
   dec de
   djnz CheckCollisionLoop2
   ex de,hl
   inc hl
   inc hl
   jr CheckCollisionLoop1
CheckCollisionSkipBullet:
   inc hl
   inc hl
   jr CheckCollisionLoop1
Edit: Take 2
Code:
CheckCollision:
   ld hl,BulletArray
CheckCollisionLoop1:
   comparehl(BulletArray+50)
   ret z
   ld a,(hl)
   inc a
   jr z,CheckCollisionSkipBullet
   ex de,hl
   ld b,18
   ld hl,EnemyArray
CheckCollisionLoop2:
   ld a,(hl)
   inc hl
   and %00000011   ;Get Health
   jr z,CheckCollisionSkipEnemy
   ld a,(de)
   sub (hl)
   add a,(enemyBubble + bulletBubble)/2
   cp enemyBubble + bulletBubble + 1
   jr nc,NoMatch1
   inc de
   inc hl
   ld a,(de)
   sub (hl)
   add a,(enemyBubble + bulletBubble)/2
   cp enemyBubble + bulletBubble + 1
   jr nc,NoMatch2   ;Else, COLLISION!!
   dec hl \ dec hl
   dec (hl)   ;Decrement the health of the enemy, this works because $00000011 will not overflow
   ex de,hl
   dec hl
   dec hl
   ld (hl),-1
   ;inc hl \ inc hl ;I might be able to get rid of this, depends on speed.  If it is faster to do this then let my own code skip it in a second
   jr CheckCollisionLoop1
CheckCollisionSkipEnemy:
   inc hl \ inc hl
   djnz CheckCollisionLoop2
   inc de \ inc de
   ex de,hl
   jr CheckCollisionLoop1
NoMatch1:
   inc hl
   inc hl
   djnz CheckCollisionLoop2
   inc de \ inc de
   ex de,hl
   jr CheckCollisionLoop1
NoMatch2:
   inc hl
   dec de
   djnz CheckCollisionLoop2
   inc de \ inc de
   ex de,hl
   jr CheckCollisionLoop1
CheckCollisionSkipBullet:
   inc hl \ inc hl
   jr CheckCollisionLoop1
Sorry to be obtuse; should I be checking your code to see if your 16-bit dec/incs can be switched to 8-bit dec/incs?
Oh, no. Not yet, I'm was making a note to myself to check when all the code is finished. That way I already have the code in place, so the positions won't change too much. And then I can go back and choose to use some saferam if I want to.

Edit: Hm, crashed the calculator after shooting two bullets, debug mode!

Edit2: I got it to work! Turns out I was "inc hl"ing once too many times, among a few other bugs. Here's a new screenie:


Edit3: I got bullets shooting from the enemies Smile Another screenie:

Now, a question, how should I do health? Should I have a line, or use numbers, and if a line, what side?
Do a line, and make it run horizontally at the bottom of the screen.
Dots, everytime you get hit, a dot, or half a dot goes bye bye Very Happy
Half a pixel... How would I do that >.> Wink Is a line the best way to tell? I was trying to shy away from that because it is exactly what Phoenix did iirc. Another idea would be to show you ship deteriorating as you got hit, so maybe there would be 6 sprites and as your health gets closer to zero, it would change the sprite again. I could also do what Galaxian did, which was to have a menu show up that had your lives left, but with the speed of this game, I'm not sure how well that would fly.

Edit: After rethinking what Qazz42 said, I kinda get what he means, like little circles somewhere that show up depending on how much life you have left. Kinda like Zelda hearts, I'll think about it. Note to future self: Make it switch sides depending on where you are.
I initially was thinking a line, similar to what Phoenix does, but now that you explained what Qazz was saying, I quite like the Zelda-hearts-esque idea! That would be fairly unique.
Woo! 2:27 AM and I got the hearts finished Very Happy So glad I got out of bed Razz
Edit: Added a way to show if you have more hearts than can be displayed. Also, if you think of another sprite, or another "Moar hearts!" sprite, could you post it Razz The hearts are 4x4, and the "Moar hearts!" sprite can be between 8x8 and 4x4 (Though I'd like the X to match, so 8x4 is better)
To be honest, I find the side-switching to be slightly distracting, but that's just me. What do other people feel about that?
Yeah, I agree that it is kinda distracting. I had an idea on the way back home, I could change sides only if you are within, say, 10 pixels from the far sides. Then it won't be so suddenly changing. Any ideas?
_player1537 wrote:
Yeah, I agree that it is kinda distracting. I had an idea on the way back home, I could change sides only if you are within, say, 10 pixels from the far sides. Then it won't be so suddenly changing. Any ideas?
I think that would be a lot better; can you give it a try and see how it feels?
Yup, I'll implement in a second Smile

That's great, I think that's much better and much less distracting. Kudos for thinking up an amenable solution. Smile I see that you have enemy removal working, which is spiffy; what's next?
Hmm, I'm thinking power-ups. Kinda like the old one, where they looked somewhat like:

Edit: Pardon the obnoxious slowness x.x

Double Edit: Can you all help me think of powerups? I'm thinking about doing: Speed++, health++, Bombs, Invincibility, more? The bombs would go up into the enemies, and "explode" when you press a button (Alpha? Second again?)
*bump* I got powerups to be added (in a single test run, after killing all enemies, it didn't crash >.>), I still need ideas for what powerups to add. I'm also about to work on displaying the powerups (It's freaking cold, so it's hard to type this...). I also had a question, in brass, can I have functions split up on multiple lines? ie:
Code:
#define somefunction(A,B,C) ld a,A \ ld b,B \ ld c,C

somefunction(100,
200,
90)
That looks great tanner, keep up the good work. Smile
What about "bad" powerups too? I feel like that always helps keep it interesting.
Haha, exactly Smile In the old version of Raven that I included a screenshot of, I got hit by one of my "bad" powerups, which keeps you in one place for a little while. So, a "stop" powerup, maybe a "slower shooting" powerup?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 2 of 3
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement