added chaser animated sprite. stops current drone when collides with

player. moves randomly.
This commit is contained in:
lee2sman 2022-05-14 01:11:07 -04:00
parent 18c46b7a3a
commit 89130f4534
1 changed files with 50 additions and 6 deletions

View File

@ -8,6 +8,7 @@ function love.load()
player = newAnimation(love.graphics.newImage("assets/img/animation/player-test-size.png"),20,30,1)
fog = newAnimation(love.graphics.newImage("assets/img/fog/fog-sheet-resize.png"),20,30,1)
chaser = newAnimation(love.graphics.newImage("assets/img/chaser/dr2.png"),26,33,1)
block_width = sprite[1]:getWidth()
block_height = sprite[1]:getHeight()
@ -20,6 +21,7 @@ function love.load()
create_player()
create_portal()
create_chaser()
choose_drone()
@ -27,10 +29,14 @@ end
function love.update(dt)
move_chaser()
local terrain = get_terrain(p_x,p_y)
--play drone corresponding to current space if not playing
if terrain<5 and sound_switched == false then
if p_x == chaser_x and p_y == chaser_y then
stop_old_drone(current_drone)
elseif terrain<5 and sound_switched == false then
stop_old_drone(current_drone)
choose_drone()
sound_switched = true
@ -51,6 +57,12 @@ function love.update(dt)
fog.currentTime = fog.currentTime - fog.duration
end
--chaser animation
chaser.currentTime = chaser.currentTime + dt
if chaser.currentTime >= chaser.duration then
chaser.currentTime = chaser.currentTime - chaser.duration
end
end
function love.keypressed(key)
@ -73,8 +85,8 @@ function love.keypressed(key)
if p_x>10 then p_x = 10 end
if p_y>10 then p_y = 10 end
print('player x: '..p_x..' y: '..p_y)
print('grid piece there: '..grid[p_x][p_y])
--print('player x: '..p_x..' y: '..p_y)
--print('grid piece there: '..grid[p_x][p_y])
check_player_on_portal()
@ -119,11 +131,18 @@ end
function create_portal()
portal_x = love. math.random(10)
portal_y = love.math.random(10)
print('portal created at '..portal_x,portal_y)
--print('portal created at '..portal_x,portal_y)
building_base = love.math.random(#building_sprite-6)
end
function create_chaser()
chaser_x= love. math.random(10)
chaser_y = love.math.random(10)
--print('chaser created '..chaser_x..','..chaser_y)
end
function draw_grid()
for x = 1,grid_size do
for y = 1,grid_size do
@ -132,8 +151,8 @@ function draw_grid()
grid_x + ((y-x) * (block_width / 2)),
grid_y + ((x+y) * (block_depth / 2)) - (block_depth * (grid_size / 2)) - block_depth)
--draw fog on terrain<5
if grid[x][y]<4 then
--draw fog on terrain<3
if grid[x][y]<3 then
draw_fog(x,y)
end
@ -144,6 +163,13 @@ function draw_grid()
grid_y + ((x+y) * (block_depth / 2)) - (block_depth * (grid_size / 2)) - block_depth)
end
--draw chaser
if x == chaser_x and y == chaser_y then
draw_chaser(x,y)
end
end
end
@ -168,6 +194,13 @@ function draw_fog(fog_x,fog_y)
end
function draw_chaser(chaser_x,chaser_y)
local spriteNum = math.floor(chaser.currentTime / chaser.duration * #chaser.quads) + 1
love.graphics.draw(chaser.spriteSheet, chaser.quads[spriteNum], grid_x + ((chaser_x-chaser_y) * (block_width / 2)) + block_width/4, grid_y + ((chaser_x+chaser_y) * (block_depth / 2)) - (block_depth * (grid_size / 2)) - block_depth - block_height/8, 0, 2)
end
function draw_portal()
local spriteNum = math.floor(player.currentTime / player.duration * 2) + building_base
@ -175,6 +208,17 @@ function draw_portal()
end
function move_chaser()
if chaser_x<1 then chaser_x = 1 end
if chaser_y<1 then chaser_y = 1 end
if chaser_x>10 then chaser_x = 10 end
if chaser_y>10 then chaser_y = 10 end
if love.math.random(100)<3 then
chaser_x = chaser_x + love.math.random(-1,1)
chaser_y = chaser_y + love.math.random(-1,1)
end
--print('chaser_x '..chaser_x..' chaser_y '..chaser_y)
end
function newAnimation(image, width, height, duration)
local player = {}