Commit c5799b70 by Oriol Gómez

changes

parent b92421c7
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -46,45 +46,46 @@ soundObject.playOnce("g_nokill")
}
else {
this.killers--;
game.killInsects()
this.killInsects()
sKill.play()
this.spawner.reset()
}
break;
case KeyEvent.DOM_VK_S:
speech.speak(game.score)
speech.speak(this.score)
break;
case KeyEvent.DOM_VK_RIGHT:
game.hit(3)
this.hit(3)
break;
case KeyEvent.DOM_VK_DOWN:
game.hit(2)
this.hit(2)
break;
case KeyEvent.DOM_VK_LEFT:
game.hit(1)
this.hit(1)
break;
case KeyEvent.DOM_VK_PAGE_UP:
game.musicVolume+=0.2;
game.music.volume=game.musicVolume;
this.musicVolume+=0.2;
this.music.volume=this.musicVolume;
break;
case KeyEvent.DOM_VK_PAGE_DOWN:
game.musicVolume-=0.2;
game.music.volume=game.musicVolume;
this.musicVolume-=0.2;
this.music.volume=this.musicVolume;
break;
case KeyEvent.DOM_VK_I:
ins=new Insect();
ins.position=game.enemies.push(ins)
ins.position=this.enemies.push(ins)
break;
}
}
reset() {
this.btime=randomInt(8000,20000);
this.musicVolume=1;
this.shields=0;
this.kills=0;
this.bcount=0;
this.btime=randomInt(8000,20000);
this.btimer.reset()
this.btimer.reset();
this.hp=100;
this.spawner.reset();
this.spawn=2000;
......@@ -92,71 +93,71 @@ this.score=0;
this.levcounter=3;
this.curcounter=0;
this.score=0;
this.enemies.splice()
this.enemies.splice();
this.level=1;
this.misses=0;
this.hits=0;
this.mode="insects";
this.curcounter=0;
this.rewart.reset()
this.rewart.reset();
this.reward=0;
}
killInsects() {
game.enemies.forEach(function(insect) {
this.enemies.forEach(function(insect) {
insect.destroy()
})
}
looper() {
if (game.spawner.elapsed>=game.spawn) {
game.spawner.reset();
game.spawn=randomInt(2000-(game.level*200),3000-(game.level*100));
var ins=new Insect()
game.enemies.push(ins)
if (this.spawner.elapsed>=this.spawn) {
this.spawner.reset();
this.spawn=randomInt(2000-(this.level*200),3000-(this.level*100));
var ins=new Insect();
this.enemies.push(ins);
}
}
hit(position) {
var hit=false;
var vol=-100;
var v=-1
for (var i=0;i<game.enemies.length-1;i++) {
if (game.enemies[i].vol>vol & game.enemies[i].pos==position) {
vol=game.enemies[i].volume
v=i
var v=-1;
for (var i=0;i<this.enemies.length-1;i++) {
if (this.enemies[i].vol>vol & this.enemies[i].pos==position) {
vol=this.enemies[i].volume;
v=i;
}//if
}//for
var v1=null;
var v2=null;
if (v==-1) v1=0;
if (v==-1) v2=game.enemies.length-1
if (v==-1) v2=this.enemies.length-1;
if (v!=-1) v1=v;
if (v!=-1) v2=v;
for (var i=v1;i<=v2;i++) {
if (game.enemies[i].pos==position) {
if (this.enemies[i].pos==position) {
hit=true;
var cs;
var v=game.enemies[i].vol
cs=game.level+(30+Math.abs(v)*100);
game.score+=cs;
game.enemies[i].die()
game.curcounter++;
if (game.curcounter>=game.levcounter) {
game.level++;
game.music.playbackRate+=0.05;
game.levcounter=game.level;
soundObject.playOnce("g_level")
game.curcounter=0;
var v=this.enemies[i].vol;
cs=this.level+(30+Math.abs(v)*100);
this.score+=cs;
this.enemies[i].die();
this.curcounter++;
if (this.curcounter>=this.levcounter) {
this.level++;
this.music.playbackRate+=0.05;
this.levcounter=this.level;
soundObject.playOnce("g_level");
this.curcounter=0;
}//if level
}//if position
}//for
if(!hit) {
var miss=soundObject.create(game.mode+"/miss");
var miss=soundObject.create(this.mode+"/miss");
var pan=miss.effects.add(sono.panner())
switch(position) {
case 1:pan.set(-1); break;
case 2:pan.set(0); break;
case 3:pan.set(1); break;
}
game.score-=game.level*10;
this.score-=this.level*10;
}//hit not
}
}
......
"use strict";
import {getRandomArbitrary,getRandomInt} from 'util'
import {TTS,useWebTTS} from 'tts'
if (typeof speech == "undefined") var speech = new TTS();
import $ from 'jquery'
......@@ -49,6 +50,8 @@ function playIntro() {
}
function startGame() {
console.log(getRandomArbitrary(12,20));
//console.log(randomInt(12,20));
if (game!=null & game.music!=null) {
game.music.stop();
......@@ -107,21 +110,20 @@ soundObject.loadQueue();
export function playGame() {
soundObject.setCallback(null);
soundObject.setQueueCallback(null);
inp=new KeyboardInput()
inp.init()
inp=new KeyboardInput();
inp.init();
inp.justPressedEventCallback=game.pressKey;
sKill=soundObject.create("g_kill")
game.reset()
game.music=soundObject.create("g_bgm")
sKill=soundObject.create("g_kill");
game.reset();
game.music=soundObject.create("g_bgm");
game.music.loop=true;
game.music.play()
sDeath=soundObject.create("g_death")
game.music.play();
sDeath=soundObject.create("g_death");
tick=window.setInterval(function() {
game.enemies.forEach(function(insect) { insect.tick();
})
game.looper()
game.looper();
},16)
}
function speakProg(progress) {
if (sndProgress == null) sndProgress = soundObject.create("ui/loading");
......
'use strict';
export function distance3D(x1, y1, z1, x2, y2, z2) {
function distance3D(x1, y1, z1, x2, y2, z2) {
return Math.sqrt((x2-x1)*(x2-x1) +
(y2-y1)*(y2-y1) +
(z2-z1)*(z2-z1));
}
export function distance(jx, jy, kx, ky) {
function distance(jx, jy, kx, ky) {
//return Math.hypot(jx-kx, jy-ky)
return Math.sqrt(((jx - kx) * (jx - kx)) + ((jy - ky)) * (jy - ky))
}
export function calculateAngle(x1, y1, x2, y2) {
function calculateAngle(x1, y1, x2, y2) {
var angle = Math.atan2((y2-y1), (x2-x1));
angle = (angle >= 0) ? 0 : (2*Math.PI) + angle;
return angle;
// return Math.atan2((y2 - y1),(x2 - x1));
}
export function isCollide3D(a, b)
function isCollide3D(a, b)
{
return(a.x <= (b.x+b.width) && (a.x+a.width) >= b.x)&&(a.y <= (b.y+b.height) && (a.y+a.height) >= b.y)&&(a.z <= (b.z+b.depth) && (a.z+a.depth) >= b.z);
}
export function randomInt(min, max) {
function randomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
export function getRandomArbitrary(min, max) {
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
export {distance3D,distance,calculateAngle,isCollide3D,randomInt,getRandomArbitrary}
\ No newline at end of file
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