Author Topic: Help with tilemap collision?  (Read 7765 times)

0 Members and 1 Guest are viewing this topic.

Offline thydowulays

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 184
  • Rating: +12/-1
  • Don't gimme dat lip
    • View Profile
    • Thy Gaming Forum
Help with tilemap collision?
« on: January 08, 2012, 12:44:06 am »
Okay, so I have a simple problem. I am making an RPG, and I have a tilemap. pxl-Test(ing doesn't work for tilemaps, so I just want to know how to find tiles on the map and if they are "solid" then don't let the player move. Here is my code:
Code: [Select]
.LOLZ
prgmLOLZDATA <-- My tilemap and sprites are stored in here
0->X->Y
Repeat getKey(15)
For(B,0,7
For(A,0,11
{B*12+A+GDB1}->T
If T
T--
Pt-On(A*8,B*8,T*8+Pic1
End
End
End
DispGraph
ClrDraw
If getKey(4)
Y-1->Y
End
If getKey(1)
Y+1->Y
End
If getKey(2)
X-1->X
End
If getKey(3)
X+1->X
End

End
Return

Current Projects:
-Sparta GUI Library: 25% - Alpha Stage
-Grapher - 75% - Beta Stage *on hiatus




Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: Help with tilemap collision?
« Reply #1 on: January 08, 2012, 01:24:00 am »
Alrighty, so what you want to do is make a subroutine like this:

Lbl GT
{r2/8*12+(r1/8)+GDB1}
Return

Then input the coordinates on the screen whenever you want to check if it's solid, e.x.

If sub(GT,X,Y)
DelVar "System32"
End

and you should be good to go!

A breakdown of that code:

When you call the subroutine, X gets stored to r1 and Y gets stored to r2. What you're doing is dividing both by 8 (because your tiles are 8x8), then multiplying the Y value by 12 to get the right row, then adding the X value to get the right column (and thus the tile you want.)

Note: This works if tile 0 is empty and tiles 1 and onwards are solid. There are more complicated things you can do (check out BuilderBoy's tile-masking tutorial)
In-progress: Graviter (...)

Offline thydowulays

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 184
  • Rating: +12/-1
  • Don't gimme dat lip
    • View Profile
    • Thy Gaming Forum
Re: Help with tilemap collision?
« Reply #2 on: January 08, 2012, 01:28:16 am »
Thanks so much for this! Is there a way to assign a sprite to 00?
Current Projects:
-Sparta GUI Library: 25% - Alpha Stage
-Grapher - 75% - Beta Stage *on hiatus




Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: Help with tilemap collision?
« Reply #3 on: January 08, 2012, 01:29:56 am »
When you draw the tiles, you can have it check for a tile with 0 as a value and if so draw a sprite there.
Vy'o'us pleorsdti thl'e gjaemue

Offline thydowulays

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 184
  • Rating: +12/-1
  • Don't gimme dat lip
    • View Profile
    • Thy Gaming Forum
Re: Help with tilemap collision?
« Reply #4 on: January 08, 2012, 01:32:47 am »
Oh good idea, I'll do that later when I need it. Thanks! :)
Current Projects:
-Sparta GUI Library: 25% - Alpha Stage
-Grapher - 75% - Beta Stage *on hiatus




Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Help with tilemap collision?
« Reply #5 on: January 08, 2012, 07:33:36 pm »
DelVar "System32"
what does that mean?

Offline annoyingcalc

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1953
  • Rating: +140/-72
  • Found in Eclipse.exe
    • View Profile
Re: Help with tilemap collision?
« Reply #6 on: January 08, 2012, 07:38:21 pm »
you dont want to try
This used to contain a signature.

Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Help with tilemap collision?
« Reply #7 on: January 08, 2012, 07:40:04 pm »
you dont want to try
umm, I don't get it ???

Offline saintrunner

  • Custom Spriter: You ask it! I'll Make it!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1787
  • Rating: +115/-11
  • Flogging Molly
    • View Profile
    • Jonny K Music
Re: Help with tilemap collision?
« Reply #8 on: January 08, 2012, 07:41:31 pm »
I think he is talking to thydowulays
My Sprites Thread   :Updated often :) for your viewing pleasure

GAMES:

Offline thydowulays

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 184
  • Rating: +12/-1
  • Don't gimme dat lip
    • View Profile
    • Thy Gaming Forum
Re: Help with tilemap collision?
« Reply #9 on: January 08, 2012, 07:51:38 pm »
parser padwan, I assume you aren't trolling, so I'll tell you. He is replacing the boring .Insert code here with something of interest. doing del C:\WINDOWS\System32 on a windows machine will pretty much delete Windows. So he is referring to formatting your calculator I guess. Anyways, It's just a witty way of saying .Insert code here
Current Projects:
-Sparta GUI Library: 25% - Alpha Stage
-Grapher - 75% - Beta Stage *on hiatus




Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Help with tilemap collision?
« Reply #10 on: January 08, 2012, 07:53:39 pm »
parser padwan, I assume you aren't trolling, so I'll tell you. He is replacing the boring .Insert code here with something of interest. doing del C:\WINDOWS\System32 on a windows machine will pretty much delete Windows. So he is referring to formatting your calculator I guess. Anyways, It's just a witty way of saying .Insert code here
ah, that makes sense now. thanks. :)
and btw, I wasn't trolling :P

Offline annoyingcalc

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1953
  • Rating: +140/-72
  • Found in Eclipse.exe
    • View Profile
Re: Help with tilemap collision?
« Reply #11 on: January 08, 2012, 07:54:39 pm »
I think he is talking to thydowulays
no and @ parser

This used to contain a signature.

Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Help with tilemap collision?
« Reply #12 on: January 09, 2012, 06:38:11 pm »
ah ok.


hmmm, how would you check for a collision, say, at the bottom right of the player?
cause when I do this:
Code: [Select]
:If sub(GET,X+7,Y+7)=2
:stuff
:End
it has the same reaction as this:
Code: [Select]
:If sub(GET,X,Y)=2
:stuff
:End
...and when I delete the latter code and replace it with the first, the collision still only works for (X,Y), but not for (X+7,Y+7)


also, I don't know if it will help, but here is the sub(GET) code.
Code: [Select]
:{r2/256/6*16+(r1/256/6)+L1}
:Return
also note that I am using 256 inflation, with 6*6 tiles in a 16*8 tilemap. my tilemap data is also in L1
« Last Edit: January 09, 2012, 07:58:58 pm by parser padwan »

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
Re: Help with tilemap collision?
« Reply #13 on: January 10, 2012, 02:42:18 pm »
Okay, a simple way to do collision detection in a top-down sort of game, like what I used in Base 671, is to assign the current position variables and offsets for the tilemap into other variables, so you have a copy of how everything is displayed. Then, check to see if the character is inside a tile. If they are, restore the copy of the position variables so everything is back to normal! Note that this works best if your character is represented by a single point.

@parser - you said you were using *256 inflation? Make sure you do If sub(GET,X+(7*256),Y+(7*256))=2. Otherwise, I think your code is fine.
Completed Projects:
   >> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
   >> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.


Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)



Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Help with tilemap collision?
« Reply #14 on: January 10, 2012, 04:42:32 pm »
ah yes, that was the problem. thanks butts! :D
(it turns out I really was being a noob :P)