Created
December 25, 2012 20:46
-
-
Save juaxix/4375317 to your computer and use it in GitHub Desktop.
Ludum Dare #25 -- You Are The Invader
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
-- multiplatform Game made for Ludum Dare using Stonetrip ShiVa 3D Engine | |
-- More info: http://www.ludumdare.com/compo/ludum-dare-25/?action=preview&uid=10960 | |
-- Support developer from XIXGAMES: http://www.xixgames.com @juaxix | |
-------------------------------------------------------------------------------- | |
function alien.onInit ( ) | |
-------------------------------------------------------------------------------- | |
sensor.setActiveAt ( this.getObject ( ),0,false ) | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function alien.onEnterFrame ( ) | |
-------------------------------------------------------------------------------- | |
local me = this.getObject ( ) | |
object.translate ( me, 0,0,-0.6,object.kLocalSpace ) | |
local x,y,z = object.getTranslation ( me, object.kGlobalSpace ) | |
if z < -33 then | |
scene.destroyRuntimeObject ( application.getCurrentUserScene ( ), me ) | |
elseif z < 40 and not sensor.isActiveAt ( me,0 ) then | |
sensor.setActiveAt ( this.getObject ( ),0, true ) | |
end | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function alien.onSensorCollisionBegin ( nSensorID, hTargetObject, nTargetSensorID ) | |
-------------------------------------------------------------------------------- | |
if hTargetObject then | |
local model = object.getModelName( hTargetObject) | |
if model == "fire" then | |
log.warning ( "dead" ) | |
user.postEvent ( application.getCurrentUser ( ), 0 , "main", "onAlienKilled",hTargetObject ) | |
sensor.removeAll ( this.getObject ( ) ) | |
-- remove me | |
scene.destroyRuntimeObject ( application.getCurrentUserScene ( ), this.getObject ( ) ) | |
elseif model == "ship" then | |
user.postEvent ( application.getCurrentUser ( ), 0 , "main", "onShipKilled",hTargetObject ) | |
sensor.removeAll ( this.getObject ( ) ) | |
-- remove me | |
scene.destroyRuntimeObject ( application.getCurrentUserScene ( ), this.getObject ( ) ) | |
else | |
log.warning ( "Colision:"..model ) | |
end | |
end | |
-------------------------------------------------------------------------------- | |
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
-- multiplatform Game made for Ludum Dare using Stonetrip ShiVa 3D Engine | |
-- More info: http://www.ludumdare.com/compo/ludum-dare-25/?action=preview&uid=10960 | |
-- Support developer from XIXGAMES: http://www.xixgames.com @juaxix | |
-------------------------------------------------------------------------------- | |
function Goat.onEnterFrame ( ) | |
-------------------------------------------------------------------------------- | |
local goat = this.getObject ( ) | |
if object.isVisible ( goat ) then | |
object.translate ( goat, 0,0,-0.15,object.kGlobalSpace ) | |
if animation.getCurrentClip ( goat,0 )==1 then | |
if animation.getPlaybackCursor ( goat,0 )>= animation.getClipKeyFrameRangeMax ( goat,1 )-2 then | |
animation.setCurrentClip ( goat,0,0 ) | |
animation.setPlaybackCursor ( goat,0,0 ) | |
end | |
end | |
end | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function Goat.onSensorCollisionBegin ( nSensorID, hTargetObject, nTargetSensorID ) | |
-------------------------------------------------------------------------------- | |
if not object.isVisible ( this.getObject ( ) ) then return end | |
if hTargetObject then | |
local model = object.getModelName ( hTargetObject ) | |
if model == "ship" then | |
--object.setVisible ( this.getObject ( ), false ) | |
animation.setCurrentClip ( this.getObject ( ),0,1 ) | |
user.postEvent ( application.getCurrentUser ( ), 0, "main", "onShipKilled", hTargetObject ) | |
elseif model == "fire" then | |
user.postEvent ( application.getCurrentUser ( ), 0, "main", "onGoatGotFire" ) | |
if math.random ( 1,100 )>97 then | |
--sensor.setAllActive ( this.getObject ( ), false ) | |
object.setVisible ( this.getObject ( ), false ) | |
end | |
end | |
end | |
-------------------------------------------------------------------------------- | |
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
-- multiplatform Game made for Ludum Dare using Stonetrip ShiVa 3D Engine | |
-- More info: http://www.ludumdare.com/compo/ludum-dare-25/?action=preview&uid=10960 | |
-- Support developer from XIXGAMES: http://www.xixgames.com @juaxix | |
function main.checkKills ( ) | |
-------------------------------------------------------------------------------- | |
for i=0,5 do | |
if object.isVisible ( application.getCurrentUserSceneTaggedObject ( "fighter"..i ) ) | |
then | |
return | |
end | |
end | |
hud.callAction ( application.getCurrentUser ( ), "game.showGameOver" ) | |
this.mode ( -1 ) --game over | |
this.postEvent ( 6, "onResetGame" ) | |
-------------------------------------------------------------------------------- | |
function main.colorSelectedShip ( ) | |
-------------------------------------------------------------------------------- | |
local select = this.selected ( ) | |
local fighter = nil | |
local R , G , B = 215, 251, 250 | |
if select==-1 then | |
-- all invaders at once: | |
for i=0,5 do | |
fighter = application.getCurrentUserSceneTaggedObject ( "fighter"..i ) | |
shape.overrideMeshSubsetMaterialAmbient ( | |
fighter, | |
0, R/255, G/255, B/255, 1 | |
) | |
end | |
elseif select==-2 then --none | |
R , G , B = 127, 127, 127 | |
-- all invaders at once: | |
for i=0,5 do | |
fighter = application.getCurrentUserSceneTaggedObject ( "fighter"..i ) | |
shape.overrideMeshSubsetMaterialAmbient ( | |
fighter, | |
0, R/255, G/255, B/255, 1 | |
) | |
end | |
elseif select>-1 then | |
fighter = application.getCurrentUserSceneTaggedObject ( "fighter"..select ) | |
shape.overrideMeshSubsetMaterialAmbient ( | |
fighter, | |
0, R/255, G/255, B/255, 1 | |
) | |
end | |
-------------------------------------------------------------------------------- | |
function main.computeShipsMovements ( nX0,nY0 ) | |
-------------------------------------------------------------------------------- | |
local nStick0BackMaxX = 23 | |
local nStick0BackMinX = 4.5 | |
local nStick0BackMinY = 4.5 | |
local nStick0BackMaxY = 23 | |
local tcX = this.nStick0TrackCX ( ) | |
local tcY = this.nStick0TrackCY ( ) | |
local tlX = this.nStick0TrackLX ( ) | |
local tlY = this.nStick0TrackLY ( ) | |
local nAspect = application.getCurrentUserViewportAspectRatio ( ) | |
if ( math.vectorLength ( nX0 - tlX, nY0 - tlY, 0 ) < 25 ) | |
then | |
local sX = 0.5 * ( nStick0BackMaxX - nStick0BackMinX ) | |
local sY = 0.5 * ( nStick0BackMaxY - nStick0BackMinY ) | |
local cX = 0.5 * ( nStick0BackMaxX + nStick0BackMinX ) | |
local cY = 0.5 * ( nStick0BackMaxY + nStick0BackMinY ) | |
local dX = nX0 - cX | |
local dY = ( nY0 - cY ) / nAspect | |
local dL = math.sqrt ( dX * dX + dY * dY ) | |
local dLimX = sX * 0.7 | |
local dLimY = sY * 0.7 | |
if ( dL > dLimX or dL > dLimY ) | |
then | |
dX = dX / dL * dLimX | |
dY = dY / dL * dLimY | |
else | |
dY = dY * nAspect | |
end | |
--user_sendEvent ( hUser, this_sTargetAIModel, "onJoypadStickMove", 0, 0, dX * nAspect, dY ) | |
--hud_setComponentPosition ( hStick0Thumb, cX + dX, cY + dY ) | |
this.nStick0TrackLX ( nX0 ) | |
this.nStick0TrackLY ( nY0 ) | |
this.nStick0TrackCX ( nX0 ) | |
this.nStick0TrackCY ( nY0 ) | |
this.moveX ( dX * nAspect / 10 ) | |
this.moveY ( dY / 10 ) | |
end | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
function main.createMoveFires ( ) | |
-------------------------------------------------------------------------------- | |
local f = this.fires ( ) | |
local n = table.getSize ( f ) | |
if n > 333 then return end | |
local s = application.getCurrentUserScene ( ) | |
local x,y,z = 0,0,0 | |
local fire = nil | |
-- | |
if math.random ( 1,100 )>40 then | |
local i = math.roundToNearestInteger ( math.random ( 0,5 ) ) | |
local ship = table.getAt ( this.ships ( ), i ) | |
if object.isVisible ( ship ) then | |
x,y,z = object.getTranslation ( ship, object.kGlobalSpace ) | |
-- create fire | |
fire = scene.createRuntimeObject ( s, "fire" ) | |
object.setTranslation ( fire, x,y,z+0.1,object.kGlobalSpace ) | |
table.add ( f, fire ) | |
n = table.getSize ( f ) | |
end | |
end | |
for j=0,n do | |
fire = table.getAt ( f,j ) | |
if fire then | |
x,y,z = object.getTranslation ( fire, object.kGlobalSpace ) | |
if z > 50 then | |
scene.destroyRuntimeObject ( s, fire ) | |
table.removeAt ( f,j ) | |
else | |
object.translate ( fire, 0,0,3,object.kLocalSpace ) | |
end | |
end | |
end | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
function main.generateShipsInfo ( ) | |
-------------------------------------------------------------------------------- | |
application.loadCurrentUserEnvironment ( "YouAreTheInvader" ) | |
local gev = application.getCurrentUserEnvironmentVariable | |
local sev = application.setCurrentUserEnvironmentVariable | |
--[[for i=0,22 do | |
end]]-- | |
local fs = table.newInstance ( ) | |
if not gev( "f0speed" ) then | |
for i=0,5 do | |
local k = -1 | |
while k== -1 or table.contains ( fs,k ) do | |
k = math.roundToNearestInteger ( math.random ( 0,22 ) ) | |
end | |
-- save | |
table.add ( fs,k ) | |
end | |
else | |
for i=0,5 do | |
-- load info | |
table.add ( fs, gev("f"..i.."model" )) | |
end | |
end | |
for i=0,5 do | |
local j = table.getAt ( fs,i ) | |
if not gev( "f"..i.."speed" ) then | |
sev( "f"..i.."speed" , this.getShipStat ("speed",j)) | |
sev( "f"..i.."shield" , this.getShipStat ("shield",j)) | |
sev( "f"..i.."power" , this.getShipStat ("power",j)) | |
sev( "f"..i.."name" , this.getShipStat ("name",j)) | |
sev( "f"..i.."model", j) | |
end | |
-- paint ship | |
local fighter = application.getCurrentUserSceneTaggedObject ( "fighter"..i ) | |
if fighter then | |
shape.overrideMeshSubsetMaterialEffectMap0 ( fighter, 0, | |
"fighter".. j | |
) | |
end | |
end | |
application.saveCurrentUserEnvironment ( ) | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
function main.getShipName (c ) | |
-------------------------------------------------------------------------------- | |
local s = "The " | |
if c == 1 then s = s.."Avar" | |
elseif c == 2 then s = s.. "Despot" | |
elseif c == 3 then s = s.. "Cruel" | |
elseif c == 4 then s = s.. "Parent" | |
elseif c == 5 then s = s.. "Hypocrite" | |
elseif c == 6 then s = s.. "Merciless" | |
elseif c == 7 then s = s.. "Manipulator" | |
elseif c == 8 then s = s.. "Liar" | |
elseif c == 9 then s = s.. "Interested" | |
elseif c == 10 then s = s.. "Stalker" | |
elseif c == 11 then s = s.. "Violent" | |
elseif c == 12 then s = s.. "Arrogant" | |
elseif c == 13 then s = s.. "scoundrel" | |
elseif c == 14 then s = s.. "Alcoholic" | |
elseif c == 15 then s = s.. "Junkie" | |
elseif c == 16 then s = s.. "convicted" | |
elseif c == 17 then s = s.. "Murderer" | |
elseif c == 18 then s = s.. "Arson" | |
elseif c == 19 then s = s.. "Looter" | |
elseif c == 20 then s = s.. "Thief" | |
elseif c == 21 then s = s.. "Rapist" | |
elseif c == 22 then s = s.. "Evil" | |
elseif c == 23 then s = s.. "Aggressive" | |
end | |
return s | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
function main.getShipStat ( field, c ) | |
-------------------------------------------------------------------------------- | |
local speed = 0 | |
local shield= 0 | |
local power = 0 | |
local name = "" | |
if c == 1 then | |
name = "Avar" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 2 then | |
name = "Despot" | |
power = 7 | |
shield= 7 | |
speed = 8 | |
elseif c == 3 then | |
name = "Cruel" | |
power = 9 | |
shield= 6 | |
speed = 7 | |
elseif c == 4 then | |
name = "Parent" | |
power = 8 | |
shield= 7 | |
speed = 7 | |
elseif c == 5 then | |
name = "Hypocrite" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 6 then | |
name = "Merciless" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 7 then | |
name = "Manipulator" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 8 then | |
name = "Liar" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 9 then | |
name = "Interested" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 10 then | |
name = "Stalker" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 11 then | |
name = "Violent" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 12 then | |
name = "Arrogant" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 13 then | |
name = "scoundrel" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 14 then | |
name = "Alcoholic" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 15 then | |
name = "Junkie" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 16 then | |
name = "convicted" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 17 then | |
name = "Murderer" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 18 then | |
name = "Arson" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 19 then | |
name = "Looter" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 20 then | |
name = "Thief" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 21 then | |
name = "Rapist" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 22 then | |
name = "Evil" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
elseif c == 23 then | |
name = "Aggressive" | |
power = 6 | |
shield= 7 | |
speed = 9 | |
end | |
if field == "name" then return name | |
elseif field == "speed" then return speed | |
elseif field == "power" then return power | |
elseif field == "shield" then return shield | |
elseif field == "all" then | |
return "Power: "..power.."\n".. | |
"Shield: "..shield.."\n".. | |
"Speed: "..speed | |
end | |
-- @TODO: Set random statuses... | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
function main.moveShips ( ) | |
-------------------------------------------------------------------------------- | |
-- move fighter | |
--[[ | |
local fighter = nil | |
if this.selected ( )==-1 then | |
-- all invaders at once: | |
fighter = application.getCurrentUserSceneTaggedObject ( "invaders" ) | |
elseif this.selected ( )>-1 then | |
fighter = application.getCurrentUserSceneTaggedObject ( "fighter"..this.selected ( ) ) | |
end | |
]]-- | |
local fighter = this.invaders() | |
if fighter then | |
object.translate ( fighter, 0 , this.moveY ( ), this.moveX ( ), object.kGlobalSpace ) | |
local x,y,z = object.getTranslation ( fighter, object.kGlobalSpace ) | |
if y > 40 then | |
y = 40 | |
elseif y < 5 then | |
y = 5 | |
end | |
if z<-26 then | |
z = -26 | |
elseif z > 23 then | |
z = 23 | |
end | |
object.setTranslation ( fighter, x,y,z,object.kGlobalSpace ) | |
--object.translate ( fighter, 0, trY, 0, object.kLocalSpace ) | |
if this.moveY ( )>0 then | |
if this.shiprz ( ) > -9 then | |
this.shiprz ( this.shiprz ( ) - 1 ) | |
for i = 0, 5 do | |
object.setRotation ( | |
application.getCurrentUserSceneTaggedObject ( "fighter"..i), | |
0,0,this.shiprz ( ),object.kLocalSpace ) | |
end | |
end | |
elseif this.moveY ( )<0 then | |
if this.shiprz ( ) < 9 then | |
this.shiprz ( this.shiprz ( ) + 1 ) | |
for i = 0, 5 do | |
object.setRotation ( | |
application.getCurrentUserSceneTaggedObject ( "fighter"..i), | |
0,0,this.shiprz ( ),object.kLocalSpace | |
) | |
end | |
end | |
--[[else | |
if math.floor ( rz ) ~= 0 then | |
object.rotateTo ( fighter,0,0,0,object.kLocalSpace, application.getLastFrameTime ( ) ) | |
this.shiprz ( 0 ) | |
end]]-- | |
end | |
else | |
end | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.paintShip ( i ) | |
-------------------------------------------------------------------------------- | |
-- painting ships | |
local fighter = application.getCurrentUserSceneTaggedObject ( "fighter"..i ) | |
if fighter then | |
shape.overrideMeshSubsetMaterialEffectMap0 ( fighter, 0, | |
"fighter".. | |
application.getCurrentUserEnvironmentVariable ( "f"..i.."model" ) | |
) | |
end | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.selectShips ( nButton, nPointX, nPointY, nRayPntX, nRayPntY, nRayPntZ, nRayDirX, nRayDirY, nRayDirZ ) | |
-------------------------------------------------------------------------------- | |
----- | |
-- check if the click is over the hud | |
local c = hud.getUnderCursorComponent ( this.getUser ( ) ) | |
if c then | |
local nX0 = 50 * ( nPointX + 1 ) | |
local nY0 = 50 * ( nPointY + 1 ) | |
local stick = hud.getComponent ( this.getUser ( ), "game.padStick" ) | |
hud.setComponentPosition ( stick, nX0,nY0 ) | |
this.computeShipsMovements ( nX0, nY0 ) | |
return | |
end | |
local sce = application.getCurrentUserScene ( ) | |
local hObj, dist,sid = scene.getFirstHitSensor ( sce, nRayPntX, nRayPntY, nRayPntZ, nRayDirX, nRayDirY, nRayDirZ, 300 ) | |
if hObj then | |
local tag = scene.getObjectTag ( sce , hObj ) | |
local model = object.getModelName ( hObj ) | |
if ( string.getSubString ( tag,0,7 ) == "fighter") then | |
local i = string.getSubString ( tag,7,string.getLength ( tag ) - 7 ) + 0 | |
if this.selected ( ) == i then | |
return | |
-- select all | |
--this.selected ( -1 ) | |
-- hightlight all ships | |
--this.colorSelectedShip() | |
else | |
this.selected ( i ) | |
this.colorSelectedShip( ) | |
this.showShipOption ( i, true ) | |
end | |
end | |
else | |
this.selected ( -2 ) --none | |
this.colorSelectedShip() | |
hud.callAction ( this.getUser ( ), "game.hideShipOption" ) | |
end | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.setRandomColorsToInvaders ( shipNumber ) | |
-------------------------------------------------------------------------------- | |
if shipNumber == nil then | |
-- painting ships | |
for i=0, 5 do | |
local fighter = application.getCurrentUserSceneTaggedObject ( "fighter"..i ) | |
if fighter then | |
shape.overrideMeshSubsetMaterialEffectMap0 ( fighter, 0, | |
"fighter".. | |
math.roundToNearestInteger ( math.random ( 0,23 ) ) | |
) | |
end | |
end | |
else | |
local fighter = application.getCurrentUserSceneTaggedObject ( "fighter"..shipNumber ) | |
if fighter then | |
shape.overrideMeshSubsetMaterialEffectMap0 ( fighter, 0, | |
"fighter".. | |
math.roundToNearestInteger ( math.random ( 0,23 ) ) | |
) | |
end | |
end | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.showShipOption ( i, call ) | |
-------------------------------------------------------------------------------- | |
local s = this.selected ( ) | |
local gev = application.getCurrentUserEnvironmentVariable | |
local u = application.getCurrentUser ( ) | |
hud.setEditText ( | |
hud.getComponent ( u,"game.txtStats" ), | |
"Speed: ".. gev( "f"..i.."speed" ).."\n".. | |
"Shield: "..gev( "f"..i.."shield" ).."\n".. | |
"Power: ".. gev( "f"..i.."power" ) | |
) | |
hud.setLabelText ( | |
hud.getComponent ( u, "game.ShipName" ), | |
gev( "f"..i.."name" ) | |
) | |
local model = gev( "f"..i.."model" )+0 | |
hud.setSliderValue ( hud.getComponent ( u, "game.selectedShip" ), model ) | |
if call then | |
hud.callAction ( this.getUser ( ), "game.showShipOption" ) | |
end | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
function main.game_onEnter ( ) | |
-------------------------------------------------------------------------------- | |
local sce= application.getCurrentUserScene ( ) | |
-- set the ships in their initial position | |
local g = application.getCurrentUserSceneTaggedObject ( "invaders" ) | |
this.invaders(g) | |
object.translateTo ( g, 0,21,0,object.kGlobalSpace, 1) | |
--rotate each ship | |
local t = this.ships ( ) | |
for i=0,5 do | |
local s = table.getAt ( t,i) | |
object.rotateTo ( s,0,0,0,object.kGlobalSpace,1 ) | |
end | |
-- set the camera in it position | |
local c = application.getCurrentUserActiveCamera ( ) | |
object.rotateTo ( c,0, -90,0, object.kGlobalSpace, 1 ) | |
object.translateTo ( c,-66,23,0,object.kGlobalSpace, 1) | |
hud.callAction ( application.getCurrentUser ( ), "game.showJoyPad" ) | |
music.stop ( sce,2 ) | |
music.play ( sce, 2, 1 ) | |
table.empty ( this.fires ( ) ) | |
table.empty ( this.aliens ( ) ) | |
-------------------------------------------------------------------------------- | |
end | |
-------------- | |
function main.game_onLoop ( ) | |
-------------------------------------------------------------------------------- | |
this.moveShips ( ) | |
this.createMoveFires() | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
function main.startingGame_onEnter ( ) | |
-------------------------------------------------------------------------------- | |
local sce = application.getCurrentUserScene ( ) | |
local s = this.ships ( ) | |
-- empty table | |
local k = this.selected ( ) | |
table.empty ( s ) | |
-- first the selected | |
table.add ( s, application.getCurrentUserSceneTaggedObject ( "fighter"..k ) ) | |
for i=0,5 do | |
if i == k then | |
else | |
table.add ( | |
s, | |
application.getCurrentUserSceneTaggedObject ( "fighter"..i ) | |
) | |
end | |
end | |
-- begin moving to the start position | |
--[[camera initial position: | |
translation: -3.094, 45.446, 57.449 | |
rotation: -24.505, -2.760, 0 | |
]]-- | |
object.rotateTo (application.getCurrentUserSceneTaggedObject ( "invaders" ) ,0,0,0,object.kGlobalSpace,1 ) | |
this.postStateChange ( 6, "game" ) | |
object.postEvent ( this.planet ( ), 1, "planet","onStartGame" ) | |
application.forceModelToStayLoaded ( "Goat",true ) | |
application.forceModelToStayLoaded ( "alien",true ) | |
application.forceModelToStayLoaded ( "fire",true ) | |
this.postEvent (6,"onCreateAlien") | |
music.stop ( sce,2 ) | |
music.play ( sce, 1, 1 ) | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.startingGame_onLoop ( ) | |
-------------------------------------------------------------------------------- | |
local dt = application.getLastFrameTime( ) | |
local g = application.getCurrentUserSceneTaggedObject ( "invaders" ) | |
object.translateTo ( g, 0,21,0,object.kGlobalSpace, dt) | |
--rotate each ship | |
local t = this.ships ( ) | |
for i=0,5 do | |
local s = table.getAt ( t,i) | |
object.rotateTo ( s,0,0,0,object.kGlobalSpace,dt ) | |
if i == 0 then | |
object.translateTo ( s,1,21,1,object.kGlobalSpace,dt ) | |
end | |
end | |
local c = application.getCurrentUserActiveCamera ( ) | |
object.rotateTo ( c,0, -90,0, object.kGlobalSpace, dt ) | |
object.translateTo ( c,-66,23,0,object.kGlobalSpace, dt) | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.onAlienKilled ( fireObj ) | |
-------------------------------------------------------------------------------- | |
local f = this.fires ( ) | |
local n = table.getSize ( f ) | |
for i=0,n do | |
local fire = table.getAt ( f,i ) | |
if fire and fire == fireObj then | |
scene.destroyRuntimeObject ( application.getCurrentUserScene ( ), fire ) | |
table.removeAt ( f,i ) | |
end | |
end | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.onChangingShip ( newShip ) | |
-------------------------------------------------------------------------------- | |
if this.selected ( )<0 then return end | |
local i = this.selected ( ) | |
local sev = application.setCurrentUserEnvironmentVariable | |
sev( "f"..i.."speed" , this.getShipStat ("speed",newShip)) | |
sev( "f"..i.."shield" , this.getShipStat ("shield",newShip)) | |
sev( "f"..i.."power" , this.getShipStat ("power",newShip)) | |
sev( "f"..i.."name" , this.getShipStat ("name",newShip)) | |
sev( "f"..i.."model", newShip) | |
this.paintShip ( i ) | |
this.showShipOption ( i, false ) | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.onCloseShipOptions ( ) | |
-------------------------------------------------------------------------------- | |
this.selected ( -2 ) --none | |
this.colorSelectedShip() | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.onCreateAlien ( ) | |
-------------------------------------------------------------------------------- | |
if this.mode ( )==1 then | |
local sce = application.getCurrentUserScene ( ) | |
this.postEvent ( math.random ( 6,9 ),"onCreateAlien") | |
local alien = scene.createRuntimeObject ( sce, "alien" ) | |
object.setTranslation ( alien, 0,math.random ( 6,33 ),math.random ( 23,44 ),object.kGlobalSpace ) | |
end | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.onGoatGotFire ( fireObj ) | |
-------------------------------------------------------------------------------- | |
local f = this.fires ( ) | |
local n = table.getSize ( f ) | |
for i=0,n do | |
local fire = table.getAt ( f,i ) | |
if fire and fire == fireObj then | |
scene.destroyRuntimeObject ( application.getCurrentUserScene ( ), fire ) | |
table.removeAt ( f,i ) | |
end | |
end | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.onInit ( ) | |
-------------------------------------------------------------------------------- | |
hud.newTemplateInstance ( this.getUser ( ) , "game","game" ) | |
-- | |
application.setCurrentUserScene ( "space" ) | |
this.generateShipsInfo() | |
this.planet ( application.getCurrentUserSceneTaggedObject ( "planet" ) ) | |
-- play music | |
local sce = application.getCurrentUserScene() | |
music.setVolume ( sce, 0.6, 0 ) | |
music.play ( sce, 0, 0.1 ) | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.onMouseButtonDown ( nButton, nPointX, nPointY, nRayPntX, nRayPntY, nRayPntZ, nRayDirX, nRayDirY, nRayDirZ ) | |
-------------------------------------------------------------------------------- | |
if nButton ~= 0 then | |
return | |
end | |
this.button0 ( true ) | |
if this.mode ( ) == 0 then | |
this.selectShips ( nButton, nPointX, nPointY, nRayPntX, nRayPntY, nRayPntZ, nRayDirX, nRayDirY, nRayDirZ ) | |
elseif this.mode ( ) == 1 then | |
end | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.onMouseButtonUp ( nButton, nPointX, nPointY, nRayPntX, nRayPntY, nRayPntZ, nRayDirX, nRayDirY, nRayDirZ ) | |
-------------------------------------------------------------------------------- | |
if nButton ~= 0 then | |
return | |
end | |
-- check if the click is over the hud | |
local stick = hud.getComponent ( this.getUser ( ), "game.padStick" ) | |
hud.setComponentPosition ( stick, 15,15 ) | |
this.button0 ( false ) | |
this.moveX ( 0 ) | |
this.moveY ( 0 ) | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.onMouseMove ( nPointX, nPointY, nDeltaX, nDeltaY, nRayPntX, nRayPntY, nRayPntZ, nRayDirX, nRayDirY, nRayDirZ ) | |
-------------------------------------------------------------------------------- | |
if this.button0 ( ) then | |
local c = hud.getUnderCursorComponent ( this.getUser ( ) ) | |
if c then | |
local nX0 = 50 * ( nPointX + 1 ) | |
local nY0 = 50 * ( nPointY + 1 ) | |
local stick = hud.getComponent ( this.getUser ( ), "game.padStick" ) | |
hud.setComponentPosition ( stick, nX0,nY0 ) | |
this.computeShipsMovements ( nX0, nY0 ) | |
return | |
end | |
end | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.onPlanetGotFire ( fireObj ) | |
-------------------------------------------------------------------------------- | |
local f = this.fires ( ) | |
local n = table.getSize ( f ) | |
for i=0,n do | |
local fire = table.getAt ( f,i ) | |
if fire and fire == fireObj then | |
scene.destroyRuntimeObject ( application.getCurrentUserScene ( ), fire ) | |
table.removeAt ( f,i ) | |
end | |
end | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.onPlay ( ) | |
-------------------------------------------------------------------------------- | |
this.mode ( 1 ) | |
application.saveCurrentUserEnvironment ( ) | |
-- start the travel | |
this.startingGame ( ) | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.onResetGame ( ) | |
-------------------------------------------------------------------------------- | |
application.restart ( ) | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function main.onShipKilled ( shipObj ) | |
-------------------------------------------------------------------------------- | |
-- | |
object.setVisible ( shipObj, false ) -- add particle system... | |
this.checkKills() | |
-------------------------------------------------------------------------------- | |
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
-- multiplatform Game made for Ludum Dare using Stonetrip ShiVa 3D Engine | |
-- More info: http://www.ludumdare.com/compo/ludum-dare-25/?action=preview&uid=10960 | |
-- Support developer from XIXGAMES: http://www.xixgames.com @juaxix | |
-------------------------------------------------------------------------------- | |
function planet.game_onLoop ( ) | |
-------------------------------------------------------------------------------- | |
local dt = application.getAverageFrameTime ( ) | |
-- | |
object.rotate ( this.getObject ( ), 0, 2*dt, 0, object.kLocalSpace ) | |
object.translate ( this.getObject ( ), 0,0,-0.1,object.kGlobalSpace ) | |
local x,y,z = object.getTranslation ( this.getObject ( ),object.kGlobalSpace ) | |
if z <= -66 then | |
object.setTranslation ( | |
this.getObject ( ), | |
0, | |
math.random ( -17,42 ), | |
66 | |
,object.kGlobalSpace | |
) | |
sensor.setActiveAt ( this.getObject ( ),0,true ) | |
object.setVisible ( this.getObject ( ),true ) | |
local goat = application.getCurrentUserSceneTaggedObject ( "Goat" ) | |
if math.random ( 1,100 )>20 then | |
object.setTranslation( goat, 0,y+12,66,object.kGlobalSpace ) | |
object.setVisible ( goat,true ) | |
else | |
object.setVisible ( goat,false ) | |
end | |
end | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function planet.waiting_onEnter ( ) | |
-------------------------------------------------------------------------------- | |
object.resetRotation ( this.getObject ( ), object.kGlobalSpace ) | |
object.resetTranslation ( this.getObject ( ), object.kGlobalSpace ) | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function planet.waiting_onLoop ( ) | |
-------------------------------------------------------------------------------- | |
local dt = application.getAverageFrameTime ( ) | |
-- | |
object.rotate ( this.getObject ( ), 0, 1*dt, 0, object.kLocalSpace ) | |
-- | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function planet.onSensorCollisionBegin ( nSensorID, hTargetObject, nTargetSensorID ) | |
-------------------------------------------------------------------------------- | |
if hTargetObject then | |
local model = object.getModelName ( hTargetObject ) | |
if model == "ship" then | |
user.postEvent ( application.getCurrentUser ( ), 0, "main","onShipKilled",hTargetObject ) | |
elseif model == "fire" then | |
user.postEvent ( application.getCurrentUser ( ),0,"main","onPlanetGotFire",hTargetObject ) | |
if math.random ( 1,100 )>99 then | |
sensor.setActiveAt ( this.getObject ( ),0,false ) | |
object.setVisible ( this.getObject ( ),false ) | |
end | |
end | |
end | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- | |
-------------------------------------------------------------------------------- | |
function planet.onStartGame ( ) | |
-------------------------------------------------------------------------------- | |
this.game ( ) | |
-------------------------------------------------------------------------------- | |
end | |
-------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment