Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: GreenFreak on June 05, 2011, 11:47:34 am
-
Hi!
First: I'm sorry for my bad english :P
I tried to write a collision detection in Axe for 2 of my programs.
But I made a mistake in my code.
This is a test program for my collision detection:
.PXLTEST BYEBYE
DiagnosticOff
[FFFFFFFFFFFFFFFFüPic1
0->X+1->D
Zeros(10)->{L1}
44->{L1+0}
54->{L1+1}
.For(X,1,3)
.rand^88->{X*2+L1}
.rand^56>{X*2+1+L1}
.Pt-On({X*2+L1},{X*2+1+L1},Pic1
.End
.StorePic
Repeat getKey(15)
Pt-On({L1+2},{L1+3},Pic1
Line(0,63,95,63)
.RecallPic
Pt-On({L1+0},{L1+1},Pic1)
DispGraphClrDraw
If getKey(2)
{L1+0}--
ElseIf getKey(3)
{L1+0}++
End
If D
{L1+1}--
D--
End
!If D
If {L1+0}>{L1+2}
If {L1+0}<8+{L1+2}
If {L1+1}=8+{L1+3}
20->D
End
End
End
{L1+1}++
End
If {L1+1}=54
20->D
End
End
The problem seems to be at the !If D
If {L1+0}>{L1+2}
If {L1+0}<8+{L1+2}
If {L1+1}=8+{L1+3}
20->D
End
End
End
{L1+1}++
End
Can you please help me to find the problem? :(
If you don't know where my problem is, you should run this program.
I need this for all of my 3 first Axe games.
Thanks a lot :D
-
Hi and welcome, GreenFreak! Haven't looked too closely at your code, but I see the lines
If {L1+0}<8+{L1+2}
If {L1+1}=8+{L1+3}
Remember that Axe has a strictly left-to-right order of operations, so those lines would actually be interpreted asIf ({L1+0}<8)+{L1+2}
If ({L1+1}=8)+{L1+3}
I'm guessing there's a fair chance that's your problem right there, but again, haven't looked at the rest of your code yet (don't have time, sorry). Hope this helps :)
-
Thanks, Deep Thought!
I've worked on it, but it won't work :(
There must be another mistake...
My currently code:
.PXLTEST
DiagnosticOff
[FFFFFFFFFFFFFFFF]->Pic1
0->X->D
44->{0+L1}
53->{1+L1}
66->{2+L1}
50->{3+L1}
Repeat getKey(15)
Pt-On({2+L1},{3+L1},Pic1
Line(0,63,95,63)
Pt-On({0+L1},{1+L1},Pic1)
DispGraphClrDraw
If getKey(2)
{0+L1}--
ElseIf getKey(3)
{0+L1}++
End
!If D
If ({2+L1})<({0+L1})
If (8+{2+L1})>({0+L1})
If (8+{3+L1})=({1+L1})
40->D
End
End
End
End
!If D
{1+L1}++
If {1+L1}=56
20->D
End
End
If D
{1+L1}--
D--
End
End
-
No idea? :(
I need this check in all of my 3 Axe-games :(
-
For the sake of testing, instead of using {1+L1} and {2+L1} and stuff, I would recommend using temporary variables that no one else will use (such as r1-r6 which are normally used for subroutine arguments, but can be considered fair game).
-
Thanks for your answer! ;)
How would you write this? ???
Isn't it possible with {X+L1} to do this? :-\
Because I'll use this for many different sprites and their positions (in my DoodleJump game.. BTW: I need a name for it ;))
Thanks for your help :)
-
Usually, whenever you write a routine that can be used in multiple programs, you code it in such a way that it can be used as easily as possible, without restricting where people can store things. In Axe, you write a subroutine and have it accept arguments, like so:
sub(SUB, EXP1, EXP2, ... , EXP6
In this code, EXP1-EXP6 are loaded in the variables r1-r6 (the Polar variables), respectively. Then the subroutine is called. You can use this to pass up to 6 values into a subroutine.
I also looked at your collision code, and I see serious flaws in the logic. Below is a piece of code that should function the same as the second chunk in your code (the collision between the two sprites).
If sub(COL, {0+L1}, {1+L1}, Pic1, {2+L1}, {3+L1}, Pic1
40→D
End
Lbl COL
If abs(r1-r4)<8 and (abs(r2-r5)<8)
.So that we can use the same For loop no matter how the sprites are positioned, we will flip the arguments if Sprite1 is higher up than Sprite2
If r5<r2:Exch(r1º, r4º, 6):End
.Count up the sprite rows
For(X1T, 0, 7
.Now, we will take the first potentially colliding row of the first sprite and bit shift it so it is in correct space with the second sprite. We will bitwise AND that result with the second sprite. If the two sprites share a pixel at that location, the If statement will become true.
If {r5-r2+X1T+r6}*e^(r4-r1) and {X1T+r3}
.Pixel Collision Occured
1:Return
End
End
0:Return
The actual per pixel test logic might not be accurate... Please correct me.
Thank you for bringing this up, BTW. I might use this myself in my next project.
-
I'm sorry, but it's too diffcult to understand for me...
But I found the solution that I have searched for in your code:
If sub(COL, {0+L1}, {1+L1}, Pic1, {2+L1}, {3+L1}, Pic1
40→D
End
Lbl COL
If abs(r1-r4)<8 and (abs(r2-r5)<8)
Thanks ;)
-
I was just trying to do something fancy with bitshifting and stuff so that irregularly shaped sprites don't collide if their pixel maps don't touch. But the first line just checks the squares, and that's usually fine for most purposes.
-
But you don't mind, if I didn't use your code in my code?
-
But you don't mind, if I didn't use your code in my code?
No, not at all. Unless the owner says otherwise (and I don't), any code samples posted on the Internet can be used by anyone who finds them useful. To say that you can't use posted code is to taunt you sadistically. :)