Skip to content

Commit

Permalink
Woot ! Got the animation and blood working:
Browse files Browse the repository at this point in the history
Added walk animation on player move
Added Blood class
Added pellet logic to ShotgunComponent
Added health point deduction to ShotgunComponent
Added death animation activation on death
  • Loading branch information
Raymond Hulha committed Nov 20, 2013
1 parent 6428223 commit bcd77d4
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 12 deletions.
10 changes: 7 additions & 3 deletions js/loadScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ require([
Game.userEntity.setComponent(new FlashlightComponent());

var zombie = loader.getCachedObjectForRef("zombie_idle/entities/Zombie_Geo_0.entity");
zombie.removeFromWorld();
var z2 = EntityUtils.clone(goo.world, zombie);
//zombie.removeFromWorld(); // this breaks the parent child relationship, the parent has the animation that I need...
var z2 = zombie; // EntityUtils.clone(goo.world, zombie);
z2.transformComponent.setTranslation(-2,0,2);
z2.setComponent(new AIComponent(z2));
z2.aIComponent.addBehavior({name:"Zombie-Idle", update:ZombieIdle}, 0);
z2.aIComponent.addBehavior({name:"Zombie-PathFind", update:ZombiePathFind}, 1);
z2.addToWorld();
// z2.addToWorld();
Game.zombie = zombie;
Game.zombieRoot = zombie.transformComponent.parent.entity;

goo.renderer.domElement.id = 'goo';
document.body.appendChild(goo.renderer.domElement);
Expand Down Expand Up @@ -342,6 +344,8 @@ require([
node.doorPos = navMesh.room[entity.room].door[node.curNode.door].center;
entity.aIComponent.setActiveByName("Zombie-Idle", false);
node.state = 1;
var eac = Game.zombieRoot.animationComponent;
eac.transitionTo( eac.getStates()[1]);
}
}

Expand Down
57 changes: 57 additions & 0 deletions lib/Blood.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

define(['goo/entities/EntityUtils', 'goo/math/Vector3', 'goo/renderer/TextureCreator', 'goo/renderer/Material', 'goo/renderer/shaders/ShaderLib',
'goo/particles/ParticleUtils', 'goo/entities/components/ParticleComponent'], function( EntityUtils, Vector3, TextureCreator, Material, ShaderLib, ParticleUtils, ParticleComponent) {
'use strict';

function Blood( goo) {

this.goo = goo;

var particleTex = new TextureCreator().loadTexture2D('../res/flare.png');
particleTex.generateMipmaps = true;

//texture.wrapS = 'EdgeClamp';
//texture.wrapT = 'EdgeClamp';

var material = this.material = Material.createMaterial(ShaderLib.particles);
material.setTexture('DIFFUSE_MAP', particleTex);
material.blendState.blending = 'AlphaBlending'; // 'AdditiveBlending';
material.cullState.enabled = false;
material.depthState.write = false;
material.renderQueue = 2001;

this.config = {
//particleCount : 200,
timeline : [
{timeOffset: 0.00, color: [1, 0, 0, 0.5], size: 0.3, spin: 0, mass: 0},
//{timeOffset: 0.25, color: [1, 0, 0, 0.5], size: 50.0},
//{timeOffset: 0.25, color: [1, 0, 0, 0.5], size: 100.0},
{timeOffset: 0.25, color: [1, 0, 0, 0], size: 3.0,}
],
emitters : [{
totalParticlesToSpawn : 1,
releaseRatePerSecond : 5,
minLifetime : 1.25,
maxLifetime : 1.25,
getEmissionVelocity : function (particle/*, particleEntity*/) {
var vec3 = particle.velocity;
return ParticleUtils.getRandomVelocityOffY(vec3, 0, Math.PI * 15 / 180, 5);
}
}]
};

}

Blood.prototype.spawn = function( pos) {
var particleComponent = new ParticleComponent(this.config);
//particleComponent.emitters[0].influences.push(ParticleUtils.createConstantForce(new Vector3(0, -20, 0)));

var entity = EntityUtils.createTypicalEntity( this.goo.world, this.material, particleComponent.meshData, [pos.x,pos.y,pos.z]);
entity.meshRendererComponent.isPickable = false;
entity.setComponent(particleComponent);
entity.addToWorld();
return entity;
}

return Blood;
});
76 changes: 67 additions & 9 deletions lib/ShotgunComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ define([
'goo/renderer/Material',
'goo/addons/howler/systems/HowlerSystem',
'goo/addons/howler/components/HowlerComponent',
'goo/math/Ray',
'goo/math/Vector3',
'lib/Blood'

], function(
Component,
Game,
Expand All @@ -17,14 +21,17 @@ define([
ShapeCreator,
Material,
HowlerSystem,
HowlerComponent
HowlerComponent,
Ray,
Vector3,
Blood
) {
'use strict';
var shotgun;
var sound;
function ShotgunComponent(){
this.type = "ShotgunComponent";
sound = new Howl({urls: ["res/sounds/ssg.ogg", "res/sounds/ssg.mp3"], volume:1.0});
sound = new Howl({urls: ["res/sounds/ssg.ogg", "res/sounds/ssg.mp3"], volume:0.3});

var mesh = ShapeCreator.createCylinder( 30, 2);
var mat = Material.createMaterial( ShaderLib.simpleLit, 'BoxMaterial');
Expand Down Expand Up @@ -54,7 +61,58 @@ define([

function resetSSG() {
shotgun.transformComponent.setRotation( 0.15, 0.1, 0);
};
}

var blood;

var pickingStore = {};
var md_pos = new Vector3();
var md_dir = new Vector3();
var md_ray = new Ray();
function pellet( camera, x, y, w, h) {

blood = blood || new Blood(Game.goo);

Game.goo.renderer.pick( x, y, pickingStore, camera);
if( pickingStore.id == -1)
return;
camera.getPickRay( x, y, w, h, md_ray);
md_ray.direction.mul( pickingStore.depth);
md_ray.origin.add( md_ray.direction);

var entity = Game.goo.world.entityManager.getEntityById(pickingStore.id);

console.log(entity);

if( ! entity.transformComponent.parent )
return;


var p = entity.transformComponent.parent.entity;
if( ! p.animationComponent )
return;
var eac = p.animationComponent;

blood.spawn(md_ray.origin);

if( entity.dmg) entity.dmg += 7; else entity.dmg = 7;
if( entity.dmg && entity.dmg == 7) {
eac.transitionTo( eac.getStates()[1]); // idle, injured_walk, uppercut_jab, dying
}
if( entity.dmg && entity.dmg > 100) {
eac.layers[0]._steadyStates['mixamo_com__']._sourceTree._clipInstance._loopCount=1;
eac.transitionTo( eac.getStates()[3]); // idle, injured_walk, uppercut_jab, dying
Game.zombie.aIComponent.setActiveByName("Zombie-PathFind", false);
}
}

function randInt(max) {
return Math.floor(Math.random()*max);
}
function randBlood() {
return randInt(200)-100;
}

function mouseButton1(bool0){
//console.log(bool0);
if(true == bool0){
Expand All @@ -70,14 +128,14 @@ define([
Game.goo.pick( x, y, function( id, depth){
if( id < 0)
return;
console.log( depth);

var pos = Game.viewCam.cameraComponent.camera.getWorldCoordinates( x, y, w, h, depth);
//blood.spawn([pos.x,pos.y,pos.z]);
var entity = Game.goo.world.entityManager.getEntityById(id);
var camera = Game.viewCam.cameraComponent.camera
for( var i=0; i<10; i++) {
pellet( camera, x+randBlood(), y+randBlood(), w, h);
}
});
}
}
};
}
return ShotgunComponent;
});
Binary file added res/flare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bcd77d4

Please sign in to comment.