This commit is contained in:
Juhani Krekelä 2019-06-30 12:41:27 +03:00
parent 5d9e9113ea
commit 507080a695
1 changed files with 76 additions and 10 deletions

View File

@ -10,9 +10,13 @@ local spawn_x = 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 player_x = nil
local player_y = nil
local player_direction = nil
local hp = nil
local flash_player_white_counter = 0
local flash_player_red_counter = 0
local slimes = {}
@ -162,6 +166,8 @@ function spawnPlayer()
else
error("Cavern is weirdly generated and player cannot spawn")
end
hp = 3
end
function spawnOrb()
@ -688,10 +694,16 @@ function step(direction)
end
if collidedPlayerSlime() then
if math.random(0, 1) == 0 then
game_mode = gamemodes.lost
killSlime()
if math.random() < 0.2 then
flash_player_white_counter = 0.2
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
@ -729,12 +741,12 @@ function drawCavern()
love.graphics.setColor(0.5, 0.3, 0.3)
love.graphics.rectangle('fill', x, y, scale, scale)
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
love.graphics.setColor(0, 0, 0)
love.graphics.rectangle('fill', x, y, scale, scale)
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)
elseif tile == tiletypes.unknown then
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.rectangle('fill', x, y, scale, scale)
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
love.graphics.setColor(0.2, 0.2, 0.2)
love.graphics.rectangle('fill', x, y, scale, scale)
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)
else
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_y = (player_y - 1) * scale + y_offset + 0.5 * scale
love.graphics.setColor(0.6, 0.3, 0.2)
love.graphics.ellipse('fill', player_head_center_x, player_head_center_y, scale/2, scale/2)
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.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_x - 1) * scale + x_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)
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()
local img_width, img_height = win_image:getDimensions()
@ -911,6 +966,16 @@ function love.update(dt)
step(last_direction_moved)
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
function love.keypressed(key)
@ -963,6 +1028,7 @@ function love.draw()
if not debug then
drawPlayer()
end
drawHP()
elseif game_mode == gamemodes.won then
drawWin()
elseif game_mode == gamemodes.lost then