Browse Source

Initial commit of new space game example (with new UI, main loop, etc)

Josh Engebretson 10 years ago
parent
commit
94940e88b5
41 changed files with 1103 additions and 0 deletions
  1. 9 0
      NewSpaceGame/NewSpaceGame.atomic
  2. 55 0
      NewSpaceGame/Resources/Components/AI.js
  3. 121 0
      NewSpaceGame/Resources/Components/Bullet.js
  4. 76 0
      NewSpaceGame/Resources/Components/CapitalShip.js
  5. 57 0
      NewSpaceGame/Resources/Components/Enemy.js
  6. 66 0
      NewSpaceGame/Resources/Components/Explosion.js
  7. 44 0
      NewSpaceGame/Resources/Components/HUD.js
  8. 99 0
      NewSpaceGame/Resources/Components/Player.js
  9. 29 0
      NewSpaceGame/Resources/Components/SpaceBackground.js
  10. 191 0
      NewSpaceGame/Resources/Components/SpaceGame.js
  11. 19 0
      NewSpaceGame/Resources/Components/TouchInput.js
  12. 6 0
      NewSpaceGame/Resources/Data/RenderPath.xml
  13. BIN
      NewSpaceGame/Resources/Music/battle.ogg
  14. 40 0
      NewSpaceGame/Resources/Scripts/main.js
  15. 20 0
      NewSpaceGame/Resources/Scripts/precache.js
  16. 14 0
      NewSpaceGame/Resources/Scripts/utils.js
  17. 14 0
      NewSpaceGame/Resources/Skin/skin.ui.txt
  18. BIN
      NewSpaceGame/Resources/Skin/spaceship.png
  19. BIN
      NewSpaceGame/Resources/Skin/window.png
  20. BIN
      NewSpaceGame/Resources/Sounds/boom0.wav
  21. BIN
      NewSpaceGame/Resources/Sounds/boom1.wav
  22. BIN
      NewSpaceGame/Resources/Sounds/laser01.wav
  23. BIN
      NewSpaceGame/Resources/Sounds/laser02.wav
  24. BIN
      NewSpaceGame/Resources/Sprites/blue_beam.png
  25. BIN
      NewSpaceGame/Resources/Sprites/blue_star.png
  26. BIN
      NewSpaceGame/Resources/Sprites/explosions_sheet.png
  27. 134 0
      NewSpaceGame/Resources/Sprites/explosions_sheet.xml
  28. BIN
      NewSpaceGame/Resources/Sprites/green_beam.png
  29. BIN
      NewSpaceGame/Resources/Sprites/space_background.png
  30. BIN
      NewSpaceGame/Resources/Sprites/spacegame_sheet.png
  31. 11 0
      NewSpaceGame/Resources/Sprites/spacegame_sheet.xml
  32. BIN
      NewSpaceGame/Resources/Sprites/spaceship_cricket.png
  33. BIN
      NewSpaceGame/Resources/Sprites/spaceship_flea.png
  34. BIN
      NewSpaceGame/Resources/Sprites/spaceship_locust.png
  35. BIN
      NewSpaceGame/Resources/Sprites/spaceship_louse.png
  36. BIN
      NewSpaceGame/Resources/Sprites/spaceship_mantis.png
  37. BIN
      NewSpaceGame/Resources/Sprites/spaceship_scarab.png
  38. 25 0
      NewSpaceGame/Resources/UI/Hud.ui.txt
  39. 45 0
      NewSpaceGame/Resources/UI/mainMenu.js
  40. 14 0
      NewSpaceGame/Resources/UI/mainMenu.ui.txt
  41. 14 0
      NewSpaceGame/Resources/UI/ui.js

+ 9 - 0
NewSpaceGame/NewSpaceGame.atomic

@@ -0,0 +1,9 @@
+{
+   "version": 1,
+   "project": {
+      "version": "1.0.0"
+   },
+   "platforms": [
+      "mac", "windows"
+   ]
+}

+ 55 - 0
NewSpaceGame/Resources/Components/AI.js

@@ -0,0 +1,55 @@
+var game = Atomic.game;
+var node = self.node;
+
+self.canMove = false;
+self.allowShoot = true;
+self.shootDelta = 0;
+
+function start() {
+
+
+}
+
+function update(timeStep) {
+
+    if (SpaceGame.gameOver)
+        return;
+
+    var pos = node.worldPosition2D;
+    var ppos = SpaceGame.playerNode.worldPosition2D;
+
+    if (self.canMove) {
+
+        if (Math.abs(pos[0] - ppos[0]) > .25) {
+            if (pos[0] < ppos[0])
+                pos[0] += timeStep * .95;
+            else
+                pos[0] -= timeStep * .95;
+
+            node.position2D = pos;
+        }
+    }
+
+    if (self.shootDelta > 0) {
+    
+        self.shootDelta -= timeStep;
+        
+        if (self.shootDelta < 0)
+            self.shootDelta = 0;
+
+        return;
+    }
+
+    if (Math.abs(pos[0] - ppos[0]) < .25) {
+    
+        self.shootDelta = 0.5;            
+
+        if (Math.random() > .1)
+            return;
+
+        var pos = node.worldPosition2D;
+        pos[1] -= .25;
+        SpaceGame.spawnBullet(pos, false);
+    }
+
+}

+ 121 - 0
NewSpaceGame/Resources/Components/Bullet.js

@@ -0,0 +1,121 @@
+var game = Atomic.game;
+var node = self.node;
+
+self.isPlayer = false;
+
+self.init = function(isPlayer, spawnPosition) {
+
+    self.isPlayer = isPlayer;
+
+    var laserSound = game.getSound(self.isPlayer ? "Sounds/laser01.wav" : "Sounds/laser02.wav");
+    var sprite2D = node.createComponent("StaticSprite2D");
+
+    if (self.isPlayer)
+        sprite2D.sprite = game.getSprite2D("Sprites/blue_beam.png");
+    else
+        sprite2D.sprite = game.getSprite2D("Sprites/green_beam.png");
+
+    sprite2D.blendMode = Atomic.BLEND_ADDALPHA;
+
+    self.soundSource = node.createComponent("SoundSource");
+    self.soundSource.soundType = Atomic.SOUND_EFFECT;
+    self.soundSource.gain = 0.75;
+    self.soundSource.play(laserSound);
+
+    node.position2D = spawnPosition;
+
+    if (!self.isPlayer) {
+        node.roll(180);
+    }
+
+}
+
+function start() {
+
+
+}
+
+function updateEnemyBullet() {
+
+    var bpos = node.position2D;
+
+    // off the bottom of the screen
+    if (bpos[1] < -SpaceGame.halfHeight) {
+        return true;
+    }
+
+    if (SpaceGame.player) {
+
+        var epos = SpaceGame.player.node.worldPosition2D;
+
+        if (Math.abs(epos[0] - bpos[0]) < 0.25 &&
+            Math.abs(epos[1] - bpos[1]) < 0.25) {
+
+            SpaceGame.player.onHit();
+
+            return true;
+        }
+
+    }
+
+}
+
+function updatePlayerBullet() {
+
+    var bpos = node.position2D;
+
+    // off the top of the screen
+    if (bpos[1] > SpaceGame.halfHeight) {
+        return true;
+    }
+
+    for (var i = 0; i < SpaceGame.enemies.length; i++) {
+
+        var enemy = SpaceGame.enemies[i];
+
+        var epos = enemy.node.worldPosition2D;
+
+        if (Math.abs(epos[0] - bpos[0]) < 0.25 &&
+            Math.abs(epos[1] - bpos[1]) < 0.25) {
+
+            enemy.onHit();
+
+            return true;
+        }
+
+    }
+
+    if (SpaceGame.capitalShip) {
+
+        var epos = SpaceGame.capitalShip.node.worldPosition2D;
+
+        if (Math.abs(epos[0] - bpos[0]) < 0.75 &&
+            Math.abs(epos[1] - bpos[1]) < 0.75) {
+
+            SpaceGame.capitalShip.onHit(bpos);
+
+            return true;
+        }
+
+    }
+
+}
+
+function update(timeStep) {
+
+    var speed = self.isPlayer ? 8 : 5;
+    speed *= timeStep;
+    node.translate2D([0, speed]);
+
+    if (self.isPlayer) {
+        if (updatePlayerBullet()) {
+            Atomic.destroy(node);
+        }
+    } else {
+        if (updateEnemyBullet()) {
+            Atomic.destroy(node);
+        }
+    }
+
+
+}

+ 76 - 0
NewSpaceGame/Resources/Components/CapitalShip.js

@@ -0,0 +1,76 @@
+var game = Atomic.game;
+var node = self.node;
+var scene = game.scene;
+
+self.allowShoot = true;
+self.shootDelta = 0;
+
+self.health = 10;
+
+self.onHit = function(pos) {
+
+
+    var expNode = game.scene.createChild("Explosion");
+    var exp = expNode.createJSComponent("Explosion");
+    exp.init(pos);
+
+    var expNode = game.scene.createChild("Explosion");
+    exp = expNode.createComponent("JSComponent");
+    exp.spawnPosition = pos;
+    exp.node.scale2D = [2.0, 2.0];
+
+    self.health--;
+    if (!self.health) {
+        die();
+        SpaceGame.win();
+    }
+
+}
+
+function die() {
+
+    SpaceGame.capitalShipDestroyed();
+
+    for (var i = 0; i < 16; i++) {
+        var pos = node.position2D;
+        pos[0] += SpaceGame.random(-2, 2);
+        pos[1] += SpaceGame.random(-2, 2);
+
+        var expNode = scene.createChild("Explosion");
+        var exp = expNode.createJSComponent("Explosion");
+        exp.init(pos);
+
+        var randomSize = SpaceGame.random(4, 8);
+        exp.node.scale2D = [randomSize, randomSize];
+    }
+
+
+}
+
+
+// using start to initialize the script component
+function start() {
+
+    // install AI
+    var ai = node.createJSComponent("AI");
+    ai.canMove = true;
+
+
+
+    var spaceSheet = game.getSpriteSheet("Sprites/spacegame_sheet.xml");
+
+    // add a sprite component to our node
+    var sprite2D = node.createComponent("StaticSprite2D");
+    sprite2D.blendMode = Atomic.BLEND_ALPHA;
+    sprite2D.sprite = spaceSheet.getSprite("spaceship_locust");
+
+    node.position2D = [-4, SpaceGame.halfHeight - 1];
+    node.roll(180);
+
+}
+
+// update function called per frame with delta time
+function update(timeStep) {
+
+
+}

+ 57 - 0
NewSpaceGame/Resources/Components/Enemy.js

