Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: animaaron on April 25, 2015, 05:47:04 pm

Title: HELP- Problems with Collision Detection
Post by: animaaron on April 25, 2015, 05:47:04 pm
I'm having trouble with the collision detecting in a simple map I made using a tut I found on the forum.. I don't know whats wrong, cant find a problem anywhere. :w00t:

Here's the code, if you can help me.

Code: [Select]
.TILENOSC
[AA4400552200AA44]->Pic0
[FFFFFFFFFFFFFFFFFF]

[020202020202010202020202]->GBD1
[020000000000000000000002]
[020000000000000000000002]
[020000000000000000000002]
[020000000000000000000002]
[020000000000000000000002]
[020000000000000000000002]
[020202020202010202020202]

48->X
40->Y

Repeat getKey(56)
For(B,0,7
For(A,0,11
{B*12+A+GBD1}->T
If T
T--
Pt-On(A*8,B*8,T*8+Pic0
End
End
End
Pt-On(X,Y,[7E81FFA57E5A7E42])
DispGraph
ClrDraw

If getKey(4)
!If sub(GT,X,Y-8)=2
Y-8->Y
Pause 500
End
End

If getKey(1)
!If sub(GT,X,Y+8)=2
Y+8->Y
Pause 500
End
End

If getKey(2)
!If sub(GT,X-8,Y)=2
X-8->X
Pause 500
End
End

If getKey(3)
!If sub(GT,X+8,Y)=2
X+8->X
Pause 500
End
End

End
Return

Lbl GT
{r[sub]2[/sub]/8+12+(r[sub]1[/sub]/8)+GBD1}
Return

There it is. Please, if you find something wrong, tell me so I can make this work
Title: Re: HELP- Problems with Collision Detection
Post by: ben_g on April 25, 2015, 06:23:13 pm
I think you made a mistake here:
Code: [Select]
{r2/8+12+(r1/8)+GBD1}I think that should be:
Code: [Select]
{r2/8*12+(r1/8)+GBD1}(* instead of +)

EDIT: I just noticed that you move your player 8 pixels (or 1 tile) at a time. If you plan on doing that in the final version of your game, then I'd reccomend using tile coordinates instead of pixel coordinates. Now, the X and Y are the location at which the sprite should be drawn, and you have to multiply/divide with 8 troughout your whole program, but if you set the X and Y to the tile the player is on, then you'd only have to multiply by 8 when you draw the sprite.

This could save you a few bytes and a few cycles, and it makes everything a little bit clearer, though you won't be able to place your player halfway on a tile.
Title: Re: HELP- Problems with Collision Detection
Post by: pimathbrainiac on April 25, 2015, 06:33:39 pm
Just for future reference, please use the [code] bbcode to surround code. It puts it in monospaced font and it's easier organization-wise.
Title: Re: HELP- Problems with Collision Detection
Post by: animaaron on April 25, 2015, 07:46:54 pm
@ben_g THANK YOU SO MUCH!!! Ugh stupid little mistakes... its always just one little stupid mistake..
Title: Re: HELP- Problems with Collision Detection
Post by: animaaron on April 26, 2015, 02:31:10 pm
How would I make it so I can switch between GDBs when my character is at a certain spot, to enter a new area?
Title: Re: HELP- Problems with Collision Detection
Post by: ben_g on April 26, 2015, 03:23:17 pm
Simple: instead of using GBD's, you use a normal variable, for example L. Then, at the start, you just to GBD1->L, and then when switching levels, you simply store the next gdb in the variable (for example GDB3->L)
Title: Re: HELP- Problems with Collision Detection
Post by: animaaron on April 26, 2015, 07:49:03 pm
I'm still having problems...
Code: [Select]
prgmASSETS   //loads all my sprites
prgmGDB        //loads my GDBs (rn theres only 2)

GDB1->G

48->X
40->Y
32->S             //S and T are the variables that mark where you
32->T             //need to go for the next GDB

Repeat getKey(56)
...                   //Stuff to load the GDB
If getKey(4) and (sub(GT,X,Y-8)=0 or (sub(GT,X,Y-8)=7))
Y-8->Y
Pause 500
sub(LOC)
End

...                    //The rest of the keys

End
Return
prgmSUB          //Has all my routines
That's my main program, and there might already be problems, idk. Here's my routine prgm

Code: [Select]
Lbl GT
{r[sub]2[/sub]/8*12+(r[sub]1[/sub]/8)+G}
Return

Lbl LOC
If X=S and Y=T
If G=GBD1
GBD2->G
80->S                  //These are just temporary numbers. I might change them later. I don't really
48->T                  //think it matters though
Pause 2000
End
Return
End

That's it... tell me what you find out
Title: Re: HELP- Problems with Collision Detection
Post by: ben_g on April 27, 2015, 01:14:48 pm
What's the problem you're having? It's hard to look for problems when you don't know what's happening.
Title: Re: HELP- Problems with Collision Detection
Post by: TheMachine02 on April 28, 2015, 06:32:28 am
It does seems taht there is an error in operation orders at this line :
Code: [Select]
If X=S and Y=TAxe doesn't have opertaion orders and operate from left to right without care to 'actual' rules. I guess you want more to put this:
Code: [Select]
If X=S and (Y=T)(note parenthesis to restore correct order)