This file contains hidden or 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
### Keybase proof | |
I hereby claim: | |
* I am omidahourai on github. | |
* I am omidahourai (https://keybase.io/omidahourai) on keybase. | |
* I have a public key ASCeZXQLzyC_PXdWkSt556zirWKEaqBNf85ArSIWBOq-Fgo | |
To claim this, I am signing this object: |
This file contains hidden or 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
function character:move() | |
--Localized variables and function calls | |
local mCos, mSin = math.cos, math.sin | |
local group = self.group | |
--Closure enterFrame | |
local function onEachFrame(event) | |
local speed = self.speed or 0 | |
local angle = self.angle or 0 |
This file contains hidden or 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
--WITHOUT CLOSURE | |
function character:enterFrame(event) | |
local speed = self.speed or 0 | |
local angle = self.angle or 0 | |
local xval = math.cos(angle) * speed | |
local yval = -math.sin(angle) * speed | |
self.group:translate(xval, yval) |
This file contains hidden or 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
function character:enterFrame(event) | |
--Get speed and angle | |
local speed = self.speed or 0 | |
local angle = self.angle or 0 | |
--Claculate x-y distances | |
local xval = math.cos(angle) * speed | |
local yval = -math.sin(angle) * speed | |
--Move the character's group/ sprite/ image |
This file contains hidden or 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
--Classes/Objects/Animal.lua | |
local scene = scene | |
local Super = require('Classes.Object') | |
local Animal = Class(Super) --inherits Object Class | |
--INSTANCE FUNCTIONS | |
function Animal:initialize(img) | |
--calls parent Class's initialize() | |
--with "self" as this instance |
This file contains hidden or 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
--Hud.lua | |
scene:addEventListener('onEnemyKill', Hud) | |
function Hud:onEnemyKill(event) | |
local points = self.points + 20 | |
self.points = points | |
self:dispatchEvent({name='onEnemyKill', points=points}) --dispatch to Hud scope | |
end | |
--Score.lua | |
Hud:addEventListener('onEnemyKill', Score) --listen on Hud scope |
This file contains hidden or 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
--main.lua | |
local storyboard = require('storyboard') | |
storyboard.gotoScene('SceneGame') | |
--SceneGame.lua | |
local Game = storyboard.newScene() | |
Game:addEventListener('createScene', Game) | |
function Game:createScene() | |
scene = self.view | |
local scene = scene |
This file contains hidden or 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
--Cat.lua | |
local scene = scene | |
local Cat = {Instances={}} | |
--CAT CLASS METHODS (FIRST LETTER IS CAPITOLIZED) | |
Cat.Get = scene.Get | |
Cat.Show = scene.Show | |
Cat.Dispose = scene.Dispose |
This file contains hidden or 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
--Mouse.lua | |
local scene = scene | |
local Mouse = {Instances={}} | |
--MOUSE CLASS METHODS (FIRST LETTER IS CAPITOLIZED) | |
Mouse.Get = scene.Get | |
Mouse.Show = scene.Show | |
Mouse.Dispose = scene.Dispose |
This file contains hidden or 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
--Enemy.lua | |
local scene = scene | |
local Enemy = {Instances={}}; scene.Enemy = Enemy | |
--STATIC CLASS FUNCTIONS (self refers to Enemy, not enemy) | |
function Enemy:New() | |
--creates an enemy instance | |
local enemy = display.newImage('image_name') |
NewerOlder