Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: lookitsan00b on November 04, 2010, 06:12:04 pm

Title: My hittesting doesn't work.
Post by: lookitsan00b on November 04, 2010, 06:12:04 pm
Why doesn't this work? ???
Code: [Select]
.Ball move
{B-1}+{B-3}→{B-1} .move X
{B}+{B-2}→{B}       .move Y
If -2>=>={B-1} or ({B-1}>=>=90)
  0-{B-3}→{B-3}
End
If -4>=>={B} or ({B}>=>=56)
  0-{B-2}→{B-2}
End

where:
{B-3} = xvel
{B-2} = yvel
{B-1} = x
{B} = y

The ball does not bounce off the left and top walls.  It eventually bounces, but REALLY far off screen.
Btw the reason for the odd numbers is I'm using a padded sprite... (4 on top, 2 on each side)
Title: Re: My hittesting doesn't work.
Post by: SirCmpwn on November 04, 2010, 06:14:04 pm
It looks like you are having problems with unsigned numbers.  Try this:
Code: [Select]
.Ball move
{B-1}+{B-3}→{B-1} .move X
{B}+{B-2}→{B}       .move Y
If -2>=>=sign{B-1} or (sign{B-1}>=>=90)
  0-{B-3}→{B-3}
End
If -4>=>=sign{B} or (sign{B}>=>=56)
  0-{B-2}→{B-2}
End

where:
{B-3} = xvel
{B-2} = yvel
{B-1} = x
{B} = y
Title: Re: My hittesting doesn't work.
Post by: yunhua98 on November 04, 2010, 06:14:45 pm
hello, and welcome here.  I'm that sure at the moment, but are you using the B as a location in RAM or as a variable?

EDIT:  ninja'd
Title: Re: My hittesting doesn't work.
Post by: lookitsan00b on November 04, 2010, 06:16:16 pm
So it doesn't just assume that my numbers are signed, even if I use the signed comparisons?
I never really understood signed numbers, thanks.

EDIT: B is a location in ram, L1 + 3, to be exact.
Title: Re: My hittesting doesn't work.
Post by: ASHBAD_ALVIN on November 04, 2010, 06:19:29 pm
Welcome, lookitsan00b! :D

yeah, signed numbers have a different range of numbers to them all together.

EDIT: well maybe not all together, but they are kinda different

For example, an unsigned byte is 0-255, but a signed one is -128-127.
For words (two bytes), it's 0-65535 unsigned, -32768-32767 signed.

Though unless you use sign{, they're read as the same numbers.
Title: Re: My hittesting doesn't work.
Post by: DJ Omnimaga on November 04, 2010, 06:21:03 pm
1 byte signed = -128 to 127
1 byte unsigned = 0 to 255
2 byte signed = -32768 to 32767
2 byte unsigned = 0 to 65535

Welcome here, by the way :)

EDIT: I got ninja'd
Title: Re: My hittesting doesn't work.
Post by: SirCmpwn on November 04, 2010, 06:21:13 pm
Welcome to Omnimaga, by the way.  Here's a quick overview of how signed numbers work:
You really can't store negative numbers on a computer.  You probably know you can store any number in a single byte from 0-255.  However, we have decided that from 0-127 will be 0 to 127, and from 128-255 will be -1 to -128.  So for example, if you have -1, it would be stored as 255.  However, if you add 1 to -1, you should get zero, right?  Well, this works because when you hit 256 or higher adding single bytes, you start over at zero.  So, adding 1 (1) to -1 (255) is the same as 255+1, which equals 256, which rolls over to zero (-1+1).  Don't worry if you have trouble, this is one of the hardest concepts in computing ever.
Axe gives you the option of using signed or unsigned numbers.  So with signed numbers that are single bytes, you have to specify what kind of numbers they are.
Title: Re: My hittesting doesn't work.
Post by: lookitsan00b on November 04, 2010, 06:21:25 pm
I understand signed numbers, I did a little asm before moving to axe.  I just assumed that the signed comparisons took care of that for me...
Speaking of which, where do i find "Sign{"? I know I saw it somewhere, but I can't seem to find it again.
Title: Re: My hittesting doesn't work.
Post by: SirCmpwn on November 04, 2010, 06:23:14 pm
It's in the Math menu.  They key is int(.
Title: Re: My hittesting doesn't work.
Post by: lookitsan00b on November 04, 2010, 06:24:05 pm
Okay thanks!
Title: Re: My hittesting doesn't work.
Post by: calc84maniac on November 04, 2010, 06:25:29 pm
It's needed for loading signed 8-bit values, because the value is extended to 16-bit after the load. So for example, you'll want the 16-bit result to end up as -1 (aka 65535) instead of 255. The sign{} instruction does this for you.
Title: Re: My hittesting doesn't work.
Post by: ASHBAD_ALVIN on November 04, 2010, 06:26:44 pm
I found it in the math menu, instead of int( methinks

EDIT: super ninja'd
Title: Re: My hittesting doesn't work.
Post by: yunhua98 on November 04, 2010, 06:27:27 pm
yeah, thats the Axe Tokens, it intalls a hook when you have an Axe header.

Edit: oh, I thought that was a question.
Title: Re: My hittesting doesn't work.
Post by: lookitsan00b on November 04, 2010, 06:30:01 pm
Wow! I just expected it to keep it as an 8-bit number. That explains it. Now what happens when I load 255 from B, increment it, and store it back?
Btw, works like a charm. Time to add hittesting for the paddle and blocks!
(btw, yes, it is a breakout clone, figured it was a good first project)
Title: Re: My hittesting doesn't work.
Post by: SirCmpwn on November 04, 2010, 06:30:40 pm
Very nice!  Glad to help!  And may I direct you to our Introduce Yourself board?
Title: Re: My hittesting doesn't work.
Post by: lookitsan00b on November 04, 2010, 06:32:14 pm
Sure! *looks around* Where is it? XD
Title: Re: My hittesting doesn't work.
Post by: ASHBAD_ALVIN on November 04, 2010, 06:32:47 pm
http://www.omnimaga.org/index.php?board=10.0
Title: Re: My hittesting doesn't work.
Post by: lookitsan00b on November 04, 2010, 06:33:17 pm
... I was joking lol
Title: Re: My hittesting doesn't work.
Post by: ASHBAD_ALVIN on November 04, 2010, 06:34:43 pm
lol, got me there, wow I'm so gullible today for some reason :D

EDIT: I felt introduced already, but yeah introducing yourself there is always cool :)