From b0a7c55e078a5605b3f442bc47b7b1a0c2bfc30a Mon Sep 17 00:00:00 2001 From: lee2sman Date: Thu, 12 May 2022 19:14:02 -0400 Subject: [PATCH] updated player location (moved y down a bit), added plants and random objects. added echo and reverb audio effects. hitting an object (any sprite less than 5 currently) will end past drone and start new one. --- main.lua | 69 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/main.lua b/main.lua index 4621726..f3394f4 100644 --- a/main.lua +++ b/main.lua @@ -18,13 +18,26 @@ function love.load() grid_y = love.graphics.getHeight()/2 create_player() + + choose_drone() + end function love.update(dt) - player_dr.currentTime = player_dr.currentTime + dt - if player_dr.currentTime >= player_dr.duration then - player_dr.currentTime = player_dr.currentTime - player_dr.duration - end + + local terrain = get_terrain(p_x,p_y) + + if terrain<5 then + stop_old_drone(current_drone) + choose_drone() + end + play_drone(current_drone) + + player_dr.currentTime = player_dr.currentTime + dt + + if player_dr.currentTime >= player_dr.duration then + player_dr.currentTime = player_dr.currentTime - player_dr.duration + end end function love.keypressed(key) @@ -49,13 +62,10 @@ function love.keypressed(key) print('player x: '..p_x..' y: '..p_y) print('grid piece there: '..grid[p_x][p_y]) - local terrain_type = get_terrain(p_x,p_y) - play_drone(terrain_type) end function love.draw() - draw_grid() draw_player() end @@ -65,7 +75,7 @@ function load_sounds() local files = love.filesystem.getDirectoryItems(dir) drone = {} for k, file in ipairs(files) do - print(k .. ". " .. file) --list all soundfiles as loading + --print(k .. ". " .. file) --list all soundfiles as loading drone[k] = love.audio.newSource(dir..file, "stream") end @@ -77,7 +87,6 @@ function create_grid() for x = 1,grid_size do grid[x] = {} for y = 1,grid_size do - --make that space grass (1) --make space a random tile grid[x][y] = love.math.random(#sprite) end @@ -109,7 +118,7 @@ end function draw_player() local spriteNum = math.floor(player_dr.currentTime / player_dr.duration * #player_dr.quads) + 1 - love.graphics.draw(player_dr.spriteSheet, player_dr.quads[spriteNum], grid_x + ((p_y-p_x) * (block_width / 2)) + block_width/4, grid_y + ((p_x+p_y) * (block_depth / 2)) - (block_depth * (grid_size / 2)) - block_depth - block_height/2, 0, 2) + love.graphics.draw(player_dr.spriteSheet, player_dr.quads[spriteNum], grid_x + ((p_y-p_x) * (block_width / 2)) + block_width/4, grid_y + ((p_x+p_y) * (block_depth / 2)) - (block_depth * (grid_size / 2)) - block_depth - block_height/8, 0, 2) end @@ -135,7 +144,16 @@ function get_terrain(x,y) end function play_drone(terrain) - drone[terrain]:play() + if not drone[terrain]:isPlaying() then + + love.audio.setEffect('dronezone', {type = 'reverb'}) + love.audio.setEffect('cave', {type = 'echo'}) + + drone[terrain]:setEffect('cave') + drone[terrain]:setEffect('ensemble') + + love.audio.play(drone[terrain]) + end end function load_sprites() @@ -143,9 +161,36 @@ function load_sprites() local dir = 'assets/img/ground/' local files = love.filesystem.getDirectoryItems(dir) sprite = {} + + --load terrain for k, file in ipairs(files) do - print(k .. ". " .. file) --list all sprites as loading + --print(k .. ". " .. file) --list all sprites as loading sprite[k] = love.graphics.newImage(dir..file) end + --sprinkle some plants in + + local dir = 'assets/img/plants/' + local files = love.filesystem.getDirectoryItems(dir) + for i=1,5 do + sprite[love.math.random(#sprite)] = love.graphics.newImage(dir..files[love.math.random(#files)]) + end + + --sprinkle some special objects in + local dir = 'assets/img/objects/' + local files = love.filesystem.getDirectoryItems(dir) + + --cycle through all tiles, replace all low number ones <5 + for j=1,10 do + sprite[j] = love.graphics.newImage(dir..files[love.math.random(#files)]) + end + +end + +function choose_drone() + current_drone = love.math.random(#drone) +end + +function stop_old_drone(old_drone) + love.audio.stop(drone[old_drone]) end