loaded all ground tiles, load all drone sound files. each terrain tile
is tied 1 to 1 to the same numbered drone sound that is played when a player walks onto it.
This commit is contained in:
parent
1c17c90d93
commit
64953b94b9
58
main.lua
58
main.lua
|
@ -4,13 +4,12 @@ function love.load()
|
|||
|
||||
load_sounds()
|
||||
|
||||
--load graphics
|
||||
dirt = love.graphics.newImage("assets/img/dirt.png")
|
||||
grass = love.graphics.newImage("assets/img/grass.png")
|
||||
load_sprites()
|
||||
|
||||
player_dr = newAnimation(love.graphics.newImage("assets/img/animation/player-test-size.png"),20,30,1)
|
||||
|
||||
block_width = grass:getWidth()
|
||||
block_height = grass:getHeight()
|
||||
block_width = sprite[1]:getWidth()
|
||||
block_height = sprite[1]:getHeight()
|
||||
block_depth = block_height / 2
|
||||
|
||||
create_grid()
|
||||
|
@ -62,10 +61,12 @@ function love.draw()
|
|||
end
|
||||
|
||||
function load_sounds()
|
||||
local dir = 'assets/audio/drones-pack/'
|
||||
local files = love.filesystem.getDirectoryItems(dir)
|
||||
drone = {}
|
||||
for i=1,11
|
||||
do
|
||||
drone[i] = love.audio.newSource("assets/audio/"..i..".mp3", "stream")
|
||||
for k, file in ipairs(files) do
|
||||
print(k .. ". " .. file) --list all soundfiles as loading
|
||||
drone[k] = love.audio.newSource(dir..file, "stream")
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -77,27 +78,17 @@ function create_grid()
|
|||
grid[x] = {}
|
||||
for y = 1,grid_size do
|
||||
--make that space grass (1)
|
||||
grid[x][y] = 1
|
||||
--make space a random tile
|
||||
grid[x][y] = love.math.random(#sprite)
|
||||
end
|
||||
end
|
||||
|
||||
-- number of dirt spaces
|
||||
--local num_dirt = 0
|
||||
local num_dirt = love.math.random(20,40) --convert random spaces to dirt (2)
|
||||
for i=1,num_dirt
|
||||
do
|
||||
--make that random space dirt (2)
|
||||
grid[love.math.random(grid_size)][love.math.random(grid_size)] = 2
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function create_player()
|
||||
player_x = grid_x
|
||||
player_y = grid_y - block_depth * 2
|
||||
player_dir = "downright" -- either 'downright','upright','downleft','upleft'
|
||||
|
||||
--test
|
||||
p_x = 1
|
||||
p_y = 1
|
||||
end
|
||||
|
@ -105,15 +96,11 @@ end
|
|||
function draw_grid()
|
||||
for x = 1,grid_size do
|
||||
for y = 1,grid_size do
|
||||
if grid[x][y] == 1 then
|
||||
love.graphics.draw(grass,
|
||||
|
||||
love.graphics.draw(sprite[grid[x][y]],
|
||||
grid_x + ((y-x) * (block_width / 2)),
|
||||
grid_y + ((x+y) * (block_depth / 2)) - (block_depth * (grid_size / 2)) - block_depth)
|
||||
else -- grid[x][y] == 2
|
||||
love.graphics.draw(dirt,
|
||||
grid_x + ((y-x) * (block_width / 2)),
|
||||
grid_y + ((x+y) * (block_depth / 2)) - (block_depth * (grid_size / 2)) - block_depth)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -122,8 +109,6 @@ end
|
|||
function draw_player()
|
||||
local spriteNum = math.floor(player_dr.currentTime / player_dr.duration * #player_dr.quads) + 1
|
||||
|
||||
--test
|
||||
--love.graphics.draw(player_dr.spriteSheet, player_dr.quads[spriteNum], player_x, player_y, 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/2, 0, 2)
|
||||
|
||||
end
|
||||
|
@ -150,12 +135,17 @@ function get_terrain(x,y)
|
|||
end
|
||||
|
||||
function play_drone(terrain)
|
||||
--test
|
||||
--drone[math.random(#drone)]:play()
|
||||
drone[terrain]:play()
|
||||
end
|
||||
|
||||
--print('terrain type '..terrain)
|
||||
function load_sprites()
|
||||
|
||||
--sound varies more with more rare (higher number) terrain type
|
||||
drone[math.random(terrain)]:play()
|
||||
local dir = 'assets/img/ground/'
|
||||
local files = love.filesystem.getDirectoryItems(dir)
|
||||
sprite = {}
|
||||
for k, file in ipairs(files) do
|
||||
print(k .. ". " .. file) --list all sprites as loading
|
||||
sprite[k] = love.graphics.newImage(dir..file)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue