How do you make a Grid?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 3
- Joined: Sun Apr 22, 2012 4:09 am
- Location: Canada
How do you make a Grid?
Before i get yelled at, i would like to say this is a re-post because my previous thread name was written incorrectly. Basically how do you make a grid that allows one object to occupy each grid space? Any help would be greatly appreciated, i don't have extensive Lua experience so sorry for idiot question.
Re: How do you make a Grid?
Have you tried the tutorials? https://love2d.org/wiki/Tutorial:Gridlocked_Player seems like exactly what you want.
-
- Prole
- Posts: 3
- Joined: Sun Apr 22, 2012 4:09 am
- Location: Canada
Re: How do you make a Grid?
Yes thank you that is useful. I actually ran across that before but closed the tab by accident, and couldn't find it again. Thank you again.
-
- Prole
- Posts: 3
- Joined: Sun Apr 22, 2012 4:09 am
- Location: Canada
Re: How do you make a Grid?
Alright, so that helped a bit. However when they use numbers in the tutorial to map out the spawning of blocks, could those numbers be used, to represent different terrain types in a game? For instance is it possible to assign a picture and value that effects objects occupying the same space, to each number? Also is there a tutorial on how to spawn multiple player objects that you can switch between?
Sorry if I use improper terms, I'm completely new to Lua and love.
Sorry if I use improper terms, I'm completely new to Lua and love.
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: How do you make a Grid?
Yep, you could use any number of numbers. You could so use letters with a tiny bit of modification. An example of having more numbers which render differently:
To have multiple players, move the player variables into that new subtable, and add a couple variations. Something about like this:
speed = 10
}
}
end
[/code]
We will also need a viable to keep track of which player we're controlling, and may want to move some of the redundant variables out, like so:
Now we can can control the players by cycling through the index:
We'll also need to change the testMap function to use the current player.
Code: Select all
function love.draw()
love.graphics.rectangle("fill", player.act_x, player.act_y, 32, 32)
for y=1, #map do
for x=1, #map[y] do
if map[y][x] == 1 then
love.graphics.rectangle("line", x * 32, y * 32, 32, 32)
elseif map[y][x] == 2 then
love.graphics.rectangle("fill", x * 32, y * 32, 32, 32)
end
end
end
end
Code: Select all
function love.load()
player = {
{
grid_x = 32,
grid_y = 32,
act_x = 32,
act_y = 32,
speed = 10
},
{
grid_x = 64,
grid_y = 256,
act_x = 64,
act_y = 256,
speed = 10
},
{
grid_x = 256,
grid_y = 256,
act_x = 256,
act_y = 256,[code]
}
}
end
[/code]
We will also need a viable to keep track of which player we're controlling, and may want to move some of the redundant variables out, like so:
Code: Select all
function love.load()
playermeta = {
index = 1,
speed = 10
}
end
Code: Select all
function love.keypressed(key)
if key == "up" then
if testMap(0, -1) then
player[playermeta.index].grid_y = player[playermeta.index].grid_y - 32
end
elseif key == "down" then
if testMap(0, 1) then
player[playermeta.index].grid_y = player[playermeta.index].grid_y + 32
end
elseif key == "left" then
if testMap(-1, 0) then
player[playermeta.index].grid_x = player[playermeta.index].grid_x - 32
end
elseif key == "right" then
if testMap(1, 0) then
player[playermeta.index].grid_x = player[playermeta.index].grid_x + 32
end
elseif key == "return" then
if playermeta.index < #player then
playermeta.index = playermeta.index + 1
else
playermeta.index = 1
end
end
end
Kurosuke needs beta testers
Who is online
Users browsing this forum: Amazon [Bot], Google [Bot] and 12 guests