struct Akimbo_1_Code {
Welcome to my Akimbo 1 Code page. Here you can see a few snippets of code that I wrote for my game Akimbo 1.
Akimbo 1 is a rail-based shooter FPS shooter. You can learn more about the game at its project page. Akimbo 1 was my first venture into C#, and one part of C# I quickly found to be better than C++ is its “out of the box” ability to stream I/O with less overhead.
I set up a small scripting language for Akimbo 1 that could control when the camera moves, when to display messages, when to load more targets, and when to wait for the program to raise a flag. Akimbo_1_Code_1 shows off an example text file that uses my scripting language. Akimbo_1_Code_1 shows off the parsing code responsible for reading and executing the script code.
Akimbo_1_Code_1: scripting language
// dispatch.txt -- dispatch file //W = Wait for ___ seconds //X = execute script //M = display Message //F = wait for Flag //CP = Camera Pause //CS = Camera Start //CW = wait for Camera to reach the end of its path //MSG = display a message for ___ seconds //END = ends the level X scripts/room1.txt CS env/lvl1camPath0 MSG SHOOT THE CORRESPONDING TARGETS 2 F X scripts/room2.txt CS env/lvl1camPath1 CW MSG DRONES WILL MOVE AROUND! 2 F X scripts/room3.txt PS CS env/lvl1camPath2 CW MSG HOW DO YOU GO LEFT...? 2 F PE //this gets skipped if puzzle is solved CS env/lvl1camPath3 X scripts/room4.txt F CS env/lvl1camPath4 SECRET X scripts/roomSR1.txt CS env/lvl1camPath7 CW MSG YOU FOUND THE SECRET ROOM! 2 F CS env/lvl1camPath8 /SECRET X scripts/room5.txt PS CW MSG SOME TARGETS WILL SWITCH COLORS! 3 F PE //this gets skipped if puzzle is solved X scripts/room6.txt CS env/lvl1camPath5 CW MSG DRONES CAN SWITCH TOO! 2 F CS env/lvl1camPath6 SECRET X scripts/roomSR2.txt CS env/lvl1camPath9 CW MSG FOUND SECOND SECRET ROOM 2 F CS env/lvl1camPath10 /SECRET X scripts/room7.txt CW MSG GOOD LUCK!!! 3 F END
Akimbo_1_Code_2: parser for above scripting language
int parseToNext(float gameTime) { string line; string[] words; int argc; float t; while ((line = mFile.ReadLine()) != null) { line = line.Trim(); if (0 == line.Length) continue; if ((line[0] == '/') && (line[1] == '/')) continue; words = line.Split(mSeparators); if (advanceToSecret && words[0] != "SECRET") continue; if (advanceToSecretEnd && words[0] != "/SECRET") continue; argc = 0; switch (words[argc++]) { case "W": //wait for a t time t = (float)Convert.ToDouble(words[argc++]); tWait = gameTime + t; break; case "CW": //wait for camTime cameraWait = true; break; case "F": //wait for flag this.flag = false; break; case "CP": //camera pause Program.game.mAniFlyThrough.setPause(true); break; case "CS": //camera Start Program.game.startNewCamPath(ref words[argc]); Program.game.mAniFlyThrough.setPause(false); break; case "X": //execute script Program.game.mWorld.load(ref Program.game.content, words[argc++], 0); break; case "MSG": string msg =""; int i = argc++; for (; i < (words.Length - 1); i++) msg += words[i] + " "; Program.game.drawMsg(msg, (float)Convert.ToInt32(words[i])); break; case "PS": //puzzle start Program.game.mWorld.startPuzzle(); break; case "PE": //puzzle end Program.game.mWorld.endPuzzle(); break; case "SECRET": //secret if (advanceToSecret == false) advanceToSecretEnd = true; else advanceToSecret = false; break; case "/SECRET": //end secret if (advanceToSecretEnd == true) advanceToSecretEnd = false; break; case "END": Program.game.endLevel(); break; } // switch } // while return 0; }