3 changed files with 52 additions and 5 deletions
@ -0,0 +1,18 @@ |
|||||
|
Blaster = Object:extend() |
||||
|
|
||||
|
function Blaster:new(x, y) |
||||
|
self.x = x |
||||
|
self.y = y |
||||
|
self.radius = 10 |
||||
|
self.speed = 700 |
||||
|
self.color = { 1, 0, 0 } |
||||
|
end |
||||
|
|
||||
|
function Blaster:draw() |
||||
|
--draw stuff |
||||
|
--love.graphics.circle("fill", self.x, self.y, self.radius) |
||||
|
end |
||||
|
|
||||
|
function Blaster:update(dt) |
||||
|
self.y = self.y - self.speed * dt |
||||
|
end |
||||
@ -1,27 +1,49 @@ |
|||||
--! file: player.lua |
--! file: player.lua |
||||
Player = Object:extend() |
Player = Object:extend() |
||||
|
require("blaster") |
||||
|
|
||||
function Player:new() |
function Player:new(x, y) |
||||
self.x = 100 |
self.x = x |
||||
self.y = 100 |
self.y = y |
||||
self.health = 100 |
self.health = 100 |
||||
self.speed = 100 |
self.speed = 200 |
||||
|
|
||||
|
listOfBullets = {} |
||||
end |
end |
||||
|
|
||||
function Player:update(dt) |
function Player:update(dt) |
||||
|
--movement |
||||
if love.keyboard.isDown("left") then |
if love.keyboard.isDown("left") then |
||||
self.x = self.x - self.speed * dt |
self.x = self.x - self.speed * dt |
||||
end |
end |
||||
if love.keyboard.isDown("right") then |
if love.keyboard.isDown("right") then |
||||
self.x = self.x + self.speed * dt |
self.x = self.x + self.speed * dt |
||||
end |
end |
||||
|
|
||||
|
--bullets! |
||||
|
for _, v in ipairs(listOfBullets) do |
||||
|
v:update(dt) |
||||
|
end |
||||
end |
end |
||||
|
|
||||
function Player:draw() |
function Player:draw() |
||||
local vert = { self.x, self.y, (self.x - 70), (self.y + 70), (self.x + 70), (self.y + 70) } |
local vert = { self.x, self.y, (self.x - 70), (self.y + 70), (self.x + 70), (self.y + 70) } |
||||
love.graphics.polygon("fill", vert) |
love.graphics.polygon("fill", vert) |
||||
|
|
||||
|
for _, v in ipairs(listOfBullets) do |
||||
|
--love.graphics.setColor(v.color) |
||||
|
love.graphics.circle("fill", v.x, v.y, v.radius) |
||||
|
end |
||||
end |
end |
||||
|
|
||||
function Player:keyPressed(key) |
function Player:keyPressed(key) |
||||
|
local fire_origin_x = self.x + 35 |
||||
|
local fire_origin_y = self.y + 35 |
||||
--Add controls here |
--Add controls here |
||||
|
|
||||
|
--Shooting controls |
||||
|
if key == "space" then |
||||
|
--pew pew |
||||
|
table.insert(listOfBullets, Blaster(fire_origin_x, fire_origin_y)) |
||||
|
end |
||||
end |
end |
||||
|
|||||
Loading…
Reference in new issue