/ld28

To get this branch, use:
bzr branch http://9ix.org/bzr/ld28

« back to all changes in this revision

Viewing changes to main.lua

  • Committer: Josh C
  • Date: 2013-12-15 20:03:17 UTC
  • Revision ID: josh@9ix.org-20131215200317-nr8no8pnv222eo39
R = restart level

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
require 'zoetrope'
5
5
deque = require 'deque'
 
6
--inspect = require 'inspect'
 
7
require 'sprite'
6
8
 
 
9
require 'util'
7
10
require 'version'
8
11
require 'player'
9
12
require 'clone'
 
13
require 'goal'
 
14
require 'goal_person'
 
15
 
 
16
dirs = {'left', 'right', 'up', 'down'}
10
17
 
11
18
GameView = View:extend {
12
19
   onNew = function (self)
13
 
              --self:loadLayers('data/map.lua')
14
 
              --self.focus = the.player
15
 
              --self:clampTo(self.bg)
 
20
              self:loadLayers('data/map.lua')
 
21
 
 
22
              local tw = math.floor(the.app.width / 16)
 
23
              local th = math.floor(the.app.height / 16)
16
24
 
17
25
              the.player = Player:new{
18
 
                 x = math.random(the.app.width),
19
 
                 y = math.random(the.app.height),
 
26
                 x = math.random(2, tw-2) * 16,
 
27
                 y = math.random(2, th-2) * 16
20
28
              }
21
29
              self:add(the.player)
22
30
 
 
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
 
23
37
              the.clones = Group:new()
24
38
              self:add(the.clones)
25
 
              for _ = 1, 14 do
 
39
              for _ = 1, 15 do
26
40
                 the.clones:add(Clone:new {
27
 
                                       x = math.random(the.app.width),
28
 
                                       y = math.random(the.app.height),
29
 
                                    })
 
41
                                   x = math.random(2, tw-2) * 16,
 
42
                                   y = math.random(2, th-2) * 16
 
43
                                })
 
44
              end
 
45
 
 
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
 
 
54
              if self.level ~= 1 then
 
55
                 self:flash({0,0,0})
30
56
              end
31
57
           end,
32
58
   onUpdate = function(self, dt)
33
59
                 if the.player.moved then
34
 
                    -- this should encapsulate
 
60
                    the.clones:collide(the.player)
 
61
                    the.goalPerson:collide(the.player)
 
62
 
 
63
                    if self.level ~= 2 then
 
64
                       the.goalPerson:doMove()
 
65
                    end
 
66
 
35
67
                    for _, np in ipairs(the.clones.sprites) do
36
68
                       np:doMove()
37
69
                    end
38
70
 
 
71
                    -- yeah, again.  once for flip, twice for displace
 
72
                    the.clones:collide(the.player)
 
73
                    the.goalPerson:collide(the.player) -- will this fix?
 
74
 
 
75
                    the.clones:collide(self.map)
 
76
                    the.player:collide(self.map)
 
77
                    the.goalPerson:collide(self.map)
 
78
 
39
79
                    the.clones:collide()
40
 
                    the.clones:collide(the.player)
 
80
 
 
81
                    if math.random(1,6) == 1 then
 
82
                       local c = the.clones.sprites[math.random(the.clones:count())]
 
83
                       if self.level == 3 and not c.cured then
 
84
                          c.image = 'data/goal.png'
 
85
                       end
 
86
                    end
41
87
 
42
88
                    the.player.moved = false
43
89
                 end
44
90
 
45
 
                 if the.keys:justPressed('escape', 'q') then
46
 
                    the.app:quit()
 
91
                 if the.keys:justPressed('r') then
 
92
                    the.app.view = GameView:new{level = self.level}
47
93
                 end
48
94
              end,
49
95
}
50
96
 
 
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
 
 
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
 
51
141
the.app = App:new {
52
142
   name = "LD28",
 
143
   fps = 30,
53
144
   onRun = function (self)
54
145
              print('Version: ' .. VERSION)
55
146
 
56
 
              self.view = GameView:new()
 
147
              --self.view = GameView:new{level = 1}
 
148
              self.view = TitleView:new()
57
149
 
58
150
              if DEBUG then
59
151
                 self.console:watch('VERSION', 'VERSION')
 
152
                 self.console:watch('level', 'the.view.level')
60
153
 
61
154
                 -- back off that dark overlay a bit
62
155
                 self.console.fill.fill[4] = 75
67
160
                    local ss = love.graphics.newScreenshot()
68
161
                    ss:encode('screenshot-' ..love.timer.getTime()..'.png')
69
162
                 end
 
163
 
 
164
                 if the.keys:justPressed('escape', 'q') then
 
165
                    the.app:quit()
 
166
                 end
70
167
              end
71
168
}