Clean up the main.js code and add a title screen.
This commit is contained in:
parent
e597f19d0e
commit
a4d01fefdd
4 changed files with 84 additions and 77 deletions
|
@ -5,57 +5,48 @@ ig.module(
|
|||
'impact.entity'
|
||||
)
|
||||
.defines(function(){
|
||||
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},
|
||||
|
||||
EntityBall = ig.Entity.extend({
|
||||
init: function( x, y, settings ) {
|
||||
this.parent( x, y, settings );
|
||||
this.addAnim( 'idle', 1, [0] );
|
||||
this.randomVel();
|
||||
},
|
||||
|
||||
name: 'ball',
|
||||
ready: function() {
|
||||
this.startPos = {x: this.pos.x, y: this.pos.y};
|
||||
},
|
||||
|
||||
size: {x: 24, y: 24},
|
||||
collides: ig.Entity.COLLIDES.ACTIVE,
|
||||
type: ig.Entity.TYPE.B,
|
||||
collideWith: function( other, axis ) {
|
||||
if (other.name == 'paddle') {
|
||||
// the horizontal speed of the ball multiplied
|
||||
// every time it hits a paddle
|
||||
this.vel.x *= 1.15;
|
||||
|
||||
animSheet: new ig.AnimationSheet( 'media/ball.png', 24, 24 ),
|
||||
// the paddles y movement is added to the ball,
|
||||
// so that players can give the ball a spin
|
||||
this.vel.y += other.vel.y/2;
|
||||
}
|
||||
},
|
||||
|
||||
bounciness: 1,
|
||||
maxVel: {x: 1000, y: 1000},
|
||||
|
||||
init: function( x, y, settings ) {
|
||||
this.parent( x, y, settings );
|
||||
|
||||
this.addAnim( 'idle', 1, [0] );
|
||||
|
||||
this.randomVel();
|
||||
},
|
||||
|
||||
ready: function() {
|
||||
this.startPos = {x: this.pos.x, y: this.pos.y};
|
||||
},
|
||||
|
||||
collideWith: function( other, axis ) {
|
||||
if(other.name == 'paddle') {
|
||||
// the horizontal speed of the ball multiplied
|
||||
// every time it hits a paddle
|
||||
this.vel.x *= 1.15;
|
||||
|
||||
// the paddles y movement is added to the ball,
|
||||
// so that players can give the ball a spin
|
||||
this.vel.y += other.vel.y/2;
|
||||
}
|
||||
},
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -22,7 +22,6 @@ EntityGoal = ig.Entity.extend({
|
|||
other.reset();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -12,35 +12,52 @@ ig.module(
|
|||
'game.levels.level1'
|
||||
)
|
||||
.defines(function(){
|
||||
RunningGame = ig.Game.extend({
|
||||
font: new ig.Font( 'media/04b03.font.png' ),
|
||||
|
||||
MyGame = ig.Game.extend({
|
||||
init: function() {
|
||||
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 a font
|
||||
font: new ig.Font( 'media/04b03.font.png' ),
|
||||
// Load the level
|
||||
this.loadLevel( LevelLevel1 );
|
||||
},
|
||||
|
||||
update: function() {
|
||||
if (ig.input.pressed('mainmenu')) ig.system.setGame(StartScreen);
|
||||
this.parent(); // Update entries and background
|
||||
},
|
||||
|
||||
init: function() {
|
||||
ig.input.bind( ig.KEY.UP_ARROW, 'up' );
|
||||
ig.input.bind( ig.KEY.DOWN_ARROW, 'down' );
|
||||
draw: function() {
|
||||
this.parent(); // Draw entries and background
|
||||
}
|
||||
});
|
||||
|
||||
this.loadLevel( LevelLevel1 );
|
||||
},
|
||||
StartScreen = ig.Game.extend({
|
||||
background: new ig.Image('media/main_screen.png'),
|
||||
|
||||
update: function() {
|
||||
// Update all entities and backgroundMaps
|
||||
this.parent();
|
||||
init: function() {
|
||||
ig.input.bind(ig.KEY.ENTER, 'start');
|
||||
ig.input.bind(ig.KEY.SPACE, 'start');
|
||||
},
|
||||
|
||||
// Add your own, additional update code here
|
||||
},
|
||||
update: function() {
|
||||
if (ig.input.pressed('start')) ig.system.setGame(RunningGame);
|
||||
this.parent();
|
||||
},
|
||||
|
||||
draw: function() {
|
||||
// Draw all entities and backgroundMaps
|
||||
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
BIN
dev/media/main_screen.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 153 KiB |
Loading…
Reference in a new issue