I am making a game and it is going pretty good, but I have one part left to work on, collisions. I am using the Tile Scrolling tutorial's method of displaying the tiles. I need to find the tile to the right of the player .
(note the red is the player, and the yellow are the walls)
You guys might remember me from last year, I got a little better, and I am starting smaller so hopefully this one will work.
Thanks in advance.
Finding the tile to your right
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Finding the tile to your right
The code for that might be (I have to guess, since you didn't post a .love)
Code: Select all
local tileToRight = map[player.x+1] and map[player.x+1][player.y]
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: Finding the tile to your right
What does this return? The tile number? like 0, 1, 2, 3 ect.?
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Finding the tile to your right
Yeah. Here, create a function to return the value of a tile easily:
Where map is whatever your array is called etc...
And then call it like so for Left, Right, Up and Down:
Where x and y are the points you want to chedk. If the player is x, y then left would be x-1, right x+1, up y-1 and down y+1.
It will return whatever data you have stored in that tile. Like if you use 0 or 1 for collisions or whatever. Maybe 2 for water, 3 for lava, etc, etc...
Get it?
Code: Select all
function checkTile(x, y)
return map[x][y]
end
And then call it like so for Left, Right, Up and Down:
Code: Select all
checkTile(x-1, y) --Left
checkTile(x+1, y) --Right
checkTile(x, y-1) --Up
checkTile(x, y+1) --Down
It will return whatever data you have stored in that tile. Like if you use 0 or 1 for collisions or whatever. Maybe 2 for water, 3 for lava, etc, etc...
Get it?
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: Finding the tile to your right
-snip-
Last edited by toaster468 on Tue Oct 25, 2011 1:29 am, edited 1 time in total.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: Finding the tile to your right
I am getting this error. This is my code:
Code: Select all
if tonumber(checkTile(map_x+1, bity)) == "1" then
love.event.push("q")
end
http://dl.dropbox.com/u/27844356/bitdod ... 0Copy.love
- slime
- Solid Snayke
- Posts: 3166
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Finding the tile to your right
The checktile function (and maybe the rest of your code) needs to account for when you input an x,y coordinate that's not within the bounds of the tile arrays, e.g.
or whatever.
Code: Select all
function checkTile(x, y)
if map[x] and map[x][y] then
return map[x][y]
else
return "cheater!"
end
end
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Finding the tile to your right
Also, the following code is wrong:
Strings are not equal to numbers, so that expression will never return true.
Fix:
That still doesn't fix your crash, but slime's suggestion will probably help.
Code: Select all
if tonumber(checkTile(map_x+1, bity)) == "1" then
love.event.push("q")
end
Fix:
Code: Select all
if checkTile(map_x+1, bity) == 1 then
love.event.push("q")
end
Help us help you: attach a .love.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: Finding the tile to your right
I am not even getting any reaction from the program. As far as I know I am using the code the right way, but nothing is happening.
Newest code:
http://dl.dropbox.com/u/27844356/bitdod ... 82%29.love
Newest code:
http://dl.dropbox.com/u/27844356/bitdod ... 82%29.love
Who is online
Users browsing this forum: No registered users and 7 guests