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
|
STRICT = true
DEBUG = true
require 'zoetrope'
Player = Tile:extend {
image = 'data/player.png',
onNew = function (self)
self.velocity.y = 0
self.maxVelocity.y = 400
end,
onStartFrame = function (self)
-- this is all in startframe so it happens before
-- physics calc at beginning of update
self.velocity.x = 0
self.acceleration.y = 800
if the.keys:pressed('left') then
self.velocity.x = -200
elseif the.keys:pressed('right') then
self.velocity.x = 200
end
if the.keys:justPressed('up') then
self.velocity.y = -400
end
end,
onCollide = function (self, other, xOverlap, yOverlap)
-- seriously, why does this even fire?
if other == the.view.map then return end
--print(string.format('col s{x=%i y=%i w=%i h=%i} %s', self.x, self.y, self.width, self.height, tostring(other)))
--print('vel.x:'..self.velocity.x.." vel.y:"..self.velocity.y)
-- assumption: any other collision is with a solid map tile
if yOverlap > xOverlap then
other:displace(self)
elseif xOverlap > yOverlap then
-- check if we've moved since collisions were generated
local xov, yov = self:overlap(other.x, other.y,
other.width, other.height)
if xov ~= 0 and yov ~= 0 then
self.velocity.y = 0
other:displace(self)
end
else
print('??')
end
end
}
GameView = View:extend {
onNew = function (self)
self:loadLayers('data/map.lua')
self.focus = the.player
self:clampTo(self.map)
end,
onUpdate = function (self)
--print('tick')
the.player:collide(self.map)
--self.map:collide(the.player)
end
}
the.app = App:new {
onRun = function (self)
self.view = GameView:new()
end,
onUpdate = function (self, dt)
-- apparently I can do this w/ C-A-q if DEBUG is on
-- if the.keys:justPressed('escape') then
-- love.event.quit()
-- end
end
}
|