/ld28

To get this branch, use:
bzr branch http://9ix.org/bzr/ld28
2 by Josh C
basic delayed movement
1
STRICT = true
2
DEBUG = true
3
4
require 'zoetrope'
5
deque = require 'deque'
10 by Josh C
collide w/ the map
6
--inspect = require 'inspect'
7
require 'sprite'
2 by Josh C
basic delayed movement
8
10 by Josh C
collide w/ the map
9
require 'util'
2 by Josh C
basic delayed movement
10
require 'version'
11
require 'player'
7 by Josh C
rename NotPlayer to Clone cuz they're clones, and it's way too early
12
require 'clone'
15 by Josh C
put some walls and a goal... doesn't feel quite right.
13
require 'goal'
16 by Josh C
moving goal, clones turning green...
14
require 'goal_person'
15
16
dirs = {'left', 'right', 'up', 'down'}
2 by Josh C
basic delayed movement
17
18
GameView = View:extend {
19
   onNew = function (self)
10 by Josh C
collide w/ the map
20
              self:loadLayers('data/map.lua')
2 by Josh C
basic delayed movement
21
13 by Josh C
align to grid
22
              local tw = math.floor(the.app.width / 16)
23
              local th = math.floor(the.app.height / 16)
24
3 by Josh C
add a couple other clones that move randomly
25
              the.player = Player:new{
13 by Josh C
align to grid
26
                 x = math.random(2, tw-2) * 16,
27
                 y = math.random(2, th-2) * 16
3 by Josh C
add a couple other clones that move randomly
28
              }
2 by Josh C
basic delayed movement
29
              self:add(the.player)
3 by Josh C
add a couple other clones that move randomly
30
16 by Josh C
moving goal, clones turning green...
31
              the.goalPerson = GoalPerson:new{
32
                 x = math.random(2, tw-2) * 16,
33
                 y = math.random(2, th-2) * 16
34
              }
35
              self:add(the.goalPerson)
36
7 by Josh C
rename NotPlayer to Clone cuz they're clones, and it's way too early
37
              the.clones = Group:new()
38
              self:add(the.clones)
14 by Josh C
16 is a more fun number. :D
39
              for _ = 1, 15 do
7 by Josh C
rename NotPlayer to Clone cuz they're clones, and it's way too early
40
                 the.clones:add(Clone:new {
13 by Josh C
align to grid
41
                                   x = math.random(2, tw-2) * 16,
42
                                   y = math.random(2, th-2) * 16
43
                                })
3 by Josh C
add a couple other clones that move randomly
44
              end
24 by Josh C
intermidiate + win screens
45
27 by Josh C
R = restart level
46
              if self.level == 3 then
47
                 self:add(Text:new{
48
                             text = "R = Restart level",
49
                             x = 20, y = 20,
50
                             width = 200
51
                          })
52
              end
53
24 by Josh C
intermidiate + win screens
54
              if self.level ~= 1 then
55
                 self:flash({0,0,0})
56
              end
2 by Josh C
basic delayed movement
57
           end,
58
   onUpdate = function(self, dt)
3 by Josh C
add a couple other clones that move randomly
59
                 if the.player.moved then
21 by Josh C
super hacky fix for passing through clones/goals
60
                    the.clones:collide(the.player)
61
                    the.goalPerson:collide(the.player)
62
23 by Josh C
levels. ish.
63
                    if self.level ~= 2 then
64
                       the.goalPerson:doMove()
65
                    end
16 by Josh C
moving goal, clones turning green...
66
7 by Josh C
rename NotPlayer to Clone cuz they're clones, and it's way too early
67
                    for _, np in ipairs(the.clones.sprites) do
3 by Josh C
add a couple other clones that move randomly
68
                       np:doMove()
69
                    end
70
21 by Josh C
super hacky fix for passing through clones/goals
71
                    -- yeah, again.  once for flip, twice for displace
72
                    the.clones:collide(the.player)
24 by Josh C
intermidiate + win screens
73
                    the.goalPerson:collide(the.player) -- will this fix?
21 by Josh C
super hacky fix for passing through clones/goals
74
10 by Josh C
collide w/ the map
75
                    the.clones:collide(self.map)
76
                    the.player:collide(self.map)
16 by Josh C
moving goal, clones turning green...
77
                    the.goalPerson:collide(self.map)
10 by Josh C
collide w/ the map
78
9 by Josh C
collision
79
                    the.clones:collide()
80
23 by Josh C
levels. ish.
81
                    if math.random(1,6) == 1 then
20 by Josh C
clones you flip don't flip back
82
                       local c = the.clones.sprites[math.random(the.clones:count())]
23 by Josh C
levels. ish.
83
                       if self.level == 3 and not c.cured then
20 by Josh C
clones you flip don't flip back
84
                          c.image = 'data/goal.png'
85
                       end
16 by Josh C
moving goal, clones turning green...
86
                    end
87
3 by Josh C
add a couple other clones that move randomly
88
                    the.player.moved = false
89
                 end
27 by Josh C
R = restart level
90
91
                 if the.keys:justPressed('r') then
92
                    the.app.view = GameView:new{level = self.level}
93
                 end
2 by Josh C
basic delayed movement
94
              end,
95
}
96
24 by Josh C
intermidiate + win screens
97
SlowView = View:extend {
98
   onNew = function(self)
99
              local text = Text:new {
100
                 text = 'Your movements have slowed...',
101
                 --height = the.app.height,
102
                 width = the.app.width,
103
                 align = 'center',
104
                 font = 18
105
              }
106
              text:centerAround(the.app.width / 2, the.app.height / 2)
107
              self:add(text)
108
109
              self.timer:after(2, function()
110
                 the.app.view = GameView:new{level = self.level}
111
              end)
112
           end
113
}
114
115
WinView = View:extend {
116
   onNew = function(self)
117
              local text = Text:new {
118
                 text = 'You win!',
119
                 width = the.app.width,
120
                 align = 'center',
121
                 font = 18
122
              }
123
              text:centerAround(the.app.width / 2, the.app.height / 2)
124
              self:add(text)
125
           end
126
}
127
25 by Josh C
title screen
128
TitleView = View:extend {
129
   onNew = function(self)
130
              self:add(Tile:new{
131
                          image = 'data/title.png'
132
                       })
133
           end,
134
   onUpdate = function(self)
135
                 if the.keys:allJustPressed() then
136
                    the.app.view = GameView:new{level = 1}
137
                 end
138
              end
139
}
140
2 by Josh C
basic delayed movement
141
the.app = App:new {
3 by Josh C
add a couple other clones that move randomly
142
   name = "LD28",
15 by Josh C
put some walls and a goal... doesn't feel quite right.
143
   fps = 30,
2 by Josh C
basic delayed movement
144
   onRun = function (self)
145
              print('Version: ' .. VERSION)
146
25 by Josh C
title screen
147
              --self.view = GameView:new{level = 1}
148
              self.view = TitleView:new()
2 by Josh C
basic delayed movement
149
150
              if DEBUG then
151
                 self.console:watch('VERSION', 'VERSION')
23 by Josh C
levels. ish.
152
                 self.console:watch('level', 'the.view.level')
2 by Josh C
basic delayed movement
153
154
                 -- back off that dark overlay a bit
155
                 self.console.fill.fill[4] = 75
156
              end
157
           end,
8 by Josh C
screenshots
158
   onUpdate = function (self, dt)
159
                 if the.keys:justPressed('f1') then
160
                    local ss = love.graphics.newScreenshot()
161
                    ss:encode('screenshot-' ..love.timer.getTime()..'.png')
162
                 end
26 by Josh C
move quit keybindings to app
163
164
                 if the.keys:justPressed('escape', 'q') then
165
                    the.app:quit()
166
                 end
8 by Josh C
screenshots
167
              end
2 by Josh C
basic delayed movement
168
}