@@ -0,0 +1,57 @@
+var game = Atomic.game;
+var node = self.node;
+
+self.allowShoot = true;
+self.shootDelta = 0;
+
+var moveDelta = 0;
+
+var dead = false;
+
+self.onHit = function() {
+    
+    var expNode = game.scene.createChild("Explosion");
+    var exp = expNode.createJSComponent("Explosion");
+    exp.init(node.worldPosition2D);    
+    SpaceGame.removeEnemy(self);
+    
+}
+
+function start() {
+
+    // install AI
+    node.createJSComponent("AI");
+
+    var spaceSheet = game.getSpriteSheet("Sprites/spacegame_sheet.xml");
+
+    // add a sprite component to our node
+    var sprite2D = node.createComponent("StaticSprite2D");
+    sprite2D.blendMode = Atomic.BLEND_ALPHA;
+    sprite2D.sprite = spaceSheet.getSprite(self.spriteName);
+
+    node.position2D = self.spawnPosition;
+    node.roll(180);
+    node.scale2D = [0.65, 0.65];
+
+    self.dir = (Math.random() > .5);
+
+
+}
+
+// update function called per frame with delta time
+function update(timeStep) {
+
+    var pos = node.position2D;
+    var ppos = SpaceGame.playerNode.position2D;
+
+    if (Math.random() > .98) {
+        self.dir = !self.dir;
+    }
+
+    moveDelta += (self.dir ? timeStep * 4 : -timeStep * 4);
+
+    pos = [self.spawnPosition[0], self.spawnPosition[1]];
+    pos[1] += Math.sin(moveDelta) * .1;
+    node.position2D = pos;
+
+}

+ 66 - 0
NewSpaceGame/Resources/Components/Explosion.js

@@ -0,0 +1,66 @@
+
+var game = Atomic.game;
+var node = self.node;
+var cache = game.cache;
+
+var expSheet = cache.getResource("SpriteSheet2D", "Sprites/explosions_sheet.xml");
+var boomSound = cache.getResource("Sound", "Sounds/boom" + Math.round(Math.random(0, 1)) + ".wav");
+
+
+var sprites = [];
+var frame = 0;
+var frameTime = 0;
+
+self.init = function(spawnPosition) {
+
+    self.spawnPosition = spawnPosition;
+
+}
+
+// using start to initialize the script component
+function start() {
+
+    var i = Math.round(Math.random() * 7);
+
+    for (var j = 0; j < 16; j++)
+    {
+        sprites.push(expSheet.getSprite(i + "_" + j));
+    }
+
+    // add a sprite component to our node
+    var sprite2D = self.sprite2D = node.createComponent("StaticSprite2D");
+    sprite2D.blendMode = Atomic.BLEND_ADDALPHA
+    sprite2D.sprite = sprites[0];
+    node.position2D =  self.spawnPosition;
+    node.scale2D = [1.5, 1.5];
+    sprite2D.orderInLayer = 200;
+
+    self.soundSource = node.createComponent("SoundSource");
+    self.soundSource.soundType = Atomic.SOUND_EFFECT;
+    self.soundSource.gain;
+
+    self.soundSource.play(boomSound);
+
+
+}
+
+// update function called per frame with delta time
+function update(timeStep) {
+
+    frameTime += timeStep;
+    if (frameTime > .05)
+    {
+        frameTime = 0;
+        frame++;
+        if (frame == 16)
+        {
+            Atomic.destroy(node);
+            return;
+        }
+
+        self.sprite2D.sprite = sprites[frame];
+    }
+
+}
+
+

+ 44 - 0
NewSpaceGame/Resources/Components/HUD.js

@@ -0,0 +1,44 @@
+
+var game = Atomic.game;
+var view = game.uiView;
+var UI = Atomic.UI;
+var UIButton = Atomic.UIButton;
+var UITextField = Atomic.UITextField;
+var UILayout = Atomic.UILayout;
+
+var layout = new Atomic.UIWidget();
+layout.load("UI/Hud.ui.txt");
+layout.setSize(1280, 720);
+view.addChild(layout);
+
+game.viewport.rect = layout.getWidget("viewport").rect;
+
+var scoretext = layout.getWidget("scoretext");
+
+//UI.debugShowSettingsWindow(view);
+
+self.updateScore = function (value) {
+
+	scoretext.text = "Score: " + value;
+
+}
+
+self.updateHealth = function (value) {
+
+    //healthText.text = "Health: " + value;
+
+}
+
+self.updateGameText = function (text) {
+
+    //gameText.text = text;
+
+}
+
+function start() {
+
+}
+
+function update(timeStep) {
+
+}

+ 99 - 0
NewSpaceGame/Resources/Components/Player.js

