7 entity object constructor
8 properties: xPos, yPos, speed, density
10 function entity
:new(o
)
19 function entity
:init(xPos
,yPos
)
23 function entity
:setSprite(sprite
)
27 function entity
:draw(x
,y
)
30 -- method to set horizontal speed
31 function entity
:setSpeed(speed
)
35 -- method to set density, makes entities 'dive' (NOT density of love.physics)
36 function entity
:setDensity(density
)
37 self
.density
= density
41 function entity
:setPosition(xPos
, yPos
)
46 --ship object inherits methods from entity
47 Ship
= inherits(entity
)
49 function Ship
:init(xPos
,yPos
)
50 local shipShape
= {-5,0,0,5,5,0,0,-5} -- the shape of a ship
52 self
.body
,self
.shape
,self
.fixture
= physics_createBodyWithShape(xPos
,yPos
,shipShape
)
56 draws a ship TODO new..
58 function Ship
:draw(camX
,camY
)
60 love
.graphics
.setColor(255,255,255)
61 local sx
= self
.body
:getX()-camX
62 local sy
= self
.body
:getY()-camY
63 love
.graphics
.polygon('fill',sx
-5,sy
,sx
,sy
+5,sx
+5,sy
,sx
,sy
-5)
69 --torpedo object inherits methods from entity
70 Torpedo
= inherits(entity
)