Author Topic: Collision Detection Help  (Read 9392 times)

0 Members and 2 Guests are viewing this topic.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Collision Detection Help
« on: March 09, 2010, 05:52:17 pm »
So I have been planning on making a homescreen maze type game (there is still a lot I need to figure out haha). The problem I'm having though is that I was trying to make a test program that would just give me the way to move the character. For some reason though it isn't working and I can't figure out what the problem is 

Code: [Select]
PROGRAM:MOVE
"//////////////// //Broke it down so it's easier to see.
/___///___///__/
/_///___///__/_/
/______/////___/
/__///__///__/_/
/_////__//__////
/______________/
////////////////→Str1
Output(1,1,Str1
2→A
2→B
Repeat 0
Output(A,B,"*
Repeat Ans
getKey→K
End
Output(A,B,"_
A+(Ans=34)(sub(Str1,AB+16,1)="_")-(Ans=25)(sub(Str1,AB-16,1)="_→A
B+(K=26)-(K=24)→B
End

I know it is happening in the sub( parts. Which I'm guessing they are probably wrong, they just look correct to me.
Thanks for any help.

By the way, I'm aware this is not the most efficient method of doing this. Just trying to do this without looking up help code from something like TIBD. O0
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Collision Detection Help
« Reply #1 on: March 09, 2010, 06:02:37 pm »
Think this would work:
Code: [Select]
PROGRAM:MOVE
"//////////////// //Broke it down so it's easier to see.
/___///___///__/
/_///___///__/_/
/______/////___/
/__///__///__/_/
/_////__//__////
/______________/
////////////////→Str1
Output(1,1,Ans //Save speed and a byte :)
2→A
2→B
Repeat 0
Output(A,B,"*
Repeat Ans
getKey→K
End
Output(A,B,"_
A+(Ans=34 and sub(Str1+"________________",16A+B,1)="_")-(Ans=25 and sub("________________"+Str1,16A+B-16,1)="_→A //That is 16 spaces both times
B+(K=26 and sub(Str1+"_",16A+B-15,1)="_")-(K=24 and sub("_"+Str1,16A+B-16,1)="_→B //One space each time
End
Good luck! ;D

Edit: Did I just double ninja?!?!  Wow!  And I beat Nyrax by 3 seconds! ;D
« Last Edit: March 09, 2010, 06:20:52 pm by ztrumpet »

Offline Radical Pi

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1143
  • Rating: +5/-2
    • View Profile
    • RealityRevolution
Re: Collision Detection Help
« Reply #2 on: March 09, 2010, 06:02:40 pm »
Disregarding the fact that you could totally rewrite that code for efficiency...
Change AB+16 to 16A+B, and change AB-16 to 16A-32+B.
Warning, though, this solution still doesn't take into account when you're trying to move off the screen, so do something about that. I just fixed your subs :P

EDIT: Argh, beaten with a more in depth solution
« Last Edit: March 09, 2010, 06:03:18 pm by Nyrax »
One of these days I'll get a sig I'm really proud of.

Offline tifreak

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2708
  • Rating: +82/-3
  • My Kung Fu IS strong...
    • View Profile
    • TI-Freakware
Re: Collision Detection Help
« Reply #3 on: March 09, 2010, 06:04:38 pm »
To be truthful, I never was able to get a proper hit detection working like this. Mainly because not only did I have the 2 variables to move the character around, I had a third that was used to test the string as it moved. It eliminated a great many problems I had with hit detection and still had a pretty decent speed.

I have an RPG Starter Kit that uses a similar method that you are trying to make, but won't show unless asked for.

And I am pretty sure your A+(Ans=34)(sub(Str1,AB+16,1)="_")-(Ans=25)(sub(Str1,AB-16,1)="_→A won't work.

say you are on the 3rd row, 2nd colum. A*B, or in this case, 3*2=6. So the string is looking at the 6th space. it doesn't work. =/

I am sure if enough thought is put into it, something could be made, but really, you will save yourself a ton of headaches if you have a third variable that keeps track of where the character is at in the string.
Projects: AOD Series: 75% | FFME: 80% | Pokemon: 18% | RPGSK: 60% | Star Trek: 70% | Star Trek 83+: 40% | TI-City: 5%

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Collision Detection Help
« Reply #4 on: March 09, 2010, 06:06:49 pm »
Thanks! Ztrumpet, could you maybe explain it a little? Or anyone haha. I see where it went wrong but not sure how it is being fixed (especially with the adding of spaces).
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Radical Pi

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1143
  • Rating: +5/-2
    • View Profile
    • RealityRevolution
Re: Collision Detection Help
« Reply #5 on: March 09, 2010, 06:10:21 pm »
tifreak: But your current location in the string is just 16A-16+B at any given time, assuming you're using the typical 8x16 homescreen map string. That's not really worth its own variable in my opinion.

meishe91: Your location in the string at any time is just 16A-16+B. To get the above space, subtract 16 from that. To get the left space, subtract 1. Down: +16. Right: +1. See how it works?
One of these days I'll get a sig I'm really proud of.

Offline tifreak

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2708
  • Rating: +82/-3
  • My Kung Fu IS strong...
    • View Profile
    • TI-Freakware
Re: Collision Detection Help
« Reply #6 on: March 09, 2010, 06:13:33 pm »
I found it to be easier when dealing with strings, but this was 5 years ago when I first developed the code for my engine that I use. At the time I hadn't thought of it that way, and currently suffering from a lack of sleep, so that doesn't really help. Besides, I use 4 way scrolling with a stationary character, my variable for the character location is mandatory now. :p
Projects: AOD Series: 75% | FFME: 80% | Pokemon: 18% | RPGSK: 60% | Star Trek: 70% | Star Trek 83+: 40% | TI-City: 5%

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Collision Detection Help
« Reply #7 on: March 09, 2010, 06:13:52 pm »
Thank you guys.
I see what you mean tifreak, it made sense in my head earlier but it didn't click. Hate when things like that happen. That third value method sounds interesting though, I might try that. I'm just trying to get a basic thing working first though so I can move from there :)

Ohhhhhhhhhhhhh, I see. Ok, ya that makes sense. I see what I was doing wrong when working the math out. Hate when simple things get past ya. But in ztrumpet's, I don't see what adding the spaces does. (Thanks though, Nyrax.)
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Radical Pi

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1143
  • Rating: +5/-2
    • View Profile
    • RealityRevolution
Re: Collision Detection Help
« Reply #8 on: March 09, 2010, 06:18:12 pm »
What spaces? *looks*
Ah, ingenious! Those spaces prevent domain errors from when you're trying to go up at the top of the screen, or down at the bottom of the screen, or the same for the sides (although those should only matter in the very first and very last place in the string). I never thought to do it that way!

EDIT: 8 seconds. We're even now :P *ZTrumpet lols...
« Last Edit: March 09, 2010, 06:21:31 pm by ztrumpet »
One of these days I'll get a sig I'm really proud of.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Collision Detection Help
« Reply #9 on: March 09, 2010, 06:18:20 pm »
But in ztrumpet's, I don't see what adding the spaces does. (Thanks though, Nyrax.)
The extra spaces let you go off the screen without it erroring. :)
Try it like this if you would like to see:
Code: [Select]
PROGRAM:MOVE
"//////////////// //Broke it down so it's easier to see.
/___///___///__/
/_///___///__/_/
/______/////___/
/__///__///__/_/
/_////__//__////
/______________/
////////////////→Str1
Output(1,1,Ans //Save speed and a byte :)
2→A
2→B
Repeat 0
Output(A,B,"*
Repeat Ans
getKey→K
End
Output(A,B,"_
A+(Ans=34 and sub(Str1,16A+B,1)="_")-(Ans=25 and sub(Str1,16A+B-16,1)="_→A
B+(K=26 and sub(Str1,16A+B-15,1)="_")-(K=24 and sub(Str1,16A+B-17,1)="_→B
End

Edit: My method won't work. :(  It will still sometimes fail when you go off the screen.  Let me think of a new solution... :)
« Last Edit: March 09, 2010, 06:24:39 pm by ztrumpet »

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Collision Detection Help
« Reply #10 on: March 09, 2010, 06:27:16 pm »
Oh, ok, I was just about to say it doesn't quite...this is really starting to bug me though because it seems like it shouldn't be this hard :P

BOO YA! I got it to work!!!!! I'll post it in a second.
« Last Edit: March 09, 2010, 06:34:58 pm by meishe91 »
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Radical Pi

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1143
  • Rating: +5/-2
    • View Profile
    • RealityRevolution
Re: Collision Detection Help
« Reply #11 on: March 09, 2010, 06:33:30 pm »
This is just me brainstorming without testing my thoughts with code, but I think ztrumpet's code fails because Str1 doesn't get updated to include the nether zone that you can move into. But if you did add all that whitespace to Str1 every time you went farther out of bounds, it would just open up a whole new can of worms regarding tracking your location in the string. And fixing all those new problems would just make this a horribly inefficient piece of code I would think, when so many alternatives are possible.

Maybe you should either completely disallow going offscreen, or make the Output(A,B,"* line be conditionally dependent on being onscreen.
One of these days I'll get a sig I'm really proud of.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Collision Detection Help
« Reply #12 on: March 09, 2010, 06:39:24 pm »
Here's my completely different code that I am 100% sure it works. ;D

Code: [Select]
"String->Str1  //Note: Put the real string here, not "String". =D
Output(1,1,Ans
2->A
2->B
Output(Ans,A,"*
DelVar C0
Repeat A+C=17 or B+Ans=9 or not((A+C)(B+Ans
If "_"=sub(Str1,16(B+Ans)+A+C-16,1
Then
Output(B,A,"_
B+Ans->B
A+C->A
Output(B,A,"*
End
Repeat Ans
getKey->K
End
(Ans=26)-(Ans=24->C
(K=34)-(K=25
End
Good luck! ;D
« Last Edit: March 09, 2010, 07:29:06 pm by ztrumpet »

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Collision Detection Help
« Reply #13 on: March 09, 2010, 06:39:32 pm »
Ok, so what was happening is that the position of the character was being determined wrong. Instead of 16A+B it is actually  16A-(16-B).

So, the code would be:

Code: [Select]
PROGRAM:MOVE
"////////////////
/___///___///__/
/_///___///__/_/
/______/////___/
/__///__///__/_/
/_////__//__////
/______________/
////////////////→Str1
Output(1,1,Ans
2→A
2→B
Repeat 0
Output(A,B,"*
Repeat Ans
getKey→K
End
Output(A,B,"_
A+(Ans=34 and sub(Str1,16A-(16-B)+16,1)="_")-(Ans=25 and sub(Str1,16A-(16-B)-16,1)="_→A
B+(K=26 and sub(Str1,16A-(16-B)+1,1)="_")-(K=24 and sub(Str1,16A-(16-B)-1,1)="_→B
End
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Collision Detection Help
« Reply #14 on: March 09, 2010, 06:41:14 pm »
Wow, this is a really hot topic.  Did you try my solution? :D