@@ -0,0 +1,99 @@
+var game = Atomic.game;
+var input = game.input;
+
+var node = self.node;
+
+self.allowMove = true;
+self.allowShoot = true;
+self.shootDelta = 0;
+
+self.health = 10;
+
+self.onHit = function() {
+
+    var expNode = game.scene.createChild("Explosion");
+    var exp = expNode.createJSComponent("Explosion");
+    exp.init(node.worldPosition2D);
+
+    self.health--;
+
+    SpaceGame.hud.updateHealth(self.health);
+
+    if (self.health == 0) {
+
+        SpaceGame.lose();
+
+    }
+
+
+}
+
+function doShooting(timeStep) {
+    if (self.shootDelta > 0) {
+
+        self.shootDelta -= timeStep;
+        if (self.shootDelta < 0)
+            self.shootDelta = 0;
+
+        return;
+    }
+
+    if (!input.getKeyDown(Atomic.KEY_W) && !input.getKeyDown(Atomic.KEY_UP) && !input.getKeyDown(Atomic.KEY_SPACE))
+        return;
+
+    self.shootDelta = 0.15;
+
+    var pos = node.position2D;
+    pos[1] += .5;
+
+    SpaceGame.spawnBullet(pos, true);
+
+}
+
+function moveShip(timeStep) {
+    var speed = 3.0 * timeStep;
+
+    var pos = node.position2D;
+
+    var left = false;
+    var right = false;
+
+
+    if (input.getKeyDown(Atomic.KEY_A) || input.getKeyDown(Atomic.KEY_LEFT))
+        pos[0] -= speed;
+
+    if (input.getKeyDown(Atomic.KEY_D) || input.getKeyDown(Atomic.KEY_RIGHT))
+        pos[0] += speed;
+
+    if (pos[0] < -SpaceGame.halfWidth + 2)
+        pos[0] = -SpaceGame.halfWidth + 2;
+
+    if (pos[0] > SpaceGame.halfWidth - 2)
+        pos[0] = SpaceGame.halfWidth - 2;
+
+
+    node.position2D = pos;
+
+}
+
+function start() {
+
+    var spaceSheet = game.getSpriteSheet("Sprites/spacegame_sheet.xml");
+
+    var sprite2D = node.createComponent("StaticSprite2D");
+    sprite2D.sprite = spaceSheet.getSprite("spaceship_mantis");
+    sprite2D.blendMode = Atomic.BLEND_ALPHA;
+
+    node.position2D = [0, -SpaceGame.halfHeight + 1];
+
+}
+
+function update(timeStep) {
+
+    if (self.allowShoot)
+        doShooting(timeStep);
+
+    if (self.allowMove)
+        moveShip(timeStep);
+
+}

+ 29 - 0
NewSpaceGame/Resources/Components/SpaceBackground.js

@@ -0,0 +1,29 @@
+
+var game = Atomic.game;
+var node = self.node;
+
+node.scale2D = [1.5, 1.5];
+node.position2D = [0, 12];
+
+function start() {
+
+  var spaceSprite = game.cache.getResource("Sprite2D", "Sprites/space_background.png");
+
+  // add a sprite component to our node
+  var sprite2D = node.createComponent("StaticSprite2D");
+
+  sprite2D.orderInLayer = -200;
+  sprite2D.blendMode = Atomic.BLEND_ADDALPHA;
+  sprite2D.sprite = spaceSprite;
+
+}
+
+function update(timeStep) {
+
+  if (node.position[1] < -19)
+    node.position2D = [0, 18];
+
+  var speed = .75;
+  node.translate([0, -timeStep * speed, 0]);
+
+}

+ 191 - 0
NewSpaceGame/Resources/Components/SpaceGame.js

@@ -0,0 +1,191 @@
+var UI = require("UI/ui");
+
+var game = Atomic.game;
+
+// expose ourselves as a global
+SpaceGame = self;
+
+createScene();
+
+self.halfWidth = game.graphics.width * Atomic.PIXEL_SIZE * 0.5;
+self.halfHeight = game.graphics.height * Atomic.PIXEL_SIZE * 0.5;
+
+var enemyBaseDir = false;
+var enemyBaseNode = self.myscene.createChild("EnemyBaseNode");
+var enemyBasePosX = 0;
+
+var score = 0;
+
+self.enemies = [];
+self.gameOver = false;
+
+self.random = function random(min, max) {
+    return Math.random() * (max - min) + min;
+}
+
+self.spawnBullet = function(pos, isPlayer) {
+
+    var bulletNode = self.myscene.createChild("Bullet");
+    var bullet = bulletNode.createJSComponent("Bullet");
+    bullet.init(isPlayer, pos);
+}
+
+self.removeEnemy = function(enemy) {
+
+    score += 10;
+
+    self.hud.updateScore(score);
+
+    self.enemies.splice(self.enemies.indexOf(enemy), 1);
+    Atomic.destroy(enemy.node);
+    return;
+
+}
+
+self.capitalShipDestroyed = function() {
+
+    score += 1000;
+
+    self.hud.updateScore(score);
+
+    Atomic.destroy(self.capitalShipNode);
+    self.capitalShipNode = self.capitalShip = null;
+
+}
+
+
+function spawnEnemies() {
+
+    self.capitalShipNode = self.myscene.createChild("CapitalShip");
+    self.capitalShip = self.capitalShipNode.createJSComponent("CapitalShip");
+
+    var pos = [0, 0];
+
+    pos[1] = self.halfHeight - 2.5;
+
+    for (var y = 0; y < 3; y++) {
+
+        pos[0] = -4.5;
+
+        for (var x = 0; x < 12; x++) {
+
+            var enemyNode = enemyBaseNode.createChild("Enemy");
+            enemy = enemyNode.createJSComponent("Enemy");
+            enemy.spriteName = Math.random() < .85 ? "spaceship_louse" : "spaceship_scarab";
+            enemy.spawnPosition = [pos[0], pos[1]];
+            self.enemies.push(enemy);
+
+            pos[0] += 0.75;
+
+        }
+
+        pos[1] -= 0.75;
+
+    }
+
+}
+
+function updateEnemies(timeStep) {
+
+    if (!enemyBaseDir)
+        enemyBasePosX += timeStep;
+    else
+        enemyBasePosX -= timeStep;
+
+    var xvalue = 2;
+
+    if (enemyBasePosX > xvalue) {
+        enemyBasePosX = xvalue;
+        enemyBaseDir = !enemyBaseDir;
+    }
+
+    if (enemyBasePosX < -xvalue) {
+        enemyBasePosX = -xvalue;
+        enemyBaseDir = !enemyBaseDir;
+    }
+
+    enemyBaseNode.position2D = [enemyBasePosX, 0];
+
+}
+
+self.cleanup = function() {
+
+  game.renderer.setViewport(1, null);
+
+}
+
+self.win = function() {
+
+    self.hud.updateGameText("YOU WIN!!!!");
+    self.gameOver = true;
+    UI.showMainMenu();
+    self.cleanup();
+
+}
+
+self.lose = function() {
+
+    self.hud.updateGameText("YOU LOSE!!!!");
+    self.gameOver = true;
+    UI.showMainMenu();
+    self.cleanup();
+
+}
+
+function spawnPlayer() {
+
+    self.playerNode = self.myscene.createChild("Player");
+    self.player = self.playerNode.createJSComponent("Player");
+}
+
+function createScene() {
+
+  var scene = new Atomic.Scene();
+  scene.createComponent("Octree");
+
+  var cameraNode = scene.createChild("Camera");
+  cameraNode.position = [0.0, 0.0, -10.0];
+
+  var camera = cameraNode.createComponent("Camera");
+  camera.orthographic = true;
+  camera.orthoSize = game.graphics.height * Atomic.PIXEL_SIZE;
+
+  var viewport = new Atomic.Viewport(scene, camera);
+
+  // assign a render path to our viewport which doesn't clear the screen
+  // so can be used to composite
+  var renderPathXML = game.cache.getResource("XMLFile", "Data/RenderPath.xml");
+  viewport.renderPath = renderPathXML;
+
+  // Example of appending a post process filter
+  //viewport.renderPath.append(game.cache.getResource("XMLFile", "PostProcess/GreyScale.xml"));
+
+  game.renderer.setViewport(1, viewport);
+
+  // this is component getScene property (there is no setter on it)
+  // this should be an error, think I saw somewhere you can raise errors on
+  // get/set of a prop when the get/set missing
+  self.myscene = scene;
+  self.cameraNode = cameraNode;
+  self.camera = camera;
+  self.viewport = viewport;
+
+}
+
+
+function start() {
+
+    self.hud = self.myscene.createJSComponent("HUD");
+
+    spawnPlayer();
+    spawnEnemies();
+
+}
+
+
+function update(timeStep) {
+
+    updateEnemies(timeStep);
+
+
+}

