Browse Source

Character Animation example

Josh Engebretson 11 years ago
parent
commit
ae0e482329

+ 0 - 0
CharacterAnimation3D/CharacterAnimation3D.atomic


+ 41 - 0
CharacterAnimation3D/Resources/Components/Roboman.js

@@ -0,0 +1,41 @@
+
+var game = Atomic.game;
+var node = self.node;
+
+RoboMan = self;
+
+self.animCtrl = node.createComponent("AnimationController");
+
+var idle = true;
+
+self.playAnimation = function(animation) {
+
+    self.animCtrl.playExclusive("Models/" + animation, 0, true, 0.1);
+}
+
+function start() {
+
+    var cache = game.cache;
+
+    var model = node.createComponent("AnimatedModel");
+    model.setModel(cache.getResource("Model", "Models/RoboMan.mdl"));
+    model.setMaterial(cache.getResource("Material", "Materials/Robot_01_Diffuse.xml"));
+
+    model.castShadows = true;
+    
+    self.animCtrl.playExclusive("Models/RoboMan_Normal_Idle.ani", 0, true, 0.0);
+
+    game.cameraNode.position = [0, 6.0, -12];
+    game.cameraNode.pitch(0);
+    
+    node.yaw(180);
+    
+}
+
+// we need an update or it doesn't run the start, fix in JSVM
+function update(timeStep) {
+
+    node.yaw(timeStep * 50);
+    
+
+}

+ 68 - 0
CharacterAnimation3D/Resources/Components/UI.js

@@ -0,0 +1,68 @@
+// Atomic Component
+
+var game = Atomic.game;
+var node = self.node;
+
+var ui = game.ui;
+var root = ui.getRoot();
+
+var font = game.cache.getResource("Font", "Fonts/Anonymous Pro.ttf");
+
+var uiStyle = game.cache.getResource("XMLFile", "UI/DefaultStyle.xml");
+root.defaultStyle = uiStyle;
+
+var container = new Atomic.UIElement();
+container.horizontalAlignment = Atomic.HA_RIGHT;
+container.verticalAlignment = Atomic.VA_CENTER;
+container.layoutMode = Atomic.LM_VERTICAL;
+
+root.addChild(container);
+
+var buttons = {};
+
+function addButton(name, text, callback) {
+
+    var button = new Atomic.Button();
+    
+    button.setName(name);
+    button.setMinWidth(120);
+    button.setMinHeight(24);
+
+    var buttonText = new Atomic.Text();
+    buttonText.text = text;
+    buttonText.setFont(font, 12);
+    buttonText.color = [0, 1, 0, 1];
+
+    buttonText.horizontalAlignment = Atomic.HA_CENTER;
+    buttonText.verticalAlignment = Atomic.VA_CENTER;
+    button.addChild(buttonText); 
+    container.addChild(button);
+    button.setStyleAuto();   
+    
+    buttons[name] = callback;       
+   
+}
+
+addButton("PlayIdle", "Idle", function() { TheRoboman.playAnimation("RoboMan_Normal_Idle.ani"); }); 
+addButton("PlayRun", "Run", function() { TheRoboman.playAnimation("RoboMan_Normal_Run.ani"); }); 
+addButton("PlayWalk", "Walk", function() { TheRoboman.playAnimation("RoboMan_Normal_Walk.ani"); }); 
+addButton("PlayAttack", "Attack", function() { TheRoboman.playAnimation("RoboMan_Attack_Idle.ani"); });
+
+function start() {
+
+}
+
+self.onMouseClick = function(element) {
+
+    var name = element.name;
+    
+    buttons[name]();
+    
+}
+
+
+function update(timeStep) {
+
+    self.listenToEvent(null, "UIMouseClick", self.onMouseClick );
+
+}

+ 5 - 0
CharacterAnimation3D/Resources/Materials/Robot_01_Diffuse.xml

@@ -0,0 +1,5 @@
+<material>
+    <technique name="Techniques/Diff.xml" />
+    <texture unit="diffuse" name="Textures/Robot_01_Diffuse.png" />
+    <parameter name="MatSpecColor" value="0.1 0.1 0.1 16" />
+</material>

BIN
CharacterAnimation3D/Resources/Models/RoboMan.mdl


BIN
CharacterAnimation3D/Resources/Models/RoboMan_Attack_Idle.ani


BIN
CharacterAnimation3D/Resources/Models/RoboMan_Attack_JumpFall.ani


BIN
CharacterAnimation3D/Resources/Models/RoboMan_Attack_Run.ani


BIN
CharacterAnimation3D/Resources/Models/RoboMan_Crouch_Idle.ani


BIN
CharacterAnimation3D/Resources/Models/RoboMan_Crouch_Walk.ani


BIN
CharacterAnimation3D/Resources/Models/RoboMan_Normal_Idle.ani


BIN
CharacterAnimation3D/Resources/Models/RoboMan_Normal_JumpFall.ani


BIN
CharacterAnimation3D/Resources/Models/RoboMan_Normal_Run.ani


BIN
CharacterAnimation3D/Resources/Models/RoboMan_Normal_Walk.ani


+ 64 - 0
CharacterAnimation3D/Resources/Scripts/main.js

@@ -0,0 +1,64 @@
+
+// This script is the main entry point of the game
+
+require("AtomicGame");
+
+Atomic.game.init(start, update);
+
+
+// called at the start of play
+function start() {
+
+	var game = Atomic.game;
+
+	// create a 2D scene
+	game.createScene3D();
+
+	var scene = game.scene;
+
+	// zone
+	var zoneNode = scene.createChild("Zone")
+    var zone = zoneNode.createComponent("Zone");
+    zone.boundingBox = [-1000, -1000, -1000, 1000, 1000 , 1000];
+    zone.ambientColor = [0.35, 0.35, 0.35];
+    zone.fogColor = [0.1, 0.1, 0.1, 1.0];
+    zone.fogStart = 10;
+    zone.fogEnd = 100;
+
+    game.cameraNode.position = [0, 2.5, -6];
+    game.cameraNode.pitch(20);
+
+    var lightNode = scene.createChild("Directional Light");
+    lightNode.direction = [0.6, -1.0, 0.8];
+    var light = lightNode.createComponent("Light")
+    light.lightType = Atomic.LIGHT_DIRECTIONAL;
+    
+    light.castShadows = true;
+    // If we're running on android tweak the shadows
+    if (Atomic.platform == "Android") {
+
+        light.setShadowCascade(20.0, 50.0, 200.0, 0.0, 0.9);
+        light.shadowIntensity = 0.33;
+        
+    } else {
+        light.setShadowCascade(10.0, 50.0, 200.0, 0.0, 0.8);
+    }
+
+    light.setShadowBias(0.00025, 0.5);
+    light.specularIntensity = 8;
+    
+
+	// create the game component
+	var node = game.scene.createChild("Roboman");
+	TheRoboman = node.createJSComponent("Roboman");
+	
+	var ui = game.scene.createChild("UI");
+	ui.createJSComponent("UI");
+
+}
+
+// called per frame
+function update(timeStep) {
+
+
+}

BIN
CharacterAnimation3D/Resources/Textures/Robot_01_Diffuse.png