/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-14 20:52:47 UTC
  • Revision ID: josh@9ix.org-20131214205247-f42dwe3rx00da9cr
player collide w/ map

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
STRICT = true
 
2
DEBUG = true
 
3
 
 
4
require 'zoetrope'
 
5
deque = require 'deque'
 
6
--inspect = require 'inspect'
 
7
require 'sprite'
 
8
 
 
9
require 'util'
 
10
require 'version'
 
11
require 'player'
 
12
require 'clone'
 
13
 
 
14
GameView = View:extend {
 
15
   onNew = function (self)
 
16
              self:loadLayers('data/map.lua')
 
17
 
 
18
              the.player = Player:new{
 
19
                 x = math.random(the.app.width),
 
20
                 y = math.random(the.app.height),
 
21
              }
 
22
              self:add(the.player)
 
23
 
 
24
              the.clones = Group:new()
 
25
              self:add(the.clones)
 
26
              for _ = 1, 14 do
 
27
                 the.clones:add(Clone:new {
 
28
                                       x = math.random(16, the.app.width-32),
 
29
                                       y = math.random(16, the.app.height-32),
 
30
                                    })
 
31
              end
 
32
           end,
 
33
   onUpdate = function(self, dt)
 
34
                 if the.player.moved then
 
35
                    -- this should encapsulate
 
36
                    for _, np in ipairs(the.clones.sprites) do
 
37
                       np:doMove()
 
38
                    end
 
39
 
 
40
                    the.clones:collide(self.map)
 
41
                    the.player:collide(self.map)
 
42
 
 
43
                    the.clones:collide()
 
44
                    the.clones:collide(the.player)
 
45
 
 
46
                    the.player.moved = false
 
47
                 end
 
48
 
 
49
                 if the.keys:justPressed('escape', 'q') then
 
50
                    the.app:quit()
 
51
                 end
 
52
              end,
 
53
}
 
54
 
 
55
the.app = App:new {
 
56
   name = "LD28",
 
57
   onRun = function (self)
 
58
              print('Version: ' .. VERSION)
 
59
 
 
60
              self.view = GameView:new()
 
61
 
 
62
              if DEBUG then
 
63
                 self.console:watch('VERSION', 'VERSION')
 
64
 
 
65
                 -- back off that dark overlay a bit
 
66
                 self.console.fill.fill[4] = 75
 
67
              end
 
68
           end,
 
69
   onUpdate = function (self, dt)
 
70
                 if the.keys:justPressed('f1') then
 
71
                    local ss = love.graphics.newScreenshot()
 
72
                    ss:encode('screenshot-' ..love.timer.getTime()..'.png')
 
73
                 end
 
74
              end
 
75
}