+ 19 - 0
NewSpaceGame/Resources/Components/TouchInput.js

@@ -0,0 +1,19 @@
+
+// Atomic Component
+
+var game = Atomic.game;
+var node = self.node;
+var input = game.input;
+
+function start() {
+
+	// input.setTouchEmulation(true);
+    var layout = game.cache.getResource("XMLFile", "Data/ScreenJoystick.xml");
+    var uiStyle = game.cache.getResource("XMLFile", "UI/DefaultStyle.xml");    
+    input.addScreenJoystick(layout, uiStyle);
+
+}
+
+function update(timeStep) {
+
+}

+ 6 - 0
NewSpaceGame/Resources/Data/RenderPath.xml

@@ -0,0 +1,6 @@
+<renderpath>
+    <command type="scenepass" pass="base" vertexlights="true" metadata="base" />
+    <command type="scenepass" pass="postopaque" />
+    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" />
+    <command type="scenepass" pass="postalpha" sort="backtofront" />
+</renderpath>

BIN
NewSpaceGame/Resources/Music/battle.ogg


+ 40 - 0
NewSpaceGame/Resources/Scripts/main.js

@@ -0,0 +1,40 @@
+
+// This script is the main entry point of the game
+
+require("AtomicGame");
+
+// relative require not working for main.js due to how it is being loaded (however, does work elsewhere)
+var precache = require("Scripts/precache");
+var utils = require("Scripts/utils");
+var UI = require("UI/ui");
+
+Atomic.game.init(start, update);
+
+// called at the start of play
+function start() {
+
+	precache.precache(true);
+
+	var game = Atomic.game;
+
+	UI.showMainMenu();
+
+	// create a main 2D scene, which will persist
+	// the space game itself uses a separate scene we can
+	// bring up and tear down
+	game.createScene2D();
+
+	var spaceNode = game.scene.createChild("SpaceBackground");
+	spaceNode.createJSComponent("SpaceBackground");
+
+	// play some music!
+	utils.playMusic("Music/battle.ogg");
+
+}
+
+// called per frame
+function update(timeStep) {
+
+  UI.update(timeStep);
+
+}

+ 20 - 0
NewSpaceGame/Resources/Scripts/precache.js

@@ -0,0 +1,20 @@
+
+
+var resources =  {
+  "Sprites/space_background.png" : "Texture2D",
+  "Music/battle.ogg" : "Sound"
+}
+
+
+// precache resources so they are ready to go
+exports.precache = function(verbose) {
+
+  var game = Atomic.game;
+
+  Object.keys(resources).forEach(function(key) {
+    game.cache.getResource(resources[key], key);
+    if (verbose)
+      print("Precaching: ", resources[key], " ", key);
+  });
+
+}

+ 14 - 0
NewSpaceGame/Resources/Scripts/utils.js

@@ -0,0 +1,14 @@
+
+exports.playMusic = function(soundFile) {
+
+  var game = Atomic.game;
+  var musicFile = game.cache.getResource("Sound", soundFile);
+	musicFile.looped = true;
+	var musicNode = game.scene.createChild("MusicNode");
+	var musicSource = musicNode.createComponent("SoundSource");
+	musicSource.gain = .5;
+	musicSource.soundType = Atomic.SOUND_MUSIC;
+	musicSource.play(musicFile);
+
+
+}

+ 14 - 0
NewSpaceGame/Resources/Skin/skin.ui.txt

