Create a sprite for the player
This commit is contained in:
parent
f5ba1bdb17
commit
32a9d7627a
2
Makefile
2
Makefile
|
@ -6,7 +6,7 @@ NIX_TARBALL=eitmer-nix.tar.gz
|
|||
|
||||
all: $(LOVEFILE) $(WIN32_ZIPBALL) $(NIX_TARBALL)
|
||||
|
||||
$(LOVEFILE): bundle/main.lua bundle/conf.lua bundle/win_image.png
|
||||
$(LOVEFILE): bundle/main.lua bundle/conf.lua bundle/win_image.png bundle/sprite.png bundle/sprite_crit.png bundle/sprite_damaged.png
|
||||
cd bundle; zip -9 -r ../$@ *
|
||||
|
||||
$(WIN32_ZIPBALL): $(LOVEFILE) CC0 README
|
||||
|
|
|
@ -15,8 +15,12 @@ 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 flash_player_crit_counter = 0
|
||||
local flash_player_damaged_counter = 0
|
||||
local player_sprite = nil
|
||||
local player_sprite_crit = nil
|
||||
local player_sprite_damaged = nil
|
||||
local player_animation_flip = false
|
||||
|
||||
local slimes = {}
|
||||
|
||||
|
@ -684,23 +688,25 @@ function step(direction)
|
|||
killSlime()
|
||||
hp = hp - 1
|
||||
if hp == 0 then
|
||||
flash_player_red_counter = 1
|
||||
flash_player_damaged_counter = 1
|
||||
else
|
||||
flash_player_red_counter = 0.2
|
||||
flash_player_damaged_counter = 0.2
|
||||
end
|
||||
elseif cavern[player_x][player_y] == tiletypes.slime then
|
||||
killSlime()
|
||||
if math.random() < 0.2 then
|
||||
flash_player_white_counter = 0.2
|
||||
flash_player_crit_counter = 0.2
|
||||
else
|
||||
hp = hp - 1
|
||||
if hp == 0 then
|
||||
flash_player_red_counter = 1
|
||||
flash_player_damaged_counter = 1
|
||||
else
|
||||
flash_player_red_counter = 0.2
|
||||
flash_player_damaged_counter = 0.2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
player_animation_flip = not player_animation_flip
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -897,28 +903,44 @@ function drawPlayer()
|
|||
local x_offset = (screen_width - cavern.width * scale) / 2
|
||||
local y_offset = (screen_height - cavern.height * scale) / 2
|
||||
|
||||
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
|
||||
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 x = (player_x - 1) * scale + x_offset
|
||||
local y = (player_y - 1) * scale + y_offset
|
||||
|
||||
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
|
||||
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)
|
||||
local sprite = nil
|
||||
if flash_player_damaged_counter > 0 then
|
||||
sprite = player_sprite_damaged
|
||||
elseif flash_player_crit_counter > 0 then
|
||||
sprite = player_sprite_crit
|
||||
else
|
||||
love.graphics.setColor(0, 0, 1)
|
||||
sprite = player_sprite
|
||||
end
|
||||
|
||||
local rotation = nil
|
||||
if player_direction == directions.up then
|
||||
rotation = 0
|
||||
x = x + scale/2
|
||||
y = y + scale
|
||||
elseif player_direction == directions.left then
|
||||
rotation = math.pi * 1.5
|
||||
x = x + scale
|
||||
y = y + scale/2
|
||||
elseif player_direction == directions.down then
|
||||
rotation = math.pi
|
||||
x = x + scale/2
|
||||
elseif player_direction == directions.right then
|
||||
rotation = math.pi * 0.5
|
||||
y = y + scale/2
|
||||
else
|
||||
error("Player facing a direction without usable sprite")
|
||||
end
|
||||
|
||||
-- Our sprite image is drawn assuming 16 pixels per tile
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
if not player_animation_flip then
|
||||
love.graphics.draw(sprite, x, y, rotation, scale/16, scale/16, scale/2, scale)
|
||||
else
|
||||
love.graphics.draw(sprite, x, y, rotation, -scale/16, scale/16, scale/2, scale)
|
||||
end
|
||||
love.graphics.rectangle('fill', player_body_x, player_body_y, scale, scale)
|
||||
end
|
||||
|
||||
function drawHP()
|
||||
|
@ -1055,6 +1077,10 @@ function love.load()
|
|||
newGame()
|
||||
|
||||
win_image = love.graphics.newImage("win_image.png")
|
||||
|
||||
player_sprite = love.graphics.newImage("sprite.png")
|
||||
player_sprite_crit = love.graphics.newImage("sprite_crit.png")
|
||||
player_sprite_damaged = love.graphics.newImage("sprite_damaged.png")
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
|
@ -1065,12 +1091,12 @@ function love.update(dt)
|
|||
end
|
||||
end
|
||||
|
||||
if flash_player_white_counter > 0 then
|
||||
flash_player_white_counter = flash_player_white_counter - dt
|
||||
if flash_player_crit_counter > 0 then
|
||||
flash_player_crit_counter = flash_player_crit_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
|
||||
if flash_player_damaged_counter > 0 then
|
||||
flash_player_damaged_counter = flash_player_damaged_counter - dt
|
||||
if hp == 0 and flash_player_damaged_counter <= 0 and game_mode ~= gamemodes.won then
|
||||
game_mode = gamemodes.lost
|
||||
end
|
||||
end
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 255 B |
Binary file not shown.
After Width: | Height: | Size: 235 B |
Binary file not shown.
After Width: | Height: | Size: 212 B |
Loading…
Reference in New Issue