forked from roaminggamer/SSK2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Roaming Gamer, LLC
committed
Dec 12, 2016
1 parent
5ed76c9
commit 553f604
Showing
919 changed files
with
58,405 additions
and
181 deletions.
There are no files selected for viewing
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-- ============================================================= | ||
-- Copyright Roaming Gamer, LLC. 2008-2016 (All Rights Reserved) | ||
-- ============================================================= | ||
-- Actions Loader | ||
-- ============================================================= | ||
-- Last Updated: 23 NOV 2016 | ||
-- Last Validated: 23 NOV 2016 | ||
-- ============================================================= | ||
|
||
local actions = {} | ||
|
||
if( _G.ssk ) then | ||
_G.ssk.actions = actions | ||
end | ||
|
||
actions.face = require "ssk2.actions.face" | ||
actions.move = require "ssk2.actions.move" | ||
actions.movep = require "ssk2.actions.movep" | ||
actions.scene = require "ssk2.actions.scene" | ||
actions.target = require "ssk2.actions.target" | ||
|
||
return actions |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
-- ============================================================= | ||
-- Copyright Roaming Gamer, LLC. 2008-2016 (All Rights Reserved) | ||
-- ============================================================= | ||
-- Actions Library - Facing Functions | ||
-- ============================================================= | ||
-- Last Updated: 29 NOV 2016 | ||
-- Last Validated: 29 NOV 2016 | ||
-- ============================================================= | ||
|
||
function face( obj, params ) | ||
local target = params.target or obj._target | ||
local angle = params.angle | ||
local doPause = params.pause | ||
|
||
-- Once started, face must be called every frame, but | ||
-- you can pause the face action any time, to avoid | ||
-- the subsequent heavy calculations. | ||
-- | ||
if(doPause) then | ||
obj.__last_face_time = system.getTimer() | ||
return | ||
end | ||
|
||
-- Face target 'immediately' | ||
if( params.rate == nil ) then | ||
if( angle == nil ) then | ||
local vec = {} | ||
vec.x = target.x - obj.x | ||
vec.y = target.y - obj.y | ||
angle = math.ceil(math.atan2( (vec.y), (vec.x) ) * 180 / math.pi) + 90 | ||
end | ||
obj.rotation = angle | ||
|
||
-- Face target at rate (degrees per second) | ||
else | ||
local curTime = system.getTimer() | ||
if( not obj.__last_face_time ) then | ||
obj.__last_face_time = curTime | ||
end | ||
local dt = curTime - obj.__last_face_time | ||
obj.__last_face_time = curTime | ||
|
||
local dps = params.rate or 180 | ||
local rate = params.rate * dt / 1000 | ||
|
||
local vec = {} | ||
if( target ) then | ||
vec.x = target.x - obj.x | ||
vec.y = target.y - obj.y | ||
else | ||
vec.x = 0 | ||
vec.y = 0 | ||
end | ||
|
||
local targetAngle = angle or math.ceil(math.atan2( (vec.y), (vec.x) ) * 180 / math.pi) + 90 | ||
|
||
local deltaAngle = math.floor((targetAngle - obj.rotation) + 0.5) | ||
deltaAngle = (deltaAngle + 180) % 360 - 180 | ||
|
||
if( math.abs( deltaAngle ) <= rate ) then | ||
obj.rotation = targetAngle | ||
elseif( deltaAngle > 0 ) then | ||
obj.rotation = obj.rotation + rate | ||
else | ||
obj.rotation = obj.rotation - rate | ||
end | ||
|
||
if( obj.rotation < 0 ) then obj.rotation = obj.rotation + 360 end | ||
if( obj.rotation >= 360 ) then obj.rotation = obj.rotation - 360 end | ||
end | ||
end | ||
return face |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
-- ============================================================= | ||
-- Copyright Roaming Gamer, LLC. 2008-2016 (All Rights Reserved) | ||
-- ============================================================= | ||
-- Actions Library - Move Functions | ||
-- ============================================================= | ||
-- Last Updated: 29 NOV 2016 | ||
-- Last Validated: 29 NOV 2016 | ||
-- ============================================================= | ||
local move = {} | ||
|
||
-- Forward Declarations | ||
-- SSK | ||
local angle2Vector = ssk.math2d.angle2Vector | ||
local vector2Angle = ssk.math2d.vector2Angle | ||
local scaleVec = ssk.math2d.scale | ||
local addVec = ssk.math2d.add | ||
local subVec = ssk.math2d.sub | ||
local getNormals = ssk.math2d.normals | ||
local lenVec = ssk.math2d.length | ||
local lenVec2 = ssk.math2d.length2 | ||
local normVec = ssk.math2d.normalize | ||
|
||
local isValid = display.isValid | ||
|
||
|
||
-- Lua and Corona | ||
local mAbs = math.abs | ||
local mRand = math.random | ||
local mDeg = math.deg | ||
local mRad = math.rad | ||
local mCos = math.cos | ||
local mSin = math.sin | ||
local mAcos = math.acos | ||
local mAsin = math.asin | ||
local mSqrt = math.sqrt | ||
local mCeil = math.ceil | ||
local mFloor = math.floor | ||
local mAtan2 = math.atan2 | ||
local mPi = math.pi | ||
local getTimer = system.getTimer | ||
|
||
|
||
|
||
-- Limit the bounds within with object may move | ||
move.limit = function( obj, params ) | ||
end | ||
|
||
-- Limit the radial bounds within with object may move | ||
move.limitr = function( obj, params ) | ||
end | ||
|
||
local lastForwardTime = {} | ||
-- Move object forward at fixed rate | ||
move.forward = function( obj, params ) | ||
if( not isValid( obj ) ) then return end | ||
params = params or {} | ||
|
||
local curTime = getTimer() | ||
if( not lastForwardTime[obj]) then | ||
lastForwardTime[obj] = curTime | ||
end | ||
local dt = curTime - lastForwardTime[obj] | ||
lastForwardTime[obj] = curTime | ||
|
||
local pps = params.rate or 100 | ||
local rate = pps * dt/1000 | ||
|
||
local v = angle2Vector( obj.rotation, true ) | ||
v = scaleVec( v, rate ) | ||
obj:translate( v.x, v.y ) | ||
end | ||
|
||
|
||
-- Move object in x,y direction at fixed rate per-second or per-frame | ||
move.at = function( obj, params ) | ||
if( not isValid( obj ) ) then | ||
return | ||
end | ||
params = params or {} | ||
|
||
local perSecond = not params.perFrame -- set this to true to move perFrame | ||
|
||
local x = params.x or 0 | ||
local y = params.y or 0 | ||
|
||
if( perSecond ) then | ||
|
||
local curTime = getTimer() | ||
if( not obj.__last_move_at_time) then | ||
obj.__last_move_at_time = curTime | ||
end | ||
local dt = curTime - obj.__last_move_at_time | ||
obj.__last_move_at_time = curTime | ||
x = x * dt/1000 | ||
y = y * dt/1000 | ||
obj:translate( x, y ) | ||
else | ||
obj:translate( x, y ) | ||
end | ||
end | ||
|
||
return move |
176 changes: 176 additions & 0 deletions
176
releases/ssk_2016.001/validation/ssk2/actions/movep.lua
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
-- ============================================================= | ||
-- Copyright Roaming Gamer, LLC. 2008-2016 (All Rights Reserved) | ||
-- ============================================================= | ||
-- Actions Library - Move via Physics Functions | ||
-- ============================================================= | ||
-- Last Updated: 29 NOV 2016 | ||
-- Last Validated: 29 NOV 2016 | ||
-- ============================================================= | ||
-- Development Notes: | ||
-- 1. Add more dampening variations | ||
-- | ||
|
||
local movep = {} | ||
|
||
-- Forward Declarations | ||
-- SSK | ||
local angle2Vector = ssk.math2d.angle2Vector | ||
local vector2Angle = ssk.math2d.vector2Angle | ||
local scaleVec = ssk.math2d.scale | ||
local addVec = ssk.math2d.add | ||
local subVec = ssk.math2d.sub | ||
local getNormals = ssk.math2d.normals | ||
local lenVec = ssk.math2d.length | ||
local lenVec2 = ssk.math2d.length2 | ||
local normVec = ssk.math2d.normalize | ||
|
||
local isValid = display.isValid | ||
|
||
|
||
-- Lua and Corona | ||
local mAbs = math.abs | ||
local mRand = math.random | ||
local mDeg = math.deg | ||
local mRad = math.rad | ||
local mCos = math.cos | ||
local mSin = math.sin | ||
local mAcos = math.acos | ||
local mAsin = math.asin | ||
local mSqrt = math.sqrt | ||
local mCeil = math.ceil | ||
local mFloor = math.floor | ||
local mAtan2 = math.atan2 | ||
local mPi = math.pi | ||
local getTimer = system.getTimer | ||
|
||
|
||
-- Dampen vertical velocity ONLY | ||
movep.dampVert = function( obj, params ) | ||
if( not isValid( obj ) ) then return end | ||
|
||
local vx,vy = obj:getLinearVelocity() | ||
|
||
local dRate = vy * (params.damping or 1)/50 | ||
vy = vy - dRate | ||
|
||
obj:setLinearVelocity( vx, vy ) | ||
end | ||
|
||
-- Dampen horizontal velocity ONLY | ||
movep.dampHoriz = function( obj, params ) | ||
if( not isValid( obj ) ) then return end | ||
|
||
local vx,vy = obj:getLinearVelocity() | ||
|
||
local dRate = vx * (params.damping or 1)/50 | ||
vx = vx - dRate | ||
|
||
obj:setLinearVelocity( vx, vy ) | ||
end | ||
|
||
-- Dampen vertical velocity in the downward direction only | ||
movep.dampDown = function( obj, params ) | ||
if( not isValid( obj ) ) then return end | ||
|
||
local vx,vy = obj:getLinearVelocity() | ||
|
||
if( vy <= 0 ) then return end | ||
|
||
local dRate = vy * (params.damping or 1)/25 | ||
|
||
if( dRate < 0.0001 ) then return end | ||
|
||
vy = vy - dRate | ||
|
||
obj:setLinearVelocity( vx, vy ) | ||
end | ||
|
||
-- Limit object's linear velocity | ||
movep.limitV = function( obj, params ) | ||
if( not isValid( obj ) ) then return end | ||
|
||
local vx,vy = obj:getLinearVelocity() | ||
local rate = params.rate or 100 | ||
|
||
if(lenVec2( vx, vy ) <= ( rate ^ 2) ) then return end | ||
|
||
local vec = normVec({ x = vx, y = vy } ) | ||
vec = scaleVec( vec, rate ) | ||
obj:setLinearVelocity( vec.x, vec.y ) | ||
end | ||
|
||
-- Limit object's angular velocity | ||
movep.limitAV = function( obj, params ) | ||
if( not isValid( obj ) ) then return end | ||
|
||
local av = obj.angularVelocity | ||
local rate = params.rate or 180 | ||
|
||
if(mAbs(av) > rate) then | ||
obj.angularVelocity = (av>0) and rate or -rate | ||
end | ||
end | ||
|
||
|
||
-- Move object forward at fixed velocity | ||
movep.forward = function( obj, params ) | ||
if( not isValid( obj ) ) then return end | ||
params = params or {} | ||
|
||
local curTime = getTimer() | ||
if( not obj.__last_forward_time ) then | ||
obj.__last_forward_time = curTime | ||
end | ||
local dt = curTime - obj.__last_forward_time | ||
obj.__last_forward_time = curTime | ||
|
||
local rate = params.rate or 100 | ||
|
||
local v = angle2Vector( obj.rotation, true ) | ||
v = scaleVec( v, rate ) | ||
|
||
obj:setLinearVelocity( v.x, v.y ) | ||
end | ||
|
||
|
||
local lastThrustForwardTime = {} | ||
-- Move object forward at fixed velocity | ||
movep.thrustForward = function( obj, params ) | ||
if( not isValid( obj ) ) then return end | ||
params = params or {} | ||
|
||
local curTime = getTimer() | ||
if( not obj.__last_thrust_forward_time) then | ||
obj.__last_thrust_forward_time = curTime | ||
end | ||
local dt = curTime - obj.__last_thrust_forward_time | ||
obj.__last_thrust_forward_time = curTime | ||
|
||
local rate = params.rate or 100 | ||
|
||
if( not params.ignoreMass ) then | ||
rate = rate * obj.mass | ||
end | ||
|
||
local v = angle2Vector( obj.rotation, true ) | ||
v = scaleVec( v, rate ) | ||
obj:applyForce( v.x, v.y, obj.x, obj.y ) | ||
end | ||
|
||
-- Move object forward at fixed velocity | ||
movep.impulseForward = function( obj, params ) | ||
if( not isValid( obj ) ) then return end | ||
params = params or {} | ||
|
||
local mag = params.mag or 1 | ||
|
||
if( not params.ignoreMass ) then | ||
mag = mag * obj.mass | ||
end | ||
|
||
local v = angle2Vector( obj.rotation, true ) | ||
v = scaleVec( v, mag ) | ||
obj:applyLinearImpulse( v.x, v.y, obj.x, obj.y ) | ||
end | ||
|
||
return movep |
Oops, something went wrong.