Skip to content

Commit

Permalink
invinc enemy
Browse files Browse the repository at this point in the history
  • Loading branch information
sornas committed Nov 10, 2019
1 parent 660720b commit b74944d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
8 changes: 5 additions & 3 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ 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
sound_enemy_hit:play()
table.remove(shots, i)
table.remove(enemies, j)
if enemy.object_type ~= "invinc" then
sound_enemy_hit:play()
table.remove(shots, i)
table.remove(enemies, j)
end
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 @@ -80,8 +80,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 b74944d

Please sign in to comment.