@@ -0,0 +1,14 @@
+elements
+	Spaceship
+		bitmap spaceship.png
+		pref-width 32
+		pref-height 32
+	SpaceGameContainer
+		type StretchBox
+		bitmap window.png
+		cut 16
+		expand 12
+		padding 8
+	SpaceText
+		text-color #00FF00
+

BIN
NewSpaceGame/Resources/Skin/spaceship.png


BIN
NewSpaceGame/Resources/Skin/window.png


BIN
NewSpaceGame/Resources/Sounds/boom0.wav


BIN
NewSpaceGame/Resources/Sounds/boom1.wav


BIN
NewSpaceGame/Resources/Sounds/laser01.wav


BIN
NewSpaceGame/Resources/Sounds/laser02.wav


BIN
NewSpaceGame/Resources/Sprites/blue_beam.png


BIN
NewSpaceGame/Resources/Sprites/blue_star.png


BIN
NewSpaceGame/Resources/Sprites/explosions_sheet.png


+ 134 - 0
NewSpaceGame/Resources/Sprites/explosions_sheet.xml

@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Created with TexturePacker http://www.codeandweb.com/texturepacker-->
+<!-- $TexturePacker:SmartUpdate:1a17c841c2e0285d52a986d357f78c54:1/1$ -->
+<TextureAtlas imagePath="explosions_sheet.png">
+    <SubTexture name="0_0" x="0" y="0" width="64" height="64"/>
+    <SubTexture name="0_1" x="64" y="0" width="64" height="64"/>
+    <SubTexture name="0_2" x="128" y="0" width="64" height="64"/>
+    <SubTexture name="0_3" x="192" y="0" width="64" height="64"/>
+    <SubTexture name="0_4" x="256" y="0" width="64" height="64"/>
+    <SubTexture name="0_5" x="320" y="0" width="64" height="64"/>
+    <SubTexture name="0_6" x="384" y="0" width="64" height="64"/>
+    <SubTexture name="0_7" x="448" y="0" width="64" height="64"/>
+    <SubTexture name="0_8" x="512" y="0" width="64" height="64"/>
+    <SubTexture name="0_9" x="576" y="0" width="64" height="64"/>
+    <SubTexture name="0_10" x="640" y="0" width="64" height="64"/>
+    <SubTexture name="0_11" x="704" y="0" width="64" height="64"/>
+    <SubTexture name="0_12" x="768" y="0" width="64" height="64"/>
+    <SubTexture name="0_13" x="832" y="0" width="64" height="64"/>
+    <SubTexture name="0_14" x="896" y="0" width="64" height="64"/>
+    <SubTexture name="0_15" x="960" y="0" width="64" height="64"/>
+    <SubTexture name="1_0" x="0" y="64" width="64" height="64"/>
+    <SubTexture name="1_1" x="64" y="64" width="64" height="64"/>
+    <SubTexture name="1_2" x="128" y="64" width="64" height="64"/>
+    <SubTexture name="1_3" x="192" y="64" width="64" height="64"/>
+    <SubTexture name="1_4" x="256" y="64" width="64" height="64"/>
+    <SubTexture name="1_5" x="320" y="64" width="64" height="64"/>
+    <SubTexture name="1_6" x="384" y="64" width="64" height="64"/>
+    <SubTexture name="1_7" x="448" y="64" width="64" height="64"/>
+    <SubTexture name="1_8" x="512" y="64" width="64" height="64"/>
+    <SubTexture name="1_9" x="576" y="64" width="64" height="64"/>
+    <SubTexture name="1_10" x="640" y="64" width="64" height="64"/>
+    <SubTexture name="1_11" x="704" y="64" width="64" height="64"/>
+    <SubTexture name="1_12" x="768" y="64" width="64" height="64"/>
+    <SubTexture name="1_13" x="832" y="64" width="64" height="64"/>
+    <SubTexture name="1_14" x="896" y="64" width="64" height="64"/>
+    <SubTexture name="1_15" x="960" y="64" width="64" height="64"/>
+    <SubTexture name="2_0" x="0" y="128" width="64" height="64"/>
+    <SubTexture name="2_1" x="64" y="128" width="64" height="64"/>
+    <SubTexture name="2_2" x="128" y="128" width="64" height="64"/>
+    <SubTexture name="2_3" x="192" y="128" width="64" height="64"/>
+    <SubTexture name="2_4" x="256" y="128" width="64" height="64"/>
+    <SubTexture name="2_5" x="320" y="128" width="64" height="64"/>
+    <SubTexture name="2_6" x="384" y="128" width="64" height="64"/>
+    <SubTexture name="2_7" x="448" y="128" width="64" height="64"/>
+    <SubTexture name="2_8" x="512" y="128" width="64" height="64"/>
+    <SubTexture name="2_9" x="576" y="128" width="64" height="64"/>
+    <SubTexture name="2_10" x="640" y="128" width="64" height="64"/>
+    <SubTexture name="2_11" x="704" y="128" width="64" height="64"/>
+    <SubTexture name="2_12" x="768" y="128" width="64" height="64"/>
+    <SubTexture name="2_13" x="832" y="128" width="64" height="64"/>
+    <SubTexture name="2_14" x="896" y="128" width="64" height="64"/>
+    <SubTexture name="2_15" x="960" y="128" width="64" height="64"/>
+    <SubTexture name="3_0" x="0" y="192" width="64" height="64"/>
+    <SubTexture name="3_1" x="64" y="192" width="64" height="64"/>
+    <SubTexture name="3_2" x="128" y="192" width="64" height="64"/>
+    <SubTexture name="3_3" x="192" y="192" width="64" height="64"/>
+    <SubTexture name="3_4" x="256" y="192" width="64" height="64"/>
+    <SubTexture name="3_5" x="320" y="192" width="64" height="64"/>
+    <SubTexture name="3_6" x="384" y="192" width="64" height="64"/>
+    <SubTexture name="3_7" x="448" y="192" width="64" height="64"/>
+    <SubTexture name="3_8" x="512" y="192" width="64" height="64"/>
+    <SubTexture name="3_9" x="576" y="192" width="64" height="64"/>
+    <SubTexture name="3_10" x="640" y="192" width="64" height="64"/>
+    <SubTexture name="3_11" x="704" y="192" width="64" height="64"/>
+    <SubTexture name="3_12" x="768" y="192" width="64" height="64"/>
+    <SubTexture name="3_13" x="832" y="192" width="64" height="64"/>
+    <SubTexture name="3_14" x="896" y="192" width="64" height="64"/>
+    <SubTexture name="3_15" x="960" y="192" width="64" height="64"/>
+    <SubTexture name="4_0" x="0" y="256" width="64" height="64"/>
+    <SubTexture name="4_1" x="64" y="256" width="64" height="64"/>
+    <SubTexture name="4_2" x="128" y="256" width="64" height="64"/>
+    <SubTexture name="4_3" x="192" y="256" width="64" height="64"/>
+    <SubTexture name="4_4" x="256" y="256" width="64" height="64"/>
+    <SubTexture name="4_5" x="320" y="256" width="64" height="64"/>
+    <SubTexture name="4_6" x="384" y="256" width="64" height="64"/>
+    <SubTexture name="4_7" x="448" y="256" width="64" height="64"/>
+    <SubTexture name="4_8" x="512" y="256" width="64" height="64"/>
+    <SubTexture name="4_9" x="576" y="256" width="64" height="64"/>
+    <SubTexture name="4_10" x="640" y="256" width="64" height="64"/>
+    <SubTexture name="4_11" x="704" y="256" width="64" height="64"/>
+    <SubTexture name="4_12" x="768" y="256" width="64" height="64"/>
+    <SubTexture name="4_13" x="832" y="256" width="64" height="64"/>
+    <SubTexture name="4_14" x="896" y="256" width="64" height="64"/>
+    <SubTexture name="4_15" x="960" y="256" width="64" height="64"/>
+    <SubTexture name="5_0" x="0" y="320" width="64" height="64"/>
+    <SubTexture name="5_1" x="64" y="320" width="64" height="64"/>
+    <SubTexture name="5_2" x="128" y="320" width="64" height="64"/>
+    <SubTexture name="5_3" x="192" y="320" width="64" height="64"/>
+    <SubTexture name="5_4" x="256" y="320" width="64" height="64"/>
+    <SubTexture name="5_5" x="320" y="320" width="64" height="64"/>
+    <SubTexture name="5_6" x="384" y="320" width="64" height="64"/>
+    <SubTexture name="5_7" x="448" y="320" width="64" height="64"/>
+    <SubTexture name="5_8" x="512" y="320" width="64" height="64"/>
+    <SubTexture name="5_9" x="576" y="320" width="64" height="64"/>
+    <SubTexture name="5_10" x="640" y="320" width="64" height="64"/>
+    <SubTexture name="5_11" x="704" y="320" width="64" height="64"/>
+    <SubTexture name="5_12" x="768" y="320" width="64" height="64"/>
+    <SubTexture name="5_13" x="832" y="320" width="64" height="64"/>
+    <SubTexture name="5_14" x="896" y="320" width="64" height="64"/>
+    <SubTexture name="5_15" x="960" y="320" width="64" height="64"/>
+    <SubTexture name="6_0" x="0" y="384" width="64" height="64"/>
+    <SubTexture name="6_1" x="64" y="384" width="64" height="64"/>
+    <SubTexture name="6_2" x="128" y="384" width="64" height="64"/>
+    <SubTexture name="6_3" x="192" y="384" width="64" height="64"/>
+    <SubTexture name="6_4" x="256" y="384" width="64" height="64"/>
+    <SubTexture name="6_5" x="320" y="384" width="64" height="64"/>
+    <SubTexture name="6_6" x="384" y="384" width="64" height="64"/>
+    <SubTexture name="6_7" x="448" y="384" width="64" height="64"/>
+    <SubTexture name="6_8" x="512" y="384" width="64" height="64"/>
+    <SubTexture name="6_9" x="576" y="384" width="64" height="64"/>
+    <SubTexture name="6_10" x="640" y="384" width="64" height="64"/>
+    <SubTexture name="6_11" x="704" y="384" width="64" height="64"/>
+    <SubTexture name="6_12" x="768" y="384" width="64" height="64"/>
+    <SubTexture name="6_13" x="832" y="384" width="64" height="64"/>
+    <SubTexture name="6_14" x="896" y="384" width="64" height="64"/>
+    <SubTexture name="6_15" x="960" y="384" width="64" height="64"/>
+    <SubTexture name="7_0" x="0" y="448" width="64" height="64"/>
+    <SubTexture name="7_1" x="64" y="448" width="64" height="64"/>
+    <SubTexture name="7_2" x="128" y="448" width="64" height="64"/>
+    <SubTexture name="7_3" x="192" y="448" width="64" height="64"/>
+    <SubTexture name="7_4" x="256" y="448" width="64" height="64"/>
+    <SubTexture name="7_5" x="320" y="448" width="64" height="64"/>
+    <SubTexture name="7_6" x="384" y="448" width="64" height="64"/>
+    <SubTexture name="7_7" x="448" y="448" width="64" height="64"/>
+    <SubTexture name="7_8" x="512" y="448" width="64" height="64"/>
+    <SubTexture name="7_9" x="576" y="448" width="64" height="64"/>
+    <SubTexture name="7_10" x="640" y="448" width="64" height="64"/>
+    <SubTexture name="7_11" x="704" y="448" width="64" height="64"/>
+    <SubTexture name="7_12" x="768" y="448" width="64" height="64"/>
+    <SubTexture name="7_13" x="832" y="448" width="64" height="64"/>
+    <SubTexture name="7_14" x="896" y="448" width="64" height="64"/>
+    <SubTexture name="7_15" x="960" y="448" width="64" height="64"/>
+
+</TextureAtlas>

