summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2022-03-30 22:17:29 +0100
committerubq323 <ubq323@ubq323.website>2022-03-30 22:17:29 +0100
commit9120ff684d62691c04564cc8a038c80a85b91bce (patch)
treeb59331677793ba1ea306360a9d7c151449c0dd19 /src
parent2ebd13947d71d78892690c45690fa49157ac4612 (diff)
more thing
Diffstat (limited to 'src')
-rw-r--r--src/conf.lua1
-rw-r--r--src/main.lua127
-rw-r--r--src/mansion.lua80
-rw-r--r--src/player.lua38
4 files changed, 131 insertions, 115 deletions
diff --git a/src/conf.lua b/src/conf.lua
index 756de2f..98bf66d 100644
--- a/src/conf.lua
+++ b/src/conf.lua
@@ -2,6 +2,7 @@ function love.conf(t)
t.window.title = "the"
t.window.width=640
t.window.height=480
+ t.window.resizeable=true
end
diff --git a/src/main.lua b/src/main.lua
index 20c532a..7a5482c 100644
--- a/src/main.lua
+++ b/src/main.lua
@@ -1,132 +1,29 @@
-local plr={
- x=250,
- y=250,
-}
+local player = require "player"
+local mansion = require "mansion"
-local bump = require "bump"
+print(string.pack)
+local current_room
-local PL_SPEED = 170
-local PL_SPRINT_SPEED = 280
-
-local font, title
-local world
-local jerma
function love.load()
- font = love.graphics.newFont("APL333.ttf",72)
- title = love.graphics.newText(font, "room A9")
- jerma = love.graphics.newImage("jerma.jpg")
- world = bump.newWorld()
- world:add("player", plr.x, plr.y, 10,10)
- world:add("jerma", 30,400, 400, 50)
-end
-
-local function player_movement(dt)
- local speed =
- (love.keyboard.isScancodeDown("lshift","rshift") and PL_SPRINT_SPEED or PL_SPEED)
- local vx = 0
- local vy = 0
-
- if love.keyboard.isScancodeDown('w','up') then vy = vy - 1 end
- if love.keyboard.isScancodeDown('s','down') then vy = vy + 1 end
- if love.keyboard.isScancodeDown('a','left') then vx = vx - 1 end
- if love.keyboard.isScancodeDown('d','right') then vx = vx + 1 end
-
- local sf = math.sqrt(vx*vx+vy*vy)
- if sf == 0 then return end
- vx = vx / sf
- vy = vy / sf
-
- local tx = plr.x + vx * dt * speed
- local ty = plr.y + vy * dt * speed
-
- local ax, ay = world:move("player",tx,ty)
- plr.x = ax
- plr.y = ay
-
-end
-
-local function draw_player()
- love.graphics.setColor(0.91,0.62,0)
- love.graphics.rectangle("fill", plr.x,plr.y, 10,10)
-end
-
-local function draw_room()
- love.graphics.setColor(0.8,0.8,0.8)
- love.graphics.setLineWidth(10)
- love.graphics.rectangle("line",30,80,580,370)
- love.graphics.draw(title,610-title:getWidth(),-10)
+ mansion.load()
+ current_room = mansion
+ -- this should go in load_room or something
+ current_room.world:add("player", player.x, player.y, 10,10)
end
-local draw_thing = coroutine.wrap(function()
- local t = 0
- local angry = false
- local tri_a = 100
- local tri_h = (math.sqrt(3)/2)*tri_a
- local ell_l = 20
- local ell_r = 30
-
- while true do
- local theta = t/10
- local c = math.cos(theta)
- local s = math.sin(theta)
-
- local dist = math.sqrt((420-plr.x)^2 + (240-plr.y)^2)
- if not angry and dist < 100 then
- angry = true
- elseif angry and dist > 200 then
- angry = false
- end
-
-
- love.graphics.push()
- love.graphics.translate(420,240)
-
- love.graphics.push()
- love.graphics.setLineWidth(10)
- love.graphics.setColor(angry and {1,0,0,0.8} or {0.7,0,0.5,0.8})
- love.graphics.rotate(-theta/1.618)
- love.graphics.polygon("line", -tri_a/2,-tri_h/3, tri_a/2,-tri_h/3, 0,2*tri_h/3)
- love.graphics.pop()
-
- love.graphics.setLineWidth(7)
- love.graphics.setColor(0.8,0.8,0,0.7)
- love.graphics.ellipse("line", ell_l*c,ell_l*s, ell_r,2*ell_r)
- love.graphics.setColor(0,0.8,0.8,0.7)
- love.graphics.ellipse("line", -ell_l*c,-ell_l*s, ell_r,2*ell_r)
-
- love.graphics.pop()
-
-
-
- t = t + (angry and 1.8 or 1)
-
- coroutine.yield()
- end
-end)
-
-function draw_jerma()
- love.graphics.setColor(1,1,1,1)
- local sx = 400/jerma:getWidth()
- local sy = 50/jerma:getHeight()
- local px =
- love.graphics.draw(jerma,30,400, 0, sx,sy)
-end
function love.update(dt)
- player_movement(dt)
+ player:move(dt,current_room.world)
end
function love.draw()
love.graphics.clear(1,1,1)
- love.graphics.setColor(0,0,0)
- -- love.graphics.print("bees "..plr.x.." "..plr.y,10,10)
- draw_room()
- draw_jerma()
- draw_player()
- draw_thing()
+
+ mansion.draw()
+ player:draw()
end
diff --git a/src/mansion.lua b/src/mansion.lua
new file mode 100644
index 0000000..d0114f9
--- /dev/null
+++ b/src/mansion.lua
@@ -0,0 +1,80 @@
+local bump = require "bump"
+local player = require "player"
+
+local mansion = {}
+
+local world = bump.newWorld()
+mansion.world=world
+
+local draw_thing = coroutine.wrap(function()
+ local t = 0
+ local angry = false
+
+ local tri_a = 100
+ local tri_h = (math.sqrt(3)/2)*tri_a
+
+ local ell_l = 20
+ local ell_r = 30
+
+ while true do
+ local theta = t/10
+ local c = math.cos(theta)
+ local s = math.sin(theta)
+
+ local dist = math.sqrt((420-player.x)^2 + (240-player.y)^2)
+ if not angry and dist < 100 then
+ angry = true
+ elseif angry and dist > 200 then
+ angry = false
+ end
+
+ love.graphics.push()
+ love.graphics.translate(420,240)
+
+ love.graphics.push()
+ love.graphics.setLineWidth(10)
+ love.graphics.setColor(angry and {1,0,0,0.8} or {0.7,0,0.5,0.8})
+ love.graphics.rotate(-theta/1.618)
+ love.graphics.polygon("line", -tri_a/2,-tri_h/3, tri_a/2,-tri_h/3, 0,2*tri_h/3)
+ love.graphics.pop()
+
+ love.graphics.setLineWidth(7)
+ love.graphics.setColor(0.8,0.8,0,0.7)
+ love.graphics.ellipse("line", ell_l*c,ell_l*s, ell_r,2*ell_r)
+ love.graphics.setColor(0,0.8,0.8,0.7)
+ love.graphics.ellipse("line", -ell_l*c,-ell_l*s, ell_r,2*ell_r)
+ love.graphics.pop()
+
+ t = t + (angry and 1.8 or 1)
+
+ coroutine.yield()
+ end
+end)
+
+local font,title,jerma
+function mansion.load()
+ font = love.graphics.newFont("APL333.ttf",72)
+ title = love.graphics.newText(font,"mansion")
+ jerma = love.graphics.newImage("jerma.jpg")
+ world:add("jerma", 30,400, 400,50)
+end
+
+local function draw_jerma()
+ love.graphics.setColor(1,1,1,1)
+ local sx = 400 / jerma:getWidth()
+ local sy = 50 / jerma:getHeight()
+ love.graphics.draw(jerma, 30,400, 0, sx,sy)
+end
+
+function mansion.draw()
+ love.graphics.setColor(0.8,0.8,0.8)
+ love.graphics.setLineWidth(10)
+ love.graphics.rectangle("line",30,80,580,370)
+ love.graphics.draw(title,610-title:getWidth(),-10)
+
+ draw_thing()
+ draw_jerma()
+end
+
+return mansion
+
diff --git a/src/player.lua b/src/player.lua
new file mode 100644
index 0000000..16a54dd
--- /dev/null
+++ b/src/player.lua
@@ -0,0 +1,38 @@
+local player = {
+ x = 250,
+ y = 250,
+}
+
+local SPEED = 170
+local SPRINT_SPEED = 280
+
+function player:move(dt,world)
+ local speed =
+ (love.keyboard.isScancodeDown("lshift","rshift") and SPRINT_SPEED or SPEED)
+ local vx = 0
+ local vy = 0
+
+ if love.keyboard.isScancodeDown('w','up') then vy = vy - 1 end
+ if love.keyboard.isScancodeDown('s','down') then vy = vy + 1 end
+ if love.keyboard.isScancodeDown('a','left') then vx = vx - 1 end
+ if love.keyboard.isScancodeDown('d','right') then vx = vx + 1 end
+
+ local sf = math.sqrt(vx*vx+vy*vy)
+ if sf == 0 then return end
+ vx = vx / sf
+ vy = vy / sf
+
+ local tx = self.x + vx * dt * speed
+ local ty = self.y + vy * dt * speed
+
+ local ax, ay = world:move("player",tx,ty)
+ self.x = ax
+ self.y = ay
+end
+
+function player:draw()
+ love.graphics.setColor(0.91,0.62,0)
+ love.graphics.rectangle("fill", self.x,self.y, 10,10)
+end
+
+return player