Commit 848eedb2 authored by ogomez92's avatar ogomez92

about to create branch

parent badd9de6
import {son} from './sonoObject';
import {GameUtils} from './utilities';
import {speech} from './tts';
var utils=new GameUtils();
const utils = new GameUtils();
class Car {
constructor(player,name,gears,maxSpeed=200,maxRate=1.5,minRate=0.5,steerFactor=5) {
this.maxRate=maxRate;
this.steerFactor=steerFactor;
this.minRate=minRate;
this.speedMod=0.01;
this.player=player;
this.speed=0;
this.maxSpeed=maxSpeed;
this.numberOfGears=gears;
this.speedPerGear=this.maxSpeed/this.numberOfGears;
this.velocity=0;
constructor(player, name, gears, maxSpeed = 200, maxRate = 1.5, minRate = 0.5, steerFactor = 5,hp=100,width=1,height=1) {
this.maxRate = maxRate;
this.steerFactor = steerFactor;
this.minRate = minRate;
this.speedMod = 0.01;
this.player = player;
this.player.hp=hp;
this.player.width=width;
this.player.height=height;
this.speed = 0;
this.maxSpeed = maxSpeed;
this.numberOfGears = gears;
this.speedPerGear = this.maxSpeed / this.numberOfGears;
this.velocity = 0;
this.name = name;
this.currentGear = 0;
this.turboMod=0;
this.accelerating=false;
this.decelerating=false;
this.sndEngine=son.create("car_loop");
this.sndEngine.volume-=0.5;
this.sndIdle=son.create("car_idle");
this.sndIdle.volume-=0.5;
this.sndEngine.loop=true;
}
getGear() {
let result= Math.floor((this.speed/this.maxSpeed)*this.numberOfGears)+1;
if (result>this.numberOfGears) result=this.numberOfGears;
return result;
this.currentGear = 0;
this.turboMod = 0;
this.accelerating = false;
this.decelerating = false;
this.sndEngine = son.create('car_loop');
this.sndEngine.volume -= 0.5;
this.sndIdle = son.create('car_idle');
this.sndIdle.volume -= 0.5;
this.sndEngine.loop = true;
}
reset() {
this.speed=0;
this.velocity=0;
}
getGear() {
let result = Math.floor((this.speed / this.maxSpeed) * this.numberOfGears) + 1;
if (result > this.numberOfGears) {
result = this.numberOfGears;
}
update() {
if (this.steering) this.accelerating=false;
return result;
}
update() {
if (this.accelerating) {
if (this.sndIdle.playing) this.sndIdle.stop();
if (!this.sndEngine.playing) this.sndEngine.play();
this.velocity+=1/1000;
this.speed+=this.velocity;
if (this.speed>=this.maxSpeed) {
this.speed=this.maxSpeed+this.turboMod;
this.velocity-=1/1000;
if (this.sndIdle.playing) {
this.sndIdle.stop();
}
if (!this.sndEngine.playing) {
this.sndEngine.play();
}
this.velocity += 1 / 1000;
this.speed += this.velocity;
if (this.speed >= this.maxSpeed) {
this.speed = this.maxSpeed + this.turboMod;
this.velocity -= 1 / 1000;
}
if (this.currentGear === 0) {
this.currentGear = 1;
}
if (this.getGear() > this.currentGear) {
this.currentGear = this.getGear();
}
this.sndEngine.playbackRate = utils.progressPitch(this.speed / this.currentGear, 1, this.speedPerGear, this.minRate, this.maxRate);
this.player.speed = this.speed * 0.0004;
this.player.move();
return;
}
if (this.currentGear==0) this.currentGear=1;
if (this.getGear()>this.currentGear) this.currentGear=this.getGear();
this.sndEngine.playbackRate=utils.progressPitch(this.speed/this.currentGear,1,this.speedPerGear,this.minRate,this.maxRate);
this.player.speed=this.speed*0.0004;
this.player.move();
return;
if (!this.accelerating) {
if (this.speed === 0) {
if (!this.sndIdle.playing) {
this.sndIdle.play();
}
if (!this.accelerating) {
if (this.speed==0) {
if (!this.sndIdle.playing) this.sndIdle.play();
this.velocity=0;
if (this.sndEngine.playing) this.sndEngine.stop();
this.accelerating=false;
return;
this.velocity = 0;
if (this.sndEngine.playing) {
this.sndEngine.stop();
}
//decelerate code
this.velocity-=1/1500;
if (this.decelerating) {
this.velocity-=1/1500;
this.speed-=this.velocity;
}
if (this.velocity<1/1000) this.velocity=1/1500;
this.speed-=this.velocity;
if (this.speed<0) {
this.speed=0;
return;
}
if (this.currentGear==0) this.currentGear=1;
if (this.getGear()<this.currentGear) this.currentGear=this.getGear();
this.sndEngine.playbackRate=utils.progressPitch(this.speed/this.currentGear,1,this.speedPerGear,this.minRate,this.maxRate);
this.player.speed=this.speed*0.0004;
this.player.move();
}
}
this.accelerating = false;
return;
}
// Decelerate code
this.velocity -= 1 / 1500;
if (this.decelerating) {
this.velocity -= 1 / 1500;
this.speed -= this.velocity;
}
if (this.velocity < 1 / 1000) {
this.velocity = 1 / 1500;
}
this.speed -= this.velocity;
if (this.speed < 0) {
this.speed = 0;
return;
}
if (this.currentGear === 0) {
this.currentGear = 1;
}
if (this.getGear() < this.currentGear) {
this.currentGear = this.getGear();
}
this.sndEngine.playbackRate = utils.progressPitch(this.speed / this.currentGear, 1, this.speedPerGear, this.minRate, this.maxRate);
this.player.speed = this.speed * 0.0004;
this.player.move();
}
export {Car}
\ No newline at end of file
}
}
export {Car};
import uniqueRandom from 'unique-random';
import panner from 'sono/effects/panner';
import {utils} from './player';
import {speech} from './tts';
import {son} from './sonoObject';
class Coin {
constructor(world) {
this.world = world;
const pos = this.findPosition();
this.x = pos.x;
this.y = 0;
this.width=1;
this.height=1;
this.z = pos.z;
console.log('coin made'+this.x+" "+this.z);
this.type=2;
this.sound = son.create('loop_coin');
this.pan = this.sound.effects.add(panner({
panningModel: 'HRTF',
distanceModel: 'linear',
refDistance: 1,
maxDistance: 15,
rolloffFactor: 1,
coneInnerAngle: 360,
coneOuterAngle: 0,
coneOuterGain: 0
}));
this.pan.setPosition(this.x, this.y, this.z);
this.sound.loop = true;
this.sound.playbackRate = utils.getRandomArbitrary(0.8, 1.2);
this.sound.play();
}
collide() {
this.world.player.sounds.playStatic('coin_collide', false);
this.destroy();
this.cash++;
}
get position() {
return [this.x, this.y, this.z];
}
findPosition() {
let cont = true;
let x = utils.randomInt(5, this.world.size - 5);
let z = utils.randomInt(5, this.world.size - 5);
if (this.world.contents.static.length == 0) {
return {x, z};
}// If
while (cont) {
x = utils.randomInt(1, this.world.size);
z = utils.randomInt(1, this.world.size);
for (const i of this.world.contents.static) {
if (i.x == x && i.z == z) {
continue;
}// If
}// For
cont = false;
return {x, z};
}// Function
}
destroy() {
this.sound.destroy();
}
}
export {Coin};
......@@ -3,60 +3,67 @@ import panner from 'sono/effects/panner';
import {utils} from './player';
import {speech} from './tts';
import {son} from './sonoObject';
class Cone {
constructor(world) {
console.log("cone made");
this.world=world;
let pos=this.findPosition();
this.x =pos.x;
this.y =0;
this.z =pos.z;
this.x=25;this.z=20;
this.sound=son.create("loop_cone");
this.pan=this.sound.effects.add(panner({
panningModel: 'HRTF',
distanceModel: 'linear',
refDistance: 1,
maxDistance: 15,
rolloffFactor: 1,
coneInnerAngle: 360,
coneOuterAngle: 0,
coneOuterGain: 0
}));
this.pan.setPosition(this.x,this.y,this.z);
this.sound.loop=true;
this.sound.playbackRate=utils.getRandomArbitrary(0.8,1.2);
this.sound.play();
}
collide() {
this.world.player.sounds.playStatic("cone_knock"+utils.randomInt(1,11),false);
this.destroy();
}
this.world = world;
const pos = this.findPosition();
this.x = pos.x;
this.y = 0;
this.width=1;
this.height=1;
this.z = pos.z;
console.log('cone made'+this.x+" "+this.z);
this.type=1;
this.sound = son.create('loop_cone');
this.pan = this.sound.effects.add(panner({
panningModel: 'HRTF',
distanceModel: 'linear',
refDistance: 1,
maxDistance: 15,
rolloffFactor: 1,
coneInnerAngle: 360,
coneOuterAngle: 0,
coneOuterGain: 0
}));
this.pan.setPosition(this.x, this.y, this.z);
this.sound.loop = true;
this.sound.playbackRate = utils.getRandomArbitrary(0.8, 1.2);
this.sound.play();
}
collide() {
this.world.player.sounds.playStatic('cone_knock' + utils.randomInt(1, 11), false);
this.destroy();
}
get position() {
return [this.x, this.y, this.z];
}
findPosition() {
let cont=true;
let x=utils.randomInt(1,this.world.size-2);
let z=utils.randomInt(1,this.world.size-2);
if (this.world.contents.static.length==0) {
return {x:x,z:z};
}//if
while (cont) {
x=utils.randomInt(1,this.world.size);
z=utils.randomInt(1,this.world.size);
for (let i of this.world.contents.static) {
if (i.x==x && i.z==z) {
continue;
}//if
}//for
cont=false;
return {x:x,z:z};
}//function
}
destroy() {
this.sound.destroy();
findPosition() {
let cont = true;
let x = utils.randomInt(5, this.world.size - 8);
let z = utils.randomInt(5, this.world.size - 8);
if (this.world.contents.static.length == 0) {
return {x, z};
}// If
while (cont) {
x = utils.randomInt(1, this.world.size);
z = utils.randomInt(1, this.world.size);
for (const i of this.world.contents.static) {
if (i.x == x && i.z == z) {
continue;
}// If
}// For
cont = false;
return {x, z};
}// Function
}
destroy() {
this.sound.destroy();
}
export {Cone}
\ No newline at end of file
}
export {Cone};
......@@ -2,111 +2,121 @@
import {GameUtils} from './utilities';
import {son} from './sonoObject';
import {speech} from './tts';
let utils=new GameUtils();
const utils = new GameUtils();
class EngineSound {
constructor(car, gears, maxAccelerate=1, minRate=0.7, speedFactor=0.0025) {
constructor(car, gears, maxAccelerate = 1, minRate = 0.7, speedFactor = 0.0025) {
this.started = false;
this.car = car;
this.gears = gears;
this.currentGear = 0;
this.currentAccelerateSound = 0;
this.accelerateSounds = maxAccelerate;
this.rateFactor = 0.8;
this.minRate = 0.8;
this.maxRate = 1;
this.rate = this.maxRate;
this.idling=1;
this.state=0;
this.idling = 1;
this.state = 0;
this.shiftTime = 5000;
this.timer = new Date();
this.time=this.timer.getMilliseconds();
this.states ={
idling:0,
accelerating:1,
decelerating:2,
shifting:3,
maxing:4
}
this.time = this.timer.getMilliseconds();
this.states = {
idling: 0,
accelerating: 1,
decelerating: 2,
shifting: 3,
maxing: 4
};
this.speedFactor = speedFactor;
this.maxVolume = 0.4;
this.sndAccelerate = new Array();
for (var i=0;i<this.accelerateSounds;i++) {
this.sndAccelerate.push(son.create("cars/"+this.car.type+"/accelerate"+(i+1)));
for (let i = 0; i < this.accelerateSounds; i++) {
this.sndAccelerate.push(son.create('cars/' + this.car.type + '/accelerate' + (i + 1)));
}
this.sndDecelerate = son.create("cars/"+this.car.type+"/decelerate");
this.sndIdle = son.create("cars/"+this.car.type+"/idle");
this.sndDecelerate = son.create('cars/' + this.car.type + '/decelerate');
this.sndIdle = son.create('cars/' + this.car.type + '/idle');
this.sndIdle.loop = true;
this.sndLoop = son.create("cars/"+this.car.type+"/high");
this.sndLoop = son.create('cars/' + this.car.type + '/high');
this.sndLoop.loop = true;
this.sndShift = son.create("cars/"+this.car.type+"/shift");
this.sndStart = son.create("cars/"+this.car.type+"/start");
this.sndShift = son.create('cars/' + this.car.type + '/shift');
this.sndStart = son.create('cars/' + this.car.type + '/start');
this.sndStart.volume = this.maxVolume;
this.sndShift.volume = this.maxVolume;
this.sndDecelerate.volume = this.maxVolume;
}
startEngine() {
this.sndStart.play();
this.sndStart.once("ended",()=> {
this.sndIdle.play();
this.currentGear = 0;
this.started = true;
this.accelerate();
});
}
this.sndStart.once('ended', () => {
this.sndIdle.play();
this.currentGear = 0;
this.started = true;
this.accelerate();
});
}
accelerate() {
if (this.started) {
if (this.state != this.states.accelerating) {
if (this.sndIdle.playing) this.sndIdle.stop();
if (this.sndDecelerate.playing) this.sndDecelerate.stop();
this.rateFactor = ((this.maxRate-this.currentGear/this.gears > this.minRate) ? this.maxRate-this.currentGear/this.gears : this.minRate);
this.rate = utils.getRandomArbitrary(this.rateFactor, this.rateFactor+0.1);
this.currentAccelerateSound = utils.randomInt(0, this.accelerateSounds-1);
if (this.sndIdle.playing) {
this.sndIdle.stop();
}
if (this.sndDecelerate.playing) {
this.sndDecelerate.stop();
}
this.rateFactor = ((this.maxRate - this.currentGear / this.gears > this.minRate) ? this.maxRate - this.currentGear / this.gears : this.minRate);
this.rate = utils.getRandomArbitrary(this.rateFactor, this.rateFactor + 0.1);
this.currentAccelerateSound = utils.randomInt(0, this.accelerateSounds - 1);
this.sndAccelerate[this.currentAccelerateSound].playbackRate = this.rate;
this.sndAccelerate[this.currentAccelerateSound].volume = this.maxVolume;
this.sndAccelerate[this.currentAccelerateSound].play();
this.state = this.states.accelerating;
this.idling=0;
this.idling = 0;
}
}
}
decelerate() {
if (this.started) {
if (this.state != this.states.decelerating) {
this.sndDecelerate.play();
this.sndAccelerate.forEach(function(sound) {
this.sndAccelerate.forEach(sound => {
sound.stop();
});
this.sndLoop.stop();
this.state = this.states.decelerating;
}
}
}
update() {
if (this.started) {
if (this.state == this.states.accelerating) { this.handleAccelerating(); }
if (this.state == this.states.decelerating) { this.handleDecelerating(); }
if (this.state == this.states.shifting) { this.handleShifting(); }
if (this.state == this.states.maxing) { this.handlePitch(); }
if (this.state == this.states.accelerating) {
this.handleAccelerating();
}
if (this.state == this.states.decelerating) {
this.handleDecelerating();
}
if (this.state == this.states.shifting) {
this.handleShifting();
}
if (this.state == this.states.maxing) {
this.handlePitch();
}
}
}
handleAccelerating() {
console.log(this.sndAccelerate[this.currentAccelerateSound].progress);
console.log(this.sndAccelerate[this.currentAccelerateSound].progress);
if (this.sndAccelerate[this.currentAccelerateSound].progress > 0.99 || this.sndAccelerate[this.currentAccelerateSound].ended) {
this.max();
}
}
max() {
if (this.started) {
this.sndAccelerate[this.currentAccelerateSound].fade(0, 0.1);
......@@ -117,7 +127,7 @@ class EngineSound {
this.sndLoop.play();
}
}
shift() {
if (this.started) {
this.sndShift.play();
......@@ -126,86 +136,81 @@ class EngineSound {
this.sndAccelerate[this.currentAccelerateSound].stop();
this.state = this.states.shifting;
this.currentGear++;
if (this.speedFactor > this.minSpeedFactor) this.speedFactor -= 0.0005;
if (this.rateFactor > this.minRate) this.rateFactor -= 0.05;
if (this.speedFactor > this.minSpeedFactor) {
this.speedFactor -= 0.0005;
}
if (this.rateFactor > this.minRate) {
this.rateFactor -= 0.05;
}
}
}
handlePitch() {
if (this.sndLoop.playbackRate < this.maxRate) {
this.sndLoop.playbackRate += this.speedFactor;
} else {
if (this.currentGear < this.gears) {
this.shift();
}
} else if (this.currentGear < this.gears) {
this.shift();
}
}
handleShifting() {
if (this.sndShift.progress > 0.9 || this.sndShift.ended) {
this.accelerate();
}
}
handleDecelerating() {
if (this.currentGear == 0) {
this.idle();
}
if ((this.sndDecelerate.ended) && this.currentGear > 0) {
this.currentGear--;
this.rate = utils.getRandomArbitrary(this.rateFactor, this.rateFactor+0.1);
if (this.rateFactor > 0.2) this.rateFactor -= 0.1;
this.rate = utils.getRandomArbitrary(this.rateFactor, this.rateFactor + 0.1);
if (this.rateFactor > 0.2) {
this.rateFactor -= 0.1;
}
this.sndDecelerate.playbackRate = this.rate;
this.sndDecelerate.seek(0);
this.sndDecelerate.play();
}
}
idle() {
this.rateFactor = this.minRate+this.maxRate/2;
this.rateFactor = this.minRate + this.maxRate / 2;
this.sndDecelerate.stop();
this.sndLoop.stop();
this.sndIdle.play();
this.state = this.states.idling;
}
stopEngine() {
this.started = false;
this.sndShift.stop();
this.sndDecelerate.stop();
this.sndAccelerate.forEach(function(sound) {
this.sndAccelerate.forEach(sound => {
sound.stop();
});
this.sndLoop.stop();
this.sndIdle.stop();
this.state = -1;
}
destroy() {
this.sndAccelerate.forEach(function(sound) {
this.sndAccelerate.forEach(sound => {
sound.destroy();
});
this.sndDecelerate.destroy();
this.sndIdle.destroy();
this.sndLoop.destroy();
this.sndShift.destroy();
this.sndStart.destroy();
}
}
export {EngineSound}
\ No newline at end of file
export {EngineSound};
'use strict';
class Player extends GameObject {
constructor(isLocal) {
super();
this.width = 2;
this.height = 2;
this.depth = 2;
this.sndStep = new SoundSource("steps/dirt.ogg");
this.sndStep.loop(true);
this.sndStep.howl.playbackRate = 1.3;
this.sndShoot = new SoundSource("Weapons/gun.ogg");
this.sndHurt = new SoundSource("player/hurt.ogg");
this.sndSpawn = new SoundSource("player/unduck.ogg");
this.sndDie = new SoundSource("player/die.ogg");
this.posHead = this.y+2;
this.posHands=this.x+1;
this.posFeet=this.x+0;
this.muffled=0;
this.frame = 0;
this.active=false;
this.id = null;
this.isLocal=isLocal;
this.oldIsLocal=isLocal;
this.health = 50;