1 decade ago by FriendlyDuck
Sorry for all of the questions - I've been searching most of the afternoon for answers to these questions and can't seem to find anything I can make work. I'm not just being lazy!
I'm trying to make a test game (my first with Impact, my first full stop in fact). I'm using box2d for the physics. Here's a screenshot.
this thread but have no idea where to put that code so the brick entity uses it to play a sound?
Here's my Player/brick code.
I'm trying to make a test game (my first with Impact, my first full stop in fact). I'm using box2d for the physics. Here's a screenshot.
this thread but have no idea where to put that code so the brick entity uses it to play a sound?Here's my Player/brick code.
ig.module(
'game.entities.player'
)
.requires(
'impact.entity',
'impact.sound',
'plugins.box2d.entity'
)
.defines(function(){
EntityPlayer = ig.Entity.extend({
size: {x:80, y:80},
maxVel: {x: 100, y: 150},
friction: {x: 600, y: 0},
gravityFactor:0,
type: ig.Entity.TYPE.A,
zIndex:99,
animSheet: new ig.AnimationSheet('media/container.png', 80, 80),
init: function( x, y, settings ) {
this.addAnim('idle', 1, [0]);
this.addAnim('containerOpen', 1, [1]);
this.parent( x, y, settings );
},
update: function() {
// move left or right
if (ig.input.state('left')) {
this.vel.x = -100;
this.currentAnim = this.anims.idle;
}
if (ig.input.state('right')) {
this.vel.x = +100;
this.currentAnim = this.anims.idle;
}
if (ig.input.pressed('drop')) {
this.currentAnim = this.anims.containerOpen;
ig.game.sortEntitiesDeferred();
for( var i = 0; i < 20; i++ ) {
var e = ig.game.spawnEntity( EntityBrick, this.pos.x+(i+20), this.pos.y+60, {zIndex:1} );
}
ig.game.brickCount = ig.game.brickCount+20;
}
this.noLeaveMap();
this.parent();
},
noLeaveMap: function() {
if (this.pos.x < 0) {
this.pos.x = 0;
}
if (this.pos.x > 80) {
this.pos.x = 80;
}
}
});
// Brick Entity
EntityBrick = ig.Box2DEntity.extend({
size: {x:11, y:7},
type: ig.Entity.TYPE.B,
checkAgainst: ig.Entity.TYPE.NONE,
collides: ig.Entity.COLLIDES.NONE,
bounciness:0.2,
zIndex:99,
brickSFX: new ig.Sound('media/sounds/brick.ogg' ),
animSheet: new ig.AnimationSheet('media/brick.png', 11, 7),
init: function(x, y, settings) {
this.addAnim('idle', 0.5, [0]);
this.parent(x, y, settings);
},
update: function() {
// If a brick goes off screen, kill it
if ((this.pos.x < 0) || (this.pos.x > 160)) {
this.kill();
ig.game.brickCount = ig.game.brickCount-1;
this.brickSFX.play();
}
this.parent();
}
});
});
