/ld28

To get this branch, use:
bzr branch http://9ix.org/bzr/ld28
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
STRICT = true
DEBUG = true

require 'zoetrope'
deque = require 'deque'
--inspect = require 'inspect'
require 'sprite'

require 'util'
require 'version'
require 'player'
require 'clone'
require 'goal'
require 'goal_person'

dirs = {'left', 'right', 'up', 'down'}

GameView = View:extend {
   onNew = function (self)
              self:loadLayers('data/map.lua')

              local tw = math.floor(the.app.width / 16)
              local th = math.floor(the.app.height / 16)

              the.player = Player:new{
                 x = math.random(2, tw-2) * 16,
                 y = math.random(2, th-2) * 16
              }
              self:add(the.player)

              the.goalPerson = GoalPerson:new{
                 x = math.random(2, tw-2) * 16,
                 y = math.random(2, th-2) * 16
              }
              self:add(the.goalPerson)

              the.clones = Group:new()
              self:add(the.clones)
              for _ = 1, 15 do
                 the.clones:add(Clone:new {
                                   x = math.random(2, tw-2) * 16,
                                   y = math.random(2, th-2) * 16
                                })
              end

              if self.level == 3 then
                 self:add(Text:new{
                             text = "R = Restart level",
                             x = 20, y = 20,
                             width = 200
                          })
              end

              if self.level ~= 1 then
                 self:flash({0,0,0})
              end
           end,
   onUpdate = function(self, dt)
                 if the.player.moved then
                    the.clones:collide(the.player)
                    the.goalPerson:collide(the.player)

                    if self.level ~= 2 then
                       the.goalPerson:doMove()
                    end

                    for _, np in ipairs(the.clones.sprites) do
                       np:doMove()
                    end

                    -- yeah, again.  once for flip, twice for displace
                    the.clones:collide(the.player)
                    the.goalPerson:collide(the.player) -- will this fix?

                    the.clones:collide(self.map)
                    the.player:collide(self.map)
                    the.goalPerson:collide(self.map)

                    the.clones:collide()

                    if math.random(1,6) == 1 then
                       local c = the.clones.sprites[math.random(the.clones:count())]
                       if self.level == 3 and not c.cured then
                          c.image = 'data/goal.png'
                       end
                    end

                    the.player.moved = false
                 end

                 if the.keys:justPressed('r') then
                    the.app.view = GameView:new{level = self.level}
                 end
              end,
}

SlowView = View:extend {
   onNew = function(self)
              local texts = {
                 '',
                 "Your movements have slowed...",
                 "Your movements have slowed...\nand they no longer only imitate you..."
              }

              local text = Text:new {
                 text = texts[self.level],
                 --height = the.app.height,
                 width = the.app.width,
                 align = 'center',
                 font = 18
              }
              text:centerAround(the.app.width / 2, the.app.height / 2)
              self:add(text)

              self.timer:after(2, function()
                 the.app.view = GameView:new{level = self.level}
              end)
           end
}

WinView = View:extend {
   onNew = function(self)
              local text = Text:new {
                 text = 'You win!',
                 width = the.app.width,
                 align = 'center',
                 font = 18
              }
              text:centerAround(the.app.width / 2, the.app.height / 2)
              self:add(text)
           end
}

TitleView = View:extend {
   onNew = function(self)
              self:add(Tile:new{
                          image = 'data/title.png'
                       })
           end,
   onUpdate = function(self)
                 if the.keys:allJustPressed() then
                    the.app.view = GameView:new{level = 1}
                 end
              end
}

the.app = App:new {
   name = "LD28",
   fps = 30,
   onRun = function (self)
              print('Version: ' .. VERSION)

              --self.view = GameView:new{level = 1}
              self.view = TitleView:new()

              if DEBUG then
                 self.console:watch('VERSION', 'VERSION')
                 self.console:watch('level', 'the.view.level')

                 -- back off that dark overlay a bit
                 self.console.fill.fill[4] = 75
              end
           end,
   onUpdate = function (self, dt)
                 if the.keys:justPressed('f1') then
                    local ss = love.graphics.newScreenshot()
                    ss:encode('screenshot-' ..love.timer.getTime()..'.png')
                 end

                 if the.keys:justPressed('escape', 'q') then
                    the.app:quit()
                 end
              end
}