Jump to content



0

Collision Not Working


4 replies to this topic

#1 Primordial Ooze OFFLINE  

Primordial Ooze

    Dragonstomper

  • 504 posts
  • Quacker Blaster Lead Programmer
  • Location:United States of America

Posted Sat May 16, 2009 10:05 AM

I just finished adding collision between the ball and missile 0 and it isn't working at all. I double checked my code and it looks ok. Could someone please help me?

Sincerely,

Michael

#2 Robert M OFFLINE  

Robert M

    Stargunner

  • 1,481 posts
  • Rootbeer!
  • Location:Western NY state

Posted Sat May 16, 2009 10:22 AM

The BIT instruction performs a bitwise-AND with the Accumulator not with the Y register. In any case you can skip the load because the BIT instruction copies bits 7 and 6 from the memory location into the N and V flags. So you can delete the LDY instruction, and after the BIT use a BVS to check if the collision bit is set.

I also recommend adding a write to the CXCLR register at some point after reading the register to clear the collision bit.

Cheers!

#3 SeaGtGruff OFFLINE  

SeaGtGruff

    River Patroller

  • 4,543 posts
  • Location:Georgia, USA

Posted Sat May 16, 2009 10:51 AM

View PostPrimordial Ooze, on Sat May 16, 2009 12:05 PM, said:

I just finished adding collision between the ball and missile 0 and it isn't working at all. I double checked my code and it looks ok. Could someone please help me?
Looks like Robert just beat me to it, but I'll respond anyway! :D

There are three problems with this code. Robert caught one that I'd missed:

SkipBallOffTopOfScreen

	ldy #%01000000

	bit CXM0FB		; did the ball collide with missile 0?	

	beq NoCollisionWithMissile0; skip if no collision occured

	ldx #256-1		; must be a hit! reverse the ball's y velocity

NoCollisionWithMissile0
(1) It looks like you're trying to use "bit" to compare CXM0FB to the value you put into the "Y" register, but "bit" compares with the accumulator. Anyway, you don't need to compare CXM0FB to anything, because "bit" copies bits 6 and 7 into the overflow and sign bits automatically. So you can take out "ldy #%01000000" entirely, and change the "beq" to "bvc."

(2) If a collision does occur, you're setting the ball's velocity to -1, but you should be setting it to +1.

(3) This is the one I missed. You should clear the collision registers after you've checked them, otherwise they stay set.

Here's the changes I made:

SkipBallOffTopOfScreen

	bit CXM0FB		; did the ball collide with missile 0?	

	bvc NoCollisionWithMissile0; skip if no collision occured

	ldx #1		; must be a hit! reverse the ball's y velocity

NoCollisionWithMissile0

	sta CXCLR		; clear the collision registers
Michael

#4 Primordial Ooze OFFLINE  

Primordial Ooze

    Dragonstomper

  • 504 posts
  • Quacker Blaster Lead Programmer
  • Location:United States of America

Posted Sat May 16, 2009 10:55 AM

View PostRobert M, on Sat May 16, 2009 11:22 AM, said:

The BIT instruction performs a bitwise-AND with the Accumulator not with the Y register. In any case you can skip the load because the BIT instruction copies bits 7 and 6 from the memory location into the N and V flags. So you can delete the LDY instruction, and after the BIT use a BVS to check if the collision bit is set.

I also recommend adding a write to the CXCLR register at some point after reading the register to clear the collision bit.

Cheers!
Still no luck, the ball still doesn't bounce off missile 0 when ball the collides with missile0. Any ideas?

Sincerely,

Michael

#5 SeaGtGruff OFFLINE  

SeaGtGruff

    River Patroller

  • 4,543 posts
  • Location:Georgia, USA

Posted Sat May 16, 2009 11:12 AM

View PostPrimordial Ooze, on Sat May 16, 2009 12:55 PM, said:

Still no luck, the ball still doesn't bounce off missile 0 when ball the collides with missile0. Any ideas?
Yes, (1) you need to change the branch instruction, and (2) you need to change the value you're loading into x.

Before:

SkipBallOffTopOfScreen

	bit CXM0FB		; did the ball collide with missile 0?	

	bvs NoCollisionWithMissile0; skip if no collision occured

	ldx #256-1		; must be a hit! reverse the ball's y velocity

NoCollisionWithMissile0
After:

SkipBallOffTopOfScreen

	bit CXM0FB		; did the ball collide with missile 0?	

	bvc NoCollisionWithMissile0; skip if no collision occured

	ldx #1		; must be a hit! reverse the ball's y velocity

NoCollisionWithMissile0
Then things will work as expected.

Michael




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users