LAMPIRAN
Lampiran Lembar Kuesioner Analisa dan Perancangan Game 2D Strategi Berbasiskan Engine Torque Game Builder
1. Jenis game yang anda sukai ? (RPG, strategi, action RPG, strategi RPG, action strategi) 2. Tema game seperti apa yang anda suka ? (fantasy, future, history, tema campuran) 3. Jenis lokasi pertempuran seperti apa yang anda sukai ? (Padang pasir, lautan, hutan, angkasa, luar angkasa, campuran) 4. Jenis kontrol apa yang anda harapkan dari sebuah game strategi ? (keyboard, mouse, joystick, keyboard dan mouse) 5. Jenis View camera seperti apa yang anda harapkan dalam sebuah game strategi ? (first person, third person) 6. Apakah anda pernah memainkan jenis game turn based strategi? (ya, tidak) 7. Berapakah Umur Anda saat ini ? (tanpa pilihan jawaban) 8. Jenis karakter seperti apa yang anda inginkan untuk game strategi ? (tanpa piliha n jawaban) 9. Jenis Spesial Ability apa yang anda inginkan untuk jenis game turn base strategi? (tanpa pilihan jawaban)
L1
L2
Lampiran Lembar Kuesioner Evaluasi Analisa dan Perancangan Game 2D Strategi Berbasiskan Engine Torque Game Builder 1. Bagaimana pendapat anda mengenai game Territorial War? (sangat menarik, menarik, tidak menarik) 2. Menurut anda bagaimana tampilan grafis dari game Territorial War? (sangat menarik, menarik, tidak menarik) 3. Bagaimana menurut anda konsep gameplay game Territorial War ? (sangat menarik, menarik, tidak menarik) 4.
Bagaimana menurut anda mengenai kontrol dari game ini? (nyaman, tidak nyaman)
5. Bagaimana menurut anda tentang penggunaan efek suara game Territorial War? (sangat sesuai, sesuai, tidak sesuai) 6. Bagaimana menurut anda tentang variasi objek pada game Territorial War? (sangat bervariasi, cukup bervariasi, tidak bervariasi)
L3 LAMPIRAN CODE GAME TERRITORIAL WAR
Berikut akan dijelaskan bagaimana Torque Game Builder bekerja dengan code-code yang kami buat.
Gambar editor Engine Torque Game Builder Gambar diatas merupakan tempat gambar editor tempat kita merancang game, pada editor ini user bisa membuat sebuah objek yang bisa digunakan dalam game nantinya. Untuk memulai sebuah project baru user harus memilih file lalu create new project. Apabila user telah menyiapkan semua objek yang diinginkan maka sekarang adalah saatnya user memberikan script code ke masing-masing objek agar objek-objek tersebut bisa melakukan tugasnya masing-masing dalam game yang ingin dibuat. Sebagai contoh, bila user ingin membuat sebuah game yang berisikan objek-objek sebagai berikut: angin, enemy, jagoan, meteor, peluru, dan roket. Untuk membuat script code user harus membuka folder game project dan membuat sebuah file text menggunakan notepad atau textpad. File text tersebut diisikan dengan script code yang ingin di buat dan di save dengan file name sesuai dengan nama objeknya diakhiri dengan .cs (contoh
L4 angin.cs). Semua objek yang sudah disebutkan tadi akan dijelaskan fungsi code nya pada lampiran code ini. Dibawah ini merupakan script code dari objek angin.cs angin.cs function angin::onLevelLoaded(%this, %scenegraph) { %this.startX = %this.getPositionX(); %this.spawn(); } function angin::onWorldLimit(%this, %mode, %limit) { if(%limit $= "left") { %this.spawn(); } } function angin::spawn(%this) { %this.setLinearVelocityX(%this.maxSpeed); %this.setPositionY(getRandom(%this.minY, %this.maxY)); %this.setPositionX(%this.startX); }
Diatas merupakan script code untuk objek angin. Pada saat game di load maka objek angin akan dibuat. Pada function on WorldLimit kita bisa men set agar angin dihilangkan dari layar pada posisi tertentu. Pada function spawn kita bisa men set bagaimana gerakan, arah, dan kecepatan angin saat angin dipanggil ke layar.
L5
Dibawah ini akan dijelaskan script code pada enemy.cs yang merupakan script dari objek musuh yang telah dibuat. Penjelasan fungsi code ada disetiap masing-masing code. //bagian ini adalah bagian yang dijalankan pertama kali saat code dipanggil function enemy::onLevelLoaded(%this, %scenegraph) { %this.spawn();
//bagian ini untuk membuat tombol spasi dapat ditekan untuk menembakkan missile moveMap.bindCmd(keyboard, "space", "%this.createMissile();", ""); // bagian ini adalah bagian untuk memainkan tema lagu dari game kami. $ambientAudio = alxPlay( ambient1Audio ); //bagian ini untuk mencari posisi awal objek enemy %this.startX = %this.getPositionX(); }
//bagian ini adalah bagian untuk memberi tahu engine bahwa objek ini akan //menggunakan mouse event function enemy::onAdd(%this) { %this.setUseMouseEvents( true ); }
//bagian ini akan membuat sebuah objek dihancurkan saat di klik function enemy::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks) { %this.explode(); }
L6
//bagian ini mengatur bagaimana enemy keluar ke layar secara random function enemy::spawn(%this) {
%x=getRandom(%this.val1)*8; %y=getRandom(%this.val2)*8;
%this.setPosition(%x,%y); }
//bagian ini adalah bagian yang mengatur efek ledakan yang keluar apabila musuh //tertembak function enemy::explode(%this) {
%explosion = new t2dParticleEffect() { scenegraph = %this.scenegraph; }; %explosion.loadEffect("~/data/particles/customExplosion.eff"); %explosion.setEffectLifeMode("KILL", 1); %explosion.setPosition(%this.getPosition()); %explosion.playEffect(); %smoke = new t2dParticleEffect() { scenegraph = %this.scenegraph; }; %smoke.loadEffect("~/data/particles/steam.eff"); %smoke.setEffectLifeMode("KILL", 1); %smoke.setPosition(%this.getPosition()); %smoke.playEffect(); %debris = new t2dParticleEffect() { scenegraph = %this.scenegraph;
L7 }; %debris.loadEffect("~/data/particles/playerDebris.eff"); %debris.setEffectLifeMode("KILL", 1); %debris.setPosition(%this.getPosition()); %debris.playEffect(); //play sound alxPlay( explosionAudio ); %this.isDead = true; %this.setEnabled(false); schedule(1000, 0, "explosionDecrease"); }
function enemy::onLevelEnded(%this) { alxStop($ambientAudio); }
Dibawah ini merupakan lampiran code dan penjelasan fungsi untuk objek meteor //merupakan code yang paling awal dipanggil saat game dijalankan function meteor::onLevelLoaded(%this, %scenegraph) { %this.startX = %this.getPositionX(); %this.spawn(); }
//untuk mengatur kapan meteor akan dihilangkan dari layar function meteor::onWorldLimit(%this, %mode, %limit) { if(%limit $= "left") { %this.spawn(); } }
L8
//untuk mengatur bagaimana meteor tampil di layar function meteor::spawn(%this) { %this.setLinearVelocityX(getRandom(%this.minSpeed, %this.maxSpeed)); %this.setPositionY(getRandom(%this.minY, %this.maxY)); %this.setPositionX(%this.startX); }
Dibawah ini akan dijelaskan fungsi script dari objek jagoan.
//fungsi untuk inisialisasi saat game dijalankan, berisi perintah untuk memutar tema lagu //game saat objek jagoan keluar dan juga membaca posisi pertama objek jagoan. function jagoan::onLevelLoaded(%this, %scenegraph) { $ambientAudio = alxPlay( ambient1Audio );
%this.startX = %this.getPositionX(); }
//untuk memberi tahu engine kalau kita akan menggunakan mouse event pada objek //jagoan function jagoan::onAdd(%this) { %this.setUseMouseEvents( true );
}
//fungsi untuk membuat objek jagoan dapat di drag oleh mouse function jagoan::onMouseDragged(%this, %modifier, %worldPosition, %mouseClicks) { %this.setPosition(%worldPosition); }
L9
//fungsi untuk membuat objek jagoan tidak bisa di drag oleh mouse function jagoan::onMouseUp(%this, %modifier, %worldPosition, %mouseClicks) { %this.setUseMouseEvents( false ); }
//fungsi yang mengatur efek ledakan yang keluar saat jagoan tertembak function jagoan::explode(%this) {
%explosion = new t2dParticleEffect() { scenegraph = %this.scenegraph; }; %explosion.loadEffect("~/data/particles/customExplosion.eff"); %explosion.setEffectLifeMode("KILL", 1); %explosion.setPosition(%this.getPosition()); %explosion.playEffect(); %smoke = new t2dParticleEffect() { scenegraph = %this.scenegraph; }; %smoke.loadEffect("~/data/particles/steam.eff"); %smoke.setEffectLifeMode("KILL", 1); %smoke.setPosition(%this.getPosition()); %smoke.playEffect(); %debris = new t2dParticleEffect() { scenegraph = %this.scenegraph; }; %debris.loadEffect("~/data/particles/playerDebris.eff"); %debris.setEffectLifeMode("KILL", 1); %debris.setPosition(%this.getPosition()); %debris.playEffect();
L10 //play sound alxPlay( explosionAudio ); %this.isDead = true; %this.setEnabled(false); schedule(1000, 0, "explosionDecrease"); }
Fungsi dibawah merupakan fungsi untuk membuat objek baru yang bernama peluru yang fungsinya sebagai senjata, apabila objek ini bertabrakan dengan objek lain maka objek peluru dan objek yang ditabraknya akan hancur dan hilang dari layar. function peluru::create(%this) { %copy = new t2dStaticSprite() { scenegraph = %this.scenegraph; class = %this.class; imageMap = %this.imageMap; size = 100; position = %this.position; CollisionActiveReceive = %this.CollisionActiveReceive; CollisionActiveSend = %this.CollisionActiveSend; CollisionCallback = %this.CollisionCallback; CollisionResponseMode = %this.CollisionResponseMode; CollisionDetectionMode = %this.CollisionDetectionMode; CollisionPolyList = %this.CollisionPolyList; CollisionPhysicsReceive = %this.CollisionPhysicsReceive; CollisionPhysicsSend = %this.CollisionPhysicsSend; WorldLimitCallback = %this.WorldLimitCallback; WorldLimitMax = %this.WorldLimitMax; WorldLimitMin = %this.WorldLimitMin; WorldLimitMode = %this.WorldLimitMode; missleSpeed = %this.missleSpeed; squadNum = %this.squadNum; squadType = %this.squadType; minY = %this.minY; maxY = %this.maxY; minSpeed = %this.minSpeed; maxSpeed = %this.maxSpeed; startX = %this.startX; startY = %this.startY; waveformSet = %this.waveformSet; isDead = false;
L11 }; attachThruster( %copy, "0.8 0", 180 ); return %copy;} Code dibawah ini merupakan code yang mengatur semua objek yang ada di game ini mulai dari nama, ukuran, gambar yang dipakai untuk objek, variabel, dan atribut-atribut lainnya.
%levelContent = new t2dSceneGraph() { canSaveDynamicFields = "1"; UseLayerSorting = "1"; layerSortMode0 = "Normal"; layerSortMode1 = "Normal"; layerSortMode2 = "Normal"; layerSortMode3 = "Normal"; layerSortMode4 = "Normal"; layerSortMode5 = "Normal"; layerSortMode6 = "Normal"; layerSortMode7 = "Normal"; layerSortMode8 = "Normal"; layerSortMode9 = "Normal"; layerSortMode10 = "Normal"; layerSortMode11 = "Normal"; layerSortMode12 = "Normal"; layerSortMode13 = "Normal"; layerSortMode14 = "Normal"; layerSortMode15 = "Normal"; layerSortMode16 = "Normal"; layerSortMode17 = "Normal"; layerSortMode18 = "Normal"; layerSortMode19 = "Normal"; layerSortMode20 = "Normal"; layerSortMode21 = "Normal"; layerSortMode22 = "Normal"; layerSortMode23 = "Normal"; layerSortMode24 = "Normal"; layerSortMode25 = "Normal"; layerSortMode26 = "Normal"; layerSortMode27 = "Normal"; layerSortMode28 = "Normal"; layerSortMode29 = "Normal"; layerSortMode30 = "Normal"; layerSortMode31 = "Normal"; cameraSize = "207.673615 161.138977"; cameraPosition = "95.714355 63.695679";
L12 new t2dStaticSprite(eunit1) { imageMap = "greenMinus_16ImageMap"; frame = "0"; canSaveDynamicFields = "1"; class = "enemy1"; UseMouseEvents = "1"; position = "46.040 58.992"; size = "8.876 8.892"; SortPoint = "0.012 0.958"; MountOffset = "0.002 -0.940"; MountOwned = "0"; MountInheritAttributes = "0"; mountToID = "2"; val2 = "7"; mountID = "3"; val1 = "5"; }; new t2dStaticSprite(eunit1) { imageMap = "greenMinus_16ImageMap"; frame = "0"; canSaveDynamicFields = "1"; class = "enemy1"; UseMouseEvents = "1"; position = "46.031 63.171"; size = "8.876 8.892"; LinkPoints = "0.002 -0.940"; val2 = "7"; mountID = "2"; val1 = "5"; }; new t2dStaticSprite() { imageMap = "testImageMap"; frame = "0"; canSaveDynamicFields = "1"; position = "95.251 63.338"; size = "208.801 161.179"; LinkPoints = "-0.311 0.765 -0.915 -0.691"; mountID = "4"; }; new t2dStaticSprite(kotak) { imageMap = "playerShipImageMap"; frame = "0"; canSaveDynamicFields = "1"; class = "enemy"; UseMouseEvents = "1"; position = "8.148 116.002"; size = "11.027 9.782";
L13 FlipY = "1"; GraphGroup = "1"; CollisionPhysicsSend = "0"; CollisionPhysicsReceive = "0"; CollisionDetectionMode = "FULL"; CollisionResponseMode = "BOUNCE"; CollisionPolyList = "-1.000 -0.976 0.991 -0.976 0.987 0.986 -0.996 0.986"; MountOffset = "0.333 -0.987"; MountOwned = "0"; MountInheritAttributes = "0"; mountToID = "5"; mountID = "7"; }; new t2dStaticSprite(kotak2) { imageMap = "playerShipImageMap"; frame = "0"; canSaveDynamicFields = "1"; class = "enemy"; UseMouseEvents = "1"; position = "8.559 131.998"; size = "11.027 9.782"; FlipY = "1"; GraphGroup = "1"; CollisionPhysicsSend = "0"; CollisionPhysicsReceive = "0"; CollisionDetectionMode = "FULL"; CollisionResponseMode = "BOUNCE"; CollisionPolyList = "-1.000 -0.990 0.979 -0.986 0.991 0.966 -0.991 0.961"; MountOffset = "0.600 0.987"; MountOwned = "0"; MountInheritAttributes = "0"; mountToID = "5"; mountID = "6"; }; new t2dStaticSprite(rangka) { imageMap = "garisImageMap"; frame = "0"; canSaveDynamicFields = "1"; class = "enemy1"; UseMouseEvents = "1"; Visible = "0"; position = "7.634 124.000"; size = "3.085 16.207"; CollisionActiveSend = "1"; CollisionActiveReceive = "1"; CollisionDetectionMode = "FULL"; CollisionResponseMode = "BOUNCE";
L14 LinkPoints = "0.333 -0.987 0.600 0.987"; val2 = "6"; mountID = "5"; missileSpeed = "1000"; val1 = "5"; }; new t2dStaticSprite(rangka) { imageMap = "garisImageMap"; frame = "0"; canSaveDynamicFields = "1"; class = "enemy1"; UseMouseEvents = "1"; Visible = "0"; position = "25.791 124.086"; size = "1.615 16.207"; LinkPoints = "-1.000 -0.996 -0.957 0.975"; val2 = "6"; mountID = "8"; val1 = "5"; }; new t2dStaticSprite(kotak2) { imageMap = "playerShipImageMap"; frame = "0"; canSaveDynamicFields = "1"; class = "enemy"; UseMouseEvents = "1"; position = "25.018 131.987"; size = "11.027 9.782"; FlipY = "1"; GraphGroup = "1"; CollisionActiveSend = "1"; CollisionActiveReceive = "1"; CollisionDetectionMode = "FULL"; CollisionResponseMode = "BOUNCE"; CollisionPolyList = "-0.991 -1.000 0.991 -0.980 0.973 0.980 -0.964 0.980"; MountOffset = "-0.957 0.975"; MountOwned = "0"; MountInheritAttributes = "0"; mountToID = "8"; mountID = "10"; }; new t2dStaticSprite(kotak) { imageMap = "playerShipImageMap"; frame = "0"; canSaveDynamicFields = "1"; class = "enemy"; UseMouseEvents = "1";
L15 position = "24.983 116.015"; size = "11.027 9.782"; FlipY = "1"; GraphGroup = "1"; CollisionActiveSend = "1"; CollisionActiveReceive = "1"; CollisionDetectionMode = "FULL"; CollisionResponseMode = "BOUNCE"; CollisionPolyList = "-0.994 -0.986 0.988 -0.993 0.983 0.925 -1.000 0.962"; DstBlendFactor = "ZERO"; MountOffset = "-1.000 -0.996"; MountOwned = "0"; MountInheritAttributes = "0"; mountToID = "8"; mountID = "9"; }; new t2dParticleEffect() { effectFile = "demoskripsi/data/particles/bossJet.eff"; useEffectCollisions = "1"; effectMode = "INFINITE"; effectTime = "0"; canSaveDynamicFields = "1"; class = "meteor"; position = "208.777 102.045"; size = "33.228 34.376"; WorldLimitMode = "NULL"; WorldLimitMin = "-20.083 -21.005"; WorldLimitMax = "244.716 117.297"; WorldLimitCallback = "1"; CollisionPhysicsSend = "0"; CollisionPhysicsReceive = "0"; CollisionGroups = "0"; CollisionLayers = "0"; CollisionResponseMode = "RIGID"; Restitution = "0.2"; MaxLinearVelocity = "2500"; MinAngularVelocity = "2.69349e-038"; MaxAngularVelocity = "1e+010"; minSpeed = "-200"; maxY = "-9"; minY = "102"; mountID = "11"; maxSpeed = "-300"; }; new t2dParticleEffect() { effectFile = "demoskripsi/data/particles/bossJet.eff"; useEffectCollisions = "1";
L16 effectMode = "INFINITE"; effectTime = "0"; canSaveDynamicFields = "1"; class = "meteor"; position = "208.777 74.045"; size = "33.228 34.376"; WorldLimitMode = "NULL"; WorldLimitMin = "-20.083 -21.005"; WorldLimitMax = "244.716 117.297"; WorldLimitCallback = "1"; CollisionPhysicsSend = "0"; CollisionPhysicsReceive = "0"; CollisionGroups = "0"; CollisionLayers = "0"; CollisionResponseMode = "RIGID"; Restitution = "0.2"; MaxLinearVelocity = "2500"; MinAngularVelocity = "2.69349e-038"; MaxAngularVelocity = "1e+010"; minSpeed = "-200"; maxY = "-9"; minY = "102"; mountID = "12"; maxSpeed = "-300"; }; new t2dStaticSprite() { imageMap = "greenMinus_16ImageMap"; frame = "0"; canSaveDynamicFields = "1"; class = "jagoan"; UseMouseEvents = "1"; position = "109.209 124.585"; size = "13.857 10.067"; CollisionActiveSend = "1"; CollisionActiveReceive = "1"; CollisionDetectionMode = "FULL"; mountID = "13"; }; new t2dStaticSprite() { imageMap = "greenMinus_16ImageMap"; frame = "0"; canSaveDynamicFields = "1"; class = "jagoan"; UseMouseEvents = "1"; position = "126.714 124.833"; size = "13.857 10.067"; CollisionActiveSend = "1";
L17 CollisionActiveReceive = "1"; CollisionDetectionMode = "FULL"; CollisionResponseMode = "KILL"; mountID = "14"; }; new t2dStaticSprite() { imageMap = "greenMinus_16ImageMap"; frame = "0"; canSaveDynamicFields = "1"; class = "jagoan"; UseMouseEvents = "1"; position = "144.723 124.337"; size = "13.857 10.067"; CollisionActiveSend = "1"; CollisionActiveReceive = "1"; CollisionDetectionMode = "FULL"; CollisionResponseMode = "KILL"; mountID = "15"; }; new t2dStaticSprite() { imageMap = "garisImageMap"; frame = "0"; canSaveDynamicFields = "1"; class = "angin"; position = "215.170 105.433"; size = "0.310 21.801"; Rotation = "90"; WorldLimitMode = "NULL"; WorldLimitMin = "-23.914 -17.944"; WorldLimitMax = "215.000 112.271"; WorldLimitCallback = "1"; maxY = "-9"; minY = "102"; mountID = "16"; maxSpeed = "-300"; }; new t2dStaticSprite() { imageMap = "garisImageMap"; frame = "0"; canSaveDynamicFields = "1"; class = "angin"; position = "218.170 70.433"; size = "0.310 21.801"; Rotation = "90"; WorldLimitMode = "NULL"; WorldLimitMin = "-101.821 -17.944"; WorldLimitMax = "215.000 112.271";
L18 WorldLimitCallback = "1"; maxY = "-9"; minY = "102"; mountID = "17"; maxSpeed = "-300"; }; new t2dStaticSprite() { imageMap = "garisImageMap"; frame = "0"; canSaveDynamicFields = "1"; class = "angin"; position = "215.170 36.433"; size = "0.310 21.801"; Rotation = "90"; WorldLimitMode = "NULL"; WorldLimitMin = "-63.733 -17.944"; WorldLimitMax = "215.000 112.271"; WorldLimitCallback = "1"; maxY = "-9"; minY = "102"; mountID = "18"; maxSpeed = "-300"; }; new t2dStaticSprite() { imageMap = "garisImageMap"; frame = "0"; canSaveDynamicFields = "1"; class = "angin"; position = "215.170 11.307"; size = "0.310 21.801"; Rotation = "90"; WorldLimitMode = "NULL"; WorldLimitMin = "-172.802 -17.944"; WorldLimitMax = "215.000 112.271"; WorldLimitCallback = "1"; maxY = "-9"; minY = "102"; mountID = "19"; maxSpeed = "-300"; }; new t2dStaticSprite() { imageMap = "garisImageMap"; frame = "0"; canSaveDynamicFields = "1"; class = "angin"; position = "215.170 -10.567"; size = "0.310 21.801";
L19 Rotation = "90"; WorldLimitMode = "NULL"; WorldLimitMin = "-23.914 -17.944"; WorldLimitMax = "215.000 112.271"; WorldLimitCallback = "1"; maxY = "-9"; minY = "102"; mountID = "20"; maxSpeed = "-300"; }; new t2dParticleEffect() { effectFile = "demoskripsi/data/particles/playerDebris.eff"; useEffectCollisions = "1"; effectMode = "INFINITE"; effectTime = "0"; canSaveDynamicFields = "1"; position = "175.554 155.973"; size = "33.228 34.376"; CollisionPhysicsSend = "0"; CollisionPhysicsReceive = "0"; CollisionGroups = "0"; CollisionLayers = "0"; CollisionResponseMode = "RIGID"; Restitution = "0.2"; MaxLinearVelocity = "2500"; MaxAngularVelocity = "1e+010"; mountID = "21"; }; new t2dParticleEffect() { effectFile = "demoskripsi/data/particles/smallThruster.eff"; useEffectCollisions = "1"; effectMode = "INFINITE"; effectTime = "0"; canSaveDynamicFields = "1"; class = "roket"; UseMouseEvents = "1"; position = "174.391 122.890"; size = "10.230 11.168"; CollisionActiveSend = "1"; CollisionActiveReceive = "1"; CollisionPhysicsSend = "0"; CollisionPhysicsReceive = "0"; CollisionDetectionMode = "FULL"; CollisionResponseMode = "KILL"; Restitution = "0.2"; MaxLinearVelocity = "2500"; MinAngularVelocity = "2.69349e-038";
L20 MaxAngularVelocity = "1e+010"; val3 = "0"; val4 = "7"; val2 = "12"; mountID = "22"; val1 = "7"; }; new t2dParticleEffect() { effectFile = "demoskripsi/data/particles/rainsplash.eff"; useEffectCollisions = "1"; effectMode = "INFINITE"; effectTime = "0"; canSaveDynamicFields = "1"; class = "map"; position = "95.338 47.330"; size = "206.169 129.044"; CollisionPhysicsSend = "0"; CollisionPhysicsReceive = "0"; CollisionGroups = "0"; CollisionLayers = "0"; CollisionResponseMode = "RIGID"; Restitution = "0.2"; MaxLinearVelocity = "2500"; MaxAngularVelocity = "1e+010"; mountID = "23"; }; new t2dParticleEffect() { effectFile = "demoskripsi/data/particles/magic_trail.eff"; useEffectCollisions = "1"; effectMode = "INFINITE"; effectTime = "0"; canSaveDynamicFields = "1"; position = "14.421 123.386"; size = "19.624 15.307"; CollisionPhysicsSend = "0"; CollisionPhysicsReceive = "0"; CollisionGroups = "0"; CollisionLayers = "0"; CollisionResponseMode = "RIGID"; Restitution = "0.2"; MaxLinearVelocity = "2500"; MinAngularVelocity = "2.69349e-038"; MaxAngularVelocity = "1e+010"; mountID = "24"; }; };
L21
Code dibawah ini meruapakan code yang mengatur semua sound yang akan di mainkan saat game dijalankan maupun saat ada event seperti ledakan dan lain-lain.
new AudioDescription(AudioNonLooping) { volume = 1.0; isLooping= false; is3D = false; type = $GuiAudioType; }; new AudioDescription(AudioLooping) { volume = 1.0; isLooping= true; is3D = false; type = $GuiAudioType; };
// -------------------------------------------------------------------// Ambient#1 Audio. // -------------------------------------------------------------------new AudioProfile(ambient1Audio) { filename = "~/data/audio/Ambient06.wav"; description = "AudioLooping"; preload = true; }; // -------------------------------------------------------------------// Player Fire Audio. // -------------------------------------------------------------------new AudioProfile(playerFireAudio) { filename = "~/data/audio/Fire17.wav"; description = "AudioNonLooping"; preload = true; }; // -------------------------------------------------------------------// Enemy Missile Fire Audio. // -------------------------------------------------------------------new AudioProfile(enemyTorpedoFireAudio)
L22 { filename = "~/data/audio/Fire22.wav"; description = "AudioNonLooping"; preload = true; }; // -------------------------------------------------------------------// Enemy Missile Fire Audio. // -------------------------------------------------------------------new AudioProfile(enemyMissileFireAudio) { filename = "~/data/audio/Fire20.wav"; description = "AudioNonLooping"; preload = true; }; // -------------------------------------------------------------------// Explosion Audio. // -------------------------------------------------------------------new AudioProfile(explosionAudio) { filename = "~/data/audio/Explosion09.wav"; description = "AudioNonLooping"; preload = true; }; // -------------------------------------------------------------------// Upgrade Appear. // -------------------------------------------------------------------new AudioProfile(upgradeAppearAudio) { filename = "~/data/audio/Pickup10.wav"; description = "AudioLooping"; preload = true; }; // -------------------------------------------------------------------// Upgrade#1 Pickup (Weapon). // -------------------------------------------------------------------new AudioProfile(upgrade1PickupAudio) { filename = "~/data/audio/Alarm09.wav"; description = "AudioNonLooping"; preload = true; };
L23
// -------------------------------------------------------------------// Upgrade#2 Pickup (Helper). // -------------------------------------------------------------------new AudioProfile(upgrade2PickupAudio) { filename = "~/data/audio/Pickup09.wav"; description = "AudioNonLooping"; preload = true; }; // -------------------------------------------------------------------// Upgrade#3 Pickup (Shield). // -------------------------------------------------------------------new AudioProfile(upgrade3PickupAudio) { filename = "~/data/audio/Pickup07.wav"; description = "AudioNonLooping"; preload = true; }; // -------------------------------------------------------------------// Upgrade#3 Loose (Shield). // -------------------------------------------------------------------new AudioProfile(upgrade3LooseAudio) { filename = "~/data/audio/Pickup01.wav"; description = "AudioNonLooping"; preload = true; }; // -------------------------------------------------------------------// Ready Sound #1 // -------------------------------------------------------------------new AudioProfile(ready1Audio) { filename = "~/data/audio/Ready01.wav"; description = "AudioNonLooping"; preload = true; };
L24
// -------------------------------------------------------------------// Ready Sound #2 // -------------------------------------------------------------------new AudioProfile(ready2Audio) { filename = "~/data/audio/Ready02.wav"; description = "AudioNonLooping"; preload = true; }; // -------------------------------------------------------------------// Ready Sound #3 // -------------------------------------------------------------------new AudioProfile(ready3Audio) { filename = "~/data/audio/Ready03.wav"; description = "AudioNonLooping"; preload = true; };
Dibawah ini merupakan code main dari game ini, code ini berfungsi untuk menjalankan seluruh code yang sudah dibuat diatas. function startGame(%level) { exec("./meteor.cs"); exec("./jagoan.cs"); exec("./angin.cs"); exec("./enemy.cs"); exec("./peluru.cs"); exec("./map.cs"); // Set The GUI. Canvas.setContent(mainScreenGui); Canvas.setCursor(DefaultCursor); moveMap.push(); sceneWindow2D.setUseObjectMouseEvents( true ); if( isFile( %level ) || isFile( %level @ ".dso")) sceneWindow2D.loadLevel(%level); }
L25
//--------------------------------------------------------------------------------------------// endGame // Game cleanup should be done here. //--------------------------------------------------------------------------------------------function endGame() { sceneWindow2D.endLevel(); moveMap.pop(); }
L26
Sintaks-Sintaks Penting TorqueScript
Variabel-Variable Sama sesperti pada bahasa pemrograman modern lainnya, variable dari TorqueScript dibagi menjadi 2 yaitu local dan global. Lokal variable akan dihancurkan apabila variable tersebut sudah tidak dipakai, contohnya apabila variable local tersebut berada dalam sebuah function maka setelah function itu selesai dijalankan variable lokalnya akan segera dihancurkan. Variabel global aka nada terus menerus secara permanen. Untuk menandakan sebuah variable local atau global digunakan karakter khusus.
%local_var = value; $global_var = value2; Data Types TorqueScript menyediakan beberapa data-types variable seperti: angka, string, Booleans, dan array.
Numbers (Angka): 123 (Integer) 1.234 (floating point) 1234e-3 (scientific notation) 0xc001 (hexadecimal) Tidak ada yang asing disini, TorqueScript menangani type data numeric standar. Strings: "abcd" (string) 'abcd' (tagged string)
L27
Booleans: Sama seperti pada bahasa pemrograman modern lainnya , TorqueScript juga mendukung Booleans. Boolean hanya mempunya dua nilai yaitu true dan false. true (1) false (0) Arrays: $MyArray[n] (Single-dimension) $MyMultiArray[m,n] (Multi-dimension) $MyMultiArray[m_n] (Multi-dimension) TorqueScrips sangatlah fleksibel dalam penggunaan array. Cara pembuatan dan pengguaannya pun hampir sama seperti pada bahasa C++ namun lebih canggih.
Control Statements TorqueScript mendukung semua control statement yang umum.
• if-else if (%val < 0) { %abs = -%val; } else { %abs = %val; }
L28
• switch switch(%val) { case 1: echo(“The value is 1”); case 2: echo(“The value is 2”); default: echo(“The value is something else”); } • switch$ switch$(%val) { case “Hello”: echo(“The string is Hello”); case “World”: echo(“The string is World”); default: echo(“The string is something else”); } Statement switch yang pertama bekerja pada angka dan yang kedua bekerja pada string walaupun fungsi mereka tidak berbeda.
• for for(%i = 0; %i < 10; %i++) { echo(%i @ “/” @ 10); } • while %i = 0; while (%i < 10)
L29
{ echo(%i @ “/” @ 10); %i++; }
Statement diatas akan dijalankan secara looping terus menerus sampai sebuah kondisi terpenuhi.
Functions Function basic pada TorqueScript didefinisikan sebagai berikut:
function myFunction(%arg1, %arg2) { %result = %arg1 + %arg2; return %result; } Contoh diatas adalah function penambahan sederhana. Function tersebut menerima dua angka sebagai parameter, jumlahkan keduanya, dan kembalikan hasilnya.
Objects Dalam Torque, setiap benda dalam sebuah game merupakan sebuah objek, dan semua objek dalam game dapat di akses melalui sript. Berikut adalah contoh script untuk membuat sebuah objek baru dengan posisi “10 10”, berukuran “5 15”, rotasi 45, dan atribut lainnya 10.
%object = new t2dSceneObject(MyObject) { Position = “10 10”; Size = “5 15”; Rotation = 45;
L30
OtherField = 10; }; script dibawah ini akan membuat objek yang baru saja dibuat ke posisi (10, 20) %object.setPosition(10, 20);
Methods Untuk mendukung penggunaan function, TorqueScript juga mengizinkan kita untuk mendefinisikan method dalam sebuah class objek.
function t2dSceneObject::move(%this, %amount) { %position = %this.getPosition(); %newPosition = t2dVectorAdd(%position, %amount); %this.setPosition(%newPosition); return %newPosition; } Method pada dasarnya sama seperti function namun method hanya bekerja pada objek maupun class dimana mereka didefinisikan.