Browse Source

More platform updates

Josh Engebretson 11 years ago
parent
commit
99497728d1

+ 64 - 0
PhysicsPlatformerNew/Resources/Components/Bat.js

@@ -0,0 +1,64 @@
+var glmatrix = require("gl-matrix");
+var vec2 = glmatrix.vec2;
+
+var game = Atomic.game;
+var node = self.node;
+
+var animationSet = game.cache.getResource("AnimationSet2D", "Sprites/Bat/Bat.scml");
+var sprite = node.createComponent("AnimatedSprite2D");
+sprite.setAnimation(animationSet, "Fly");
+sprite.setLayer(100);
+node.scale2D = [.5, .5];
+
+var cwaypoint = -1;
+
+var light = null;
+
+function start() {
+
+    if (!Platformer.daytime) {
+
+        light = node.createComponent("PointLight2D");
+        light.color = [1, 1, 1, 1];
+        light.radius = 4;
+
+        Platformer.lightGroup.addLight(light);
+
+        node.createJSComponent("LightFlicker");
+    }
+}
+
+var time = Math.random() * 10000;
+
+function update(timestep) {
+
+    time += timestep * 4;
+    
+    if (light)
+        light.color = [.5 + Math.sin(time), .5 + Math.cos(time), .5 + Math.cos(-time), 1];
+
+    var waypoints = Platformer.batWaypoints;
+    var pos = node.position2D;
+
+    if (cwaypoint == -1 || vec2.distance(pos, waypoints[cwaypoint]) < .5) {
+        cwaypoint = Math.round(Math.random() * (waypoints.length - 1));
+        return;
+    }
+
+    var dir = vec2.create();
+    var goal = waypoints[cwaypoint];
+
+    vec2.subtract(dir, goal, pos);
+    vec2.normalize(dir, dir);
+    vec2.scale(dir, dir, timestep * 2);
+
+    if (dir[0] < 0)
+        sprite.flipX = true;
+    else
+        sprite.flipX = false;
+
+    vec2.add(pos, pos, dir);
+    node.position2D = pos;
+
+
+}

+ 99 - 0
PhysicsPlatformerNew/Resources/Components/Coin.js

@@ -0,0 +1,99 @@
+var glmatrix = require("gl-matrix");
+var vec2 = glmatrix.vec2;
+
+var game = Atomic.game;
+var cameraNode = game.cameraNode;
+var cache = game.cache;
+
+var node = self.node;
+
+// Resources
+var animationSet = cache.getResource("AnimationSet2D", "Sprites/GoldIcon.scml");
+var coinSound = cache.getResource("Sound", "Sounds/Pickup_Coin8.ogg");
+var coinBounceSound = cache.getResource("Sound", "Sounds/Coin_Bounce.ogg");
+
+var sprite = node.createComponent("AnimatedSprite2D");
+sprite.setAnimation(animationSet, "idle");
+sprite.setLayer(100);
+
+var activated = false;
+var body;
+var light;
+
+function onPlayerHit() {
+
+    // sprite enabled is not removing the sprite
+    light.enabled = false;
+    node.scale2D = [0, 0];
+    sprite.enabled = false;
+    body.enabled = false;
+    self.soundSource.gain = 1.0;
+    self.soundSource.play(coinSound);
+
+}
+
+self.onPhysicsBeginContact2D = function(world, bodyA, bodyB, nodeA, nodeB) {
+
+    if (nodeA == Platformer.level.player.node && nodeB == node) {
+        onPlayerHit();
+    } else if (nodeB == node) {
+        var vel = body.linearVelocity;
+        if (vec2.length(vel) > 3) {
+            self.soundSource.gain = .3;
+            self.soundSource.play(coinBounceSound);
+        }
+    }
+
+}
+
+
+function start() {
+
+    self.soundSource = node.createComponent("SoundSource");
+    self.soundSource.soundType = Atomic.SOUND_EFFECT;
+
+    light = node.createComponent("PointLight2D");
+    if (Platformer.daytime)
+        light.color = [1, 1, .56, .4];
+    else
+        light.color = [1, 1, .56, .8];
+
+    light.radius = .85;
+    Platformer.lightGroup.addLight(light);
+
+
+    // would just like to listen to body collisions here
+    self.listenToEvent(null, "PhysicsBeginContact2D", self.onPhysicsBeginContact2D);
+
+
+}
+
+function update(timeStep) {
+
+    if (activated)
+        return false;
+
+    if (vec2.distance(cameraNode.position2D, node.position2D) < 3.0) {
+    
+        activated = true;
+
+        body = node.createComponent("RigidBody2D");
+        body.setBodyType(Atomic.BT_DYNAMIC);
+        body.fixedRotation = true;
+        body.castShadows = false;
+
+        var circle = node.createComponent("CollisionCircle2D");
+
+        // Set radius
+        circle.setRadius(.3);
+        // Set density
+        circle.setDensity(1.0);
+        // Set friction.
+        circle.friction = .2;
+        // Set restitution
+        circle.setRestitution(.8);
+
+
+    }
+
+}

