Clean up the main.js code and add a title screen.

This commit is contained in:
Aaron Mueller 2012-06-24 14:30:33 +02:00
parent e597f19d0e
commit a4d01fefdd
4 changed files with 84 additions and 77 deletions

View file

@ -5,25 +5,18 @@ ig.module(
'impact.entity'
)
.defines(function(){
EntityBall = ig.Entity.extend({
EntityBall = ig.Entity.extend({
name: 'ball',
size: {x: 24, y: 24},
collides: ig.Entity.COLLIDES.ACTIVE,
type: ig.Entity.TYPE.B,
animSheet: new ig.AnimationSheet( 'media/ball.png', 24, 24 ),
bounciness: 1,
maxVel: {x: 1000, y: 1000},
init: function( x, y, settings ) {
this.parent( x, y, settings );
this.addAnim( 'idle', 1, [0] );
this.randomVel();
},
@ -32,7 +25,7 @@ EntityBall = ig.Entity.extend({
},
collideWith: function( other, axis ) {
if(other.name == 'paddle') {
if (other.name == 'paddle') {
// the horizontal speed of the ball multiplied
// every time it hits a paddle
this.vel.x *= 1.15;
@ -45,17 +38,15 @@ EntityBall = ig.Entity.extend({
reset: function() {
this.randomVel();
this.pos.x = this.startPos.x;
this.pos.y = this.startPos.y;
},
randomVel: function() {
this.vel.x = (Math.random()*(100)) + 100;
if(Math.random() > .5) this.vel.x *= -1;
this.vel.y = (Math.random()*20) + 50;
this.vel.x = Math.random()*100+100;
if (Math.random() > .5) this.vel.x *= -1;
this.vel.y = Math.random()*20+50;
}
});
});
});

View file

@ -22,7 +22,6 @@ EntityGoal = ig.Entity.extend({
other.reset();
}
}
});
});

View file

@ -12,35 +12,52 @@ ig.module(
'game.levels.level1'
)
.defines(function(){
MyGame = ig.Game.extend({
// Load a font
RunningGame = ig.Game.extend({
font: new ig.Font( 'media/04b03.font.png' ),
init: function() {
ig.input.bind( ig.KEY.UP_ARROW, 'up' );
ig.input.bind( ig.KEY.DOWN_ARROW, 'down' );
ig.input.bind(ig.KEY.ESC, 'mainmenu');
ig.input.bind(ig.KEY.UP_ARROW, 'up');
ig.input.bind(ig.KEY.DOWN_ARROW, 'down');
// vim goodness
ig.input.bind(ig.KEY.K, 'up');
ig.input.bind(ig.KEY.J, 'down');
// Load the level
this.loadLevel( LevelLevel1 );
},
update: function() {
// Update all entities and backgroundMaps
this.parent();
// Add your own, additional update code here
if (ig.input.pressed('mainmenu')) ig.system.setGame(StartScreen);
this.parent(); // Update entries and background
},
draw: function() {
// Draw all entities and backgroundMaps
this.parent();
this.parent(); // Draw entries and background
}
});
StartScreen = ig.Game.extend({
background: new ig.Image('media/main_screen.png'),
init: function() {
ig.input.bind(ig.KEY.ENTER, 'start');
ig.input.bind(ig.KEY.SPACE, 'start');
},
update: function() {
if (ig.input.pressed('start')) ig.system.setGame(RunningGame);
this.parent();
},
draw: function() {
this.parent();
this.background.draw(0, 0);
}
});
// Start the Game with 60fps, a resolution of 640x400 (16:10), scaled
// up by a factor of 2
ig.main( '#canvas', StartScreen, 60, 624, 384, 1 );
});
// Start the Game with 60fps, a resolution of 640x400 (16:10), scaled
// up by a factor of 2
ig.main( '#canvas', MyGame, 60, 640, 400, 1 );
});

BIN
dev/media/main_screen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB