fix/workaround: removed glitches with scaling and quads
[uboot.git] / entities.lua
blob6025bd00a203289d02f48d935b1e05c9c6efa887
1 require 'inheritance'
2 require 'physics'
4 entity = {}
6 --[[
7 entity object constructor
8 properties: xPos, yPos, speed, density
9 ]]--
10 function entity:new(o)
11 setmetatable(o,self)
12 self.__index=self
13 return o
14 end
16 --[[
17 Stub
18 ]]--
19 function entity:init(xPos,yPos)
20 end
22 -- TODO stub
23 function entity:setSprite(sprite)
24 end
26 --TODO stub
27 function entity:draw(x,y)
28 end
30 -- method to set horizontal speed
31 function entity:setSpeed(speed)
32 self.speed = speed
33 end
35 -- method to set density, makes entities 'dive' (NOT density of love.physics)
36 function entity:setDensity(density)
37 self.density = density
38 end
40 -- TODO or remove
41 function entity:setPosition(xPos, yPos)
42 end
44 -- SHIP:
45 Ship ={}
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
51 self.test = true
52 self.body,self.shape,self.fixture = physics_createBodyWithShape(xPos,yPos,shipShape)
53 end
55 --[[
56 draws a ship TODO new..
57 ]]--
58 function Ship:draw(camX,camY)
59 love.graphics.push()
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)
64 love.graphics.pop()
65 end
67 -- TORPEDO:
68 Torpedo = {}
69 --torpedo object inherits methods from entity
70 Torpedo = inherits(entity)