Author Topic: Collision Detection  (Read 8457 times)

0 Members and 1 Guest are viewing this topic.

Offline Siphonic_Sugar

  • LV3 Member (Next: 100)
  • ***
  • Posts: 51
  • Rating: +0/-0
    • View Profile
Collision Detection
« on: September 16, 2015, 07:18:35 pm »
Does anyone know of another way to make a collision detection program that does not use matrices? (They use up to much memory) I read the tutorial by @meishe91 about collision detection, but there was something that I was not getting.  Could someone break it down for me, or just tell me another way to do collision detection without a matrix?
I'm on Codewalr.us now too, you should check it out.
<a href="https://codewalr.us"><img src="https://codewalr.us/other/cwaffiliate.png" /></a>

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Collision Detection
« Reply #1 on: September 17, 2015, 03:14:36 am »
well if you don't want to hit something drawn to the screen you could use pxl-test

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline Siphonic_Sugar

  • LV3 Member (Next: 100)
  • ***
  • Posts: 51
  • Rating: +0/-0
    • View Profile
Re: Collision Detection
« Reply #2 on: September 17, 2015, 07:30:09 am »
Well, I guess that I was thinking of something on the home screen, probably not on the graph screen. (Sorry if I did not specify that...)
I'm on Codewalr.us now too, you should check it out.
<a href="https://codewalr.us"><img src="https://codewalr.us/other/cwaffiliate.png" /></a>

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
Re: Collision Detection
« Reply #3 on: September 17, 2015, 09:32:53 am »
Instead of a matrix, you can use strings to store map and collision data. It's just a little extra math to convert an X and Y coordinate to something you can use to look up things in the string (usually: (Y*width)+X).

For more info, try looking here.
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline Siphonic_Sugar

  • LV3 Member (Next: 100)
  • ***
  • Posts: 51
  • Rating: +0/-0
    • View Profile
Re: Collision Detection
« Reply #4 on: September 17, 2015, 04:41:08 pm »
Whoa! That is really helpful! :D I can't believe that I have not already found that! THANK YOU!
I'm on Codewalr.us now too, you should check it out.
<a href="https://codewalr.us"><img src="https://codewalr.us/other/cwaffiliate.png" /></a>

Offline Siphonic_Sugar

  • LV3 Member (Next: 100)
  • ***
  • Posts: 51
  • Rating: +0/-0
    • View Profile
Re: Collision Detection
« Reply #5 on: September 17, 2015, 05:27:21 pm »
So, I made a sample program using information on TI-Basic Developer.  The program worked out fine except for the displaying part.  The program didn't do anything wrong, and there wasn't an error, I just do not like how it displays everything from the string row by row.

(NOTE: The list is all on one line, I just split up to make it easier to read.)
Code: [Select]
PROGRAM:TEST
:"1111111111111111
   1000000000000001
   1000000000000001
   1000000000000001
   1000000000000001
   1000000000000001
   1000000000000001
   1111111111111111->Str1
:For(A,1,8
:For(B,1,16
:Output(A,B,sub(" X",1+expr(sub(Str1,B+16(A-1),1)),1)
:End:End
I do understand what is going on here,  I think for, for the most part... But how would I:

1) Take the numbers from Str1 and convert it to characters (like 1 is going to be X)
2) How would I store that into Str2
3) How would I display Str2 all at once

Unless there is an easier way to display everything on the home screen at once, could someone tell me how to do this?

P.S. How do I create the code box thing...?
« Last Edit: September 17, 2015, 05:32:56 pm by Geekboy1011 »
I'm on Codewalr.us now too, you should check it out.
<a href="https://codewalr.us"><img src="https://codewalr.us/other/cwaffiliate.png" /></a>

Offline Geekboy1011

  • The Oneironaut
  • Donator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2031
  • Rating: +119/-2
  • Dream that Awakening dream
    • View Profile
Re: Collision Detection
« Reply #6 on: September 17, 2015, 05:33:57 pm »
This is how you use code tags!

[code] Code goes here [/code]

Makes it easier for all of us to read!

Also I edited your post to have them for you!

Offline Siphonic_Sugar

  • LV3 Member (Next: 100)
  • ***
  • Posts: 51
  • Rating: +0/-0
    • View Profile
Re: Collision Detection
« Reply #7 on: September 17, 2015, 05:38:12 pm »
Thank you @Geekboy1011! I finally understand!  :D



But seriously, how would I make a program that reads the map from Str1, and puts all of the sprites in Str2?

Oh crap,  double posting... Sorry...

