Refactorthe score and make it global ...

Still full of bugs and crap ...
This commit is contained in:
Aaron Mueller 2013-04-18 21:55:26 +02:00
parent 4aff16516e
commit b4c3d98984
7 changed files with 31 additions and 27 deletions

View file

@ -19,13 +19,13 @@ ig.module(
_wmDrawBox: false,
collides: ig.Entity.COLLIDES.ACTIVE,
type: ig.Entity.TYPE.B,
animSheet: new ig.AnimationSheet( 'media/ball.png', 40, 40 ),
animSheet: new ig.AnimationSheet('media/ball.png', 40, 40),
bounciness: 1,
maxVel: {x: 1000, y: 1000},
init: function( x, y, settings ) {
this.parent( x, y, settings );
this.addAnim( 'idle', 1, [0] );
init: function(x, y, settings) {
this.parent(x, y, settings);
this.addAnim('idle', 1, [0]);
this.randomVel();
},
@ -33,8 +33,8 @@ ig.module(
this.startPos = {x: this.pos.x, y: this.pos.y};
},
collideWith: function( other, axis ) {
if (other.name == 'paddle') {
collideWith: function(other) {
if (other.name == 'paddle-enemy' || other.name == 'paddle-player') {
// the horizontal speed of the ball multiplied
// every time it hits a paddle
this.vel.x *= 1.15;
@ -43,6 +43,9 @@ ig.module(
// so that players can give the ball a spin
this.vel.y += other.vel.y/2;
// TODO: Moooar points on speed balls
// TODO: Moar points on edge hits
if (other.name == 'paddle-player') ig.global.score += 20;
this.hitSounds[Math.floor(Math.random()*4)].play();
}
},

View file

@ -17,7 +17,9 @@ ig.module(
check: function(other) {
if (other.name == 'ball') {
ig.global.score[this.owner] -= 1;
console.log(this.owner);
if (this.owner == 'player') ig.global.lifes -= 1;
if (this.owner == 'ai') ig.global.score += 2000;
other.reset();
this.looseSound.play();
}

View file

@ -7,6 +7,7 @@ ig.module(
)
.defines(function(){
EntityPaddleEnemy = EntityPaddle.extend({
name: 'paddle-enemy',
move_delay: 35,
update: function() {
var ball = ig.game.getEntitiesByType(EntityBall)[0];

View file

@ -6,12 +6,8 @@ ig.module(
)
.defines(function(){
EntityPaddlePlayer = EntityPaddle.extend({
animSheet: new ig.AnimationSheet('media/paddle-player_sheet.png', 30, 120),
/*anim: null,
init: function(){
this.anim = new ig.Animation( this.animSheet, 0.1, [0,1,2,3,4] );
},*/
name: 'paddle-player',
animSheet: new ig.AnimationSheet('media/paddle-player.png', 30, 120),
update: function(){
if (ig.input.state('up')) {

View file

@ -7,10 +7,6 @@ ig.module(
.defines(function(){
EntityPaddle = ig.Entity.extend({
name: 'paddle',
scores: 0, // TODO: whats this?
size: {x: 30, y: 120},
collides: ig.Entity.COLLIDES.FIXED,
type: ig.Entity.TYPE.A,
@ -19,9 +15,9 @@ EntityPaddle = ig.Entity.extend({
maxVel: {x: 0, y: 400},
init: function( x, y, settings ) {
this.parent( x, y, settings );
this.addAnim( 'idle', 1, [0] );
init: function(x, y, settings) {
this.parent(x, y, settings);
this.addAnim('idle', 1, [0]);
}
});

View file

@ -1,6 +1,6 @@
ig.module( 'game.levels.level1' )
.requires( 'impact.image','game.entities.paddle-enemy','game.entities.paddle-player','game.entities.ball','game.entities.goal' )
.defines(function(){
LevelLevel1=/*JSON[*/{"entities":[{"type":"EntityPaddleEnemy","x":8,"y":152},{"type":"EntityPaddlePlayer","x":584,"y":172},{"type":"EntityBall","x":299,"y":195},{"type":"EntityGoal","x":612,"y":48,"settings":{"size":{"x":12,"y":312},"owner":"human"}},{"type":"EntityGoal","x":0,"y":48,"settings":{"size":{"x":8,"y":312},"owner":"ai"}}],"layer":[{"name":"playfield","width":13,"height":8,"linkWithCollision":false,"visible":1,"tilesetName":"media/playfield.png","repeat":false,"preRender":false,"distance":"1","tilesize":48,"foreground":false,"data":[[1,2,3,4,5,6,7,8,9,10,11,12,13],[14,15,16,17,18,19,20,21,22,23,24,25,26],[27,28,81,81,31,81,33,36,36,36,36,36,39],[40,41,81,81,81,81,46,36,36,36,36,36,52],[53,54,81,81,81,81,59,36,36,36,36,36,65],[66,67,81,81,81,31,72,36,36,36,36,36,78],[79,80,81,80,81,81,85,36,36,36,36,36,91],[92,93,94,95,96,97,98,99,100,101,102,103,104]]},{"name":"collision","width":26,"height":16,"linkWithCollision":false,"visible":0,"tilesetName":"","repeat":false,"preRender":false,"distance":1,"tilesize":24,"foreground":false,"data":[[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]}]}/*]JSON*/;
LevelLevel1=/*JSON[*/{"entities":[{"type":"EntityPaddleEnemy","x":8,"y":152},{"type":"EntityPaddlePlayer","x":584,"y":172},{"type":"EntityBall","x":299,"y":195},{"type":"EntityGoal","x":612,"y":48,"settings":{"size":{"x":12,"y":312},"owner":"player"}},{"type":"EntityGoal","x":0,"y":48,"settings":{"size":{"x":8,"y":312},"owner":"enemy"}}],"layer":[{"name":"playfield","width":13,"height":8,"linkWithCollision":false,"visible":1,"tilesetName":"media/playfield.png","repeat":false,"preRender":false,"distance":"1","tilesize":48,"foreground":false,"data":[[1,2,3,4,5,6,7,8,9,10,11,12,13],[14,15,16,17,18,19,20,21,22,23,24,25,26],[27,28,81,81,31,81,33,36,36,36,36,36,39],[40,41,81,81,81,81,46,36,36,36,36,36,52],[53,54,81,81,81,81,59,36,36,36,36,36,65],[66,67,81,81,81,31,72,36,36,36,36,36,78],[79,80,81,80,81,81,85,36,36,36,36,36,91],[92,93,94,95,96,97,98,99,100,101,102,103,104]]},{"name":"collision","width":26,"height":16,"linkWithCollision":false,"visible":0,"tilesetName":"","repeat":false,"preRender":false,"distance":1,"tilesize":24,"foreground":false,"data":[[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]}]}/*]JSON*/;
LevelLevel1Resources=[new ig.Image('media/playfield.png')];
});

View file

@ -23,7 +23,8 @@
init: function() {
ig.input.unbindAll();
ig.global.score = {'ai': 1, 'human': 1};
ig.global.lifes = 4; // increase this to 3
ig.global.score = 0;
// Menu navigation
ig.input.bind(ig.KEY.ESC, 'escape');
@ -65,8 +66,8 @@
}
}
// One player has won the game
if (ig.global.score.ai == 0 || ig.global.score.human == 0) {
// The game is over
if (ig.global.lifes == 0) {
ig.system.setGame(ScoreboardScreen);
}
@ -82,8 +83,8 @@
draw: function() {
ig.system.context.clearRect( 0 ,0, ig.system.realWidth, ig.system.realHeight );
this.parent(); // Draw entries and background
this.font.draw(ig.global.score.ai, 270, 25, ig.Font.ALIGN.CENTER);
this.font.draw(ig.global.score.human, 350, 25, ig.Font.ALIGN.CENTER);
this.font.draw(ig.global.score, 270, 25, ig.Font.ALIGN.CENTER);
this.font.draw(ig.global.lifes, 370, 25, ig.Font.ALIGN.CENTER);
if (this.showPause) {
if(this.pauseDialogAlpha < 1) {
@ -110,8 +111,12 @@
init: function() {
ig.input.bind(ig.KEY.ENTER, 'main-menu');
loadScores();
console.log('asdf');
},
update: function() {
console.log("asdfasdasdfsd");
if (ig.input.pressed('main-menu')) {
ig.system.setGame(StartScreen);
}
@ -119,6 +124,7 @@
},
loadScores: function() {
console.log('asdf');
$.post('https://www.scoreoid.com/api/getScores', this.scoreoid, function(data) {
console.log(data);
});
@ -130,7 +136,7 @@
draw: function() {
this.parent();
this.background.draw(0, 0);
this.font.draw('You ' + (ig.global.score.ai == 0 ? 'won!' : 'loose!'), 200, 50, ig.Font.ALIGN.CENTER);
this.font.draw('Score: ' + ig.global.score, 200, 50, ig.Font.ALIGN.CENTER);
this.font.draw('Press [ENTER] to move to the main menu', 200, 100, ig.Font.ALIGN.CENTER);
}
});