Created
June 6, 2012 23:30
-
-
Save Midiman/2885497 to your computer and use it in GitHub Desktop.
[Love2D] Class Inheritence Error?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--------------------------------------------------------------- | |
-- Amethyst | |
-- Created: 2012/06/05 10:02 PM | |
-- Version: 0.0.1 | |
-- Website: http://www.place.com/ | |
-- License: :) License | |
--------------------------------------------------------------- | |
require("libs/32log") | |
require("util/types") | |
RESOURCES = { | |
Fonts = {}, | |
} | |
Fonts = RESOURCES.Fonts | |
local Vector1 = Vec2:new(1,2); | |
local Vector2 = Vec2:new(2,1); | |
function love.load() | |
RESOURCES.Fonts["Normal"] = love.graphics.newFont( | |
"resource/fonts/OpenSans-Regular.ttf", | |
16 | |
) | |
love.graphics.setFont(Fonts.Normal) | |
end | |
function love.draw() | |
love.graphics.setBackgroundColor(100,149,237) | |
love.graphics.print( (Vector1:x() == Vector2:x()) and "Yes" or "No", 320, 240) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------ | |
-- Object | |
------------------------------ | |
class "Object" { | |
_id = 0; | |
_type = "Object"; | |
} | |
function Object:__init() | |
self._id = math.random(0,65535); | |
self._type = "Object"; | |
end | |
------------------------------ | |
-- Vector 2 | |
------------------------------ | |
class "Vec2" : extends("Object") { | |
_id = 64; | |
_type = "Vec2"; | |
_x = 0; | |
_y = 0; | |
} | |
function Vec2:__init(x, y) | |
self._x = x or 0 | |
self._y = y or 0 | |
end | |
function Vec2:x() | |
return self._x; | |
end | |
function Vec2:y() | |
return self._y; | |
end | |
------------------------------ | |
-- Vector 3 | |
------------------------------ | |
class "Vec3" { | |
x = 0; | |
y = 0; | |
z = 0; | |
} | |
function Vec3:__init(x, y, z) | |
self.x = x | |
self.y = y | |
self.z = z | |
end | |
function Vec3:x() | |
return self.x | |
end | |
function Vec3:y() | |
return self.y | |
end | |
function Vec3:z() | |
return self.z | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment