From 563818b0b7ba905cde2674655e1817549b8dd4d9 Mon Sep 17 00:00:00 2001 From: Matthew Ryan Dillon Date: Mon, 21 Apr 2025 16:27:17 -0400 Subject: [PATCH] stopping with love2d at this point, makes sense to just jump into playdate --- .luarc.json | 8 +++++++ main.lua | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 .luarc.json diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000..0e02584 --- /dev/null +++ b/.luarc.json @@ -0,0 +1,8 @@ +{ + "runtime.special": { + "love.filesystem.load": "loadfile" + }, + "workspace.library": [ + "${3rd}/love2d/library" + ] +} \ No newline at end of file diff --git a/main.lua b/main.lua index e69de29..9c0b755 100644 --- a/main.lua +++ b/main.lua @@ -0,0 +1,66 @@ +local lg = love.graphics + +local function make_player(x, y, width, height, screen) + local player = { position={ x=x, y=y, theta=-math.pi / 2 }, width=width, height=height, screen=screen } + + player.draw = function(self) + local w, h = self.width / 2, self.height / 2 + lg.push() + lg.setColor(0, 0, 0) + lg.translate(self.position.x, self.position.y) + lg.rotate(self.position.theta) + lg.polygon("fill", -w,-h, -w,h, w,0) + lg.pop() + end + + player.translate = function(self, amount) + local w, h = self.width / 2, self.height / 2 + local new_x = self.position.x + (amount * math.cos(self.position.theta)) + local new_y = self.position.y + (amount * math.sin(self.position.theta)) + if new_x + w > self.screen.width then new_x = self.screen.width - w end + if new_x - w < 0 then new_x = w end + if new_y + h > self.screen.height then new_y = self.screen.height - h end + if new_y - h < 0 then new_y = h end + self.position.x = new_x + self.position.y = new_y + end + + player.rotate = function(self, degrees) + local radians = math.rad(degrees) + local new_theta = self.position.theta + radians + if new_theta < 0 then new_theta = new_theta + (2 * math.pi) end + if new_theta > 2 * math.pi then new_theta = new_theta - (2 * math.pi) end + self.position.theta = new_theta + end + + return player +end + +local screen = { width=400, height=240 } +local player = make_player(screen.width / 2, screen.height / 2, 10, 10, screen) + +function love.load() + love.window.setMode(screen.width, screen.height) +end + +function love.update(dt) + if love.keyboard.isDown("w") then + player:translate(1) + end + if love.keyboard.isDown("s") then + player:translate(-1) + end + if love.keyboard.isDown("d") then + player:rotate(5) + end + if love.keyboard.isDown("a") then + player:rotate(-5) + end +end + +function love.draw() + lg.setColor(1, 1, 1) + lg.rectangle("fill", 0, 0, screen.width, screen.height) + + player:draw() +end \ No newline at end of file