Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
24 May, 2013, 06:40:50 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1] 2   Go Down
  Print  
Author Topic: Help with tilemap collision? -  (Read 1167 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
thydowulays
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: 19 March, 2013, 16:22:53
Date Registered: 02 November, 2011, 04:41:42
Location: Greenville, SC
Posts: 184


Topic starter
Total Post Ratings: +11

View Profile WWW
« on: 08 January, 2012, 07:44:06 »
0

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
.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

Logged

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



/image/33080.png[/img]
leafy
Coder Of Tomorrow
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 02:05:15
Date Registered: 26 December, 2010, 05:27:03
Location: the ninth circle of hell
Posts: 1545


Total Post Ratings: +371

View Profile WWW
« Reply #1 on: 08 January, 2012, 08:24:00 »
+2

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)
Logged

In-progress: Blastlabs, TMJO, qb?, VVVVVV?
Finished: Tag, Tap, MFQT, Nyan
Dead: Graviter
thydowulays
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: 19 March, 2013, 16:22:53
Date Registered: 02 November, 2011, 04:41:42
Location: Greenville, SC
Posts: 184


Topic starter
Total Post Ratings: +11

View Profile WWW
« Reply #2 on: 08 January, 2012, 08:28:16 »
0

Thanks so much for this! Is there a way to assign a sprite to 00?
Logged

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



/image/33080.png[/img]
Darl181
Vy'o'us pleorsdtu tlh'e gjaemue.
Coder Of Tomorrow
LV12 Extreme Poster (Next: 5000)
*
Offline Offline

Gender: Male
Last Login: Today at 05:49:36
Date Registered: 10 June, 2010, 00:32:08
Location: {I*9+L₁+1},{I*9+L₁+3}
Posts: 3280


Total Post Ratings: +267

View Profile WWW
« Reply #3 on: 08 January, 2012, 08:29:56 »
0

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.
Logged




 
Spoiler for Stuff:



OS 2.43  Boot 1.02  Hardware Rev. B

OS 1.04.32

OS 3.1.0.392  Boot1 3.0.99  Boot2 3.10.16
Spoiler for Misc:
Quote
You'll understand / It's not a shame / To be always / Losing the game / Burma-Shave
"Dynamic userbars!"
Omnimaga radio
Interactive Omnimaga radio
Our World of Text
Draw on websites
Then blow them up
In-browser flight simulator
Haxball: MMO soccer/air hockey game
  Draw with sand.  Yay?
The Game
You just lost the game
Zombo.com
light post color is #dfefff
dark post color is #cae4ff
quote box color is #6699ff
transparent color is...transparent 0.o
Spoiler for Forum search alternative (bookmarklet):
https://www.squarefree.com/bookmarklets/search.html
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("No%20selected%20text;%20enter%20search%20term.").replace(/\s\+/g,"%252B");if(q!=null)location="http://www.google.com/search?q="+q.replace(/\s+/g,"+")+"+site:"+location.hostname;void(0);
thydowulays
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: 19 March, 2013, 16:22:53
Date Registered: 02 November, 2011, 04:41:42
Location: Greenville, SC
Posts: 184


Topic starter
Total Post Ratings: +11

View Profile WWW
« Reply #4 on: 08 January, 2012, 08:32:47 »
0

Oh good idea, I'll do that later when I need it. Thanks! Smiley
Logged

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



/image/33080.png[/img]
parserp
Hero Extraordinaire
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Yesterday at 23:14:32
Date Registered: 08 September, 2011, 02:01:43
Location: Here.
Posts: 1421


Total Post Ratings: +80

View Profile WWW
« Reply #5 on: 09 January, 2012, 02:33:36 »
0

DelVar "System32"
what does that mean?
Logged

ticalc.org | Cemetech | TI-Freakware | casiocalc.org

My New Website!
Spoiler for The Rest:



A useful tool
Spoiler for bands:
Five Finger Death Punch
Disturbed
Slipknot
Linkin Park
Avenged Sevenfold
Breaking Benjamin
Skillet
30 Seconds to Mars
annoyingcalc
the annoying calculator
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Today at 05:39:28
Date Registered: 14 April, 2011, 23:02:24
Location: In the glorious land of minecraft
Posts: 1779


Total Post Ratings: +57

View Profile WWW
« Reply #6 on: 09 January, 2012, 02:38:21 »
0

you dont want to try
Logged

Click here to see where you got your post ratings

My minecraft server is usually up, even if mcserverlist says it is down

Spoiler for siq:
Spoiler for signature:
parserp
Hero Extraordinaire
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Yesterday at 23:14:32
Date Registered: 08 September, 2011, 02:01:43
Location: Here.
Posts: 1421


Total Post Ratings: +80

