-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameObject.lua
38 lines (30 loc) · 851 Bytes
/
gameObject.lua
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
-- Package: gameObject
-- This package contains the GameObject table which is the base class for all objects
local P = {}
gameObject = P
-- Imports
local print = print
local love = love
local setmetatable = setmetatable
setfenv(1, P)
GameObject = {}
function GameObject:new(xPos, yPos, width, height)
local o = {xPos = xPos, yPos = yPos, width = width, height = height}
setmetatable(o, self)
self.__index = self
return o
end
-- Draws the game object
function GameObject:draw()
local scaleX = self.scaleX or 1
local scaleY = self.scaleY or 1
love.graphics.draw(self.image, self.xPos, self.yPos, 0, scaleX, scaleY)
end
-- Returns the bottom y position
function GameObject:bottom()
return self.yPos + self.height
end
-- Returns the right x position
function GameObject:right()
return self.xPos + self.width
end