diff --git a/entities/e-fighter.lua b/entities/e-fighter.lua new file mode 100644 index 0000000..5cb9f60 --- /dev/null +++ b/entities/e-fighter.lua @@ -0,0 +1,40 @@ +--! file: e-fighter.lua +require("entities.enemy") + +local E_Fighter = Enemy:extend() + +function E_Fighter:new(x, y, radius, playableArea) + E_Fighter.super.new(x, y, radius, playableArea) + + self.image = love.graphics.newImage("/assets/enemy/e-fighter.png") + + self.type = "enemy fighter" + self.health = 10 + self.speed = 70 + self.scoreValue = 100 + self.fireRate = 1 + + self.height = 22 + self.width = 24 + self.x_offset = 18 + self.y_offset = 20 +end + +function E_Fighter:draw() + love.graphics.draw( + self.image, + self.x, + self.y, + 3.14159, + 1, + 1, + (self.x_offset + self.width * 2 - 4), + (self.y_offset + self.height * 2) + ) + + for _, v in ipairs(self.enemyBullets) do + v:draw() + end +end + +function E_Fighter:update() end diff --git a/entities/enemy-copy.lua b/entities/enemy-copy.lua new file mode 100644 index 0000000..23cd18f --- /dev/null +++ b/entities/enemy-copy.lua @@ -0,0 +1,140 @@ +--! file enemy.lua +require("blaster") +Enemy = Object:extend() + +--int x, y, radius +--playableArea -> {int[2]} +function Enemy:new(x, y, radius, playableArea) + self.origin = { x, y } + self.image = love.graphics.newImage("/assets/enemy/e-fighter.png") + + self.x = x + self.y = y + self.playableLeft = playableArea[1] + self.playableRight = playableArea[2] + + self.type = "enemy" + self.health = 10 + self.scoreValue = 100 + self.move_radius = radius + self.speed = 80 + self.fireRate = 1 + self.destroy = false + + self.height = 22 + self.width = 24 + self.x_offset = 18 + self.y_offset = 20 + + self.hitbox = { + (self.x + self.x_offset), + (self.x + self.x_offset + self.width), + (self.y + self.y_offset), + (self.y + self.y_offset + self.height), + } + + self.move_bounds = self:setMoveBounds() + --print("Move Bounds: ", self.move_bounds[1], " , ", self.move_bounds[2]) + self.fireTime = love.timer.getTime() + self.enemyBullets = {} +end + +function Enemy:draw() + --draw stuff + --for the base class, draw the hitbox + --if the enemy is destroyed, remove the image and display the score for two seconds + love.graphics.rectangle("line", self.hitbox[1], self.hitbox[3], self.width, self.height) + --TODO: Resolve this magic number bullshit on line 52. (Why do I subtract 4?) + love.graphics.draw( + self.image, + self.x, + self.y, + 3.14159, + 1, + 1, + (self.x_offset + self.width * 2 - 4), + (self.y_offset + self.height * 2) + ) + + for _, v in ipairs(self.enemyBullets) do + v:draw() + end +end + +function Enemy:update(dt, player) + -- if spawn location is near the edge, adjust the bounds such that the radius + -- does not overlap the bounds of the playable area + local window_height = love.graphics.getHeight() + + self.x = self.x + self.speed * dt + --self.hitbox = { (self.x + 18), (self.x + 44), (self.y + 20), (self.y + 44) } + self:setHitbox() + + --movement + if self.hitbox[1] < self.move_bounds[1] then + --self.x = self.move_bounds[1] + self.speed = -self.speed + elseif self.hitbox[2] > self.move_bounds[2] then + --self.x = self.move_bounds[2] - self.width - self.x_offset + self.speed = -self.speed + end + + --firing! + self:fire() + + for i, v in ipairs(self.enemyBullets) do + v:update(dt) + + if v.y > window_height then + v.destroy = true + end + + if v.destroy == true then + --print("Enemy Bullet Removed! Bullets in table remaining: ", #enemyBullets) + table.remove(self.enemyBullets, i) + end + + v:checkCollision(player) + end + --health check + if self.health < 0 then + self.destroy = true + end +end + +--shoot at the player a variable number of seconds +function Enemy:fire() + --local fire_origin = { self.x + 26, self.y + 44 } + local fire_origin = { ((self.x + (self.width / 2)) + self.x_offset), (self.y + self.height + self.y_offset) } + if love.timer.getTime() - self.fireTime > self.fireRate then + table.insert(self.enemyBullets, Blaster(fire_origin[1], fire_origin[2], "enemy")) + self.fireTime = love.timer.getTime() + end +end + +function Enemy:setMoveBounds() + local result = {} + + if (self.hitbox[1] - self.move_radius) < self.playableLeft then + result[1] = self.playableLeft + --result[2] = self.playableLeft + self.hitbox[1] + self.move_radius + result[2] = self.playableLeft + (self.move_radius * 2) + elseif (self.hitbox[2] + self.move_radius) > self.playableRight then + --result[1] = self.playableRight - self.hitbox[2] - self.move_radius + result[1] = self.playableRight - (self.move_radius * 2) + result[2] = self.playableRight + else + result[1] = self.x - self.move_radius + result[2] = self.x + self.move_radius + end + return result +end + +function Enemy:setHitbox() + self.hitbox = { + (self.x + self.x_offset), + (self.x + self.width + self.x_offset), + (self.y + self.y_offset), + (self.y + self.height + self.y_offset), + } +end diff --git a/entities/enemy.lua b/entities/enemy.lua index 9857197..23cd18f 100644 --- a/entities/enemy.lua +++ b/entities/enemy.lua @@ -15,6 +15,7 @@ function Enemy:new(x, y, radius, playableArea) self.type = "enemy" self.health = 10 + self.scoreValue = 100 self.move_radius = radius self.speed = 80 self.fireRate = 1 @@ -40,6 +41,8 @@ end function Enemy:draw() --draw stuff + --for the base class, draw the hitbox + --if the enemy is destroyed, remove the image and display the score for two seconds love.graphics.rectangle("line", self.hitbox[1], self.hitbox[3], self.width, self.height) --TODO: Resolve this magic number bullshit on line 52. (Why do I subtract 4?) love.graphics.draw( diff --git a/main.lua b/main.lua index 6c17b8b..d3be691 100644 --- a/main.lua +++ b/main.lua @@ -2,6 +2,7 @@ Object = require("scripts.classic") require("entities.player") require("entities.enemy") require("userInterface") +require("masterController") function love.load() --adjust the screen and set the bounds of the UI @@ -13,6 +14,7 @@ function love.load() print("Playable Bounds: ", bounds[1], " , ", bounds[2]) --place the player in the middle of the screen, close to the bottom Player = Player(window_width / 2, window_height * 0.9, bounds) + Controller = MasterController() ListOfEnemies = {} diff --git a/masterController.lua b/masterController.lua new file mode 100644 index 0000000..fd4d681 --- /dev/null +++ b/masterController.lua @@ -0,0 +1,22 @@ +--! file: mastercontroller.lua +--This is the master game controller for my little space game + +function MasterController:new(bounds) + self.score = 0 + self.lives = 3 + self.playableBounds = bounds +end + +function MasterController:spawnEnemy() end +--Handle game stages +--Stage Types: Meteor Swarm +--Enemy Attack (various types?) +--Boss Battle + +--Spawn enemies + +--Handle Score / Cash + +--Set interlevel bid from Space Cop or Space Waifu + +--End of Level Ledger / Score Sheet