Skip to content

Instantly share code, notes, and snippets.

View omidahourai's full-sized avatar

Omid Ahourai omidahourai

View GitHub Profile
### 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:
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
--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)
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
@omidahourai
omidahourai / OOP-Animal.lua
Created February 15, 2013 03:47
These snippets are described in detail as part of the Object-Oriented Lua Tutorial available at: http://www.ardentkid.com/blog/from-zero-to-oo-ardentkids-guide-to-object-oriented-lua-with-corona-sdk
--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
--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
@omidahourai
omidahourai / example-123112.lua
Last active December 10, 2015 10:38
AndersT - Q&A
--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
@omidahourai
omidahourai / Cat.lua
Created December 5, 2012 16:46
Custom Event Tutorial (OO-Lua, 3/4) http://blog.ardentkid.com
--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
@omidahourai
omidahourai / Mouse.lua
Created December 5, 2012 16:45
Custom Event Tutorial (OO-Lua, 3/4) http://blog.ardentkid.com
--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
@omidahourai
omidahourai / Enemy.lua
Created November 27, 2012 20:02
Enemy Class (example for OO-Lua)
--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')