1
local wall = world:newRectangleCollider(obj.x , obj.y , obj.width , obj.height)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
function love.load()
wf = require 'windfield'
world = wf.newWorld(0 ,0)
camera = require 'camera'
cam = camera()
anim8 = require 'lib/anim8'
love.graphics.setDefaultFilter("nearest","nearest")
sti = require 'lib/sti'
map = sti('map.lua')
player ={}
player.collider = world:newBSGRectangleCollider(400 , 250 , 50 , 100 , 0)
player.collider:setFixedRotation(true)
player.x = 400
player.y = 300
player.speed = 300
player.sprite = love.graphics.newImage('player1.png')
player.spritesheet = love.graphics.newImage('player-sheet.png')
player.grid = anim8.newGrid(12,18,player.spritesheet:getWidth(),player.spritesheet:getHeight())
player.animations = {}
player.animations.down = anim8.newAnimation(player.grid('1-4',1),0.2)
player.animations.left = anim8.newAnimation(player.grid('1-4',2),0.2)
player.animations.right = anim8.newAnimation(player.grid('1-4',3),0.2)
player.animations.up = anim8.newAnimation(player.grid('1-4',4),0.2)
player.anim = player.animations.left
background = love.graphics.newImage('platform1.png')
walls = {}
if map.layers['walls'] then
for i, obj in pairs(map.layers['walls'].objects) do
--[[
PLEASE ADD HERE:
]]--
print(obj.x)
print(obj.y)
print(obj.width)
print(obj.height)
local wall = world:newRectangleCollider(obj.x , obj.y , obj.width , obj.height)
wall:setType('static')
table.insert(walls , wall)
end
end
end
function love.update(dt)
local ismoving = false
local vx = 0
local vy = 0
if love.keyboard.isDown("right") then
vx = player.speed
player.anim = player.animations.right
ismoving = true
end
if love.keyboard.isDown("left") then
vx = player.speed * -1
player.anim = player.animations.left
ismoving = true
end
if love.keyboard.isDown("down") then
vy = player.speed
player.anim = player.animations.down
ismoving = true
end
if love.keyboard.isDown("up") then
vy = player.speed * -1
player.anim = player.animations.up
ismoving = true
end
player.collider:setLinearVelocity(vx , vy)
if ismoving == false then
player.anim:gotoFrame(2)
end
world:update(dt)
player.x = player.collider:getX()
player.y = player.collider:getY()
player.anim:update(dt)
cam:lookAt(player.x,player.y)
local w = love.graphics.getWidth()
local h = love.graphics.getHeight()
local mapw = map.width * map.tilewidth
local maph = map.height * map.tileheight
if cam.x < w/2 then
cam.x = w/2
end
if cam.y < h/2 then
cam.y = h/2
end
if cam.x > ( mapw - w/2) then
cam.x = (mapw - w/2)
end
if cam.y > ( maph - h/2) then
cam.y = ( maph - h/2 )
end
end
function love.draw()
cam:attach()
map:drawLayer(map.layers["ground"])
map:drawLayer(map.layers["tree"])
player.anim:draw(player.spritesheet,player.x,player.y,nil,6,nil,6,9)
world:draw()
cam:detach()
end