62 lines
1.5 KiB
Lua
62 lines
1.5 KiB
Lua
function love.load()
|
|
Breezefield = require("libraries.breezefield")
|
|
Sti = require("libraries.sti")
|
|
|
|
GameMap = Sti("tile_sets/test/test.lua")
|
|
World = Breezefield.newWorld(0, 90.81, true)
|
|
|
|
|
|
love.graphics.setDefaultFilter("nearest", "nearest")
|
|
Anim8 = require("libraries.anim8")
|
|
Player = require("player.player")
|
|
|
|
Grounds = {}
|
|
if GameMap.layers["ground"] then
|
|
for _, obj in pairs(GameMap.layers["ground"].objects) do
|
|
local ground = World:newCollider("Polygon",
|
|
{ obj.x, obj.y, obj.x + obj.width, obj.y, obj.x + obj.width, obj.y + obj.height, obj.x, obj.y +
|
|
obj.height })
|
|
ground:setType("static")
|
|
table.insert(Grounds, ground)
|
|
end
|
|
end
|
|
end
|
|
|
|
function love.update(dt)
|
|
local px, py = Player.collider:getLinearVelocity()
|
|
Player_state = 0
|
|
if love.keyboard.isDown("right") then
|
|
Player_state = 1
|
|
if px < 300 then
|
|
Player.collider:applyForce(7000, 0)
|
|
end
|
|
end
|
|
|
|
if love.keyboard.isDown("left") then
|
|
Player_state = 1
|
|
if px > -300 then
|
|
Player.collider:applyForce(-7000, 0)
|
|
end
|
|
end
|
|
|
|
if love.keyboard.isDown("space") and Player.collider:enter() then
|
|
Player.collider:applyLinearImpulse(0, -5000)
|
|
print("collide")
|
|
end
|
|
|
|
if Player.collider.contact then
|
|
print("hello")
|
|
end
|
|
|
|
World:update(dt)
|
|
Player.x = Player.collider:getX()
|
|
Player.y = Player.collider:getY()
|
|
Player:update(dt, Player_state)
|
|
end
|
|
|
|
function love.draw()
|
|
GameMap:draw()
|
|
Player:draw(Player_state)
|
|
World:draw()
|
|
end
|