/traderous

To get this branch, use:
bzr branch http://9ix.org/bzr/traderous
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
CrystalPlayer = Fill:extend{
   fill = {255,0,0},
   height = 32,
   width = 32,
   onStartFrame = function(self)
                     if the.mouse:pressed() then
                        print('hi')
                     end

                     local dx = love.mouse.getX() - the.app.width / 2
                     local dy = love.mouse.getY() - the.app.height / 2

                     self.acceleration.x = dx * 10
                     self.acceleration.y = dy * 10

                     --print(dx, dy)

                     love.mouse.setPosition(the.app.width /2, the.app.height/2)
                  end
}

local velLimit = 600
SpacePlayer = Tile:extend{
   image = 'data/ship.png',
   maxVelocity = {x=velLimit,y=velLimit},
   minVelocity = {x=-velLimit, y=-velLimit},
   lastFired = 0,
   onStartFrame = function(self)
                     --local dx = love.mouse.getX() - self.x
                     --local dy = love.mouse.getY() - self.y
                     local dx = love.mouse.getX() - the.app.width / 2
                     local dy = love.mouse.getY() - the.app.height / 2


                     self.acceleration.x = dx * 2
                     self.acceleration.y = dy * 2

                     --TODO: acceleration limit.  It should at least be proportional (not 16:9)

                     if the.mouse:pressed() then -- assumes left button
                        if love.timer.getTime() - self.lastFired > 0.25 then
                           --print('pew')
                           b = Bullet:new{
                              x = self.x, y = self.y,
                              rotation = self.rotation,
                              velocity = {
                                 x = self.velocity.x * 1.5,
                                 y = self.velocity.y * 1.5
                              },
                           }
                           the.app.view:add(b)
                           self.lastFired = love.timer.getTime()
                        end
                     end
                  end,
   onUpdate = function(self)
                 self.rotation = math.atan2(self.velocity.y, self.velocity.x)
              end
}