/traderous

To get this branch, use:
bzr branch http://9ix.org/bzr/traderous
3 by Josh C
basecode main.lua
1
STRICT = true
2
DEBUG = true
3
4
require 'zoetrope'
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
5
--__ = require 'underscore'
13 by Josh C
constant velocity for bullets. using hump.vector e9b86ef
6
vector = require 'vector'
3 by Josh C
basecode main.lua
7
24 by Josh C
monkey patch group to add onRemove hook. remove mirrors on remove.
8
require 'group'
9
3 by Josh C
basecode main.lua
10
require 'version'
21 by Josh C
extract wrapping behavior, wrap bullets
11
require 'wrap_tile'
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
12
require 'player'
7 by Josh C
enemy
13
require 'enemy'
8 by Josh C
targeting cursor (manual switch to start)
14
require 'cursor'
11 by Josh C
pew pew!
15
require 'bullet'
26 by Josh C
rocks!
16
require 'rock'
7 by Josh C
enemy
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
}
3 by Josh C
basecode main.lua
27
28
GameView = View:extend {
26 by Josh C
rocks!
29
   lastRock = 0,
30
   rockInterval = 1,
31
   gameStart = 0,
3 by Josh C
basecode main.lua
32
   onNew = function (self)
18 by Josh C
starry background
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
19 by Josh C
move player around looping world
42
              the.bg = Tile:new{
43
                 image = 'data/stars3.png',
44
                 -- 1366x768 * 3
45
                 width = 4098,
46
                 height = 2304
18 by Josh C
starry background
47
              }
19 by Josh C
move player around looping world
48
              self:add(the.bg)
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
49
50
              --the.player = CrystalPlayer:new{x=400,y=300}
19 by Josh C
move player around looping world
51
              the.player = SpacePlayer:new{x=1366,y=768}
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
52
              self:add(the.player)
53
7 by Josh C
enemy
54
              self:add(Enemy:new{x=400, y=300})
55
14 by Josh C
only fire if cursor is in target area. change cursor to reflect this.
56
              the.cursor = Cursor:new()
57
              self:add(the.cursor)
8 by Josh C
targeting cursor (manual switch to start)
58
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
59
              love.mouse.setGrab(true)
8 by Josh C
targeting cursor (manual switch to start)
60
              love.mouse.setVisible(false)
3 by Josh C
basecode main.lua
61
62
              --self:loadLayers('data/map.lua')
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
63
              self.focus = the.player
3 by Josh C
basecode main.lua
64
              --self:clampTo(self.map)
26 by Josh C
rocks!
65
66
              self.gameStart = love.timer.getTime()
3 by Josh C
basecode main.lua
67
           end,
26 by Josh C
rocks!
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,
3 by Josh C
basecode main.lua
85
   draw = function (self, x, y)
86
             View.draw(self, x, y)
87
             love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
88
          end
89
}
90
91
MenuScreen = View:extend {
92
   title = Text:new{text = "Press a key to start", font = 48, wordWrap = false},
93
   --title = Tile:new{image = 'data/title.png', x = 0, y = 0},
94
   onNew = function(self)
95
              self:add(self.title)
96
              self.title:centerAround(400, 200)
97
           end,
98
   onUpdate = function(self, elapsed)
99
                 if the.keys:allJustPressed() then
100
                    the.app.view = GameView:new()
101
                 end
102
              end
103
}
104
105
the.app = App:new {
106
   onRun = function (self)
107
              print('Version: ' .. VERSION)
26 by Josh C
rocks!
108
109
              math.randomseed(os.time())
110
3 by Josh C
basecode main.lua
111
              self.view = GameView:new()
112
              if DEBUG then
113
                 self.console:watch('VERSION', 'VERSION')
114
                 self.console:watch('updateTook', 'the.updateTook')
19 by Josh C
move player around looping world
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')
3 by Josh C
basecode main.lua
119
                 --self.console:watch('drawTook', 'the.drawTook')
22 by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored?
120
121
                 -- back off that dark overlay a bit
122
                 self.console.fill.fill[4] = 75
3 by Josh C
basecode main.lua
123
              end
124
           end,
125
   onUpdate = function (self, dt)
126
                 if the.keys:justPressed('escape') then
127
                    self.quit()
128
                 end
129
              end,
130
   update = function (self, dt)
131
               the.updateStart = love.timer.getMicroTime()
132
               App.update(self, dt)
133
               if the.updateStart then
134
                  the.updateTook = love.timer.getMicroTime() - the.updateStart
135
               end
136
            end
137
}