BIN
NewSpaceGame/Resources/Sprites/green_beam.png


BIN
NewSpaceGame/Resources/Sprites/space_background.png


BIN
NewSpaceGame/Resources/Sprites/spacegame_sheet.png


+ 11 - 0
NewSpaceGame/Resources/Sprites/spacegame_sheet.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Created with TexturePacker http://www.codeandweb.com/texturepacker-->
+<!-- $TexturePacker:SmartUpdate:1a17c841c2e0285d52a986d357f78c54:1/1$ -->
+<TextureAtlas imagePath="spacegame_sheet.png">
+    <SubTexture name="spaceship_cricket" x="2" y="170" width="127" height="184" frameX="-1" frameY="0" frameWidth="129" frameHeight="184"/>
+    <SubTexture name="spaceship_flea" x="186" y="50" width="48" height="41"/>
+    <SubTexture name="spaceship_locust" x="2" y="2" width="182" height="166"/>
+    <SubTexture name="spaceship_louse" x="186" y="2" width="60" height="46"/>
+    <SubTexture name="spaceship_mantis" x="131" y="274" width="87" height="104"/>
+    <SubTexture name="spaceship_scarab" x="131" y="170" width="105" height="102"/>
+</TextureAtlas>

BIN
NewSpaceGame/Resources/Sprites/spaceship_cricket.png