View Profile WWW
« Reply #7 on: 09 January, 2012, 02:40:04 »
0

you dont want to try
umm, I don't get it Huh?
Logged

ticalc.org | Cemetech | TI-Freakware | casiocalc.org

My New Website!
Spoiler for The Rest:



A useful tool
Spoiler for bands:
Five Finger Death Punch
Disturbed
Slipknot
Linkin Park
Avenged Sevenfold
Breaking Benjamin
Skillet
30 Seconds to Mars
saintrunner
Custom Spriter: You ask it! I'll Make it!
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: 09 March, 2013, 02:00:40
Date Registered: 27 October, 2011, 21:52:46
Location: Right here....I think?
Posts: 1776


Total Post Ratings: +97

View Profile WWW
« Reply #8 on: 09 January, 2012, 02:41:31 »
0

I think he is talking to thydowulays
Logged

My Sprites Thread   :Updated often Smiley for your viewing pleasure

GAMES:
thydowulays
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: 19 March, 2013, 16:22:53
Date Registered: 02 November, 2011, 04:41:42
Location: Greenville, SC
Posts: 184


Topic starter
Total Post Ratings: +11

View Profile WWW
« Reply #9 on: 09 January, 2012, 02:51:38 »
0

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
Logged

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



/image/33080.png[/img]
parserp
Hero Extraordinaire
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Yesterday at 23:14:32
Date Registered: 08 September, 2011, 02:01:43
Location: Here.
Posts: 1421


Total Post Ratings: +80

View Profile WWW
« Reply #10 on: 09 January, 2012, 02:53:39 »
0

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. Smiley
and btw, I wasn't trolling Tongue
Logged

ticalc.org | Cemetech | TI-Freakware | casiocalc.org

My New Website!
Spoiler for The Rest:



A useful tool
Spoiler for bands:
Five Finger Death Punch
Disturbed
Slipknot
Linkin Park
Avenged Sevenfold
Breaking Benjamin
Skillet
30 Seconds to Mars
annoyingcalc
the annoying calculator
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Today at 05:39:28
Date Registered: 14 April, 2011, 23:02:24
Location: In the glorious land of minecraft
Posts: 1779


Total Post Ratings: +57

View Profile WWW
« Reply #11 on: 09 January, 2012, 02:54:39 »
+1

I think he is talking to thydowulays
no and @ parser



* system32.bmp (3000.05 KB, 1280x800 - viewed 163 times.)
Logged

Click here to see where you got your post ratings

My minecraft server is usually up, even if mcserverlist says it is down

Spoiler for siq:
Spoiler for signature:
parserp
Hero Extraordinaire
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Yesterday at 23:14:32
Date Registered: 08 September, 2011, 02:01:43
Location: Here.
Posts: 1421


Total Post Ratings: +80

View Profile WWW
« Reply #12 on: 10 January, 2012, 01:38:11 »
0

ah ok.


hmmm, how would you check for a collision, say, at the bottom right of the player?
cause when I do this:

1
2
3
4
:If sub(GET,X+7,Y+7)=2
:stuff
:End
it has the same reaction as this:

1
2
3
: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.

1
2
3
:{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: 10 January, 2012, 02:58:58 by parser padwan » Logged

ticalc.org | Cemetech | TI-Freakware | casiocalc.org

My New Website!
Spoiler for The Rest:



A useful tool
Spoiler for bands:
Five Finger Death Punch
Disturbed
Slipknot
Linkin Park
Avenged Sevenfold
Breaking Benjamin
Skillet
30 Seconds to Mars
LincolnB
Check It Out Now
LV9 Veteran (Next: 1337)
*********
Offline Offline

Gender: Male
Last Login: 20 May, 2013, 05:36:22
Date Registered: 02 May, 2011, 00:56:28
Location: Utah Valley
Posts: 1114


Total Post Ratings: +121

View Profile
« Reply #13 on: 10 January, 2012, 21:42:18 »
0

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.
Logged

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)


parserp
Hero Extraordinaire
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Yesterday at 23:14:32
Date Registered: 08 September, 2011, 02:01:43
Location: Here.
Posts: 1421


Total Post Ratings: +80

View Profile WWW
« Reply #14 on: 10 January, 2012, 23:42:32 »
0

ah yes, that was the problem. thanks butts! Cheesy
(it turns out I really was being a noob Tongue)
Logged

ticalc.org | Cemetech | TI-Freakware | casiocalc.org

My New Website!
Spoiler for The Rest:



A useful tool
Spoiler for bands:
Five Finger Death Punch
Disturbed
Slipknot
Linkin Park
Avenged Sevenfold
Breaking Benjamin
Skillet
30 Seconds to Mars
Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.377 seconds with 31 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.