initial commit

This commit is contained in:
lee2sman 2022-05-08 02:13:52 -04:00
commit c37ff58dd8
3 changed files with 197 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/assets/*

32
README.md Normal file
View File

@ -0,0 +1,32 @@
# Drone Collector
IN-PROGRESS!
A roguelike sound collection drone-strument toy.
Created for Drone Jam, May 7 - 14, 2022.
Built in Love2d.
[Drone Jam](https://itch.io/jam/drone)
### Inspiration
[The Beachcomber - audio excerpt from Ocean Hour - rebroadcast on This American Life](https://www.thisamericanlife.org/714/day-at-the-beach/act-three-13)
[Discobog - Algobog DJed episode by Saltzshaker on WFMU](https://wfmu.org/playlists/shows/108956)
### Tutorials
[Render Isometric Tiles](https://love2d.org/wiki/Tutorial:Isometric_Graphics)
[Animation](https://love2d.org/wiki/Tutorial:Animation)
[From Processing (and p5.js) to Love by me](https://github.com/lee2sman/processing-to-love)
## Credits
[Mushy tileset by Everest Pipkin and contributors](https://everestpipkin.itch.io/mushy)
CC-BY-3.0
[Isometric Character by Elska](https://elska.itch.io/isometric-being)

164
main.lua Normal file
View File

@ -0,0 +1,164 @@
function love.load()
load_sounds()
--load graphics
dirt = love.graphics.newImage("assets/img/dirt.png")
grass = love.graphics.newImage("assets/img/grass.png")
player_dr = newAnimation(love.graphics.newImage("assets/img/player/DR.png"),20,25,1)
block_width = grass:getWidth()
block_height = grass:getHeight()
block_depth = block_height / 2
create_grid()
grid_x = love.graphics.getWidth()/2
grid_y = love.graphics.getHeight()/2
create_player()
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
end
function love.keypressed(key)
drone[math.random(#drone)]:play()
if key == 'up' or key == 'down' or key == 'left' or key == 'right' then
local playerX
local playerY
for testY, row in ipairs(level) do
for testX, cell in ipairs(row) do
if cell == player or cell == playerOnStorage then
playerX = testX
playerY = testY
end
end
end
local dx = 0
local dy = 0
if key == 'left' then
dx = -1
elseif key == 'right' then
dx = 1
elseif key == 'up' then
dy = -1
elseif key == 'down' then
dy = 1
end
local current = level[playerY][playerX]
local adjacent = level[playerY + dy][playerX + dx]
local nextAdjacent = {
[empty] = player,
[storage] = playerOnStorage,
}
local nextCurrent = {
[player] = empty,
[playerOnStorage] = storage,
}
if nextAdjacent[adjacent] then
level[playerY][playerX] = nextCurrent[current]
level[playerY + dy][playerX + dx] = nextAdjacent[adjacent]
--play a random drone
--drone[1]:play()
drone[math.random(#drone)]:play()
end
end
end
function love.draw()
draw_grid()
draw_player()
end
function load_sounds()
drone = {}
for i=1,11
do
drone[i] = love.audio.newSource("assets/audio/"..i..".mp3", "stream")
end
end
function create_grid()
grid_size = 10
grid = {}
for x = 1,grid_size do
grid[x] = {}
for y = 1,grid_size do
--make that space grass (1)
grid[x][y] = 1
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
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,
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
--draw player
--love.graphics.draw(dr, grid_x, grid_y - block_depth * 2)
end
function newAnimation(image, width, height, duration)
local player_dr = {}
player_dr.spriteSheet = image;
player_dr.quads = {};
for y = 0, image:getHeight() - height, height do
for x = 0, image:getWidth() - width, width do
table.insert(player_dr.quads, love.graphics.newQuad(x, y, width, height, image:getDimensions()))
end
end
player_dr.duration = duration or 1
player_dr.currentTime = 0
return player_dr
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], player_x, player_y, 0, 2)
end