Commit 8b7d6049 by ogomez92

walls

parent c0076497
import uniqueRandom from 'unique-random';
import {speech} from './tts';
import {Ray} from './ray';
import {SoundHandler} from './soundHandler.js';
import {OldTimer} from './oldtimer';
export default class Player {
......@@ -38,39 +39,22 @@ export default class Player {
}
}
move() {
this.position = [this.x + (Math.sin(this.alpha) * (this.speed/2)), 0, this.z - (Math.cos(this.alpha) * (this.speed/2))];
this.position = [this.x + (Math.sin(this.alpha) * (this.speed/2)), 0, this.z + (Math.cos(this.alpha) * (this.speed/2))];
this.stepCounter += this.speed;
if (this.stepCounter >= 1) {
this.stepCounter = 0;
this.sounds.playStatic('run_1');
//speech.speak(this.x+", "+this.z);
this.checkwalls();
this.checkWalls();
}
}
checkwalls() {
checkWalls() {
this.zWall=0;
this.xWall=0;
this.wallMultiplier=50;
//z
console.log(this.world.size," ",this.z);
for (let i=Math.floor(this.z);i<this.world.size;i++) {
if (this.world.map[Math.floor(i)][1]==0){
this.zWall++;
}
else {
speech.speak(this.zWall);
break;
}
}
//x
for (let i=Math.floor(this.x);i<this.world.size;i++) {
if (this.world.map[i][0]==0){
this.xWall++;
}
else {
break;
}
}
this.frontRay=new Ray(this);
let result=this.frontRay.scanWall(100,this.alpha);
speech.speak(result.distance);
/*
if (this.zWall>2 && this.zWall<11) {
if (this.zTimer.elapsed>this.zWall*this.wallMultiplier) {
//this.frontPan.setPosition(this.x,0,1);
......@@ -79,5 +63,6 @@ speech.speak("ok");
this.zTimer.restart();
}
}
*/
}
}
import {speech} from './tts';
class Ray {
constructor(player) {
this.result={
distance:0,
x:0,
y:0,
z:0,
}
this.player=player;
this.x = this.player.x;
this.y = this.player.y;
this.z = this.player.z;
this.alpha = this.player.alpha;
}
get position() {
return [this.x, this.y, this.z];
}
set position(pos) {
this.x = pos[0];
this.y = pos[1];
this.z = pos[2];
}
scanWall(amount=100,alpha=0) {
this.limit=amount;
//this function moves a ray (shadow) of the player by x(amount) units.
//it checks if a wall is there, if so it returns an object with the distance, x y and z of the wall.
this.distanceToWall=0;
this.alpha=alpha;
let foundWall=false;
let count=0;
this.result={};
while (!foundWall && count<=amount) { //let's not create unending loops
count++;
this.x=this.x + (Math.sin(this.alpha));
this.z=this.z + (Math.cos(this.alpha));
this.distanceToWall++;
//the following if condition checks if either x or z are more than 0 or max grid size.
console.log("check "+count+": "+this.z);
if (this.x<1 || this.x>this.player.world.size || this.z<1 || this.z>this.player.world.size) {
foundWall=true;
this.result={
distance:this.distanceToWall,
x:this.x,
y:this.y,
z:this.z,
}
}
else {
}
}
return this.result;
}
}
export {Ray}
\ No newline at end of file
......@@ -3,8 +3,7 @@ var isElectron = true;
var playOnceTimer;
class SoundObjectItem {
constructor(file, callback=0, tag=0) {
console.log("type "+typeof file);
this.fileName = file;
this.fileName = file;
if (typeof file=="string") {
......
......@@ -9,22 +9,9 @@ export default class World {
static: [],
dynamic: []
};
this.size=40;
this.size=50;
panner.defaults.maxDistance=this.size;
this.map=[[]];
for (let i=0;i<this.size;i++) {
this.map[i]=[0,0];
for (let j=0;j<this.size;j++) {
this.map[i][j]=0;
}
}
for (let i=0;i<this.size;i++) {
this.map[i][0]=1;
this.map[i][this.size-1]=1;
this.map[0][i]=1;
this.map[this.size-1][i]=1;
}
this.player = new Player(this);
this.player = new Player(this);
this.sides=son.create("beep_sides");
this.sidesPan=this.sides.sound.effects.add(panner());
this.front=son.create("beep_front");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment