Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enemy = {}
- enemies_controller = {}
- enemies_controller.enemies = {}
- function love.load()
- player = {}
- player.x = 0
- player.y = 450
- player.bullets = {}
- player.cooldown = 20
- player.speed = 1
- player.fire = function()
- if player.cooldown <= 0 then
- player.cooldown = 20
- bullet = {}
- bullet.x = player.x + 5
- bullet.y = player.y
- table.insert(player.bullets, bullet)
- end
- end
- enemies_controller:spawnEnemy(0,0)
- enemies_controller:spawnEnemy(100, 0)
- end
- function enemies_controller:spawnEnemy(x, y)
- enemies = {}
- enemy = {}
- enemy.x = x
- enemy.y = y
- enemy.bullets = {}
- enemy.cooldown = 20
- enemy.speed = 1
- table.insert(self.enemies, enemy)
- end
- function enemy:fire()
- if self.cooldown <= 0 then
- self.cooldown = 20
- bullet = {}
- bullet.x = self.x + 5
- bullet.y = self.y
- table.insert(self.bullets, bullet)
- end
- end
- function love.update(dt)
- player.cooldown = player.cooldown - 0.1
- if love.keyboard.isDown('a') then
- player.x = player.x - player.speed
- end
- if love.keyboard.isDown('d') then
- player.x = player.x + player.speed
- end
- if love.keyboard.isDown("space") then
- player.fire()
- end
- for _,e in pairs(enemies_controller.enemies) do
- e.y = e.y + 0.2
- end
- for i,b in ipairs(player.bullets) do
- if b.y < -10 then
- table.remove(player.bullets, i)
- end
- b.y = b.y - 0.7
- end
- end
- function love.draw()
- ---Draw the Player, kthxbye
- love.graphics.setColor(0, 0, 255)
- love.graphics.rectangle("fill", player.x, player.y, 20, 20)
- ---Draw the Enemy, kthxbye
- love.graphics.setColor(255,0,0)
- for _,e in pairs(enemies_controller.enemies) do
- love.graphics.rectangle("fill", e.x, e.y, 20, 20)
- end
- ---Draw bullets, kthxbye
- love.graphics.setColor(255,255,255)
- for _,b in pairs(player.bullets) do
- love.graphics.rectangle("fill", b.x, b.y, 10, 10)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement