Skip to content

Commit

Permalink
Merge branch 'new-enemy'
Browse files Browse the repository at this point in the history
  • Loading branch information
sornas committed Nov 10, 2019
2 parents 228687a + b74944d commit 5a76cbc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
12 changes: 7 additions & 5 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,14 @@ function love.update(dt)
for i, shot in pairs(shots) do
for j, enemy in pairs(enemies) do
if collision.collisionTest(shot.shape, enemy.shape) then
if curr_damage > 1 then
curr_damage = curr_damage - 1
if enemy.object_type ~= "invinc" then
if curr_damage > 1 then
curr_damage = curr_damage - 1
end
sound_enemy_hit:play()
table.remove(shots, i)
table.remove(enemies, j)
end
sound_enemy_hit:play()
table.remove(shots, i)
table.remove(enemies, j)
end
end
end
Expand Down
11 changes: 8 additions & 3 deletions modes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mode_see = {
func_key_released = stop_rotate_on_key,
func_update = function(dt)
reset_movements()
rotate(player, dt)
player:rotate(dt)
update(player)
update_other_objects(dt)
end,
Expand All @@ -27,7 +27,7 @@ mode_move = {
func_key_released = stop_move_on_key,
func_update = function(dt)
reset_rotations()
move(player,dt)
move(player, dt)
update(player)
update_other_objects(dt)
end,
Expand Down Expand Up @@ -79,8 +79,13 @@ function update_other_objects(dt)
if enemies_spawned < math.floor(game_time / enemy_spawn_interval) then
-- e.g. game_time = 6.01 => game_time / enemy_interval = 3.005
-- so if enemies_spawned == 2 then spawn
sound_enemy_spawn:play()
enemies_spawned = enemies_spawned + 1
spawn_enemy()
if game_time > 60 then
enemies[#enemies + 1] = random_of_two(spawn_enemy(), spawn_invinc_enemy())
else
enemies[#enemies + 1] = spawn_enemy()
end
end
for i, enemy in pairs(enemies) do
enemy:move(dt)
Expand Down
22 changes: 18 additions & 4 deletions objects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function spawn(object_type, args)
enemy.round = 0
enemy.filling = "fill"
enemy.shape = c.makeRect(enemy.x, enemy.y, enemy.width, enemy.height)
enemy.draw = get_value(args, "draw", draw_rectangle)
enemy.draw = get_value(args, "draw", draw_single_rectangle)
enemy.move = get_value(args, "move", move)
enemy.update = get_value(args, "update", update)
return enemy
Expand Down Expand Up @@ -127,13 +127,19 @@ function spawn_enemy()
args.x_speed = math.random(min_speed, max_speed) -- TODO: Change max/ min when "levelup"
args.y_speed = math.random(min_speed, max_speed)

enemies[#enemies + 1] = spawn("enemy", args)
return spawn("enemy", args)
end

sound_enemy_spawn:play()
function spawn_invinc_enemy()
local enemy = spawn_enemy()
enemy.object_type = "invinc"
enemy.filling = "line"
enemy.x_speed = enemy.x_speed * 2
enemy.y_speed = enemy.y_speed * 2
return enemy
end

-- Draw functions

function draw_rectangle(object)
love.graphics.push()
love.graphics.translate(object.x, object.y)
Expand All @@ -145,6 +151,14 @@ function draw_rectangle(object)
love.graphics.pop()
end

function draw_single_rectangle(object)
love.graphics.push()
love.graphics.translate(object.x, object.y)
love.graphics.rotate(object.rotation)
love.graphics.rectangle(object.filling, - (object.width / 2), - (object.height / 2), object.width, object.height)
love.graphics.pop()
end

function draw_ellipse(object)
love.graphics.push()
love.graphics.translate(object.x, object.y)
Expand Down

0 comments on commit 5a76cbc

Please sign in to comment.