Compare commits

...

3 Commits

Author SHA1 Message Date
lee2sman 35b2255f8b add generative text 2022-05-14 02:39:16 -04:00
lee2sman 89130f4534 added chaser animated sprite. stops current drone when collides with
player. moves randomly.
2022-05-14 01:11:07 -04:00
lee2sman 18c46b7a3a add folder with example output to .gitignore 2022-05-14 00:14:42 -04:00
2 changed files with 103 additions and 6 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/assets/*
/out

108
main.lua
View File

@ -6,8 +6,13 @@ function love.load()
load_sprites()
load_font()
load_data()
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,17 +25,26 @@ function love.load()
create_player()
create_portal()
create_chaser()
choose_drone()
change_title()
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)
change_title()
elseif terrain<5 and sound_switched == false then
stop_old_drone(current_drone)
choose_drone()
sound_switched = true
@ -51,6 +65,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 +93,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()
@ -85,6 +105,8 @@ function love.draw()
draw_player()
draw_portal()
draw_text()
end
function load_sounds()
@ -119,11 +141,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 +161,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 +173,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 +204,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 +218,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 = {}
@ -262,5 +316,47 @@ function check_player_on_portal()
create_grid()
choose_drone()
create_portal()
change_title()
end
end
function load_data()
environment = {}
for line in love.filesystem.lines("assets/data/environments.txt") do
table.insert(environment, line)
end
sense = {}
for line in love.filesystem.lines("assets/data/senses.txt") do
table.insert(sense, line)
end
transition = {}
for line in love.filesystem.lines("assets/data/transition.txt") do
table.insert(transition, line)
end
end
function draw_text()
love.graphics.print(title, 100, 100)
end
function change_title()
current_env = environment[love.math.random(#environment)]
current_sense = sense[love.math.random(#sense)]
current_transition = transition[love.math.random(#transition)]
if love.math.random(2)>1 then
title=current_transition..' '..current_env
else
title=current_sense..' of '..current_env
end
end
function load_font()
font = love.graphics.newFont(18)
love.graphics.setFont(font)
end