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,25 +5,18 @@ ig.module(
|
||||||
'impact.entity'
|
'impact.entity'
|
||||||
)
|
)
|
||||||
.defines(function(){
|
.defines(function(){
|
||||||
|
EntityBall = ig.Entity.extend({
|
||||||
EntityBall = ig.Entity.extend({
|
|
||||||
|
|
||||||
name: 'ball',
|
name: 'ball',
|
||||||
|
|
||||||
size: {x: 24, y: 24},
|
size: {x: 24, y: 24},
|
||||||
collides: ig.Entity.COLLIDES.ACTIVE,
|
collides: ig.Entity.COLLIDES.ACTIVE,
|
||||||
type: ig.Entity.TYPE.B,
|
type: ig.Entity.TYPE.B,
|
||||||
|
|
||||||
animSheet: new ig.AnimationSheet( 'media/ball.png', 24, 24 ),
|
animSheet: new ig.AnimationSheet( 'media/ball.png', 24, 24 ),
|
||||||
|
|
||||||
bounciness: 1,
|
bounciness: 1,
|
||||||
maxVel: {x: 1000, y: 1000},
|
maxVel: {x: 1000, y: 1000},
|
||||||
|
|
||||||
init: function( x, y, settings ) {
|
init: function( x, y, settings ) {
|
||||||
this.parent( x, y, settings );
|
this.parent( x, y, settings );
|
||||||
|
|
||||||
this.addAnim( 'idle', 1, [0] );
|
this.addAnim( 'idle', 1, [0] );
|
||||||
|
|
||||||
this.randomVel();
|
this.randomVel();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -32,7 +25,7 @@ EntityBall = ig.Entity.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
collideWith: function( other, axis ) {
|
collideWith: function( other, axis ) {
|
||||||
if(other.name == 'paddle') {
|
if (other.name == 'paddle') {
|
||||||
// the horizontal speed of the ball multiplied
|
// the horizontal speed of the ball multiplied
|
||||||
// every time it hits a paddle
|
// every time it hits a paddle
|
||||||
this.vel.x *= 1.15;
|
this.vel.x *= 1.15;
|
||||||
|
@ -45,17 +38,15 @@ EntityBall = ig.Entity.extend({
|
||||||
|
|
||||||
reset: function() {
|
reset: function() {
|
||||||
this.randomVel();
|
this.randomVel();
|
||||||
|
|
||||||
this.pos.x = this.startPos.x;
|
this.pos.x = this.startPos.x;
|
||||||
this.pos.y = this.startPos.y;
|
this.pos.y = this.startPos.y;
|
||||||
},
|
},
|
||||||
|
|
||||||
randomVel: function() {
|
randomVel: function() {
|
||||||
this.vel.x = (Math.random()*(100)) + 100;
|
this.vel.x = Math.random()*100+100;
|
||||||
if(Math.random() > .5) this.vel.x *= -1;
|
if (Math.random() > .5) this.vel.x *= -1;
|
||||||
this.vel.y = (Math.random()*20) + 50;
|
this.vel.y = Math.random()*20+50;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ EntityGoal = ig.Entity.extend({
|
||||||
other.reset();
|
other.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,35 +12,52 @@ ig.module(
|
||||||
'game.levels.level1'
|
'game.levels.level1'
|
||||||
)
|
)
|
||||||
.defines(function(){
|
.defines(function(){
|
||||||
|
RunningGame = ig.Game.extend({
|
||||||
MyGame = ig.Game.extend({
|
|
||||||
|
|
||||||
// Load a font
|
|
||||||
font: new ig.Font( 'media/04b03.font.png' ),
|
font: new ig.Font( 'media/04b03.font.png' ),
|
||||||
|
|
||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
ig.input.bind( ig.KEY.UP_ARROW, 'up' );
|
ig.input.bind(ig.KEY.ESC, 'mainmenu');
|
||||||
ig.input.bind( ig.KEY.DOWN_ARROW, 'down' );
|
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 );
|
this.loadLevel( LevelLevel1 );
|
||||||
},
|
},
|
||||||
|
|
||||||
update: function() {
|
update: function() {
|
||||||
// Update all entities and backgroundMaps
|
if (ig.input.pressed('mainmenu')) ig.system.setGame(StartScreen);
|
||||||
this.parent();
|
this.parent(); // Update entries and background
|
||||||
|
|
||||||
// Add your own, additional update code here
|
|
||||||
},
|
},
|
||||||
|
|
||||||
draw: function() {
|
draw: function() {
|
||||||
// Draw all entities and backgroundMaps
|
this.parent(); // Draw entries and background
|
||||||
this.parent();
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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
BIN
dev/media/main_screen.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 153 KiB |
Loading…
Reference in a new issue