stuff working sort of
This commit is contained in:
@@ -13,7 +13,7 @@ function love.conf(t)
|
|||||||
t.window.resizable = false
|
t.window.resizable = false
|
||||||
t.window.fullscreen = false
|
t.window.fullscreen = false
|
||||||
|
|
||||||
t.window.vsync = true --may change?
|
t.window.vsync = false --may change?
|
||||||
t.window.fsaa = 0
|
t.window.fsaa = 0
|
||||||
t.window.display = 1
|
t.window.display = 1
|
||||||
t.window.highdpi = false
|
t.window.highdpi = false
|
||||||
|
98
src/levels.lua
Normal file
98
src/levels.lua
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
local LightWorld = require "lib.light_world"
|
||||||
|
require "lightWorldRectangleFix"
|
||||||
|
|
||||||
|
local Object = {}
|
||||||
|
Object.__index = Object
|
||||||
|
|
||||||
|
function Object.new(x, y, w, h)
|
||||||
|
local self = {
|
||||||
|
x = x, y = y,
|
||||||
|
w = w, h = h,
|
||||||
|
shadow = lightWorldRectangleFix(lightWorld, x, y, w, h)
|
||||||
|
}
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
level = {
|
||||||
|
function()
|
||||||
|
lightWorld = LightWorld({
|
||||||
|
drawBackground = drawBackground,
|
||||||
|
drawForground = drawForeground,
|
||||||
|
ambient = {80, 80, 100} --previously 60,60,60
|
||||||
|
})
|
||||||
|
lightWorld.blur = 0
|
||||||
|
|
||||||
|
bgColor = {35, 65, 85}
|
||||||
|
|
||||||
|
lights = {
|
||||||
|
lightWorld:newLight(love.graphics.getWidth() / 2 - 35, love.graphics.getHeight() / 2, 255, 150, 100, 650)
|
||||||
|
} --x,y,r,g,b,radius
|
||||||
|
|
||||||
|
thompson = {
|
||||||
|
color = {255, 0, 0},
|
||||||
|
x = 30,
|
||||||
|
y = love.graphics.getHeight() - 73 -15 - 27, --15 above bottom, 27 is because height of thompson
|
||||||
|
w = 17,
|
||||||
|
h = 27,
|
||||||
|
v = {0, 0}
|
||||||
|
}
|
||||||
|
thompson.shadow = lightWorldRectangleFix(lightWorld, thompson.x, thompson.y, thompson.w, thompson.h)
|
||||||
|
thompson.fixShadowPosition = function()
|
||||||
|
thompson.shadow.x = thompson.x + thompson.w / 2
|
||||||
|
thompson.shadow.y = thompson.y + thompson.h / 2
|
||||||
|
thompson.shadow.data = {
|
||||||
|
thompson.x, thompson.y,
|
||||||
|
thompson.x + thompson.w, thompson.y,
|
||||||
|
thompson.x + thompson.w, thompson.y + thompson.h,
|
||||||
|
thompson.x, thompson.y + thompson.h
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
objects = {
|
||||||
|
Object.new(0, 0, love.graphics.getWidth(), 15),
|
||||||
|
Object.new(0, 0, 15, love.graphics.getHeight()),
|
||||||
|
Object.new(0, love.graphics.getHeight() - 15, love.graphics.getWidth(), 15),
|
||||||
|
Object.new(love.graphics.getWidth() - 15, 0, 15, love.graphics.getHeight()),
|
||||||
|
|
||||||
|
Object.new(100, love.graphics.getHeight() - 60 - 50, 50, 50),
|
||||||
|
Object.new(420, love.graphics.getHeight() - 170 - 50, 50, 50),
|
||||||
|
Object.new(431, love.graphics.getHeight() - 33 - 50, 49, 49),
|
||||||
|
Object.new(276, love.graphics.getHeight() - 85 - 50, 51, 51),
|
||||||
|
Object.new(27, love.graphics.getHeight() - 167 - 50, 47, 47),
|
||||||
|
Object.new(677, love.graphics.getHeight() - 81 - 50, 52, 52),
|
||||||
|
Object.new(628, love.graphics.getHeight() - 107 - 50, 49, 49),
|
||||||
|
Object.new(597, love.graphics.getHeight() - 223 - 50, 46, 46),
|
||||||
|
Object.new(311, love.graphics.getHeight() - 272 - 50, 53, 53),
|
||||||
|
Object.new(700, 68, 50, 50),
|
||||||
|
Object.new(140, 129, 47, 47),
|
||||||
|
Object.new(503, 83, 53, 53),
|
||||||
|
|
||||||
|
--remember we have 770x370 to work with (minus 30 because of walls)
|
||||||
|
--[[lightWorldRectangleFix(lightWorld, x, y, w, h),
|
||||||
|
lightWorldRectangleFix(lightWorld, x, y, w, h),
|
||||||
|
lightWorldRectangleFix(lightWorld, x, y, w, h),
|
||||||
|
lightWorldRectangleFix(lightWorld, x, y, w, h),
|
||||||
|
lightWorldRectangleFix(lightWorld, x, y, w, h),
|
||||||
|
lightWorldRectangleFix(lightWorld, x, y, w, h),
|
||||||
|
lightWorldRectangleFix(lightWorld, x, y, w, h),
|
||||||
|
lightWorldRectangleFix(lightWorld, x, y, w, h),]]
|
||||||
|
}
|
||||||
|
|
||||||
|
goal = {
|
||||||
|
x = 711,
|
||||||
|
y = 40,
|
||||||
|
w = thompson.w + 2,
|
||||||
|
h = thompson.h + 2
|
||||||
|
}
|
||||||
|
goal.collider = {
|
||||||
|
x = goal.x + goal.w / 2 - 1.5,
|
||||||
|
y = goal.y + goal.h / 2 - 1.5,
|
||||||
|
w = 3, h = 3
|
||||||
|
}
|
||||||
|
--[[goal = lightWorldRectangleFix(lightWorld, 700, 20, thompson.w + 2, thompson.h + 2)
|
||||||
|
goal.glowStrength = 5
|
||||||
|
for k,v in pairs(goal) do
|
||||||
|
print(k.."="..tostring(v))
|
||||||
|
end]]
|
||||||
|
end,
|
||||||
|
}
|
154
src/main.lua
154
src/main.lua
@@ -1,46 +1,148 @@
|
|||||||
|
--local LightWorld = require "lib.light_world"
|
||||||
|
local g = 890
|
||||||
|
local fudgeFactor = 0.8
|
||||||
|
local timer = 0
|
||||||
|
local lightSway = true
|
||||||
|
local levelBeat = false
|
||||||
|
local currentLevel = 1
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
require "lightWorldRectangleFix"
|
require "levels"
|
||||||
|
level[currentLevel]()
|
||||||
|
end
|
||||||
|
|
||||||
local LightWorld = require "lib.light_world"
|
local function checkAABB(A, B)
|
||||||
lightWorld = LightWorld({
|
--if A
|
||||||
drawBackground = drawBackground,
|
if A.x + A.w < B.x or
|
||||||
drawForground = drawForeground,
|
A.y + A.h < B.y or
|
||||||
ambient = {60, 60, 60}
|
A.x > B.x + B.w or
|
||||||
})
|
A.y > B.y + B.h
|
||||||
|
then return false end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
light = lightWorld:newLight(love.graphics.getWidth() / 2, love.graphics.getHeight() / 2, 255, 150, 100, 600) --x,y,r,g,b,radius
|
local function approxEqual(A, B)
|
||||||
|
local epsilon = 0.002
|
||||||
bgColor = {35, 65, 85}
|
return math.abs(A-B) < epsilon
|
||||||
|
|
||||||
thompson = {
|
|
||||||
color = {255, 0, 0},
|
|
||||||
x = 50,
|
|
||||||
y = 50,
|
|
||||||
w = 17,
|
|
||||||
h = 27
|
|
||||||
}
|
|
||||||
thompson.shadow = lightWorldRectangleFix(lightWorld, thompson.x, thompson.y, thompson.w, thompson.h)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
love.window.setTitle("Thompson Was a Clone (FPS:" .. love.timer.getFPS() .. ")") --for testing purposes only
|
love.window.setTitle("Thompson Was a Clone (FPS:" .. love.timer.getFPS() .. ")") --for testing purposes only
|
||||||
|
if dt > 0.002 then dt = 0.002 end
|
||||||
|
timer = timer + dt
|
||||||
|
|
||||||
|
-- adjust light position based on timer
|
||||||
|
if lightSway then
|
||||||
|
lights[1].x = lights[1].x + timer * 0.002
|
||||||
|
else
|
||||||
|
lights[1].x = lights[1].x - timer * 0.002
|
||||||
|
end
|
||||||
|
if timer > 9 then
|
||||||
|
timer = 0
|
||||||
|
lightSway = not lightSway
|
||||||
|
end
|
||||||
|
if approxEqual(timer, math.floor(timer)) then
|
||||||
|
if levelBeat then
|
||||||
|
currentLevel = currentLevel + 1
|
||||||
|
level[currentLevel]()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- player control
|
||||||
|
if thompson.onGround and love.keyboard.isDown("w") or thompson.onGround and love.keyboard.isDown(" ") then
|
||||||
|
--if not thompson.isJumping then
|
||||||
|
thompson.v[2] = -g/2
|
||||||
|
--thompson.isJumping = true
|
||||||
|
--end
|
||||||
|
--thompson.isJumping = false
|
||||||
|
elseif love.keyboard.isDown("s") then
|
||||||
|
--do nothing
|
||||||
|
else
|
||||||
|
--thompson.isJumping = false
|
||||||
|
end
|
||||||
|
if love.keyboard.isDown("a") then
|
||||||
|
thompson.v[1] = -g/4
|
||||||
|
elseif love.keyboard.isDown("d") then
|
||||||
|
thompson.v[1] = g/4
|
||||||
|
else
|
||||||
|
thompson.v[1] = 0
|
||||||
|
end
|
||||||
|
-- reset button
|
||||||
|
if love.keyboard.isDown("r") then
|
||||||
|
level[1]() --hardcoded to first level!!
|
||||||
|
end
|
||||||
|
|
||||||
|
-- apply gravity
|
||||||
|
thompson.v[2] = thompson.v[2] + g * dt
|
||||||
|
|
||||||
|
-- update position
|
||||||
|
thompson.x = thompson.x + thompson.v[1] * dt
|
||||||
|
thompson.y = thompson.y + thompson.v[2] * dt
|
||||||
|
thompson.fixShadowPosition()
|
||||||
|
|
||||||
|
-- check win condition
|
||||||
|
if checkAABB(thompson, goal.collider) then
|
||||||
|
thompson.color = {255, 255, 255}
|
||||||
|
levelBeat = true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- check for collisions & fix velocity/position
|
||||||
|
thompson.onGround = false --we assume he isn't until he hits one
|
||||||
|
for i=1,#objects do
|
||||||
|
if checkAABB(thompson, objects[i]) then
|
||||||
|
if thompson.y + thompson.h * fudgeFactor < objects[i].y then
|
||||||
|
-- thompson landed
|
||||||
|
thompson.v[2] = 0
|
||||||
|
thompson.y = objects[i].y - thompson.h
|
||||||
|
thompson.onGround = true
|
||||||
|
elseif thompson.y > objects[i].y + objects[i].h * fudgeFactor then
|
||||||
|
-- thompson bumped his head
|
||||||
|
thompson.v[2] = 0
|
||||||
|
thompson.y = objects[i].y + objects[i].h
|
||||||
|
elseif thompson.x + thompson.w * fudgeFactor < objects[i].x then
|
||||||
|
-- thompson hit his left side into a wall
|
||||||
|
thompson.v[1] = 0
|
||||||
|
thompson.x = objects[i].x - thompson.w
|
||||||
|
elseif thompson.x > objects[i].x + objects[i].w * fudgeFactor then
|
||||||
|
-- thompson hit his right side into a wall
|
||||||
|
thompson.v[1] = 0
|
||||||
|
thompson.x = objects[i].x + objects[i].w
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
lightWorld:draw(0, 0, 1)
|
lightWorld:draw(0, 0, 1)
|
||||||
--drawBackground()
|
|
||||||
--drawForeground()
|
-- goal
|
||||||
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
love.graphics.setLineWidth(2)
|
||||||
|
love.graphics.rectangle("line", goal.x, goal.y, goal.w, goal.h)
|
||||||
|
|
||||||
|
-- thompson
|
||||||
|
love.graphics.setColor(thompson.color)
|
||||||
|
love.graphics.rectangle("fill", thompson.x, thompson.y, thompson.w, thompson.h)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawBackground()
|
function drawBackground()
|
||||||
love.graphics.setColor(bgColor)
|
love.graphics.setColor(bgColor)
|
||||||
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
||||||
|
|
||||||
|
-- objects
|
||||||
|
love.graphics.setColor(0, 0, 0)
|
||||||
|
for i=1,#objects do
|
||||||
|
--love.graphics.rectangle("fill", objects[i].x - objects[i].width / 2, objects[i].y - objects[i].height / 2, objects[i].width, objects[i].height)
|
||||||
|
love.graphics.rectangle("fill", objects[i].x, objects[i].y, objects[i].w, objects[i].h)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- goal
|
||||||
|
--[[love.graphics.setColor(255, 255, 255)
|
||||||
|
love.graphics.setLineWidth(2)
|
||||||
|
love.graphics.rectangle("line", goal.x, goal.y, goal.w, goal.h)]]
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawForeground()
|
function drawForeground()
|
||||||
love.graphics.setColor(thompson.color)
|
--nothing
|
||||||
love.graphics.rectangle("fill", thompson.x, thompson.y, thompson.w, thompson.h)
|
|
||||||
--[[
|
|
||||||
love.graphics.setColor(255, 0, 0) --red
|
|
||||||
love.graphics.rectangle("fill", 10, 10, 17, 27) --x,y,width,height]]
|
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user