+ 21 - 0
PhysicsPlatformerNew/Resources/Components/Level.js

@@ -42,6 +42,27 @@ function createEntities() {
         var vine = vnode.createJSComponent("Vine");
         vine.init(vines[i].position);        
     }
+    
+    var bats = self.levelParser.getEntities("Bat");
+    for (var i = 0; i < bats.length; i++) {
+        var bnode  = scene.createChild("Bat");
+        var bat = bnode.createJSComponent("Bat");
+        bnode.position2D = bats[i].position;
+    }
+    
+    var coins = self.levelParser.getEntities("Coin");
+    for (var i = 0; i < coins.length; i++) {
+        var cnode  = scene.createChild("Coin");
+        var coin = cnode.createJSComponent("Coin");
+        cnode.position2D = coins[i].position;
+    }
+    
+    var batWaypoints = self.levelParser.getEntities("BatWaypoint");
+    for (var i = 0; i < batWaypoints.length; i++) {
+        Platformer.batWaypoints.push(batWaypoints[i].position);
+    }
+    
+    
 }
 
 function start() {

+ 2 - 0
PhysicsPlatformerNew/Resources/Components/Platformer.js

@@ -4,6 +4,8 @@ var node = self.node;
 
 Platformer = self;
 
+self.batWaypoints = [];
+
 self.init = function(daytime) {
 
     Platformer.daytime = daytime;

+ 16 - 2
PhysicsPlatformerNew/Resources/Scripts/LevelParser.js

@@ -33,12 +33,26 @@ LevelParser.prototype = {
                     entity.type = "PlayerSpawn";
                     entity.position = onode.position2D;
 
-                }
-                if (o.type == "Vine") {
+                } else if (o.type == "Vine") {
 
                     entity.type = "Vine";
                     entity.position = onode.position2D;
 
+                } else if (o.type == "Coin") {
+
+                    entity.type = "Coin";
+                    entity.position = onode.position2D;
+
+                } else if (o.type == "Bat") {
+
+                    entity.type = "Bat";
+                    entity.position = onode.position2D;
+
+                } else if (o.type == "BatWaypoint") {
+
+                    entity.type = "BatWaypoint";
+                    entity.position = onode.position2D;
+
                 } else if (o.type == "PlatformStart") {
 
 

BIN
PhysicsPlatformerNew/Resources/Sounds/Coin_Bounce.ogg


BIN
PhysicsPlatformerNew/Resources/Sounds/CrateHit.ogg


BIN
PhysicsPlatformerNew/Resources/Sounds/Jump13.ogg


BIN
PhysicsPlatformerNew/Resources/Sounds/JumpingBat.ogg


BIN
PhysicsPlatformerNew/Resources/Sounds/Pickup_Coin8.ogg


+ 69 - 0
PhysicsPlatformerNew/Resources/Sprites/Bat/Bat.scml

@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<spriter_data scml_version="1.0" generator="BrashMonkey Spriter" generator_version="r2">
+    <folder id="0">
+        <file id="0" name="bat-frame-8.png" width="128" height="128" pivot_x="0" pivot_y="1"/>
+        <file id="1" name="bat-frame-1.png" width="128" height="128" pivot_x="0" pivot_y="1"/>
+        <file id="2" name="bat-frame-2.png" width="128" height="128" pivot_x="0" pivot_y="1"/>
+        <file id="3" name="bat-frame-3.png" width="128" height="128" pivot_x="0" pivot_y="1"/>
+        <file id="4" name="bat-frame-4.png" width="128" height="128" pivot_x="0" pivot_y="1"/>
+        <file id="5" name="bat-frame-5.png" width="128" height="128" pivot_x="0" pivot_y="1"/>
+        <file id="6" name="bat-frame-6.png" width="128" height="128" pivot_x="0" pivot_y="1"/>
+        <file id="7" name="bat-frame-7.png" width="128" height="128" pivot_x="0" pivot_y="1"/>
+    </folder>
+    <entity id="0" name="Bat">
+        <animation id="0" name="Fly" length="500" interval="100">
+            <mainline>
+                <key id="0">
+                    <object_ref id="0" timeline="0" key="0" z_index="0"/>
+                </key>
+                <key id="1" time="62">
+                    <object_ref id="0" timeline="0" key="1" z_index="0"/>
+                </key>
+                <key id="2" time="125">
+                    <object_ref id="0" timeline="0" key="2" z_index="0"/>
+                </key>
+                <key id="3" time="187">
+                    <object_ref id="0" timeline="0" key="3" z_index="0"/>
+                </key>
+                <key id="4" time="250">
+                    <object_ref id="0" timeline="0" key="4" z_index="0"/>
+                </key>
+                <key id="5" time="312">
+                    <object_ref id="0" timeline="0" key="5" z_index="0"/>
+                </key>
+                <key id="6" time="375">
+                    <object_ref id="0" timeline="0" key="6" z_index="0"/>
+                </key>
+                <key id="7" time="437">
+                    <object_ref id="0" timeline="0" key="7" z_index="0"/>
+                </key>
+            </mainline>
+            <timeline id="0" name="Fly">
+                <key id="0" spin="0">
+                    <object folder="0" file="1" x="-68" y="56"/>
+                </key>
+                <key id="1" time="62" spin="0">
+                    <object folder="0" file="2" x="-68" y="56"/>
+                </key>
+                <key id="2" time="125" spin="0">
+                    <object folder="0" file="3" x="-68" y="56"/>
+                </key>
+                <key id="3" time="187" spin="0">
+                    <object folder="0" file="4" x="-68" y="56"/>
+                </key>
+                <key id="4" time="250" spin="0">
+                    <object folder="0" file="5" x="-68" y="56"/>
+                </key>
+                <key id="5" time="312" spin="0">
+                    <object folder="0" file="6" x="-68" y="56"/>
+                </key>
+                <key id="6" time="375" spin="0">
+                    <object folder="0" file="7" x="-68" y="56"/>
+                </key>
+                <key id="7" time="437" spin="0">
+                    <object folder="0" file="0" x="-68" y="56"/>
+                </key>
+            </timeline>
+        </animation>
+    </entity>
+</spriter_data>

BIN
PhysicsPlatformerNew/Resources/Sprites/Bat/bat-frame-1.png


BIN
PhysicsPlatformerNew/Resources/Sprites/Bat/bat-frame-2.png


BIN
PhysicsPlatformerNew/Resources/Sprites/Bat/bat-frame-3.png


BIN
PhysicsPlatformerNew/Resources/Sprites/Bat/bat-frame-4.png


BIN
PhysicsPlatformerNew/Resources/Sprites/Bat/bat-frame-5.png


BIN
PhysicsPlatformerNew/Resources/Sprites/Bat/bat-frame-6.png


BIN
PhysicsPlatformerNew/Resources/Sprites/Bat/bat-frame-7.png


BIN
PhysicsPlatformerNew/Resources/Sprites/Bat/bat-frame-8.png


BIN
PhysicsPlatformerNew/Resources/Sprites/GoldIcon.png


+ 48 - 0
PhysicsPlatformerNew/Resources/Sprites/GoldIcon.scml

@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<spriter_data scml_version="1.0" generator="BrashMonkey Spriter" generator_version="b8_1">
+    <folder id="0" name="GoldIcon">
+        <file id="0" name="GoldIcon/2.png" width="64" height="64" pivot_x="0.5" pivot_y="0.5"/>
+        <file id="1" name="GoldIcon/1.png" width="64" height="64" pivot_x="0.5" pivot_y="0.5"/>
+        <file id="2" name="GoldIcon/3.png" width="17" height="60" pivot_x="0.5" pivot_y="0.5"/>
+        <file id="3" name="GoldIcon/4.png" width="64" height="64" pivot_x="0.5" pivot_y="0.5"/>
+        <file id="4" name="GoldIcon/5.png" width="64" height="64" pivot_x="0.5" pivot_y="0.5"/>
+    </folder>
+    <entity id="0" name="entity_000">
+        <animation id="0" name="idle" length="500">
+            <mainline>
+                <key id="0">
+                    <object_ref id="0" timeline="0" key="0" z_index="0"/>
+                </key>
+                <key id="1" time="100">
+                    <object_ref id="0" timeline="0" key="1" z_index="0"/>
+                </key>
+                <key id="2" time="200">
+                    <object_ref id="0" timeline="0" key="2" z_index="0"/>
+                </key>
+                <key id="3" time="300">
+                    <object_ref id="0" timeline="0" key="3" z_index="0"/>
+                </key>
+                <key id="4" time="400">
+                    <object_ref id="0" timeline="0" key="4" z_index="0"/>
+                </key>
+            </mainline>
+            <timeline id="0" name="1">
+                <key id="0" spin="0">
+                    <object folder="0" file="1" angle="0"/>
+                </key>
+                <key id="1" time="100" spin="0">
+                    <object folder="0" file="0" angle="0"/>
+                </key>
+                <key id="2" time="200" spin="0">
+                    <object folder="0" file="2" angle="0"/>
+                </key>
+                <key id="3" time="300" spin="0">
+                    <object folder="0" file="3" angle="0"/>
+                </key>
+                <key id="4" time="400" spin="0">
+                    <object folder="0" file="4" angle="0"/>
+                </key>
+            </timeline>
+        </animation>
+    </entity>
+</spriter_data>

+ 10 - 0
PhysicsPlatformerNew/Resources/Sprites/GoldIcon.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Created with TexturePacker http://texturepacker.com-->
+<!-- $TexturePacker:SmartUpdate:86ac5203aadd5795b3e45516bcd6834b$ -->
+<TextureAtlas imagePath="GoldIcon.png">
+    <SubTexture name="1" x="2" y="2" width="60" height="60" frameX="-2" frameY="-2" frameWidth="64" frameHeight="64"/>
+    <SubTexture name="2" x="64" y="2" width="42" height="60" frameX="-11" frameY="-2" frameWidth="64" frameHeight="64"/>
+    <SubTexture name="3" x="108" y="2" width="17" height="60"/>
+    <SubTexture name="4" x="2" y="64" width="58" height="60" frameX="-3" frameY="-2" frameWidth="64" frameHeight="64"/>
+    <SubTexture name="5" x="62" y="64" width="42" height="60" frameX="-11" frameY="-1" frameWidth="64" frameHeight="64"/>
+</TextureAtlas>