Edit (Eeems): merged double post.
« Last Edit: September 19, 2015, 09:39:43 pm by Eeems »
I'm on Codewalr.us now too, you should check it out.
<a href="https://codewalr.us"><img src="https://codewalr.us/other/cwaffiliate.png" /></a>

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
Re: Collision Detection
« Reply #8 on: September 18, 2015, 05:38:00 pm »
You'd need string concatenation to manually piece together a string to its final form. Its syntax in TI-BASIC is very much like addition:
Code: [Select]
Str1+Str2->Str3
So long as all objects in the end are strings, you can do something like this:
Code: [Select]
Str2+sub(Str1,1+(16*B)+A,1)->Str2
All string variables have to exist if you're concatenating them. If you need to start with an empty string:
Code: [Select]
""->Str2
Strings can also be used in conditionals as direct comparisons. It tells you whether or not the two strings are identical.
Code: [Select]
If sub(Str2,1+(16*B)+A,1)="1"
## run code whatever chr at A,B is 1
Since these comparisons are being done on strings, it doesn't need to be "1".

Now, to display everything all at once, we're going to take advantage of a particular behavior of the Output() command. If the current string goes past the end of the line, it wraps to the start of the next line. You can use this to write the entire string out to the screen all at once, and it'll completely fill the screen so long as the string is exactly the size of the screen and no more (otherwise you'll end up scrolling).
Code: [Select]
Output(1,1,Str2

Hope this helps.

A Cherry-Flavored Iambian draws near... what do you do? ...

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Collision Detection
« Reply #9 on: September 19, 2015, 01:40:22 am »
I'll be honest, it's been a while since I've programmed on my calculator. But here a couple other tidbits (and others, please correct me if I am not remembering correctly). When you are using strings for collision detection you have to be a little careful for when your maps get larger. It can be a great way of doing it, but the further you have to search in the string for collision the slower your program is going to run.

You could, however, most likely use a list I believe. I can think of a few ways of accomplishing this, but with the list I don't think you will ever get slowness. The other side of that is that I believe lists are limited to a certain number of indexes, and you have a potential size issue again (but not as much as matrices if I remember correctly).

Anywho, just wanted to chime in real fast since I was mentioned.

Veterans, by all means tear this post to threads if I am incorrect :P
Spoiler For Spoiler:



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

Offline Geekboy1011

  • The Oneironaut
  • Donator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2031
  • Rating: +119/-2
  • Dream that Awakening dream
    • View Profile
Re: Collision Detection
« Reply #10 on: September 19, 2015, 08:50:12 pm »
Sadly @meishe91 I lists are just as big as matrices :( strings how ever are much much smaller :P

Offline Siphonic_Sugar

  • LV3 Member (Next: 100)
  • ***
  • Posts: 51
  • Rating: +0/-0
    • View Profile
Re: Collision Detection
« Reply #11 on: September 20, 2015, 02:13:03 pm »
Thank you! This was all really helpful!

Oh, I just bought a used TI-92 and I was wondering if there were any tutorials for programming games on it...
I'm on Codewalr.us now too, you should check it out.
<a href="https://codewalr.us"><img src="https://codewalr.us/other/cwaffiliate.png" /></a>

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Collision Detection
« Reply #12 on: September 20, 2015, 02:19:07 pm »
For one there is a thing for TI-BASIC on tibasicdev over here: http://tibasicdev.wikidot.com/68k:83coders
But those calculators also have the newprog language (more powerful than TI-BASIC), which you can find (including documentation) here. http://www.ticalc.org/archives/files/fileinfo/426/42635.html

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline Siphonic_Sugar

  • LV3 Member (Next: 100)
  • ***
  • Posts: 51
  • Rating: +0/-0
    • View Profile
Re: Collision Detection
« Reply #13 on: September 21, 2015, 04:17:26 pm »
Okay, thanks a lot! :D

Um, after messing around for a while, I noticed that to have more than 10 types of tilemap sprites, I would need to find a different way to put information in the string.  So I decided to just type in what the map would look like into Str1.

But for collision detection, how would I make the program detect if there is a not a space in the players future coordinates?

After it checks to see if your future coordinates aren't a space on Str1, it will set old coordinates (s and t) to x and y.
« Last Edit: September 21, 2015, 07:45:49 pm by Siphonic_Sugar »
I'm on Codewalr.us now too, you should check it out.
<a href="https://codewalr.us"><img src="https://codewalr.us/other/cwaffiliate.png" /></a>

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Collision Detection
« Reply #14 on: September 25, 2015, 10:15:15 am »
If I am understanding you correctly, just move only if the next spot is valid to move to.
1. Take in key input.
2. Check the spot you would move to.
3. If the spot is valid, update the players coordinates. Else, don't do anything.
4. Go back to 1.

@Geekboy1011
Ah, damn. I couldn't remember the sizes. I thought they were bigger than strings but smaller than matrices. Either way, I think they are still the fastest if I remember...And that's more what I was going for I think. I dunno, you guys know better than me now haha.
Spoiler For Spoiler:



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