From b74944dc89021b83f98a7acbc9963c3131a9cf10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sun, 10 Nov 2019 16:53:52 +0100 Subject: [PATCH] invinc enemy --- main.lua | 8 +++++--- modes.lua | 11 ++++++++--- objects.lua | 22 ++++++++++++++++++---- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/main.lua b/main.lua index ca34cee..4ad9074 100644 --- a/main.lua +++ b/main.lua @@ -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 diff --git a/modes.lua b/modes.lua index ee49d9c..e7ca840 100644 --- a/modes.lua +++ b/modes.lua @@ -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, @@ -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, @@ -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) diff --git a/objects.lua b/objects.lua index a937e05..9d30545 100644 --- a/objects.lua +++ b/objects.lua @@ -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 @@ -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) @@ -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)