Add HP
This commit is contained in:
parent
5d9e9113ea
commit
507080a695
|
@ -10,9 +10,13 @@ local spawn_x = nil
|
||||||
local spawn_y = nil
|
local spawn_y = nil
|
||||||
|
|
||||||
local directions = {up = 0, upleft = 1, left = 2, downleft = 3, down = 4, downright = 5, right = 6, upright = 7, inplace = 8}
|
local directions = {up = 0, upleft = 1, left = 2, downleft = 3, down = 4, downright = 5, right = 6, upright = 7, inplace = 8}
|
||||||
|
|
||||||
local player_x = nil
|
local player_x = nil
|
||||||
local player_y = nil
|
local player_y = nil
|
||||||
local player_direction = nil
|
local player_direction = nil
|
||||||
|
local hp = nil
|
||||||
|
local flash_player_white_counter = 0
|
||||||
|
local flash_player_red_counter = 0
|
||||||
|
|
||||||
local slimes = {}
|
local slimes = {}
|
||||||
|
|
||||||
|
@ -162,6 +166,8 @@ function spawnPlayer()
|
||||||
else
|
else
|
||||||
error("Cavern is weirdly generated and player cannot spawn")
|
error("Cavern is weirdly generated and player cannot spawn")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
hp = 3
|
||||||
end
|
end
|
||||||
|
|
||||||
function spawnOrb()
|
function spawnOrb()
|
||||||
|
@ -688,10 +694,16 @@ function step(direction)
|
||||||
end
|
end
|
||||||
|
|
||||||
if collidedPlayerSlime() then
|
if collidedPlayerSlime() then
|
||||||
if math.random(0, 1) == 0 then
|
killSlime()
|
||||||
game_mode = gamemodes.lost
|
if math.random() < 0.2 then
|
||||||
|
flash_player_white_counter = 0.2
|
||||||
else
|
else
|
||||||
killSlime()
|
hp = hp - 1
|
||||||
|
if hp == 0 then
|
||||||
|
flash_player_red_counter = 1
|
||||||
|
else
|
||||||
|
flash_player_red_counter = 0.2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -729,12 +741,12 @@ function drawCavern()
|
||||||
love.graphics.setColor(0.5, 0.3, 0.3)
|
love.graphics.setColor(0.5, 0.3, 0.3)
|
||||||
love.graphics.rectangle('fill', x, y, scale, scale)
|
love.graphics.rectangle('fill', x, y, scale, scale)
|
||||||
love.graphics.setColor(0, 1, 0)
|
love.graphics.setColor(0, 1, 0)
|
||||||
love.graphics.ellipse('fill', x + 0.5 * scale, y + 0.5 * scale, 0.7 * scale/2, 0.7 * scale/2)
|
love.graphics.circle('fill', x + 0.5 * scale, y + 0.5 * scale, 0.7 * scale/2)
|
||||||
elseif tile == tiletypes.slime then
|
elseif tile == tiletypes.slime then
|
||||||
love.graphics.setColor(0, 0, 0)
|
love.graphics.setColor(0, 0, 0)
|
||||||
love.graphics.rectangle('fill', x, y, scale, scale)
|
love.graphics.rectangle('fill', x, y, scale, scale)
|
||||||
love.graphics.setColor(1, 1, 0)
|
love.graphics.setColor(1, 1, 0)
|
||||||
love.graphics.ellipse('fill', x + 0.5 * scale, y + 0.5 * scale, 0.8 * scale/2, 0.8 * scale/2)
|
love.graphics.circle('fill', x + 0.5 * scale, y + 0.5 * scale, 0.8 * scale/2)
|
||||||
love.graphics.rectangle('fill', x + 0.1 * scale , y + 0.5 * scale, 0.8 * scale, 0.8 * scale/2)
|
love.graphics.rectangle('fill', x + 0.1 * scale , y + 0.5 * scale, 0.8 * scale, 0.8 * scale/2)
|
||||||
elseif tile == tiletypes.unknown then
|
elseif tile == tiletypes.unknown then
|
||||||
love.graphics.setColor(1, 0.5, 0.5)
|
love.graphics.setColor(1, 0.5, 0.5)
|
||||||
|
@ -757,12 +769,12 @@ function drawCavern()
|
||||||
love.graphics.setColor(0.4, 0.4, 0.4)
|
love.graphics.setColor(0.4, 0.4, 0.4)
|
||||||
love.graphics.rectangle('fill', x, y, scale, scale)
|
love.graphics.rectangle('fill', x, y, scale, scale)
|
||||||
love.graphics.setColor(0.2, 0.7, 0.2)
|
love.graphics.setColor(0.2, 0.7, 0.2)
|
||||||
love.graphics.ellipse('fill', x + 0.5 * scale, y + 0.5 * scale, 0.7 * scale/2, 0.7 * scale/2)
|
love.graphics.circle('fill', x + 0.5 * scale, y + 0.5 * scale, 0.7 * scale/2)
|
||||||
elseif tile == tiletypes.slime then
|
elseif tile == tiletypes.slime then
|
||||||
love.graphics.setColor(0.2, 0.2, 0.2)
|
love.graphics.setColor(0.2, 0.2, 0.2)
|
||||||
love.graphics.rectangle('fill', x, y, scale, scale)
|
love.graphics.rectangle('fill', x, y, scale, scale)
|
||||||
love.graphics.setColor(0.7, 0.7, 0.2)
|
love.graphics.setColor(0.7, 0.7, 0.2)
|
||||||
love.graphics.ellipse('fill', x + 0.5 * scale, y + 0.5 * scale, 0.8 * scale/2, 0.8 * scale/2)
|
love.graphics.circle('fill', x + 0.5 * scale, y + 0.5 * scale, 0.8 * scale/2)
|
||||||
love.graphics.rectangle('fill', x + 0.1 * scale , y + 0.5 * scale, 0.8 * scale, 0.8 * scale/2)
|
love.graphics.rectangle('fill', x + 0.1 * scale , y + 0.5 * scale, 0.8 * scale, 0.8 * scale/2)
|
||||||
else
|
else
|
||||||
love.graphics.setColor(0.7, 0.5, 0.5)
|
love.graphics.setColor(0.7, 0.5, 0.5)
|
||||||
|
@ -791,16 +803,59 @@ function drawPlayer()
|
||||||
|
|
||||||
local player_head_center_x = (player_x - 1) * scale + x_offset + 0.5 * scale
|
local player_head_center_x = (player_x - 1) * scale + x_offset + 0.5 * scale
|
||||||
local player_head_center_y = (player_y - 1) * scale + y_offset + 0.5 * scale
|
local player_head_center_y = (player_y - 1) * scale + y_offset + 0.5 * scale
|
||||||
love.graphics.setColor(0.6, 0.3, 0.2)
|
if flash_player_red_counter > 0 then
|
||||||
love.graphics.ellipse('fill', player_head_center_x, player_head_center_y, scale/2, scale/2)
|
love.graphics.setColor(1, 0, 0)
|
||||||
|
elseif flash_player_white_counter > 0 then
|
||||||
|
love.graphics.setColor(1, 1, 1)
|
||||||
|
else
|
||||||
|
love.graphics.setColor(0.6, 0.3, 0.2)
|
||||||
|
end
|
||||||
|
love.graphics.circle('fill', player_head_center_x, player_head_center_y, scale/2)
|
||||||
|
|
||||||
local player_body_x, player_body_y = getBodyLocation()
|
local player_body_x, player_body_y = getBodyLocation()
|
||||||
local player_body_x = (player_body_x - 1) * scale + x_offset
|
local player_body_x = (player_body_x - 1) * scale + x_offset
|
||||||
local player_body_y = (player_body_y - 1) * scale + y_offset
|
local player_body_y = (player_body_y - 1) * scale + y_offset
|
||||||
love.graphics.setColor(0, 0, 1)
|
if flash_player_red_counter > 0 then
|
||||||
|
love.graphics.setColor(1, 0, 0)
|
||||||
|
elseif flash_player_white_counter > 0 then
|
||||||
|
love.graphics.setColor(1, 1, 1)
|
||||||
|
else
|
||||||
|
love.graphics.setColor(0, 0, 1)
|
||||||
|
end
|
||||||
love.graphics.rectangle('fill', player_body_x, player_body_y, scale, scale)
|
love.graphics.rectangle('fill', player_body_x, player_body_y, scale, scale)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function drawHP()
|
||||||
|
local screen_width = love.graphics.getWidth()
|
||||||
|
local screen_height = love.graphics.getHeight()
|
||||||
|
|
||||||
|
local width_scale = screen_width / cavern.width
|
||||||
|
local height_scale = screen_height / cavern.height
|
||||||
|
local scale = math.min(width_scale, height_scale)
|
||||||
|
|
||||||
|
local x_offset = (screen_width - cavern.width * scale) / 2
|
||||||
|
local y_offset = (screen_height - cavern.height * scale) / 2
|
||||||
|
|
||||||
|
for i = 1, hp do
|
||||||
|
local x = (i - 1) * scale + x_offset
|
||||||
|
local y = y_offset
|
||||||
|
|
||||||
|
love.graphics.setColor(1, 0, 0)
|
||||||
|
love.graphics.circle('fill', x + 0.25 * scale, y + 0.25 * scale, scale/4)
|
||||||
|
love.graphics.circle('fill', x + 0.75 * scale, y + 0.25 * scale, scale/4)
|
||||||
|
love.graphics.setColor(0, 0, 0)
|
||||||
|
love.graphics.circle('line', x + 0.25 * scale, y + 0.25 * scale, scale/4)
|
||||||
|
love.graphics.circle('line', x + 0.75 * scale, y + 0.25 * scale, scale/4)
|
||||||
|
love.graphics.setColor(0.7, 0.5, 0.5)
|
||||||
|
love.graphics.rectangle('fill', x, y + 0.25 * scale, scale, 0.75 * scale)
|
||||||
|
love.graphics.setColor(1, 0, 0)
|
||||||
|
love.graphics.polygon('fill', x, y + 0.25 * scale, x + 0.5 * scale, y + scale, x + scale, y + 0.25 * scale)
|
||||||
|
love.graphics.setColor(0, 0, 0)
|
||||||
|
love.graphics.line(x, y + 0.25 * scale, x + 0.5 * scale, y + scale)
|
||||||
|
love.graphics.line(x + 0.5 * scale, y + scale, x + scale, y + 0.25 * scale)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function drawWin()
|
function drawWin()
|
||||||
local img_width, img_height = win_image:getDimensions()
|
local img_width, img_height = win_image:getDimensions()
|
||||||
|
|
||||||
|
@ -911,6 +966,16 @@ function love.update(dt)
|
||||||
step(last_direction_moved)
|
step(last_direction_moved)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if flash_player_white_counter > 0 then
|
||||||
|
flash_player_white_counter = flash_player_white_counter - dt
|
||||||
|
end
|
||||||
|
if flash_player_red_counter > 0 then
|
||||||
|
flash_player_red_counter = flash_player_red_counter - dt
|
||||||
|
if hp == 0 and flash_player_red_counter <= 0 then
|
||||||
|
game_mode = gamemodes.lost
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.keypressed(key)
|
function love.keypressed(key)
|
||||||
|
@ -963,6 +1028,7 @@ function love.draw()
|
||||||
if not debug then
|
if not debug then
|
||||||
drawPlayer()
|
drawPlayer()
|
||||||
end
|
end
|
||||||
|
drawHP()
|
||||||
elseif game_mode == gamemodes.won then
|
elseif game_mode == gamemodes.won then
|
||||||
drawWin()
|
drawWin()
|
||||||
elseif game_mode == gamemodes.lost then
|
elseif game_mode == gamemodes.lost then
|
||||||
|
|
Loading…
Reference in New Issue