groundwork for the base classes and some simple movement

This commit is contained in:
Ruben Müller 2012-06-22 18:20:41 +02:00
parent 7ac4f0dbce
commit 6159963b32
11 changed files with 143 additions and 13 deletions

View file

@ -0,0 +1,29 @@
ig.module(
'game.entities.ball'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityBall = ig.Entity.extend({
size: {x:48, y:48},
collides: ig.Entity.COLLIDES.ACTIVE,
animSheet: new ig.AnimationSheet( 'media/ball.png', 48, 48 ),
bounciness: 1,
init: function( x, y, settings ) {
this.parent( x, y, settings );
this.addAnim( 'idle', 1, [0] );
this.vel.x = -400;
this.vel.y = 200;
}
});
});

View file

@ -0,0 +1,26 @@
ig.module(
'game.entities.paddle-enemy'
)
.requires(
'game.entities.ball',
'game.entities.paddle'
)
.defines(function(){
EntityPaddleEnemy = EntityPaddle.extend({
update: function(){
var ball = ig.game.getEntitiesByType( EntityBall )[0];
if( ball.pos.y + ball.size.y / 2 > this.pos.y + this.size.y / 2 ) {
this.vel.y = 100;
} else {
this.vel.y = -100;
}
this.parent();
}
});
});

View file

@ -0,0 +1,39 @@
ig.module(
'game.entities.paddle-player'
)
.requires(
'game.entities.paddle'
)
.defines(function(){
EntityPaddlePlayer = EntityPaddle.extend({
animSheet: new ig.AnimationSheet( 'media/paddle-player.png', 64, 128 ),
update: function(){
if( ig.input.state('up') ) {
this.vel.y = -400;
}
else if( ig.input.state('down') ) {
this.vel.y = 400;
}
else {
this.vel.y = 0;
}
if( ig.input.state('left') ) {
this.vel.x = -400;
}
else if( ig.input.state('right') ) {
this.vel.x = 400;
}
else {
this.vel.x = 0;
}
this.parent();
}
});
});

View file

@ -0,0 +1,26 @@
ig.module(
'game.entities.paddle'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityPaddle = ig.Entity.extend({
size: {x:64, y:128},
collides: ig.Entity.COLLIDES.FIXED,
animSheet: new ig.AnimationSheet( 'media/paddle.png', 64, 128 ),
maxVel: {x: 400, y: 400},
init: function( x, y, settings ) {
this.parent( x, y, settings );
this.addAnim( 'idle', 1, [0] );
}
});
});

View file

@ -0,0 +1,6 @@
ig.module( 'game.levels.level1' )
.requires( 'impact.image','game.entities.paddle-enemy','game.entities.paddle-player','game.entities.ball' )
.defines(function(){
LevelLevel1=/*JSON[*/{"entities":[{"type":"EntityPaddleEnemy","x":8,"y":152},{"type":"EntityPaddlePlayer","x":548,"y":112},{"type":"EntityBall","x":288,"y":144}],"layer":[{"name":"bg","width":13,"height":8,"linkWithCollision":false,"visible":1,"tilesetName":"media/tileset.png","repeat":false,"preRender":false,"distance":"1","tilesize":48,"foreground":false,"data":[[1,1,1,1,1,1,1,1,1,1,1,1,1],[2,2,2,2,2,2,2,2,2,2,2,2,2],[2,2,2,2,1,2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2,1,2,2,2,2],[2,2,2,2,2,2,2,2,2,2,2,2,2],[1,1,1,1,1,1,1,1,1,1,1,1,1]]},{"name":"collision","width":13,"height":8,"linkWithCollision":false,"visible":1,"tilesetName":"","repeat":false,"preRender":false,"distance":1,"tilesize":48,"foreground":false,"data":[[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,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,1,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]]}]}/*]JSON*/;
LevelLevel1Resources=[new ig.Image('media/tileset.png')];
});

View file

@ -3,7 +3,13 @@ ig.module(
)
.requires(
'impact.game',
'impact.font'
'impact.font',
'game.entities.ball',
'game.entities.paddle-enemy',
'game.entities.paddle-player',
'game.levels.level1'
)
.defines(function(){
@ -14,7 +20,12 @@ MyGame = ig.Game.extend({
init: function() {
// Initialize your game here; bind keys etc.
ig.input.bind( ig.KEY.UP_ARROW, 'up' );
ig.input.bind( ig.KEY.DOWN_ARROW, 'down' );
ig.input.bind( ig.KEY.LEFT_ARROW, 'left' );
ig.input.bind( ig.KEY.RIGHT_ARROW, 'right' );
this.loadLevel( LevelLevel1 );
},
update: function() {
@ -27,19 +38,12 @@ MyGame = ig.Game.extend({
draw: function() {
// Draw all entities and backgroundMaps
this.parent();
// Add your own drawing code here
var x = ig.system.width/2,
y = ig.system.height/2;
this.font.draw( 'It Works!', x, y, ig.Font.ALIGN.CENTER );
}
});
// Start the Game with 60fps, a resolution of 320x240, scaled
// Start the Game with 60fps, a resolution of 640x400 (16:10), scaled
// up by a factor of 2
ig.main( '#canvas', MyGame, 60, 320, 240, 2 );
ig.main( '#canvas', MyGame, 60, 640, 400, 1 );
});

View file

@ -44,8 +44,8 @@ wm.config = {
'view': {
'zoom': 1,
'zoomMax': 4,
'zoomMin': 0.125,
'zoomMax': 1,
'zoomMin': 1,
'grid': false
},

BIN
dev/media/ball.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
dev/media/paddle-player.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
dev/media/paddle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4 KiB

BIN
dev/media/tileset.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB