Compare commits
2 Commits
ba2e986ee5
...
1c17c90d93
Author | SHA1 | Date |
---|---|---|
lee2sman | 1c17c90d93 | |
lee2sman | 418c241a70 |
158
main.lua
158
main.lua
|
@ -30,132 +30,28 @@ end
|
|||
|
||||
function love.keypressed(key)
|
||||
|
||||
--test, play a drone sound on any keypress
|
||||
drone[math.random(#drone)]:play()
|
||||
|
||||
--print('starting player dir '..player_dir)
|
||||
|
||||
if player_dir == 'downright' then
|
||||
if key == 'down' or key == 'right' then
|
||||
p_y = p_y + 1
|
||||
elseif key == 'up' then
|
||||
--player_x = player_x + block_width/2
|
||||
--player_y = player_y - block_height/4
|
||||
p_x = p_x - 1
|
||||
player_dir = 'upright'
|
||||
elseif key == 'left' then
|
||||
--player_x = player_x - block_width/2
|
||||
--player_y = player_y + block_height/4
|
||||
p_x = p_x + 1
|
||||
player_dir = 'downleft'
|
||||
end
|
||||
elseif player_dir == 'upright' then
|
||||
if key == 'down' then
|
||||
--player_x = player_x + block_width/2
|
||||
--player_y = player_y + block_height/4
|
||||
p_x = p_x + 1
|
||||
player_dir = 'downright'
|
||||
elseif key == 'right' or key == 'up' then
|
||||
--player_x = player_x + block_width/2
|
||||
--player_y = player_y - block_height/4
|
||||
p_x = p_y - 1
|
||||
elseif key == 'left' then
|
||||
--player_x = player_x - block_width/2
|
||||
--player_y = player_y - block_height/4
|
||||
p_x = p_x - 1
|
||||
player_dir = 'upleft'
|
||||
end
|
||||
elseif player_dir == 'upleft' then
|
||||
if key == 'left' or key == 'up' then
|
||||
--player_x = player_x - block_width/2
|
||||
--player_y = player_y - block_height/4
|
||||
p_y = p_y - 1
|
||||
elseif key == 'down' then
|
||||
--player_x = player_x - block_width/2
|
||||
--player_y = player_y + block_height/4
|
||||
p_y = p_y - 1
|
||||
player_dir = 'downleft'
|
||||
elseif key == 'right' then
|
||||
--player_x = player_x + block_width/2
|
||||
--player_y = player_y - block_height/4
|
||||
p_x = p_x + 1
|
||||
player_dir = 'upright'
|
||||
end
|
||||
elseif player_dir == 'downleft' then
|
||||
if key == 'down' or key =='left' then
|
||||
--player_x = player_x - block_width/2
|
||||
--player_y = player_y + block_height/4
|
||||
p_x = p_x + 1
|
||||
elseif key == 'up' then
|
||||
--player_x = player_x - block_width/2
|
||||
--player_y = player_y - block_height/4
|
||||
p_x = p_x - 1
|
||||
player_dir = 'upleft'
|
||||
elseif key == 'right' then
|
||||
--player_x = player_x + block_width/2
|
||||
--player_y = player_y + block_height/4
|
||||
p_x = p_x + 1
|
||||
player_dir = 'downright'
|
||||
end
|
||||
|
||||
if key == 'down' then
|
||||
p_x = p_x + 1
|
||||
end
|
||||
if key == 'up' then
|
||||
p_x = p_x - 1
|
||||
end
|
||||
if key == 'left' then
|
||||
p_y = p_y - 1
|
||||
end
|
||||
if key == 'right' then
|
||||
p_y = p_y + 1
|
||||
end
|
||||
--keep the player on the board!
|
||||
if p_x<1 then p_x = 1 end
|
||||
if p_y<1 then p_y = 1 end
|
||||
if p_x>10 then p_x = 10 end
|
||||
if p_y>10 then p_y = 10 end
|
||||
|
||||
--print('ending player dir '..player_dir)
|
||||
print('player x: '..p_x..' y: '..p_y)
|
||||
print('grid piece there: '..grid[p_x][p_y])
|
||||
--print(player_x)
|
||||
--TODO: Fix bug. I'm registering one space over than i think i am.
|
||||
--print('standing on '..grid[p_x+1][p_y+1])
|
||||
|
||||
--[[
|
||||
if key == 'up' or key == 'down' or key == 'left' or key == 'right' then
|
||||
|
||||
player_x = playerX + block_width/2
|
||||
player_y = playerY + block_height/4
|
||||
|
||||
for testY, row in ipairs(level) do
|
||||
for testX, cell in ipairs(row) do
|
||||
if cell == player or cell == playerOnStorage then
|
||||
playerX = testX
|
||||
playerY = testY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local dx = 0
|
||||
local dy = 0
|
||||
if key == 'left' then
|
||||
dx = -1
|
||||
elseif key == 'right' then
|
||||
dx = 1
|
||||
elseif key == 'up' then
|
||||
dy = -1
|
||||
elseif key == 'down' then
|
||||
dy = 1
|
||||
end
|
||||
|
||||
local current = level[playerY][playerX]
|
||||
local adjacent = level[playerY + dy][playerX + dx]
|
||||
local nextAdjacent = {
|
||||
[empty] = player,
|
||||
[storage] = playerOnStorage,
|
||||
}
|
||||
local nextCurrent = {
|
||||
[player] = empty,
|
||||
[playerOnStorage] = storage,
|
||||
}
|
||||
|
||||
if nextAdjacent[adjacent] then
|
||||
level[playerY][playerX] = nextCurrent[current]
|
||||
level[playerY + dy][playerX + dx] = nextAdjacent[adjacent]
|
||||
|
||||
--play a random drone
|
||||
--drone[1]:play()
|
||||
drone[math.random(#drone)]:play()
|
||||
end
|
||||
|
||||
end
|
||||
]]--
|
||||
local terrain_type = get_terrain(p_x,p_y)
|
||||
play_drone(terrain_type)
|
||||
|
||||
end
|
||||
|
||||
|
@ -228,11 +124,8 @@ function draw_player()
|
|||
|
||||
--test
|
||||
--love.graphics.draw(player_dr.spriteSheet, player_dr.quads[spriteNum], player_x, player_y, 0, 2)
|
||||
--note: there's some weird half-solution that will come back to bite me. i added block_width/4 to p_x and subtracted block_height/2 from p_y to get player to right place in grid
|
||||
love.graphics.draw(player_dr.spriteSheet, player_dr.quads[spriteNum], grid_x + ((p_y-p_x) * (block_width / 2)) + block_width/4, grid_y + ((p_x+p_y) * (block_depth / 2)) - (block_depth * (grid_size / 2)) - block_depth - block_height/2, 0, 2)
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
function newAnimation(image, width, height, duration)
|
||||
|
@ -251,3 +144,18 @@ function newAnimation(image, width, height, duration)
|
|||
|
||||
return player_dr
|
||||
end
|
||||
|
||||
function get_terrain(x,y)
|
||||
return grid[p_x][p_y]
|
||||
end
|
||||
|
||||
function play_drone(terrain)
|
||||
--test
|
||||
--drone[math.random(#drone)]:play()
|
||||
|
||||
--print('terrain type '..terrain)
|
||||
|
||||
--sound varies more with more rare (higher number) terrain type
|
||||
drone[math.random(terrain)]:play()
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue