|
@@ -13,10 +13,15 @@ var opponentspeedfactor=0.75;
|
|
|
var fatdownloadsize=130;
|
|
|
var score=0;
|
|
|
var fatscore=0;
|
|
|
+var fwscore=0;
|
|
|
var fatrisk=false;
|
|
|
var stext;
|
|
|
var fstext;
|
|
|
+var fwtext;
|
|
|
var fdcs=15;
|
|
|
+var shightext;
|
|
|
+var fhightext;
|
|
|
+var fwhightext;
|
|
|
var game = new Phaser.Game(width, height, Phaser.CANVAS, 'gameContainer', { preload: preload, create: create, update: update, render: render });
|
|
|
|
|
|
function preload() {
|
|
@@ -26,13 +31,14 @@ function preload() {
|
|
|
game.load.image('opponent2', 'opponent2.png');
|
|
|
game.load.image('opponent2b', 'opponent2b.png');
|
|
|
game.load.image('background', 'background.png');
|
|
|
-
|
|
|
+ game.load.image('firewall', 'firewall.png');
|
|
|
}
|
|
|
|
|
|
var player;
|
|
|
var pad;
|
|
|
var opponents=[];
|
|
|
var fatdownload=[];
|
|
|
+var firewall=[];
|
|
|
var bg;
|
|
|
function create() {
|
|
|
|
|
@@ -49,8 +55,9 @@ function create() {
|
|
|
|
|
|
player = game.add.sprite((width/2)-16,height-200,'player')
|
|
|
this.game.physics.enable(player, Phaser.Physics.ARCADE);
|
|
|
- player.body.drag.set(0.2);
|
|
|
- player.body.maxVelocity.setTo(400, 400);
|
|
|
+ //player.body.drag.set(0.2);
|
|
|
+ player.body.setSize(player.width,player.height/2,0,player.height/4);
|
|
|
+ //player.body.maxVelocity.setTo(400, 400);
|
|
|
player.body.collideWorldBounds = true;
|
|
|
game.input.gamepad.start();
|
|
|
initOpponents();
|
|
@@ -63,11 +70,39 @@ function create() {
|
|
|
fill: "#ff0044",
|
|
|
align: "center"
|
|
|
});
|
|
|
- fstext = game.add.text(10, 80, "Fat downloads:0",{
|
|
|
+ fstext = game.add.text(10, 80, "Long downloads:0",{
|
|
|
+ font: "30px arial",
|
|
|
+ fill: "#ff0044",
|
|
|
+ align: "center"
|
|
|
+ });
|
|
|
+ fwtext = game.add.text(10, 120, "Firewalls:0",{
|
|
|
+ font: "30px arial",
|
|
|
+ fill: "#ff0044",
|
|
|
+ align: "center"
|
|
|
+ });
|
|
|
+
|
|
|
+ game.add.text(10, height-160, "Highscore:",{
|
|
|
+ font: "30px arial",
|
|
|
+ fill: "#ff0044",
|
|
|
+ align: "center"
|
|
|
+ });
|
|
|
+
|
|
|
+ shightext=game.add.text(10, height-120, "No Highscore saved",{
|
|
|
+ font: "30px arial",
|
|
|
+ fill: "#ff0044",
|
|
|
+ align: "center"
|
|
|
+ });
|
|
|
+ fhightext=game.add.text(10, height-80, "No Highscore saved",{
|
|
|
font: "30px arial",
|
|
|
fill: "#ff0044",
|
|
|
align: "center"
|
|
|
});
|
|
|
+ fwhightext=game.add.text(10, height-40, "No Highscore saved:",{
|
|
|
+ font: "30px arial",
|
|
|
+ fill: "#ff0044",
|
|
|
+ align: "center"
|
|
|
+ });
|
|
|
+ updateHighscore();
|
|
|
}
|
|
|
|
|
|
function initOpponents()
|
|
@@ -78,7 +113,8 @@ function initOpponents()
|
|
|
var flubberflargh = game.add.sprite(0,-100,(bx?'opponent':'opponentb'));
|
|
|
this.game.physics.enable(flubberflargh, Phaser.Physics.ARCADE);
|
|
|
flubberflargh.body.drag.set(0.2);
|
|
|
- flubberflargh.body.maxVelocity.setTo(400, 400);
|
|
|
+ //flubberflargh.body.maxVelocity.setTo(400, 400);
|
|
|
+ flubberflargh.body.setSize(flubberflargh.width-4,flubberflargh.height-4-(bx?8:0),2,2+(bx?4:0));
|
|
|
opponents[oc]=flubberflargh;
|
|
|
}
|
|
|
for(var fc=0;fc<fatdownloadsize;fc++)
|
|
@@ -87,8 +123,23 @@ function initOpponents()
|
|
|
var blubberlutsch = game.add.sprite(0,-100-(fdcs*fc),(b?'opponent2':'opponent2b'));
|
|
|
this.game.physics.enable(blubberlutsch, Phaser.Physics.ARCADE);
|
|
|
blubberlutsch.body.drag.set(0.2);
|
|
|
- blubberlutsch.body.maxVelocity.setTo(400, 400);
|
|
|
+ //blubberlutsch.body.maxVelocity.setTo(400, 400);
|
|
|
+ blubberlutsch.body.setSize(blubberlutsch.width-4,blubberlutsch.height,2,0);
|
|
|
fatdownload[fc]=blubberlutsch;
|
|
|
+
|
|
|
+ }
|
|
|
+ for(var fwc=0;fwc<3;fwc++)
|
|
|
+ {//preseed of fatdl cache
|
|
|
+ //var b=game.rnd.between(0,4)>1;
|
|
|
+ var blubberlutsch = game.add.sprite(0,-500,'firewall');
|
|
|
+ this.game.physics.enable(blubberlutsch, Phaser.Physics.ARCADE);
|
|
|
+ blubberlutsch.body.drag.set(0.2);
|
|
|
+ //blubberlutsch.body.maxVelocity.setTo(400, 400);
|
|
|
+ blubberlutsch.scale.y=0.25;
|
|
|
+ //hässlicher hack wegen verschieberitis
|
|
|
+ blubberlutsch.body.immovable=true;
|
|
|
+
|
|
|
+ firewall[fwc]=blubberlutsch;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -120,7 +171,8 @@ function update() {
|
|
|
bg.tilePosition.y += 10;
|
|
|
|
|
|
stext.setText("Packets:"+score);
|
|
|
- fstext.setText("Fat downloads:"+fatscore);
|
|
|
+ fstext.setText("Long downloads:"+fatscore);
|
|
|
+ fwtext.setText("Firewalls:"+fwscore);
|
|
|
if(pad&&pad._rawPad)
|
|
|
{
|
|
|
var vx =0;
|
|
@@ -199,6 +251,22 @@ function update() {
|
|
|
game.physics.arcade.collide(player, opn,
|
|
|
gameover,
|
|
|
function(){return true}, this);
|
|
|
+ //runterrauschenden traffic nullrouten
|
|
|
+ var blubb = function()
|
|
|
+ {
|
|
|
+ opn.body.velocity.y=0;
|
|
|
+ opn.y=-100; //müssen hintenraus geschossen werden sonst datensalat;
|
|
|
+ }
|
|
|
+
|
|
|
+ game.physics.arcade.collide(firewall[0],opn ,
|
|
|
+ blubb,
|
|
|
+ function(){return true}, this);
|
|
|
+ game.physics.arcade.collide(firewall[1],opn ,
|
|
|
+ blubb,
|
|
|
+ function(){return true}, this);
|
|
|
+ game.physics.arcade.collide(firewall[2],opn ,
|
|
|
+ blubb,
|
|
|
+ function(){return true}, this);
|
|
|
}
|
|
|
if(ocb%opponentpause==0)
|
|
|
{
|
|
@@ -230,6 +298,46 @@ function update() {
|
|
|
//ocb++;
|
|
|
}
|
|
|
ocb=(ocb+1)%(opponentcount*opponentpause);
|
|
|
+ var firewallchance = game.rnd.between(0,100000);
|
|
|
+ if(firewallchance>99995&&firewall[0].y<-400)
|
|
|
+ {
|
|
|
+ var firstport = game.rnd.between(tqwbase,tqwbase+tqwidth/2);
|
|
|
+ var secondport = game.rnd.between(tqwbase+tqwidth/2,tqwbase+tqwidth);
|
|
|
+ //firewall segment width = 1000
|
|
|
+ fw0width = (firstport-tqwbase);
|
|
|
+ firewall[0].x=tqwbase;
|
|
|
+ firewall[0].scale.x=fw0width/1000;
|
|
|
+ firewall[0].y=-350;
|
|
|
+ firewall[0].body.velocity.y=50;
|
|
|
+ firewall[0].body.setSize(1000, 60, 0, 30);
|
|
|
+
|
|
|
+ fw1base = firstport+10+player.width;
|
|
|
+ var fw1width = secondport-fw1base;
|
|
|
+ firewall[1].x=fw1base;
|
|
|
+ firewall[1].scale.x=(fw1width)/1000;
|
|
|
+ firewall[1].y=-350;
|
|
|
+ firewall[1].body.velocity.y=50;
|
|
|
+ firewall[1].body.setSize(1000, 60, 0, 30);
|
|
|
+ fw2base = secondport+10+player.width;
|
|
|
+ fw2width = width-tqwbase-fw2base;
|
|
|
+ firewall[2].x=fw2base;
|
|
|
+ firewall[2].scale.x=fw2width/1000;
|
|
|
+ firewall[2].y=-350;
|
|
|
+ firewall[2].body.velocity.y=50;
|
|
|
+ firewall[2].body.setSize(1000, 60, 0, 30);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(firewall[0].y>height)
|
|
|
+ {
|
|
|
+ fwscore++;
|
|
|
+ firewall[0].y=-500
|
|
|
+ firewall[0].body.velocity.y=0;
|
|
|
+ firewall[1].y=-500
|
|
|
+ firewall[1].body.velocity.y=0;
|
|
|
+ firewall[2].y=-500
|
|
|
+ firewall[2].body.velocity.y=0;
|
|
|
+ }
|
|
|
+
|
|
|
var fdc = game.rnd.between(0,1000);
|
|
|
if(fdc>500&&fatdownload[0].y<-50)
|
|
|
{
|
|
@@ -253,6 +361,27 @@ function update() {
|
|
|
game.physics.arcade.collide(player,fds ,
|
|
|
gameover,
|
|
|
function(){return true}, this);
|
|
|
+
|
|
|
+ //runterrauschenden traffic nullrouten
|
|
|
+ var blubb = function()
|
|
|
+ {
|
|
|
+ fds.body.velocity.y=0;
|
|
|
+ fds.y=height+500; //müssen hintenraus geschossen werden sonst datensalat, und nicht gescored;
|
|
|
+ }
|
|
|
+ if(firewall[0].y>-300)
|
|
|
+ {
|
|
|
+ game.physics.arcade.collide(firewall[0],fds ,
|
|
|
+ blubb,
|
|
|
+ function(){return true}, this);
|
|
|
+ game.physics.arcade.collide(firewall[1],fds ,
|
|
|
+ blubb,
|
|
|
+ function(){return true}, this);
|
|
|
+ game.physics.arcade.collide(firewall[2],fds ,
|
|
|
+ blubb,
|
|
|
+ function(){return true}, this);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -275,7 +404,10 @@ function update() {
|
|
|
}
|
|
|
if(fatdownload[fatdownloadsize-1].y>height)
|
|
|
{
|
|
|
- fatscore++;
|
|
|
+ if(fatdownload[fatdownloadsize-1].y<height+200)
|
|
|
+ {
|
|
|
+ fatscore++;
|
|
|
+ }
|
|
|
fatrisk=false;
|
|
|
for(var fc=0;fc<fatdownloadsize;fc++)
|
|
|
{
|
|
@@ -285,13 +417,56 @@ function update() {
|
|
|
fds.body.velocity.y=0;
|
|
|
}
|
|
|
}
|
|
|
+ game.physics.arcade.collide(firewall[0],player ,
|
|
|
+ gameoverFW,
|
|
|
+ function(){return true}, this);
|
|
|
+ game.physics.arcade.collide(firewall[1],player ,
|
|
|
+ gameoverFW,
|
|
|
+ function(){return true}, this);
|
|
|
+ game.physics.arcade.collide(firewall[2],player ,
|
|
|
+ gameoverFW,
|
|
|
+ function(){return true}, this);
|
|
|
}
|
|
|
|
|
|
+function writeScore(scorekey,value)
|
|
|
+{
|
|
|
+ if(localStorage.getItem(scorekey) === null)
|
|
|
+ {
|
|
|
|
|
|
-function gameover()
|
|
|
+ localStorage.setItem(scorekey,value);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ else if(value > localStorage.getItem(scorekey))
|
|
|
+ {
|
|
|
+
|
|
|
+ localStorage.setItem(scorekey,value);
|
|
|
+ }
|
|
|
+}
|
|
|
+function updateHighscore()
|
|
|
+{
|
|
|
+ updateHighscoreInternal('packets',shightext,'Packets:');
|
|
|
+ updateHighscoreInternal('fatdownloasds',fhightext,'Long downloads:');
|
|
|
+ updateHighscoreInternal('firewalls',fwhightext,'Firewalls:');
|
|
|
+}
|
|
|
+function updateHighscoreInternal(scorekey,scoretext,scorelabel)
|
|
|
+{
|
|
|
+ var value =localStorage.getItem(scorekey)
|
|
|
+ if(value != null)
|
|
|
+ {
|
|
|
+ scoretext.setText(scorelabel+value);
|
|
|
+ }
|
|
|
+}
|
|
|
+function gameoverpre()
|
|
|
{
|
|
|
+ writeScore('packets',score);
|
|
|
+ writeScore('fatdownloasds',fatscore);
|
|
|
+ writeScore('firewalls',fwscore);
|
|
|
+ updateHighscore()
|
|
|
+
|
|
|
score=0;
|
|
|
fatscore=0;
|
|
|
+ fwscore=0;
|
|
|
for(var p=0;p<opponentcount;p++)
|
|
|
{
|
|
|
var o = opponents[p];
|
|
@@ -304,12 +479,35 @@ function gameover()
|
|
|
r.exists=false;
|
|
|
fatdownload[q]=null;
|
|
|
}
|
|
|
- console.log("Ätschebätsche");
|
|
|
- alert("Packet Loss");
|
|
|
+ for(var q=0;q<3;q++)
|
|
|
+ {
|
|
|
+ var r = firewall[q];
|
|
|
+ r.exists=false;
|
|
|
+ firewall[q]=null;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function gameoverpost()
|
|
|
+{
|
|
|
initOpponents();
|
|
|
player.y=height-200;
|
|
|
player.body.velocity.y=0;
|
|
|
}
|
|
|
+
|
|
|
+function gameover()
|
|
|
+{
|
|
|
+ gameoverpre();
|
|
|
+ console.log("Ätschebätsche");
|
|
|
+ alert("Packet Loss");
|
|
|
+ gameoverpost();
|
|
|
+}
|
|
|
+function gameoverFW()
|
|
|
+{
|
|
|
+ gameoverpre();
|
|
|
+ console.log("Ätschebätsche");
|
|
|
+ alert("Filtered by a firewall");
|
|
|
+ gameoverpost();
|
|
|
+}
|
|
|
function onDown(button, value) {
|
|
|
/*
|
|
|
if (button.buttonCode === Phaser.Gamepad.XBOX360_A)
|
|
@@ -337,8 +535,11 @@ function onUp(button, value) {
|
|
|
|
|
|
function render () {
|
|
|
|
|
|
+ //game.debug.body(firewall[0]);
|
|
|
+ //game.debug.body(firewall[1]);
|
|
|
+ //game.debug.body(firewall[2]);
|
|
|
// game.debug.text(game.time.physicsElapsed, 32, 32);
|
|
|
- // game.debug.body(player);
|
|
|
+ //game.debug.body(player);
|
|
|
// game.debug.bodyInfo(player, 16, 24);
|
|
|
|
|
|
}
|