Skip to content
Browse files

messed with examples

  • Loading branch information...
1 parent e9b3ecc commit 04ba512a02f6e6371edf31e0c5466b9ca101c3ee @vonkow committed Apr 13, 2011
Showing with 113 additions and 113 deletions.
  1. +37 −37 examples/bouncy_balls/game.js
  2. +76 −76 examples/socoman/game.js
View
74 examples/bouncy_balls/game.js
@@ -1,7 +1,7 @@
var lagTimer = function() {
var worst = -25,
- timer = 1800;
- this.base = new rw.Ent('lag','text',150,20);
+ timer = 1800
+ this.base = new rw.Ent('lag','text',150,20)
this.text = {
text: 'Lag: ',
form: 'fill',
@@ -13,64 +13,64 @@ var lagTimer = function() {
this.update = function() {
var lag = rw.getLag();
if (timer>0) {
- if ((lag!=0)&&(lag>worst)) worst = lag;
- timer--;
+ if ((lag!=0)&&(lag>worst)) worst = lag
+ timer--
} else {
- worst = -25;
- timer = 1800;
+ worst = -25
+ timer = 1800
}
- this.text.text = 'Lag: '+rw.getLag()+'(ms) Worst: '+worst;
+ this.text.text = 'Lag: '+rw.getLag()+'(ms) Worst: '+worst
}
}
-var wallCount=0;
+var wallCount=0
var wall=function(type,x,y) {
- this.base = new rw.Ent('wall_'+wallCount++,' ',x,y);
- this.update=function() {};
- this.hitMap=[[type,['ball'],0,0,x,y]];
-};
+ this.base = new rw.Ent('wall_'+wallCount++,' ',x,y)
+ this.update=function() {}
+ this.hitMap=[[type,['ball'],0,0,x,y]]
+}
var ball = function(name, ty, dirX, dirY) {
- this.spdMod = 10*Math.random();
- this.base = new rw.Ent(name, ty, 40, 40);
- this.dirX = dirX;
- this.dirY = dirY;
- this.hit = false;
+ this.spdMod = 10*Math.random()
+ this.base = new rw.Ent(name, ty, 40, 40)
+ this.dirX = dirX
+ this.dirY = dirY
+ this.hit = false
this.update = function() {
- this.hit = false;
- (this.dirX=='r') ? this.base.move(this.spdMod,0) : this.base.move(-this.spdMod,0);
- (this.dirY=='d') ? this.base.move(0,this.spdMod) : this.base.move(0,-this.spdMod);
+ this.hit = false
+ ;(this.dirX=='r') ? this.base.move(this.spdMod,0) : this.base.move(-this.spdMod,0)
+ ;(this.dirY=='d') ? this.base.move(0,this.spdMod) : this.base.move(0,-this.spdMod)
}
if (ty=='ball') {
- this.hitMap=[['ball',['rWall','lWall','tWall','bWall','tri','ball'],20,20,20]];
+ this.hitMap=[['ball',['rWall','lWall','tWall','bWall','tri','ball'],20,20,20]]
} else if (ty=='tri') {
- this.hitMap=[['ball',['rWall','lWall','tWall','bWall','tri','ball'],0.001,40,40,40,20,0.001]];
+ this.hitMap=[['ball',['rWall','lWall','tWall','bWall','tri','ball'],0.001,40,40,40,20,0.001]]
} else if (ty=='box') {
- this.hitMap=[['ball',['rWall','lWall','tWall','bWall','tri','ball'],0,0,40,40]];
+ this.hitMap=[['ball',['rWall','lWall','tWall','bWall','tri','ball'],0,0,40,40]]
}
this.gotHit = function(by) {
if (this.hit==false) {
switch (by) {
case 'rWall':
- this.dirX = 'l';
- break;
+ this.dirX = 'l'
+ break
case 'lWall':
this.dirX = 'r';
- break;
+ break
case 'tWall':
- this.dirY = 'd';
- break;
+ this.dirY = 'd'
+ break
case 'bWall':
- this.dirY = 'u';
- break;
+ this.dirY = 'u'
+ break
case 'ball':
- (this.dirX=='r') ? this.dirX='l' : this.dirX='r';
- (this.dirY=='u') ? this.dirY='d' : this.dirY='u';
- this.base.wipeMove();
- this.spdMod = 10*Math.random();
- break;
+ (this.dirX=='r') ? this.dirX='l' : this.dirX='r'
+ ;(this.dirY=='u') ? this.dirY='d' : this.dirY='u'
+ this.base.wipeMove()
+ this.spdMod = 10*Math.random()
+ break
}
- this.hit=true;
+ this.hit=true
}
}
}
@@ -127,6 +127,6 @@ function startGame() {
.base.display(314, 122, 50).end()
.newEnt(new ball('ball_15', 'tri', 'r', 'u'))
.base.display(112, 392, 50).end()
- .start();
+ .start()
})
}
View
152 examples/socoman/game.js
@@ -107,106 +107,106 @@
[6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6]
*/
]
- ];
+ ]
function game(lData) {
var that = this,
tX = 1,
tY = 1,
- keyDelay = 0;
- this.lvl = [];
+ keyDelay = 0
+ this.lvl = []
for (var y=0; y<lData.length; y++) {
- this.lvl.push([]);
+ this.lvl.push([])
for (var x=0; x<lData[0].length; x++) {
- this.lvl[y].push(lData[y][x]);
+ this.lvl[y].push(lData[y][x])
if ((lData[y][x]==4)||(lData[y][x]==7)) {
- tX = x;
- tY = y;
+ tX = x
+ tY = y
}
}
}
function checkMove(d) {
if (d=='u') {
- var t = that.lvl[tY-1][tX];
+ var t = that.lvl[tY-1][tX]
if ((t==0)||(t==3)) {
- that.lvl[tY][tX]-=4;
- that.lvl[tY-1][tX]+=4;
- tY-=1;
+ that.lvl[tY][tX]-=4
+ that.lvl[tY-1][tX]+=4
+ tY-=1
} else if ((t==2)||(t==5)) {
- var t1 = that.lvl[tY-2][tX];
+ var t1 = that.lvl[tY-2][tX]
if ((t1==0)||(t1==3)) {
- that.lvl[tY][tX]-=4;
- that.lvl[tY-1][tX]+=2;
- that.lvl[tY-2][tX]+=2;
- tY-=1;
+ that.lvl[tY][tX]-=4
+ that.lvl[tY-1][tX]+=2
+ that.lvl[tY-2][tX]+=2
+ tY-=1
}
}
} else if (d=='d') {
- var t = that.lvl[tY+1][tX];
+ var t = that.lvl[tY+1][tX]
if ((t==0)||(t==3)) {
- that.lvl[tY][tX]-=4;
- that.lvl[tY+1][tX]+=4;
- tY+=1;
+ that.lvl[tY][tX]-=4
+ that.lvl[tY+1][tX]+=4
+ tY+=1
} else if ((t==2)||(t==5)) {
- var t1 = that.lvl[tY+2][tX];
+ var t1 = that.lvl[tY+2][tX]
if ((t1==0)||(t1==3)) {
- that.lvl[tY][tX]-=4;
- that.lvl[tY+1][tX]+=2;
- that.lvl[tY+2][tX]+=2;
- tY+=1;
+ that.lvl[tY][tX]-=4
+ that.lvl[tY+1][tX]+=2
+ that.lvl[tY+2][tX]+=2
+ tY+=1
}
}
} else if (d=='l') {
- var t = that.lvl[tY][tX-1];
+ var t = that.lvl[tY][tX-1]
if ((t==0)||(t==3)) {
- that.lvl[tY][tX]-=4;
- that.lvl[tY][tX-1]+=4;
- tX-=1;
+ that.lvl[tY][tX]-=4
+ that.lvl[tY][tX-1]+=4
+ tX-=1
} else if ((t==2)||(t==5)) {
- var t1 = that.lvl[tY][tX-2];
+ var t1 = that.lvl[tY][tX-2]
if ((t1==0)||(t1==3)) {
- that.lvl[tY][tX]-=4;
- that.lvl[tY][tX-1]+=2;
- that.lvl[tY][tX-2]+=2;
- tX-=1;
+ that.lvl[tY][tX]-=4
+ that.lvl[tY][tX-1]+=2
+ that.lvl[tY][tX-2]+=2
+ tX-=1
}
}
} else if (d=='r') {
// square and square above
- var t = that.lvl[tY][tX+1];
+ var t = that.lvl[tY][tX+1]
// if targ empty or goal
if ((t==0)||(t==3)) {
- that.lvl[tY][tX]-=4;
- that.lvl[tY][tX+1]+=4;
- tX+=1;
+ that.lvl[tY][tX]-=4
+ that.lvl[tY][tX+1]+=4
+ tX+=1
// elif box or boxgoal
} else if ((t==2)||(t==5)) {
// square past square above
- var t1 = that.lvl[tY][tX+2];
+ var t1 = that.lvl[tY][tX+2]
// if empty or goal
if ((t1==0)||(t1==3)) {
- that.lvl[tY][tX]-=4;
- that.lvl[tY][tX+1]+=2;
- that.lvl[tY][tX+2]+=2;
- tX+=1;
+ that.lvl[tY][tX]-=4
+ that.lvl[tY][tX+1]+=2
+ that.lvl[tY][tX+2]+=2
+ tX+=1
}
}
}
}
- this.base = new rw.Rule(0);
+ this.base = new rw.Rule(0)
this.rule = function() {
- var victory = true;
+ var victory = true
for (var y=0, ylen=this.lvl.length; y<ylen; y++) {
for (var x=0, xlen=this.lvl.length; x<xlen; x++) {
- if (this.lvl[y][x]==2) victory = false;
+ if (this.lvl[y][x]==2) victory = false
}
}
if (victory) {
if (curLvl<lvls.length-1){
- makeGame(++curLvl);
+ makeGame(++curLvl)
} else {
rw.stop(function() {
- alert('victory is yours!');
- });
+ alert('victory is yours!')
+ })
}
}
if (keyDelay==0) {
@@ -216,71 +216,71 @@
(rw.key('la')) ? (checkMove('l'), keyDelay=5) :
(rw.key('r')) ? makeGame(curLvl) :
(rw.key('n')) ? checkMake(curLvl+1) :
- (rw.key('b')) ? checkMake(curLvl-1) : true;
+ (rw.key('b')) ? checkMake(curLvl-1) : true
} else {
- keyDelay--;
+ keyDelay--
}
}
}
function square(tY,tX) {
- this.base = new rw.Ent(tY+'_'+tX, 'wall', 16, 16);
+ this.base = new rw.Ent(tY+'_'+tX, 'wall', 16, 16)
this.update = function() {
var stat = rw.rules['game'].lvl[tY][tX],
- img = 'none';
+ img = 'none'
if (stat==1) {
- img = 'wall';
+ img = 'wall'
} else if (stat==2) {
- img = 'box';
+ img = 'box'
} else if (stat==3) {
- img = 'area';
+ img = 'area'
} else if (stat==4) {
- img = 'man';
+ img = 'man'
} else if (stat==5) {
- img = 'boxdone';
+ img = 'boxdone'
} else if (stat==7) {
- img = 'manarea';
+ img = 'manarea'
}
- this.base.changeSprite(img);
+ this.base.changeSprite(img)
}
};
function checkMake(lv) {
if (lv>=0) {
if (lv<lvls.length) {
- curLvl = lv;
- makeGame(curLvl);
+ curLvl = lv
+ makeGame(curLvl)
} else {
- makeGame(curLvl);
+ makeGame(curLvl)
}
} else {
- makeGame(curLvl);
+ makeGame(curLvl)
}
}
function makeGame(lv) {
rw.stop(function() {
- rw.wipeAll();
- rw.newRule('game', new game(lvls[lv]));
+ rw.wipeAll()
+ rw.newRule('game', new game(lvls[lv]))
for (var y=0, ylen=lvls[lv].length; y<ylen; y++) {
for (var x=0, xlen=lvls[lv][y].length; x<xlen; x++) {
- rw.newEnt(new square(y, x)).base.display(16*x,16*y);
+ rw.newEnt(new square(y, x)).base.display(16*x,16*y)
}
}
- rw.start();
- });
+ rw.start()
+ })
}
- var curLvl = 0;
+ var curLvl = 0
function start() {
rw.init('playarea', {
x:320,
y:240,
sequence:['rule','ents','blit'],
keys:['ua','da','ra','la','n','b','r']
- }).setFPS(30).start();
- makeGame(curLvl);
- };
+ }).setFPS(30).start()
+ makeGame(curLvl)
+ }
rw.loadSprites({
'man': ['sprites/man.png',16,16,0,0],
'manarea': ['sprites/manarea.png',16,16,0,0],
@@ -290,6 +290,6 @@
'boxdone': ['sprites/boxdone.png',16,16,0,0],
'wall': ['sprites/wall.png',16,16,0,0],
}, function() {
- start();
- });
-})();
+ start()
+ })
+})()

0 comments on commit 04ba512

Please sign in to comment.
Something went wrong with that request. Please try again.