#include <Scratc.h> int main (int arc, char **argv) { whenGreenFlag (); startScene ("tg"); wait_elapsed_from (0.01); startScene ("blank"); whenIReceive ("Shutdown"); startScene ("tg"); clearPenTrails (); whenGreenFlag (); hide (); procDef ("draw tg intro %n", rot (), 1, true); if (StrEQ (readVariable ("stop intro flag"), "2")) { stopScripts ("this script"); } setVar_to ("tg i", 0); if (StrGT (computeFunction_of ("cos", getParam ("rot", "r")), "0")) { setVar_to ("objects", StrDIV (lineCountOfList ("tailgunner logo"), 2)); } else { setVar_to ("objects", "8"); } { int _i; for (_i = 0; _i < readVariable ("objects"); _i++) { changeVar_by ("tg i", 1); setVar_to ("tg from", getLine_ofList (readVariable ("tg i"), "tailgunner logo")); changeVar_by ("tg i", 1); setVar_to ("tg to", getLine_ofList (readVariable ("tg i"), "tailgunner logo")); call ("draw rotated line %n %n %n", readVariable ("tg from"), readVariable ("tg to"), getParam ("rot", "r")); } } procDef ("draw rotated line %n %n %n", from ("to", "rot"), 1; 1; 1, true); if (not (StrEQ (getParam ("from", "r"), getParam ("to", "r")))) { call ("Unpack positive %n", getParam ("from", "r")); setVar_to ("tg x", readVariable ("Pack X")); setVar_to ("tg y", readVariable ("Pack Y")); setVar_to ("tg z", readVariable ("Pack Z")); call ("Unpack positive %n", getParam ("to", "r")); changeVar_by ("Pack Z", StrMUL (readVariable ("Pack Y"), computeFunction_of ("sin", getParam ("rot", "r")))); setVar_to ("Pack Y", StrMUL (readVariable ("Pack Y"), computeFunction_of ("cos", getParam ("rot", "r")))); setVar_to ("screen x", StrDIV (StrMUL (512, readVariable ("Pack X")), StrADD (512, readVariable ("Pack Z")))); setVar_to ("screen y", StrDIV (StrMUL (512, readVariable ("Pack Y")), StrADD (512, readVariable ("Pack Z")))); gotoX_y (StrADD (readVariable ("cur x"), readVariable ("screen x")), StrADD (readVariable ("cur y"), readVariable ("screen y"))); penColor (readVariable ("pen colour")); putPenDown (); changeVar_by ("tg z", StrMUL (readVariable ("tg y"), computeFunction_of ("sin", getParam ("rot", "r")))); setVar_to ("tg y", StrMUL (readVariable ("tg y"), computeFunction_of ("cos", getParam ("rot", "r")))); setVar_to ("screen x", StrDIV (StrMUL (512, readVariable ("tg x")), StrADD (512, readVariable ("tg z")))); setVar_to ("screen y", StrDIV (StrMUL (512, readVariable ("tg y")), StrADD (512, readVariable ("tg z")))); gotoX_y (StrADD (readVariable ("cur x"), readVariable ("screen x")), StrADD (readVariable ("cur y"), readVariable ("screen y"))); putPenUp (); } procDef ("Unpack positive %n", packed (), 1, true); setVar_to ("Pack X", %(getParam ("packed", "r"), 2048)); setVar_to ("Pack Y", %(computeFunction_of ("floor", StrDIV (getParam ("packed", "r"), 2048)), 2048)); setVar_to ("Pack Z", %(computeFunction_of ("floor", StrDIV (getParam ("packed", "r"), StrMUL (2048, 2048))), 2048)); changeVar_by ("Pack X", -128); changeVar_by ("Pack Y", -128); changeVar_by ("Pack Z", readVariable ("cur z")); whenIReceive ("Kill banner"); setVar_to ("stop intro flag", "2"); whenIReceive ("Play Intro"); call ("Play intro"); procDef ("Play intro",,, true); setVar_to ("cur x", "0"); setVar_to ("cur y", "0"); setVar_to ("cur z", "206"); setVar_to ("pen colour", StrMUL (220, 256)); setVar_to ("rot", "90"); setVar_to ("flashing", 0); setVar_to ("hide", 0); setVar_to ("stop intro flag", "0"); whenIReceive ("Draw next frame"); penColor (readVariable ("pen colour")); penSize (1); if (StrGT (readVariable ("flashing"), "0")) { changeVar_by ("flashing", -1); setVar_to ("pen colour", StrMUL (computeFunction_of ("floor", StrADD (127, StrMUL (64, StrADD (computeFunction_of ("sin", StrMUL (readVariable ("flashing"), 16)), 1)))), 256)); if (StrEQ (readVariable ("flashing"), "0")) { setVar_to ("rot", "90"); setVar_to ("cur z", "206"); setVar_to ("hide", "60"); } } if (StrEQ (readVariable ("hide"), "0")) { call ("draw tg intro %n", readVariable ("rot")); if (StrEQ (readVariable ("flashing"), "0")) { setVar_to ("rot", %(StrADD (readVariable ("rot"), -2), 360)); changeVar_by ("cur z", -1); if (StrLT (readVariable ("cur z"), "-199")) { if (StrEQ (readVariable ("stop intro flag"), "1")) { clearPenTrails (); stopScripts ("this script"); } setVar_to ("pen colour", StrMUL (220, 256)); setVar_to ("flashing", "181"); setVar_to ("rot", 0); } } } else { changeVar_by ("hide", -1); if (StrEQ (readVariable ("hide"), "0")) { null} } penColor (StrMUL (250, 256)); setVar_to ("cur z", "-300"); setVar_to ("stop intro flag", "0"); call ("draw tg intro %n", 0); setVar_to ("stop intro flag", "2"); broadcast ("Start new round"); whenGreenFlag (); hide (); putPenUp (); setVar_to ("text x", "-220"); setVar_to ("text y", "32"); setVar_to ("ptr", "1"); setVar_to ("flashing text timer", 0); whenIReceive ("Draw next frame"); if (StrGT (readVariable ("#Mode"), getAttribute_of ("COINED", "CONSTS"))) { call ("Draw score"); call ("Draw ships passed"); call ("Draw shields left"); } else { call ("Draw highscore"); call ("Draw last game score"); if (StrGT (readVariable ("#Credits"), "0")) { broadcast ("Kill banner"); call ("Draw credits"); call ("Press start"); } else { null} } setVar_to ("flashing text timer", %(StrADD (readVariable ("flashing text timer"), 16), 360)); procDef ("segment %n %n", coords ("text scale"), 1; 1, true); setVar_to ("to", %(getParam ("coords", "r"), 16)); setVar_to ("to x", StrMUL (%(readVariable ("to"), 5), StrDIV (StrMUL (4, getParam ("text scale", "r")), 128))); setVar_to ("to y", StrMUL (computeFunction_of ("floor", StrDIV (readVariable ("to"), 5)), StrDIV (StrMUL (12, getParam ("text scale", "r")), 128))); setVar_to ("from", computeFunction_of ("floor", StrDIV (getParam ("coords", "r"), 16))); setVar_to ("from x", StrMUL (%(readVariable ("from"), 5), StrDIV (StrMUL (4, getParam ("text scale", "r")), 128))); setVar_to ("from y", StrMUL (computeFunction_of ("floor", StrDIV (readVariable ("from"), 5)), StrDIV (StrMUL (12, getParam ("text scale", "r")), 128))); call ("draw line 3d %n %n %n %n %n %n", readVariable ("from x"), readVariable ("from y"), readVariable ("text z"), readVariable ("to x"), readVariable ("to y"), readVariable ("text z")); procDef ("draw line 3d %n %n %n %n %n %n", from x ("from y", "from z", "to x", "to y", "to z"), 1; 1; 1; 1; 1; 1, true); gotoX_y (StrADD (readVariable ("from x"), readVariable ("text x")), StrADD (readVariable ("from y"), readVariable ("text y"))); putPenDown (); gotoX_y (StrADD (readVariable ("to x"), readVariable ("text x")), StrADD (readVariable ("to y"), readVariable ("text y"))); putPenUp (); procDef ("next char",,, true); call ("ch %n %n", readVariable ("ptr"), 128); changeVar_by ("ptr", 1); procDef ("Draw shields left",,, true); penColor (StrMUL (220, 256)); call ("Draw num %n at %n %n", readVariable ("#Shields"), -10, 140); procDef ("Draw num %n at %n %n", num ("x", "y"), 1; 1; 1, true); setVar_to ("text x", getParam ("x", "r")); setVar_to ("text y", getParam ("y", "r")); setVar_to ("ptr", "1"); { int _i; for (_i = 0; _i < stringLength (getParam ("num", "r")); _i++) { call ("ch %n %n", StrADD (letter_of (readVariable ("ptr"), getParam ("num", "r")), 1), 128); changeVar_by ("ptr", 1); } } procDef ("Insert Coin",,, true); setVar_to ("text x", "-135"); setVar_to ("text y", "-120"); setVar_to ("pen colour", StrMUL (StrADD (128, computeFunction_of ("floor", StrMUL (StrADD (computeFunction_of ("sin", readVariable ("flashing text timer")), 1), 64))), 256)); penColor (readVariable ("pen colour")); call ("ch %n %n", 19, 128); call ("ch %n %n", 24, 128); call ("ch %n %n", 29, 128); call ("ch %n %n", 15, 128); call ("ch %n %n", 28, 128); call ("ch %n %n", 30, 128); call ("ch %n %n", 0, 128); call ("ch %n %n", 13, 128); call ("ch %n %n", 25, 128); call ("ch %n %n", 19, 128); call ("ch %n %n", 24, 128); procDef ("Draw score",,, false); penColor (StrMUL (220, 256)); call ("Draw num %n at %n %n", readVariable ("#Score"), -220, 130); procDef ("Draw highscore",,, true); penColor (StrMUL (220, 256)); setVar_to ("text x", "42"); setVar_to ("text y", "130"); call ("ch %n %n", 18, 96); call ("ch %n %n", 19, 96); call ("ch %n %n", 17, 96); call ("ch %n %n", 18, 96); call ("ch %n %n", 0, 96); call ("ch %n %n", 29, 96); call ("ch %n %n", 13, 96); call ("ch %n %n", 25, 96); call ("ch %n %n", 28, 96); call ("ch %n %n", 15, 96); if (StrGT (readVariable ("☁ Highscore"), readVariable ("#HighScore"))) { setVar_to ("#HighScore", readVariable ("☁ Highscore")); } if (StrGT (readVariable ("#HighScore"), readVariable ("☁ Highscore"))) { setVar_to ("☁ Highscore", readVariable ("#HighScore")); } call ("Draw small num %n at %n %n", readVariable ("#HighScore"), StrSUB (208, StrMUL (24, StrSUB (stringLength (readVariable ("#HighScore")), 1))), 105); procDef ("Draw ships passed",,, true); penColor (StrMUL (220, 256)); call ("Draw num %n at %n %n", readVariable ("#ShipsPassed"), 200, 130); call ("Insert Coin"); procDef ("Draw small num %n at %n %n", num ("x", "y"), 1; 1; 1, true); setVar_to ("text x", getParam ("x", "r")); setVar_to ("text y", getParam ("y", "r")); setVar_to ("ptr", "1"); { int _i; for (_i = 0; _i < stringLength (getParam ("num", "r")); _i++) { call ("ch %n %n", StrADD (letter_of (readVariable ("ptr"), getParam ("num", "r")), 1), 96); changeVar_by ("ptr", 1); } } procDef ("Press start",,, true); setVar_to ("text x", "-120"); setVar_to ("text y", "-10"); setVar_to ("pen colour", StrMUL (StrADD (128, computeFunction_of ("floor", StrMUL (StrADD (computeFunction_of ("sin", readVariable ("flashing text timer")), 1), 64))), 256)); penColor (readVariable ("pen colour")); call ("ch %n %n", 26, 128); call ("ch %n %n", 28, 128); call ("ch %n %n", 15, 128); call ("ch %n %n", 29, 128); call ("ch %n %n", 29, 128); call ("ch %n %n", 0, 128); call ("ch %n %n", 29, 128); call ("ch %n %n", 30, 128); call ("ch %n %n", 11, 128); call ("ch %n %n", 28, 128); call ("ch %n %n", 30, 128); procDef ("Draw credits",,, true); penColor (StrMUL (220, 256)); setVar_to ("text x", "-100"); setVar_to ("text y", "-120"); call ("ch %n %n", 13, 128); call ("ch %n %n", 28, 128); call ("ch %n %n", 15, 128); call ("ch %n %n", 14, 128); call ("ch %n %n", 19, 128); call ("ch %n %n", 30, 128); call ("ch %n %n", 29, 128); call ("ch %n %n", 0, 128); if (StrGT (readVariable ("#Credits"), "9")) { call ("ch %n %n", 10, 128); } else { call ("ch %n %n", StrADD (readVariable ("#Credits"), 1), 128); } procDef ("Draw last game score",,, true); penColor (StrMUL (220, 256)); setVar_to ("text x", "-220"); setVar_to ("text y", "130"); call ("ch %n %n", 29, 96); call ("ch %n %n", 13, 96); call ("ch %n %n", 25, 96); call ("ch %n %n", 28, 96); call ("ch %n %n", 15, 96); call ("Draw small num %n at %n %n", readVariable ("#LastScore"), -220, 105); procDef ("alphabet test",,, true); setVar_to ("text x", "-220"); setVar_to ("text y", "30"); setVar_to ("ptr", "1"); penColor (StrMUL (220, 256)); { int _i; for (_i = 0; _i < 10; _i++) { call ("next char"); } } { int _i; for (_i = 0; _i < 8; _i++) { call ("next char"); } } changeVar_by ("text y", -32); setVar_to ("text x", "-220"); { int _i; for (_i = 0; _i < 18; _i++) { call ("next char"); } } procDef ("ch %n %n", charno ("text scale"), 1; 1, true); if (StrGT (getParam ("charno", "r"), "0")) { setVar_to ("i", getLine_ofList (getParam ("charno", "r"), "encoded")); setVar_to ("char", %(readVariable ("i"), 256)); setVar_to ("i", computeFunction_of ("floor", StrDIV (readVariable ("i"), 256))); setVar_to ("segments", %(readVariable ("i"), 7)); setVar_to ("i", computeFunction_of ("floor", StrDIV (readVariable ("i"), 7))); { int _i; for (_i = 0; _i < readVariable ("segments"); _i++) { call ("segment %n %n", %(readVariable ("i"), 256), getParam ("text scale", "r")); setVar_to ("i", computeFunction_of ("floor", StrDIV (readVariable ("i"), 256))); } } } changeVar_by ("text x", StrMUL (24, StrDIV (getParam ("text scale", "r"), 128))); whenGreenFlag (); hide (); setVar_to ("star movement", "0.025"); setVar_to ("my clone id", "0"); { int _i; for (_i = 0; _i < 64; _i++) { if (StrEQ (readVariable ("my clone id"), "0")) { createCloneOf ("_myself_"); wait_elapsed_from (0.07); } } } whenCloned (); changeVar_by ("my clone id", 1); call ("Reinit"); whenIReceive ("Draw next frame"); if (StrGT (readVariable ("my clone id"), "0")) { if (StrLT (distanceTo ("StarfieldCenter"), "20")) { call ("Reinit"); } else { changeGraphicEffect_by ("ghost", 1); if (StrGT (scale (), "10")) { changeSizeBy (-10); } forward (StrMUL (readVariable ("star movement"), distanceTo ("StarfieldCenter"))); } } whenIReceive ("Passing"); if (StrEQ (readVariable ("my clone id"), "0")) { setVar_to ("star movement", "0.05"); { int _i; for (_i = 0; _i < 6; _i++) { playSound ("star"); wait_elapsed_from (1); } } setVar_to ("star movement", "0.025"); } procDef ("Point to %n %n", x ("y"), 1; 1, false); heading (StrADD (computeFunction_of ("atan", StrDIV (StrSUB (getParam ("x", "r"), xpos ()), StrSUB (getParam ("y", "r"), ypos ()))), StrMUL (180, StrLT (getParam ("y", "r"), ypos ())))); procDef ("Choose random edge to start on",,, false); setVar_to ("edge", randomFrom_to (1, 4)); if (StrEQ (readVariable ("edge"), "1")) { gotoX_y (-239, randomFrom_to (-179, 180)); } else { if (StrEQ (readVariable ("edge"), "2")) { gotoX_y (239, randomFrom_to (-179, 180)); } else { if (StrEQ (readVariable ("edge"), "3")) { gotoX_y (randomFrom_to (-239, 239), 179); } else { gotoX_y (randomFrom_to (-239, 239), -179); } ; } } procDef ("Reinit",,, true); hide (); call ("Choose random edge to start on"); pointTowards ("StarfieldCenter"); setGraphicEffect_to ("ghost", 25); setSizeTo (250); comeToFront (); show (); whenGreenFlag (); hide (); setVar_to ("shield segment", "0"); setVar_to ("shield subticks left", "0"); whenIReceive ("Draw next frame"); if (StrAND (StrEQ (readVariable ("#Mode"), getAttribute_of ("PLAYING", "CONSTS")), StrEQ (readVariable ("?UsingShields"), "1"))) { call ("Shield"); } else { setVar_to ("shield subticks left", 0); } procDef ("Shield",,, true); if (StrEQ (readVariable ("shield subticks left"), "0")) { playSound ("shield"); setVar_to ("shield subticks left", computeFunction_of ("ceiling", StrDIV (0.1, 0.03333))); changeVar_by ("#Shields", -1); } else { changeVar_by ("shield subticks left", -1); } if (StrGT (randomFrom_to (0, 3), "0")) { penColor (StrMUL (randomFrom_to (160, 255), 256)); setVar_to ("shield segment", "1"); while (!(StrGT (readVariable ("shield segment"), "25"))) { gotoX_y (StrSUB (StrMUL (getLine_ofList (readVariable ("shield segment"), "shieldvec"), 32), 256), StrSUB (StrMUL (getLine_ofList (StrADD (readVariable ("shield segment"), 1), "shieldvec"), 32), 192)); putPenDown (); changeVar_by ("shield segment", 2); } putPenUp (); } whenGreenFlag (); deleteLine_ofList ("all", "debug"); setVar_to ("drawing semaphore", 0); putPenUp (); hide (); setVar_to ("next wave ship type", "1"); deleteLine_ofList ("all", "ships"); deleteLine_ofList ("all", "projectiles"); whenIReceive ("New game"); deleteLine_ofList ("all", "ships"); deleteLine_ofList ("all", "projectiles"); procDef ("ship hit check %n %n", x ("y"), 1; 1, false); setVar_to ("e", 0); { int _i; for (_i = 0; _i < StrDIV (lineCountOfList ("ships"), readVariable ("*SHIP_MULT")); _i++) { call ("Get ship pos %n", readVariable ("e")); call ("Get ship scale %n", readVariable ("e")); call ("Get screen pos %n %n %n", readVariable ("X"), readVariable ("Y"), readVariable ("Z")); if (StrLT (computeFunction_of ("sqrt", StrADD (StrMUL (StrSUB (getParam ("x", "r"), readVariable ("X")), StrSUB (getParam ("x", "r"), readVariable ("X"))), StrMUL (StrSUB (getParam ("y", "r"), readVariable ("Y")), StrSUB (getParam ("y", "r"), readVariable ("Y"))))), StrMUL (StrMUL (15, readVariable ("scale")), StrDIV (readVariable ("focalLength"), readVariable ("Z"))))) { changeVar_by ("#Score", 5); playSound ("explode"); call ("Delete ship %n", readVariable ("e")); } else { changeVar_by ("e", 1); } ; } } procDef ("Draw ship %n at %n %n %n rotated %n %n %n scale %n", ship type ("x", "y", "z", "xrot", "yrot", "zrot", "scale"), 1; 1; 1; 1; 1; 1; 1; 1, true); penColor (StrMUL (170, 256)); penSize (1); call ("Set rotation vars %n %n %n", getParam ("xrot", "r"), getParam ("yrot", "r"), getParam ("zrot", "r")); setVar_to ("e", getLine_ofList (getParam ("ship type", "r"), "ShipMeshPointers")); { int _i; for (_i = 0; _i < StrSUB (getLine_ofList (StrADD (getParam ("ship type", "r"), 1), "ShipMeshPointers"), readVariable ("e")); _i++) { call ("Transform point %n %n %n", StrMUL (getLine_ofList (StrADD (StrMUL (readVariable ("e"), 6), 1), "ShipMeshes"), getParam ("scale", "r")), StrMUL (getLine_ofList (StrADD (StrMUL (readVariable ("e"), 6), 2), "ShipMeshes"), getParam ("scale", "r")), StrMUL (getLine_ofList (StrADD (StrMUL (readVariable ("e"), 6), 3), "ShipMeshes"), getParam ("scale", "r"))); call ("Get screen pos %n %n %n", StrADD (getParam ("x", "r"), readVariable ("X")), StrADD (getParam ("y", "r"), readVariable ("Y")), StrADD (getParam ("z", "r"), readVariable ("Z"))); gotoX_y (readVariable ("X"), readVariable ("Y")); putPenDown (); call ("Transform point %n %n %n", StrMUL (getLine_ofList (StrADD (StrMUL (readVariable ("e"), 6), 4), "ShipMeshes"), getParam ("scale", "r")), StrMUL (getLine_ofList (StrADD (StrMUL (readVariable ("e"), 6), 5), "ShipMeshes"), getParam ("scale", "r")), StrMUL (getLine_ofList (StrADD (StrMUL (readVariable ("e"), 6), 6), "ShipMeshes"), getParam ("scale", "r"))); call ("Get screen pos %n %n %n", StrADD (getParam ("x", "r"), readVariable ("X")), StrADD (getParam ("y", "r"), readVariable ("Y")), StrADD (getParam ("z", "r"), readVariable ("Z"))); gotoX_y (readVariable ("X"), readVariable ("Y")); putPenUp (); changeVar_by ("e", 1); } } procDef ("Update ship %n", id (), 1, false); call ("Get ship pos %n", getParam ("id", "r")); call ("Apply vel to ship pos %n", getParam ("id", "r")); call ("Change ship %n velocity by %n", getParam ("id", "r"), readVariable ("*SHIP_ACCEL")); if (StrAND (StrLT (readVariable ("Z Pos"), "100"), StrEQ (readVariable ("?UsingShields"), "1"))) { playSound ("bounce"); call ("Set ship %n destination to %n %n %n", getParam ("id", "r"), randomFrom_to (-100, 100), randomFrom_to (-100, 100), StrADD (readVariable ("*SHIP_SPAWN_Z"), 1000)); call ("Get ship vel %n", getParam ("id", "r")); call ("Set ship %n velocity to %n", getParam ("id", "r"), StrMUL (-1, readVariable ("vel"))); call ("Apply vel to ship pos %n", getParam ("id", "r")); call ("Head ship towards destination %n", getParam ("id", "r")); call ("Change ship %n time by %n", getParam ("id", "r"), 1); call ("Get ship pos %n", getParam ("id", "r")); } if (StrGT (readVariable ("Z Pos"), StrADD (readVariable ("*SHIP_SPAWN_Z"), 500))) { call ("Delete ship %n", getParam ("id", "r")); } if (StrLT (readVariable ("Z Pos"), "30")) { call ("Delete ship %n", getParam ("id", "r")); changeVar_by ("#ShipsPassed", 1); } else { call ("Get ship destination %n", getParam ("id", "r")); if (not (StrAND (StrAND (StrEQ (readVariable ("X"), "0"), StrEQ (readVariable ("Y"), "0")), StrGT (readVariable ("Z"), readVariable ("*SHIP_SPAWN_Z"))))) { call ("Get ship time %n", getParam ("id", "r")); if (StrEQ (%(readVariable ("ship t"), 40), "39")) { call ("Get ship pos %n", getParam ("id", "r")); if (StrLT (readVariable ("Z Pos"), "1000")) { call ("Set ship %n destination to %n %n %n", getParam ("id", "r"), 0, 0, 0); } else { call ("Set ship %n destination to %n %n %n", getParam ("id", "r"), randomFrom_to (StrDIV (StrMUL (-300, readVariable ("Z Pos")), 2000), StrDIV (StrMUL (300, readVariable ("Z Pos")), 2000)), randomFrom_to (StrDIV (StrMUL (-200, readVariable ("Z Pos")), 2000), StrDIV (StrMUL (200, readVariable ("Z Pos")), 2000)), -200); } ; } } call ("Head ship towards destination %n", getParam ("id", "r")); call ("Change ship %n time by %n", getParam ("id", "r"), 1); } procDef ("Change ship %n time by %n", id ("dt"), 1; 1, false); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 10), "ships", StrADD (getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 10), "ships"), getParam ("dt", "r"))); procDef ("Get ship pos %n", id (), 1, false); setVar_to ("X", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 2), "ships")); setVar_to ("Y", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 3), "ships")); setVar_to ("Z", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 4), "ships")); setVar_to ("X Pos", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 2), "ships")); setVar_to ("Y Pos", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 3), "ships")); setVar_to ("Z Pos", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 4), "ships")); procDef ("Transform point %n %n %n", x ("y", "z"), 1; 1; 1, false); setVar_to ("XY", StrSUB (StrMUL (readVariable ("cosX"), getParam ("y", "r")), StrMUL (readVariable ("sinX"), getParam ("z", "r")))); setVar_to ("XZ", StrADD (StrMUL (readVariable ("sinX"), getParam ("y", "r")), StrMUL (readVariable ("cosX"), getParam ("z", "r")))); setVar_to ("Z", StrSUB (StrMUL (readVariable ("cosY"), readVariable ("XZ")), StrMUL (readVariable ("sinY"), getParam ("x", "r")))); setVar_to ("YX", StrADD (StrMUL (readVariable ("sinY"), readVariable ("XZ")), StrMUL (readVariable ("cosY"), getParam ("x", "r")))); setVar_to ("X", StrSUB (StrMUL (readVariable ("cosZ"), readVariable ("YX")), StrMUL (readVariable ("sinZ"), readVariable ("XY")))); setVar_to ("Y", StrADD (StrMUL (readVariable ("sinZ"), readVariable ("YX")), StrMUL (readVariable ("cosZ"), readVariable ("XY")))); procDef ("Change ship %n pos by %n %n %n", id ("dx", "dy", "dz"), 1; 1; 1; 1, false); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 2), "ships", StrADD (getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 2), "ships"), getParam ("dx", "r"))); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 3), "ships", StrADD (getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 3), "ships"), getParam ("dy", "r"))); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 4), "ships", StrADD (getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 4), "ships"), getParam ("dz", "r"))); procDef ("Change ship %n rotation by %n %n %n", id ("xrot", "yrot", "zrot"), 1; 1; 1; 1, false); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 5), "ships", StrADD (getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 5), "ships"), getParam ("xrot", "r"))); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 6), "ships", StrADD (getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 6), "ships"), getParam ("yrot", "r"))); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 7), "ships", StrADD (getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 7), "ships"), getParam ("zrot", "r"))); procDef ("Get ship rotation %n", id (), 1, false); setVar_to ("x rot", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 5), "ships")); setVar_to ("y rot", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 6), "ships")); setVar_to ("z rot", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 7), "ships")); procDef ("Get length of %n %n %n", x ("y", "z"), 1; 1; 1, false); setVar_to ("distance", computeFunction_of ("sqrt", StrADD (StrMUL (getParam ("x", "r"), getParam ("x", "r")), StrADD (StrMUL (getParam ("y", "r"), getParam ("y", "r")), StrMUL (getParam ("z", "r"), getParam ("z", "r")))))); procDef ("Get ship time %n", id (), 1, false); setVar_to ("ship t", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 10), "ships")); procDef ("Point to %n %n", x ("y"), 1; 1, false); heading (StrADD (computeFunction_of ("atan", StrDIV (StrSUB (getParam ("x", "r"), xpos ()), StrSUB (getParam ("y", "r"), ypos ()))), StrMUL (180, StrLT (getParam ("y", "r"), ypos ())))); procDef ("Get ship scale %n", id (), 1, false); setVar_to ("scale", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 8), "ships")); procDef ("Get ship destination %n", id (), 1, false); setVar_to ("X", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 11), "ships")); setVar_to ("Y", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 12), "ships")); setVar_to ("Z", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 13), "ships")); setVar_to ("X Dest", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 11), "ships")); setVar_to ("Y Dest", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 12), "ships")); setVar_to ("Z Dest", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 13), "ships")); procDef ("Change ship %n velocity by %n", id ("accel"), 1; 1, false); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 9), "ships", StrADD (getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 9), "ships"), getParam ("accel", "r"))); if (StrGT (getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 9), "ships"), readVariable ("*SHIP_MAXVEL"))) { setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 9), "ships", readVariable ("*SHIP_MAXVEL")); } procDef ("Create attack wave",,, false); setVar_to ("model", readVariable ("next wave ship type")); setVar_to ("x rot", "270"); setVar_to ("y rot", "180"); setVar_to ("Z", readVariable ("*SHIP_SPAWN_Z")); setVar_to ("scale", "2.0"); { int _i; for (_i = 0; _i < getAttribute_of ("SHIPS PER WAVE", "CONSTS"); _i++) { setVar_to ("random edge", randomFrom_to (1, 3)); if (StrEQ (readVariable ("random edge"), "1")) { setVar_to ("X", "-900"); setVar_to ("Y", randomFrom_to (-500, 500)); setVar_to ("z rot", "90"); call ("New ship: type %n pos %n %n %n rot %n %n %n scale %n", readVariable ("model"), readVariable ("X"), readVariable ("Y"), readVariable ("Z"), readVariable ("x rot"), readVariable ("y rot"), readVariable ("z rot"), readVariable ("scale")); } else { if (StrEQ (readVariable ("random edge"), "2")) { setVar_to ("X", randomFrom_to (-500, 500)); setVar_to ("Y", "700"); setVar_to ("z rot", "0"); call ("New ship: type %n pos %n %n %n rot %n %n %n scale %n", readVariable ("model"), readVariable ("X"), readVariable ("Y"), readVariable ("Z"), readVariable ("x rot"), readVariable ("y rot"), readVariable ("z rot"), readVariable ("scale")); } else { setVar_to ("X", "900"); setVar_to ("Y", randomFrom_to (-500, 500)); setVar_to ("z rot", "-90"); call ("New ship: type %n pos %n %n %n rot %n %n %n scale %n", readVariable ("model"), readVariable ("X"), readVariable ("Y"), readVariable ("Z"), readVariable ("x rot"), readVariable ("y rot"), readVariable ("z rot"), readVariable ("scale")); } ; } ; } } whenIReceive ("Draw next frame"); call ("Draw frame"); procDef ("Set ship %n pos to %n %n %n", id ("x", "y", "z"), 1; 1; 1; 1, false); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 2), "ships", getParam ("x", "r")); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 3), "ships", getParam ("y", "r")); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 4), "ships", getParam ("z", "r")); procDef ("Get eigenvector to %n %n %n", x ("y", "z"), 1; 1; 1, false); setVar_to ("dirXZ", StrADD (computeFunction_of ("atan", StrDIV (getParam ("x", "r"), getParam ("z", "r"))), StrMUL (180, StrLT (getParam ("z", "r"), "0")))); setVar_to ("dirY", computeFunction_of ("asin", StrDIV (getParam ("y", "r"), computeFunction_of ("sqrt", StrADD (StrMUL (getParam ("x", "r"), getParam ("x", "r")), StrADD (StrMUL (getParam ("y", "r"), getParam ("y", "r")), StrMUL (getParam ("z", "r"), getParam ("z", "r")))))))); procDef ("Apply vel to ship pos %n", id (), 1, false); call ("Get ship vel %n", getParam ("id", "r")); call ("Get ship rotation %n", getParam ("id", "r")); call ("Change ship %n pos by %n %n %n", getParam ("id", "r"), StrMUL (readVariable ("vel"), StrMUL (computeFunction_of ("sin", readVariable ("y rot")), computeFunction_of ("cos", readVariable ("x rot")))), StrMUL (readVariable ("vel"), computeFunction_of ("sin", readVariable ("x rot"))), StrMUL (readVariable ("vel"), StrMUL (computeFunction_of ("cos", readVariable ("y rot")), computeFunction_of ("cos", readVariable ("x rot"))))); procDef ("Set rotation vars %n %n %n", xrot ("yrot", "zrot"), 1; 1; 1, false); setVar_to ("sinX", computeFunction_of ("sin", getParam ("xrot", "r"))); setVar_to ("cosX", computeFunction_of ("cos", getParam ("xrot", "r"))); setVar_to ("sinY", computeFunction_of ("sin", getParam ("yrot", "r"))); setVar_to ("cosY", computeFunction_of ("cos", getParam ("yrot", "r"))); setVar_to ("sinZ", computeFunction_of ("sin", getParam ("zrot", "r"))); setVar_to ("cosZ", computeFunction_of ("cos", getParam ("zrot", "r"))); procDef ("Set ship %n rotation to %n %n %n", id ("xrot", "yrot", "zrot"), 1; 1; 1; 1, false); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 5), "ships", getParam ("xrot", "r")); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 6), "ships", getParam ("yrot", "r")); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 7), "ships", getParam ("zrot", "r")); procDef ("Get ship vel %n", id (), 1, false); setVar_to ("vel", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 9), "ships")); procDef ("Head ship towards destination %n", id (), 1, false); call ("Get ship pos %n", getParam ("id", "r")); setVar_to ("old X", readVariable ("X")); setVar_to ("old Y", readVariable ("Y")); setVar_to ("old Z", readVariable ("Z")); call ("Get ship destination %n", getParam ("id", "r")); call ("Get length of %n %n %n", StrSUB (readVariable ("X"), readVariable ("old X")), StrSUB (readVariable ("Y"), readVariable ("old Y")), StrSUB (readVariable ("Z"), readVariable ("old Z"))); call ("Rotate ship %n toward %n %n %n by %n \\%", getParam ("id", "r"), readVariable ("X"), readVariable ("Y"), readVariable ("Z"), 10); setVar_to ("Z", StrSUB (readVariable ("*SHIP_SPAWN_Z"), 1)); procDef ("Draw frame",,, true); if (StrEQ (readVariable ("drawing semaphore"), "0")) { changeVar_by ("drawing semaphore", 1); if (StrGT (readVariable ("#Mode"), getAttribute_of ("COINED", "CONSTS"))) { call ("Update ships"); if (StrLT (readVariable ("#ShipsPassed"), "10")) { if (StrEQ (lineCountOfList ("ships"), "0")) { call ("Start attack wave"); } } else { if (StrGT (readVariable ("#Credits"), "0")) { setVar_to ("#Mode", getAttribute_of ("COINED", "CONSTS")); } else { setVar_to ("#Mode", getAttribute_of ("PREGAME", "CONSTS")); setVar_to ("#LastScore", readVariable ("#Score")); } ; } ; if (StrGT (readVariable ("#Score"), readVariable ("#HighScore"))) { setVar_to ("#HighScore", readVariable ("#Score")); } call ("Render ships"); call ("Render lasers"); } else { call ("Update ships"); call ("Render ships"); } changeVar_by ("drawing semaphore", -1); } procDef ("Render lasers",,, true); setVar_to ("laser id", 0); { int _i; for (_i = 0; _i < StrDIV (lineCountOfList ("projectiles"), 3); _i++) { setVar_to ("laser t", getLine_ofList (StrADD (StrMUL (3, readVariable ("laser id")), 1), "projectiles")); setVar_to ("targetting x", mouseX ()); setVar_to ("targetting y", mouseY ()); if (StrLT (readVariable ("laser t"), "0.98")) { setSizeTo (StrMUL (100, StrSUB (1, readVariable ("laser t")))); gotoX_y (-240, -180); call ("Point to %n %n", readVariable ("targetting x"), readVariable ("targetting y")); forward (StrMUL (readVariable ("laser t"), computeFunction_of ("sqrt", StrADD (StrMUL (StrSUB (readVariable ("targetting x"), xpos ()), StrSUB (readVariable ("targetting x"), xpos ())), StrMUL (StrSUB (readVariable ("targetting y"), ypos ()), StrSUB (readVariable ("targetting y"), ypos ())))))); stampCostume (); gotoX_y (240, -180); call ("Point to %n %n", readVariable ("targetting x"), readVariable ("targetting y")); forward (StrMUL (readVariable ("laser t"), computeFunction_of ("sqrt", StrADD (StrMUL (StrSUB (readVariable ("targetting x"), xpos ()), StrSUB (readVariable ("targetting x"), xpos ())), StrMUL (StrSUB (readVariable ("targetting y"), ypos ()), StrSUB (readVariable ("targetting y"), ypos ())))))); stampCostume (); setLine_ofList_to (StrADD (StrMUL (3, readVariable ("laser id")), 1), "projectiles", StrADD (readVariable ("laser t"), StrMUL (0.25, StrSUB (1, readVariable ("laser t"))))); changeVar_by ("laser id", 1); } else { call ("ship hit check %n %n", readVariable ("targetting x"), readVariable ("targetting y")); { int _i; for (_i = 0; _i < 3; _i++) { deleteLine_ofList (StrADD (StrMUL (3, readVariable ("laser id")), 1), "projectiles"); } } ; } ; } } whenIReceive ("Start new round"); setVar_to ("#Shields", "80"); setVar_to ("#ShipsPassed", 0); deleteLine_ofList ("all", "ships"); deleteLine_ofList ("all", "projectiles"); call ("Start attack wave"); procDef ("Start attack wave",,, true); call ("Create attack wave"); setVar_to ("next wave ship type", StrADD (%(readVariable ("next wave ship type"), 4), 1)); procDef ("Render ships",,, true); setVar_to ("laser id", "0"); { int _i; for (_i = 0; _i < StrDIV (lineCountOfList ("ships"), readVariable ("*SHIP_MULT")); _i++) { call ("Get ship type %n", readVariable ("laser id")); call ("Get ship pos %n", readVariable ("laser id")); call ("Get ship rotation %n", readVariable ("laser id")); call ("Get ship scale %n", readVariable ("laser id")); call ("Draw ship %n at %n %n %n rotated %n %n %n scale %n", readVariable ("model"), readVariable ("X"), readVariable ("Y"), readVariable ("Z"), StrSUB (0, readVariable ("x rot")), readVariable ("y rot"), readVariable ("z rot"), readVariable ("scale")); changeVar_by ("laser id", 1); } } procDef ("Get screen pos %n %n %n", x ("y", "z"), 1; 1; 1, false); setVar_to ("X", StrMUL (readVariable ("focalLength"), StrDIV (getParam ("x", "r"), getParam ("z", "r")))); setVar_to ("Y", StrMUL (readVariable ("focalLength"), StrDIV (getParam ("y", "r"), getParam ("z", "r")))); procDef ("New ship: type %n pos %n %n %n rot %n %n %n scale %n", type ("x", "y", "z", "xrot", "yrot", "zrot", "scale"), 1; 1; 1; 1; 1; 1; 1; 1, false); append_toList (getParam ("type", "r"), "ships"); append_toList (getParam ("x", "r"), "ships"); append_toList (getParam ("y", "r"), "ships"); append_toList (getParam ("z", "r"), "ships"); append_toList (getParam ("xrot", "r"), "ships"); append_toList (getParam ("yrot", "r"), "ships"); append_toList (getParam ("zrot", "r"), "ships"); append_toList (getParam ("scale", "r"), "ships"); append_toList (StrDIV (StrMUL (readVariable ("*SHIP_MAXVEL"), randomFrom_to (80, 120)), 100), "ships"); append_toList ("0", "ships"); append_toList (randomFrom_to (-400, 400), "ships"); append_toList (randomFrom_to (-300, 300), "ships"); append_toList (getParam ("z", "r"), "ships"); procDef ("Set ship %n velocity to %n", id ("vel"), 1; 1, false); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 9), "ships", getParam ("vel", "r")); if (StrEQ (lineCountOfList ("ships"), "0")) { call ("Start attack wave"); } setVar_to ("#ShipsPassed", 0); call ("Set ship %n velocity to %n", getParam ("id", "r"), StrMUL (0.5, readVariable ("vel"))); whenIReceive ("Init arcade"); setVar_to ("*SHIP_MULT", "13"); setVar_to ("*SHIP_ACCEL", "0.1"); setVar_to ("*SHIP_MAXVEL", "20"); setVar_to ("*SHIP_SPAWN_Z", "2000"); setVar_to ("focalLength", "512"); procDef ("Delete ship %n", id (), 1, false); { int _i; for (_i = 0; _i < readVariable ("*SHIP_MULT"); _i++) { deleteLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 1), "ships"); } } setVar_to ("deleted ship id", getParam ("id", "r")); procDef ("Get ship type %n", id (), 1, false); setVar_to ("model", getLine_ofList (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 1), "ships")); procDef ("Set ship %n destination to %n %n %n", id ("x", "y", "z"), 1; 1; 1; 1, false); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 11), "ships", getParam ("x", "r")); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 12), "ships", getParam ("y", "r")); setLine_ofList_to (StrADD (StrMUL (readVariable ("*SHIP_MULT"), getParam ("id", "r")), 13), "ships", getParam ("z", "r")); procDef ("Update ships",,, true); setVar_to ("ship id", "0"); setVar_to ("deleted ship id", "-1"); while (! (not (StrLT (readVariable ("ship id"), StrDIV (lineCountOfList ("ships"), readVariable ("*SHIP_MULT")))))) { call ("Update ship %n", readVariable ("ship id")); if (not (StrEQ (readVariable ("deleted ship id"), readVariable ("ship id")))) { changeVar_by ("ship id", 1); } } procDef ("Rotate ship %n toward %n %n %n by %n \\%", id ("x", "y", "z", "%"), 1; 1; 1; 1; 1, false); call ("Get ship pos %n", getParam ("id", "r")); call ("Get eigenvector to %n %n %n", StrSUB (getParam ("x", "r"), readVariable ("X")), StrSUB (getParam ("y", "r"), readVariable ("Y")), StrSUB (getParam ("z", "r"), readVariable ("Z"))); call ("Get ship rotation %n", getParam ("id", "r")); call ("Change ship %n rotation by %n %n %n", getParam ("id", "r"), StrMUL (StrDIV (getParam ("%", "r"), 100), StrSUB (% (StrADD (StrSUB (readVariable ("dirY"), readVariable ("x rot")), 180), 360), 180)), StrMUL (StrDIV (getParam ("%", "r"), 100), StrSUB (% (StrADD (StrSUB (readVariable ("dirXZ"), readVariable ("y rot")), 180), 360), 180)), StrMUL (StrDIV (getParam ("%", "r"), 100), StrSUB (0, readVariable ("z rot")))); whenGreenFlag (); setVar_to ("PREGAME", "1"); setVar_to ("DEMO WAVE", "2"); setVar_to ("COINED", "3"); setVar_to ("PLAYING", "4"); setVar_to ("PASSING", "5"); setVar_to ("SHIPS PER WAVE", "3"); setVar_to ("TUMBLING", "1.1"); setVar_to ("INSERT COIN", "1.3"); whenGreenFlag (); hide (); setVar_to ("?mouseDownPrev", 0); setVar_to ("last firing time", timer ()); whenIReceive ("Fire"); playSound ("laser"); append_toList ("0", "projectiles"); append_toList (mouseX (), "projectiles"); append_toList (mouseY (), "projectiles"); whenIReceive ("Check Mouse and Keyboard"); gotoX_y (mouseX (), mouseY ()); if (StrEQ (readVariable ("#Mode"), getAttribute_of ("PLAYING", "CONSTS"))) { comeToFront (); show (); if (mousePressed ()) { if (StrEQ (readVariable ("?mouseDownPrev"), "0")) { if (StrGT (StrSUB (timer (), readVariable ("last firing time")), "0.6")) { setVar_to ("last firing time", timer ()); broadcast ("Fire"); } } setVar_to ("?mouseDownPrev", "1"); } else { setVar_to ("?mouseDownPrev", 0); } if (StrAND (keyPressed ("space"), StrGT (readVariable ("#Shields"), "0"))) { setVar_to ("?UsingShields", "1"); } else { setVar_to ("?UsingShields", 0); } } else { setVar_to ("?mouseDownPrev", 0); hide (); } whenIReceive ("Start new round"); setVar_to ("last firing time", timer ()); changeVar_by ("#Shields", -1); }