home *** CD-ROM | disk | FTP | other *** search
/ Enter 2010 January / ENTER_2010_01.iso / Programy / Gry / Base_Invaders_ / BaseInvadersSetup1.3.exe / {app} / Scripts / Spawn Waves.lua < prev    next >
Encoding:
Text File  |  2007-01-25  |  10.6 KB  |  391 lines

  1. ---------------------------------------------------------------------------
  2.                         OLD LEVEL SCRIPT TEXT:
  3. ---------------------------------------------------------------------------
  4.  
  5.     
  6.     TraitorTalk("Good morning!  Ah, would you look at this weather.  What better way to start off the week?")
  7.     GameWait(6)
  8.     TraitorTalk("In case you don't remember me from the tutorial, I'm Traitor.")
  9.     GameWait(5)
  10.     TraitorTalk("I'll be helping you out for a while.")
  11.     GameWait(4)
  12.     
  13.     TraitorTalk("You may be wondering, 'Why do I need his help?  Everything looks calm and peaceful.' ");
  14.     GameWait(5)
  15.     TraitorTalk("But just you wait. Since you were kind enough to let me seek refuge in your tower, ")
  16.     GameWait(5)
  17.     TraitorTalk("you'll be rewarded with the wrath of my Invader brethren.");
  18.     GameWait(5)
  19.     TraitorTalk("See, they're not too happy at me for being a...  well, being a traitor, ");
  20.     GameWait(5)
  21.     TraitorTalk("and they're also not too happy that you're protecting me.");
  22.     GameWait(5)
  23.     
  24.     TraitorTalk("So anyway, let me show my appreciation by giving you a hand defending the place. ")
  25.     GameWait(6)
  26.     TraitorTalk("Won't be long until my former friends start showing up to pay us a visit.");
  27.     GameWait(6)
  28.     
  29.     -- drop walls
  30.     GameWait(3)
  31.     -- drop traps
  32.     GameWait(3)
  33.     
  34.     TraitorTalk("There, now isn't that better?")
  35.     GameWait(2)
  36.     
  37.     -- pan camera to parachuting invaders
  38.     GameWait(1)
  39.     
  40.     TraitorTalk("Uh oh, looks like they're here already.  ...  I think I'll sit this one out.")
  41.     GameWait(6)
  42.     TraitorTalk("You have fun now, and...  *gulp* ... good luck.")
  43.     GameWait(4)
  44.     G.ActivateTrapDrop()
  45. end
  46.  
  47. function TraitorScript_InGame1()
  48.     EnableTraitor();
  49.     TraitorTalk("See those little green ones that look like me?")
  50.     GameWait(4)
  51.     TraitorTalk("So handsome...  those are Basic Invaders.");
  52.     GameWait(4)
  53.     TraitorTalk("Not much to 'em, I guess.  Just give 'em a toss to get rid of 'em.");
  54.     GameWait(6)
  55.     DisableTraitor();
  56. end
  57.  
  58. function TraitorScript_InGame2()
  59.     EnableTraitor();
  60.     TraitorTalk("Hey, look there.  That box-looking guy there is a Stacker.")
  61.     GameWait(5)
  62.     TraitorTalk("He's pretty slow and weak, but he's got a neat little trick he does.");
  63.     GameWait(5)
  64.     TraitorTalk("He can hunker down in front of a wall, and allow other Invaders to climb up and over that wall.");
  65.     GameWait(8)
  66.     DisableTraitor();
  67. end
  68.  
  69. function TraitorScript_InGame3()
  70.     EnableTraitor();
  71.     TraitorTalk("Now there's a mean guy.  That nasty pick-axe shaped Invader is called a Miner.")
  72.     GameWait(5)
  73.     TraitorTalk("He's got an angry streak as wide as...   something really wide.");
  74.     GameWait(4)
  75.     TraitorTalk("He'll attack anything he sees!  That could put a serious chink in your defenses.");
  76.     GameWait(7)
  77.  
  78.  
  79.     LargeTextPopup( "Level 2: \n Krazy Kamikazes", Color(1,1,1,1) )
  80.     
  81.     G.DisableTrapAll()
  82.     G.EnableTrap("wall");
  83.     G.EnableTrap("laser");
  84.     G.EnableTrap("spring");
  85.     DisableTraitor()
  86.     GameWait(.5)
  87.     EnableTraitor()
  88.     Traitor.SetGuiPosition( "TraitorWindow"  , Vector3(0.6, -0.5, 1) );
  89.     
  90.     TraitorTalk("*Yawn*  Hey, how're you?  I slept great last night, that couch is real comfy!")
  91.     GameWait(6)
  92.     TraitorTalk("How did that thing with the other Invaders go?")
  93.     GameWait(4)
  94.     TraitorTalk("You're still here, so I guess that means you won.  Good for you!")
  95.     GameWait(5)
  96.     TraitorTalk("...  and, good for me too, hehe.")
  97.     GameWait(3)
  98.     
  99.     --explosion
  100.     GameWait(1)
  101.     TraitorTalk("What was that?!")
  102.     GameWait(1)
  103.     --pan camera to kamikaze running into a wall
  104.     TraitorTalk("Oh no, they must be really mad now!")
  105.     GameWait(3)
  106.     TraitorTalk("They're sending in the demolitionists to try and tear down our defenses.")
  107.     GameWait(6)
  108.     TraitorTalk("Lets get this place into fighting shape!");
  109.     GameWait(3)
  110.     
  111.     -- drop springs
  112.     GameWait(3)
  113.     
  114.     TraitorTalk("Those Spring Traps alone wont be enough.")
  115.     GameWait(4)
  116.     TraitorTalk("These guys will probably just run right by 'em.")
  117.     GameWait(5)
  118.     TraitorTalk("Oh, wait a minute!  Here we go, try this...")
  119.     GameWait(3)
  120.     
  121.     -- drop fans
  122.     GameWait(3)
  123.     
  124.     TraitorTalk("These will help push all those hot-heads into the Spring Traps.")
  125.     GameWait(6)
  126.     TraitorTalk("Here, you better put some more down.")
  127.     GameWait(3)
  128.     
  129.     G.EnableTrap("fan")
  130.     -- explosion
  131.     GameWait(1)
  132.     
  133.     TraitorTalk("Yikes! Let me know when its over!")
  134.     GameWait(3)
  135.     DisableTraitor()
  136. end
  137.  
  138. function TraitorScript_InGame1()
  139.     EnableTraitor();
  140.     TraitorTalk("Boy those Kamikazes are fast!")
  141.     GameWait(3)
  142.     TraitorTalk("Be sure you get rid of them before they get to close to the tower.");
  143.     GameWait(6)
  144.     TraitorTalk("They can do some serious damage if they hit!");
  145.     GameWait(5)
  146.     DisableTraitor();
  147. end
  148.  
  149. function TraitorScript_InGame2()
  150.     EnableTraitor();
  151.     TraitorTalk("Those Bombers may look slow, but they pack a mighty wallop.")
  152.     GameWait(5)
  153.     TraitorTalk("They've got a countdown timer, and when it hits zero, they blow up!");
  154.     GameWait(6)
  155.     TraitorTalk("Almost makes you feel sorry for them, doesn't it.");
  156.     GameWait(5)
  157.     DisableTrait
  158.  
  159.  
  160.  
  161. --
  162. -- This file describes the functions and various ways to create Spawn Waves:
  163. -- Groups of enemies that will spawn at the same time of position to attack the enemy.
  164. --
  165.  
  166. -- This determines where the enemies spawn
  167. SpawnMode
  168. SpawnLocation
  169.  
  170. Circle Spawn    -- Standard
  171. No Waves        -- Starting a level
  172. Wait for Kills    -- After so many kills, spawn this wave
  173. Wait for Time    -- After this much time ... 
  174.  
  175. ...
  176.  
  177. The main thing is to allow the scripts to set the spawning time and frequency.
  178. The problem is that the spawners are in a separate file (For --- Knows what reason)
  179. Solution:
  180. Move spawners to the same file as the config.
  181.  
  182. Campaign File Layout:
  183.  
  184. ---------------------------------------------------------------------------
  185.                             LEVEL CODE 
  186. ---------------------------------------------------------------------------
  187.  
  188. bool Setup = false
  189. Setup()
  190. {
  191.     -- Create all the objects and stuff for the level to start
  192.     -- This ends with a paused screen looking at ... something ...
  193. }
  194.  
  195. bool IntroOver = false
  196.  
  197. -- This should be SKIPABLE
  198. LevelStart()
  199. {
  200.     -- After unpausing the level proper starts with this
  201.     -- This does the intro with Traitor, and that is all
  202.     Traitor.Say( "Talk talk talk" );
  203.     SpawnStuff
  204.     etc.
  205. }
  206.  
  207. -- NOT SKIPABLE (Though we may add in cheats to help us test)
  208. InGame()
  209. {
  210.     -- This function describes the in-game sequence of events that leads to victory. Ex:
  211.     Traitor.Say( "Look, here comes a lot of guys" )
  212.     Spawner.StartWave( 1 )
  213.     
  214.     -- The player must survive for 2 Minutes or 50 guys
  215.     WaitForTimeOrKills( 120, 50 )
  216.     Spawners.StopWave()
  217.     Traitor.Say( "I think they're letting up!" )
  218.     
  219.     -- Make sure the rest are killed (30 seconds and they all die)
  220.     WaitForClearEnemies( 30 )
  221.     dg.Invaders()
  222.     Traitor.Say( "That's all of them!" )
  223.     
  224.     Traitor.Say( "You Should Repair or something!" )
  225.     WaitForTime( 30 )
  226.     
  227.     Traitor.Say( "Crap! Here come more! )
  228.     Spawners.StartWave( 2 )
  229.     
  230.     WaitForTimeOrKills( 120, 50 )
  231.     Spawners.StopWave()
  232.     Traitor.Say( "I think they're letting up!" )
  233.     
  234.     -- Make sure the rest are killed (30 seconds and they all die)
  235.     WaitForClearEnemies( 30 )
  236.     
  237.     Traitor.Say( "That's great! You survived! Hooray!" )
  238.  
  239.     ---------------- ANY INGAME VICTORY STUFFF WOULD GO HERE -----------------
  240.  
  241.  
  242.     -- The level is now over
  243.     LevelVictory = true    
  244. }
  245.  
  246. LevelOverCheck()
  247. {
  248.     -- Check to see if the level is over for any reason, and exit if so.
  249.     -- This has a custom destruction option for the level
  250. }
  251.  
  252. ---------------------------------------------------------------------------
  253.                             SPAWNING CODE 
  254. ---------------------------------------------------------------------------
  255.  
  256. SpawnWaves = {}
  257. DefaultWaveStruct = {}
  258.  
  259. -- SPAWN STATS --
  260. DefaultWaveStruct.SpawnSpeed    = 0.0;
  261. DefaultWaveStruct.MaxSpawn        = 0;
  262. DefaultWaveStruct.GroupPercent    = 0.0;
  263. DefaultWaveStruct.GroupSize        = 0;
  264. DefaultWaveStruct.WhereToSpawn    = RandomAnywhere()
  265.  
  266. -- INVADER SPAWN PERCENTS: --
  267. DefaultWaveStruct.Prob = {};
  268. DefaultWaveStruct.Prob.miner    = 0.0;
  269. DefaultWaveStruct.Prob.squad    = 0.0;
  270. DefaultWaveStruct.Prob.bomber    = 0.0;
  271. DefaultWaveStruct.Prob.kamikaze = 0.0;
  272. DefaultWaveStruct.Prob.driller  = 0.0;
  273. DefaultWaveStruct.Prob.psychic  = 0.0;
  274. DefaultWaveStruct.Prob.ninja    = 0.0;
  275. DefaultWaveStruct.Prob.spiker    = 0.0;
  276. DefaultWaveStruct.Prob.stacker  = 0.0;
  277. DefaultWaveStruct.Prob.basic    = 0.0;
  278. DefaultWaveStruct.ProbTotal        = 0.0;
  279.  
  280. -- INTERNAL VARIABLES --
  281. DefaultWaveStruct.NumSpawnNext    = 0.0;
  282. DefaultWaveStruct.NextGroupSize    = 1;
  283.  
  284. SpawnWaves[0] = DefaultWaveStruct
  285.  
  286. ------------------- EXAMPLE WAVES ---------------------
  287. BasicWave = DefaultWaveStruct
  288.  
  289. BasicWave.Prob.basic = 1.0;
  290.  
  291. BasicWave.SpawnSpeed    = 0.5;
  292. BasicWave.MaxSpawn        = 25;
  293. BasicWave.GroupPercent    = 0.1;
  294. BasicWave.GroupSize        = 3;
  295. BasicWave.WhereToSpawn    = CircleAroundTower()
  296.  
  297. ------------------- EXAMPLE WAVES ---------------------
  298. KamikazeWave = DefaultWaveStruct
  299.  
  300. BasicWave.Prob.basic = 1.0;
  301.  
  302. BasicWave.SpawnSpeed    = 0.5;
  303. BasicWave.MaxSpawn        = 25;
  304. BasicWave.GroupPercent    = 0.1;
  305. BasicWave.GroupSize        = 3;
  306. BasicWave.WhereToSpawn    = CircleAroundTower()
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313. StartWave( num, waveStruct )
  314. {
  315.     if( SpawnWaves[num] == nil )
  316.         SpawnWaves[num] = waveStruct
  317.     else
  318.         -- THIS IS AN ERROR! 
  319. }
  320.  
  321. EndWave( num )
  322. {
  323.     if( not( SpawnWaves[num] == nil ) )
  324.         SpawnWaves[num] = nil
  325. }
  326.  
  327. EndAllWaves()
  328. {
  329.     SpawnWaves = nil
  330. }
  331.  
  332. SpawnUpdate()
  333. {
  334.     -- Check what wave is spawning:
  335.     wave = GetCurWave()
  336.     
  337.     if( wave.ShouldSpawn() )
  338.         wave.DoSpawn()
  339.         
  340. }
  341.  
  342. MaxNumInvaders = 100    -- Max simultaneous
  343. SpawnRate = 0.1            -- NumInvaders per second
  344. GroupPercent = 0.5        -- How many invaders are spawned as part of a group?
  345. GroupSize = 5            -- How many invaders are in a group (max)
  346. TotalToSpawn = 0        -- Limit on number to spawn ... This is one way of doing it ... 
  347.  
  348. -- Increments time, and checks if a spawn should be done now:
  349. ShouldSpawn()
  350. {
  351.       curNumSpawn += SpawnRate * TimeDiff
  352.  
  353.     if( curNumSpawn > curGroupSize )
  354.     {
  355.         -- Check waht the restriction on # of invaders is
  356.         if( MaxNumInvaders < numInvaders + groupSize )
  357.             return true;
  358.     }
  359.     
  360.     return false
  361. }
  362.  
  363. -- This is a function that is need for spawning
  364. GetSpawnLocation()
  365. {
  366.     -- Since we moved away from the "Spawners" system, this is better for the game:
  367.     -- Here are some defaults:
  368.     
  369.     -- Remember that squad leaders also serve as mobile spawn locations, so use them here: 
  370.     if( squads.exist() && rand(0, 1 ) > 0.1 )
  371.         return squad.position
  372.     
  373.     return CircleAroundTower( radius );
  374.     return HardCodedSpawnpoints( );
  375.     return RandomAnywhere( );
  376.     
  377. }
  378.  
  379. -- Knowing that a spawn is valid (May be called by level) spawn it
  380. DoSpawn()
  381. {
  382.     -- Find WHERE to spawn
  383.     location = GetSpawnLocation()
  384.     
  385.     for( groupSize )
  386.     {
  387.         -- Find What type to spawn, and spawn it!
  388.         -- Using the probabilities given, spawn the guy:
  389.     }
  390. }
  391.