/ld27

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

« back to all changes in this revision

Viewing changes to player.lua

  • Committer: Josh C
  • Date: 2013-08-25 16:32:40 UTC
  • Revision ID: josh@9ix.org-20130825163240-ga1iviz5lgizi8bu
oops, actually check in win view

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
local velLimit = 400
1
2
Player = Tile:extend{
2
3
   image = 'data/player.png',
 
4
   maxVelocity = {x=velLimit,y=velLimit},
 
5
   minVelocity = {x=-velLimit, y=-velLimit},
3
6
   onNew = function(self)
4
 
              self.collider = PlayerCollider:new{x=self.x, y=self.y}
 
7
              self.collider = PlayerCollider:new()
5
8
              the.view:add(self.collider)
6
9
           end,
7
 
   -- onUpdate = function(self, dt)
8
 
   --               self.collider.x = self.x + self.width / 2 * (1 - self.scale)
9
 
   --               self.collider.y = self.y + self.height / 2 * (1 - self.scale)
10
 
   --            end,
11
 
}
12
 
 
13
 
PlayerCollider = Fill:extend{
14
 
   fill = {0,0,255},
15
 
   collisions = {},
16
10
   onStartFrame = function(self)
17
11
                     if the.keys:pressed('left') then
18
12
                        self.velocity.x = -200 * the.activeMaze.moveMod
30
24
                        self.velocity.y = 0
31
25
                     end
32
26
                  end,
33
 
   update = function(self, elapsed)
34
 
               self.visible = DEBUG and the.console.visible
35
 
 
36
 
               self:doPhysics('x', elapsed)
37
 
               if not (DEBUG and the.console.visible) then
38
 
                  self:collide(the.activeMaze)
39
 
               end
40
 
 
41
 
               -- handle X collisions
42
 
               for _, col in ipairs(self.collisions) do
43
 
                  col.other:displaceDir(self, 'x')
44
 
               end
45
 
 
46
 
               self:doPhysics('y', elapsed)
47
 
               if not (DEBUG and the.console.visible) then
48
 
                  self:collide(the.activeMaze)
49
 
               end
50
 
 
51
 
               -- handle Y collisions
52
 
               for _, col in ipairs(self.collisions) do
53
 
                  col.other:displaceDir(self, 'y')
54
 
               end
55
 
 
56
 
               local p = the.player
57
 
               p.x = self.x - p.width / 2 * (1 - p.scale)
58
 
               p.y = self.y - p.height / 2 * (1 - p.scale)
59
 
            end,
60
 
   collide = function (self, ...)
61
 
                self.collisions = {}
62
 
                Fill.collide(self, ...)
63
 
             end,
64
 
   onCollide = function (self, other, xOverlap, yOverlap)
65
 
                  if other == the.activeMaze then return end
66
 
 
67
 
                  --print('collision')
68
 
                  --print(inspect(other))
69
 
 
70
 
                  table.insert(self.collisions, {other = other,
71
 
                                                 xOverlap = xOverlap,
72
 
                                                 yOverlap = yOverlap })
73
 
               end
74
 
 
 
27
   onUpdate = function(self, dt)
 
28
                 self.collider.x = self.x + self.width / 2 * (1 - self.scale)
 
29
                 self.collider.y = self.y + self.height / 2 * (1 - self.scale)
 
30
              end,
 
31
}
 
32
 
 
33
PlayerCollider = Fill:extend{
 
34
   fill = {0,0,255},
 
35
   onUpdate = function(self, dt)
 
36
                 self.visible = DEBUG and the.console.visible
 
37
              end,
 
38
   onCollide = function(self, other)
 
39
                  local p = the.player
 
40
 
 
41
                  other:displace(self)
 
42
                  p.x = self.x - p.width / 2 * (1 - p.scale)
 
43
                  p.y = self.y - p.height / 2 * (1 - p.scale)
 
44
               end
75
45
}
 
 
b'\\ No newline at end of file'