]> Untitled Git - lightcycles-love.git/commitdiff
Added player
authorClifton James Palmer <clifton.palmer@gmail.com>
Fri, 7 Dec 2018 23:49:38 +0000 (17:49 -0600)
committerClifton James Palmer <clifton.palmer@gmail.com>
Fri, 7 Dec 2018 23:49:38 +0000 (17:49 -0600)
main.lua
player.lua [new file with mode: 0644]

index b4dd09cfb30ff9a5cba51596a5410b7f9b3fc4bf..804c413d7249eaf9e63139610690bfa4b9056812 100644 (file)
--- a/main.lua
+++ b/main.lua
@@ -1,13 +1,18 @@
 -- main
 
 -- main
 
+require 'player'
+
 function love.load()
 function love.load()
+    player = Player:new({position={x=100, y=100}})
 end
 
 function love.draw()
     -- set bg
 end
 
 function love.draw()
     -- set bg
-    love.graphics.setBackgroundColor(0.2, 0.2, 0.5)
+    local bgcolor = {0.2, 0.2, 0.5}
+    love.graphics.setBackgroundColor(bgcolor)
 
     -- draw basic grid
 
     -- draw basic grid
+    love.graphics.setColor(0.3, 0.3, 0.6)
     local width = love.graphics.getWidth()
     local height = love.graphics.getHeight()
     local delta = 50
     local width = love.graphics.getWidth()
     local height = love.graphics.getHeight()
     local delta = 50
@@ -19,10 +24,14 @@ function love.draw()
     for y=0,height,delta do
         love.graphics.line(0, y, width, y)
     end
     for y=0,height,delta do
         love.graphics.line(0, y, width, y)
     end
+
+    -- misc
+    player:draw()
 end
 
 function love.update(dt)
     if love.keyboard.isDown('escape') then
         love.event.quit()
     end
 end
 
 function love.update(dt)
     if love.keyboard.isDown('escape') then
         love.event.quit()
     end
+    player:update(dt)
 end
 end
diff --git a/player.lua b/player.lua
new file mode 100644 (file)
index 0000000..0bf6990
--- /dev/null
@@ -0,0 +1,35 @@
+Player = {}
+Player.name = 'player'
+Player.color = {255, 0, 0}
+Player.width = 5
+Player.height = 5
+Player.acceleration = 100
+Player.position = {x=0, y=0}
+Player.vector = {x=0, y=0}
+
+function Player:new(o)
+    o = o or {}
+    setmetatable(o, self)
+    self.__index = self
+    return o
+end
+
+function Player:draw()
+    love.graphics.setColor(self.color)
+    love.graphics.rectangle('fill', self.position.x, self.position.y, self.width, self.height)
+end
+
+function Player:update(dt)
+    if love.keyboard.isDown("w") then
+        self.vector = {x=0, y=-self.acceleration}
+    elseif love.keyboard.isDown("s") then
+        self.vector = {x=0, y=self.acceleration}
+    elseif love.keyboard.isDown("a") then
+        self.vector = {x=-self.acceleration, y=0}
+    elseif love.keyboard.isDown("d") then
+        self.vector = {x=self.acceleration, y=0}
+    end
+
+    self.position.x = self.position.x + self.vector.x * dt
+    self.position.y = self.position.y + self.vector.y * dt
+end