BIN
NewSpaceGame/Resources/Sprites/spaceship_flea.png


BIN
NewSpaceGame/Resources/Sprites/spaceship_locust.png


BIN
NewSpaceGame/Resources/Sprites/spaceship_louse.png


BIN
NewSpaceGame/Resources/Sprites/spaceship_mantis.png


BIN
NewSpaceGame/Resources/Sprites/spaceship_scarab.png


+ 25 - 0
NewSpaceGame/Resources/UI/Hud.ui.txt

@@ -0,0 +1,25 @@
+#SpaceGame HUD
+
+# definitions is not a keyword, it is just a node which we can include later
+definitions
+	atomictext
+		skin SpaceText
+
+TBLayout: axis: y, distribution: available, size: available, spacing: 0
+	TBLayout: distribution: gravity
+		TBContainer: skin: "SpaceGameContainer", gravity: left right
+			TBLayout: distribution: available, size: available, spacing: 0
+				TBWidget:
+					TBTextField: text: "Score: 0", id: "scoretext", text-align: "left", gravity: left
+						@include definitions>atomictext
+						lp: width: 192
+						font: size: 24
+					TBTextField: text: "Atomic Space Game", gravity: all
+						@include definitions>atomictext
+						font: size: 24
+					TBLayout: gravity: right, distribution: available, size: available, spacing: 4
+						lp: width: 128, height: 32
+						TBSkinImage: skin: "Spaceship", id: "ship1"
+						TBSkinImage: skin: "Spaceship", id: "ship2"
+						TBSkinImage: skin: "Spaceship", id: "ship3"
+	TBWidget: id: "viewport"

+ 45 - 0
NewSpaceGame/Resources/UI/mainMenu.js

@@ -0,0 +1,45 @@
+'use strict';
+
+var game = Atomic.game;
+var view = game.uiView;
+var UI = Atomic.UI;
+var UIWindow = Atomic.UIWindow;
+
+var window;
+
+function closeWindow() {
+
+  if (window)
+    window.die();
+  window = null;
+
+}
+
+exports.init = function() {
+
+  window = new UIWindow();
+
+  window.settings = Atomic.UI.WINDOW_SETTINGS_TITLEBAR;
+  window.text = "Main Menu";
+
+  window.load("UI/MainMenu.ui.txt");
+  window.resizeToFitContent();
+  view.addChild(window);
+  window.center();
+
+  window.getWidget("new_game").onClick = function () {
+
+    closeWindow();
+    
+  	var node = game.scene.createChild("SpaceGame");
+  	node.createJSComponent("SpaceGame");
+
+  }
+
+}
+
+exports.shutdown = function() {
+
+  closeWindow();
+
+}

+ 14 - 0
NewSpaceGame/Resources/UI/mainMenu.ui.txt

@@ -0,0 +1,14 @@
+definitions
+	menubutton
+		font: size: 24
+
+TBLayout: axis: y, size: available
+
+	TBButton: text: "New Game", id: "new_game"
+		@include definitions>menubutton
+	TBButton: text: "High Scores"
+		@include definitions>menubutton
+	TBButton: text: "About"
+		@include definitions>menubutton
+	TBButton: text: "Quit"
+		@include definitions>menubutton

+ 14 - 0
NewSpaceGame/Resources/UI/ui.js

@@ -0,0 +1,14 @@
+'use strict';
+
+
+
+
+exports.showMainMenu = function() {
+    var mainMenu = require("./mainMenu");
+    mainMenu.init();
+}
+
+exports.update = function(timeStep) {
+
+
+}