/spacey

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

« back to all changes in this revision

Viewing changes to main.lua

  • Committer: Josh C
  • Date: 2013-05-05 17:28:21 UTC
  • Revision ID: josh@9ix.org-20130505172821-t5ba218dz1pkjois
ignore deploy dir

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
STRICT = true
 
2
DEBUG = true
 
3
 
 
4
require 'zoetrope'
 
5
--__ = require 'underscore'
 
6
 
 
7
require 'version'
 
8
require 'player'
 
9
require 'enemy'
 
10
require 'cursor'
 
11
 
 
12
util = {
 
13
   signOf = function(value)
 
14
               if value >= 0 then
 
15
                  return 1
 
16
               else
 
17
                  return -1
 
18
               end
 
19
            end
 
20
}
 
21
 
 
22
GameView = View:extend {
 
23
   onNew = function (self)
 
24
              for x = 1,30 do
 
25
                 for y = 1,30 do
 
26
                    self:add(Fill:new{x=x*400, y=y*400,
 
27
                                      width = 32, height = 32,
 
28
                                      fill = {0,0,255}
 
29
                                   })
 
30
                 end
 
31
              end
 
32
 
 
33
              --the.player = CrystalPlayer:new{x=400,y=300}
 
34
              the.player = SpacePlayer:new{x=400,y=300}
 
35
              self:add(the.player)
 
36
 
 
37
              self:add(Enemy:new{x=400, y=300})
 
38
 
 
39
              self:add(Cursor:new())
 
40
 
 
41
              love.mouse.setGrab(true)
 
42
              love.mouse.setVisible(false)
 
43
 
 
44
              --self:loadLayers('data/map.lua')
 
45
              self.focus = the.player
 
46
              --self:clampTo(self.map)
 
47
           end,
 
48
   draw = function (self, x, y)
 
49
             View.draw(self, x, y)
 
50
             love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
 
51
          end
 
52
}
 
53
 
 
54
MenuScreen = View:extend {
 
55
   title = Text:new{text = "Press a key to start", font = 48, wordWrap = false},
 
56
   --title = Tile:new{image = 'data/title.png', x = 0, y = 0},
 
57
   onNew = function(self)
 
58
              self:add(self.title)
 
59
              self.title:centerAround(400, 200)
 
60
           end,
 
61
   onUpdate = function(self, elapsed)
 
62
                 if the.keys:allJustPressed() then
 
63
                    the.app.view = GameView:new()
 
64
                 end
 
65
              end
 
66
}
 
67
 
 
68
the.app = App:new {
 
69
   onRun = function (self)
 
70
              print('Version: ' .. VERSION)
 
71
              self.view = GameView:new()
 
72
              if DEBUG then
 
73
                 self.console:watch('VERSION', 'VERSION')
 
74
                 self.console:watch('updateTook', 'the.updateTook')
 
75
                 --self.console:watch('drawTook', 'the.drawTook')
 
76
              end
 
77
           end,
 
78
   onUpdate = function (self, dt)
 
79
                 if the.keys:justPressed('escape') then
 
80
                    self.quit()
 
81
                 end
 
82
              end,
 
83
   update = function (self, dt)
 
84
               the.updateStart = love.timer.getMicroTime()
 
85
               App.update(self, dt)
 
86
               if the.updateStart then
 
87
                  the.updateTook = love.timer.getMicroTime() - the.updateStart
 
88
               end
 
89
            end
 
90
}