bzr branch
http://9ix.org/bzr/zoeplat
2
by Josh C
basic tiles, map, player, movement |
1 |
STRICT = true |
2 |
DEBUG = true |
|
3 |
||
4 |
require 'zoetrope' |
|
5 |
||
3
by Josh C
jump |
6 |
TERM_VEL = 400 |
7 |
||
2
by Josh C
basic tiles, map, player, movement |
8 |
Player = Tile:extend { |
9 |
image = 'data/player.png', |
|
3
by Josh C
jump |
10 |
onNew = function (self) |
11 |
self.velocity.y = 0 |
|
12 |
end, |
|
4
by Josh C
fix jitter caused by focus shift happening in the wrong order. Looks |
13 |
onStartFrame = function (self) |
14 |
-- this is all in startframe so it happens before |
|
15 |
-- physics calc at beginning of update |
|
3
by Josh C
jump |
16 |
|
2
by Josh C
basic tiles, map, player, movement |
17 |
self.velocity.x = 0 |
4
by Josh C
fix jitter caused by focus shift happening in the wrong order. Looks |
18 |
-- TODO: this can be replaced with sprite.maxVel.y |
3
by Josh C
jump |
19 |
if self.velocity.y >= TERM_VEL then |
20 |
self.velocity.y = TERM_VEL |
|
21 |
self.acceleration.y = 0 |
|
22 |
else |
|
23 |
self.acceleration.y = 800 |
|
24 |
end |
|
2
by Josh C
basic tiles, map, player, movement |
25 |
|
26 |
if the.keys:pressed('left') then |
|
27 |
self.velocity.x = -200 |
|
28 |
elseif the.keys:pressed('right') then |
|
29 |
self.velocity.x = 200 |
|
30 |
end |
|
3
by Josh C
jump |
31 |
|
32 |
if the.keys:justPressed('up') then |
|
33 |
self.velocity.y = -400 |
|
34 |
end |
|
4
by Josh C
fix jitter caused by focus shift happening in the wrong order. Looks |
35 |
end, |
36 |
onUpdate = function (self) |
|
37 |
-- this is called after physics, so this makes sense here |
|
38 |
the.view.map:subdisplace(self) |
|
2
by Josh C
basic tiles, map, player, movement |
39 |
end |
40 |
} |
|
41 |
||
42 |
GameView = View:extend { |
|
43 |
onNew = function (self) |
|
44 |
self:loadLayers('data/map.lua') |
|
45 |
self.focus = the.player |
|
46 |
self:clampTo(self.map) |
|
4
by Josh C
fix jitter caused by focus shift happening in the wrong order. Looks |
47 |
end |
2
by Josh C
basic tiles, map, player, movement |
48 |
} |
49 |
||
50 |
the.app = App:new { |
|
51 |
onRun = function (self) |
|
52 |
self.view = GameView:new() |
|
53 |
end, |
|
54 |
onUpdate = function (self, dt) |
|
55 |
if the.keys:justPressed('escape') then |
|
56 |
love.event.quit() |
|
57 |
end |
|
58 |
end |
|
59 |
} |