well, got player movement somewhat working, albeit with some bugs. need

to get player x y to align with grid spaces better
This commit is contained in:
lee2sman 2022-05-09 01:25:27 -04:00
parent 1e8902b90c
commit 97e9dc2c50
1 changed files with 48 additions and 31 deletions

View File

@ -31,64 +31,79 @@ 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
player_x = player_x + block_width/2
player_y = player_y + block_height/4
p_y = p_y + 1
elseif key == 'up' then
player_x = player_x + block_width/2
player_y = player_y - block_height/4
--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
--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
--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
--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
--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
--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
--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
--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
--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
--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
--player_x = player_x + block_width/2
--player_y = player_y + block_height/4
p_x = p_x + 1
player_dir = 'downright'
end
end
--print(grid[player_x][player_y])
--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)
print(grid[1][1])
--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
@ -183,6 +198,10 @@ function create_player()
player_x = grid_x
player_y = grid_y - block_depth * 2
player_dir = "downright" -- either 'downright','upright','downleft','upleft'
--test
p_x = 1
p_y = 1
end
function draw_grid()
@ -200,17 +219,15 @@ function draw_grid()
end
end
--draw player
--love.graphics.draw(dr, grid_x, grid_y - block_depth * 2)
end
function draw_player()
local spriteNum = math.floor(player_dr.currentTime / player_dr.duration * #player_dr.quads) + 1
--test
--love.graphics.draw(player_dr.spriteSheet, player_dr.quads[spriteNum], player_x, player_y, 0, 2)
love.graphics.draw(player_dr.spriteSheet, player_dr.quads[spriteNum], grid_x + ((p_y-p_x) * (block_width / 2)), grid_y + ((p_x+p_y) * (block_depth / 2)) - (block_depth * (grid_size / 2)) - block_depth, 0, 2)
love.graphics.draw(player_dr.spriteSheet, player_dr.quads[spriteNum], player_x, player_y, 0, 2)
end