/traderous

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

« back to all changes in this revision

Viewing changes to main.lua

  • Committer: Josh C
  • Date: 2013-05-05 01:05:32 UTC
  • Revision ID: josh@9ix.org-20130505010532-905cpj0k6o7kpm02
ship graphic.  point it in the direction of movement.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
require 'zoetrope'
5
5
--__ = require 'underscore'
6
 
vector = require 'vector'
7
 
 
8
 
require 'group'
9
6
 
10
7
require 'version'
11
 
require 'wrap_tile'
12
8
require 'player'
13
 
require 'enemy'
14
 
require 'cursor'
15
 
require 'bullet'
16
 
require 'rock'
17
 
 
18
 
util = {
19
 
   signOf = function(value)
20
 
               if value >= 0 then
21
 
                  return 1
22
 
               else
23
 
                  return -1
24
 
               end
25
 
            end
26
 
}
27
9
 
28
10
GameView = View:extend {
29
 
   lastRock = 0,
30
 
   rockInterval = 1,
31
 
   gameStart = 0,
32
11
   onNew = function (self)
33
 
              -- for x = 1,30 do
34
 
              --    for y = 1,30 do
35
 
              --       self:add(Fill:new{x=x*400, y=y*400,
36
 
              --                         width = 32, height = 32,
37
 
              --                         fill = {0,0,255}
38
 
              --                      })
39
 
              --    end
40
 
              -- end
41
 
 
42
 
              the.bg = Tile:new{
43
 
                 image = 'data/stars3.png',
44
 
                 -- 1366x768 * 3
45
 
                 width = 4098,
46
 
                 height = 2304
47
 
              }
48
 
              self:add(the.bg)
 
12
              for x = 1,30 do
 
13
                 for y = 1,30 do
 
14
                    self:add(Fill:new{x=x*400, y=y*400,
 
15
                                      width = 32, height = 32,
 
16
                                      fill = {0,0,255}
 
17
                                   })
 
18
                 end
 
19
              end
49
20
 
50
21
              --the.player = CrystalPlayer:new{x=400,y=300}
51
 
              the.player = SpacePlayer:new{x=1366,y=768}
 
22
              the.player = SpacePlayer:new{x=400,y=300}
52
23
              self:add(the.player)
53
24
 
54
 
              self:add(Enemy:new{x=400, y=300})
55
 
 
56
 
              the.cursor = Cursor:new()
57
 
              self:add(the.cursor)
58
 
 
59
25
              love.mouse.setGrab(true)
60
 
              love.mouse.setVisible(false)
 
26
              --love.mouse.setVisible(false)
61
27
 
62
28
              --self:loadLayers('data/map.lua')
63
29
              self.focus = the.player
64
30
              --self:clampTo(self.map)
65
 
 
66
 
              self.gameStart = love.timer.getTime()
67
31
           end,
68
 
   onUpdate = function(self, dt)
69
 
                 if love.timer.getTime() > self.lastRock + self.rockInterval then
70
 
                    local rock = Rock:new{
71
 
                       x = math.random(the.bg.width),
72
 
                       y = math.random(the.bg.height),
73
 
                       velocity = {
74
 
                          x = math.random(-300, 300),
75
 
                          y = math.random(-300, 300),
76
 
                          rotation = math.random(-7, 7)
77
 
                       },
78
 
                       scale = math.random() + 0.5
79
 
                    }
80
 
                    self:add(rock)
81
 
 
82
 
                    self.lastRock = love.timer.getTime()
83
 
                 end
84
 
              end,
85
32
   draw = function (self, x, y)
86
33
             View.draw(self, x, y)
87
34
             love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
105
52
the.app = App:new {
106
53
   onRun = function (self)
107
54
              print('Version: ' .. VERSION)
108
 
 
109
 
              math.randomseed(os.time())
110
 
 
111
55
              self.view = GameView:new()
112
56
              if DEBUG then
113
57
                 self.console:watch('VERSION', 'VERSION')
114
58
                 self.console:watch('updateTook', 'the.updateTook')
115
 
                 self.console:watch('the.player.x', 'the.player.x')
116
 
                 self.console:watch('the.player.y', 'the.player.y')
117
 
                 self.console:watch('the.app.width', 'the.app.width')
118
 
                 self.console:watch('the.app.height', 'the.app.height')
119
59
                 --self.console:watch('drawTook', 'the.drawTook')
120
 
 
121
 
                 -- back off that dark overlay a bit
122
 
                 self.console.fill.fill[4] = 75
123
60
              end
124
61
           end,
125
62
   onUpdate = function (self, dt)