-
-
Save TannerRogalsky/7171480 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function love.load() | |
player = { | |
grid_x = 256, | |
grid_y = 256, | |
act_x = 256, | |
act_y = 256, | |
speed = 10 | |
} | |
map = { | |
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, | |
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 }, | |
{ 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 }, | |
{ 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1 }, | |
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }, | |
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } | |
} | |
-- this makes a 2d array the same size as the map 2d array | |
seen_tiles = {} | |
for yindex,column in ipairs(map) do | |
seen_tiles[yindex] = {} | |
for xindex,tile in ipairs(column) do | |
seen_tiles[yindex][xindex] = 0 | |
end | |
end | |
end | |
function love.update(dt) | |
player.act_y = player.act_y - ((player.act_y - player.grid_y) * player.speed * dt) | |
player.act_x = player.act_x - ((player.act_x - player.grid_x) * player.speed * dt) | |
end | |
function love.draw() | |
love.graphics.rectangle("fill", player.act_x, player.act_y, 32, 32) | |
-- draw the seen tiles if they have been marked as seen | |
for y=1, #seen_tiles do | |
for x=1, #seen_tiles[y] do | |
if seen_tiles[y][x] == 1 then | |
love.graphics.rectangle("line", x * 32, y * 32, 32, 32) | |
end | |
end | |
end | |
end | |
function love.keypressed (key) | |
if key == "up" then | |
if testMap (0, -1) then | |
player.grid_y = player.grid_y - 32 | |
end | |
elseif key == "down" then | |
if testMap (0, 1) then | |
player.grid_y = player.grid_y + 32 | |
end | |
elseif key == "left" then | |
if testMap (-1, 0) then | |
player.grid_x = player.grid_x - 32 | |
end | |
elseif key == "right" then | |
if testMap (1, 0) then | |
player.grid_x = player.grid_x + 32 | |
end | |
end | |
end | |
function testMap (x, y) | |
if map[(player.grid_y / 32) + y][(player.grid_x / 32) + x] == 1 then | |
-- mark a tile as seen by setting it to a value of 1 | |
seen_tiles[(player.grid_y / 32) + y][(player.grid_x / 32) + x] = 1 | |
return false | |
end | |
return true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment