Skip to content

Instantly share code, notes, and snippets.

@unstoppablecarl
Created January 8, 2013 21:36
Show Gist options
  • Save unstoppablecarl/4488202 to your computer and use it in GitHub Desktop.
Save unstoppablecarl/4488202 to your computer and use it in GitHub Desktop.
ig.module(
'game.entities.container'
)
.requires(
'impact.entity',
'game.helpers.geometry'
)
.defines(function(){
EntityObstacle = ig.Entity.extend({
type: ig.Entity.TYPE.B,
checkAgainst: ig.Entity.TYPE.A,
check:function(unit){
if(this.unitCollision(unit)){
this.unitColliding = true;
}
},
unitCollision: function(unit){
var boundingBoxPolygon = unit.getBoundingBoxPolygon();
for(var i = 0; i < 4; i++){
if(Geometry.pointInPolygon(boundingBoxPolygon[i], this.collisionArea)){
return true;
}
}
return false;
},
unitColliding: false,
name : null,
footprint: [
{
x: 0,
y: 187
},
{
x: 112,
y: 299
},
{
x: 196,
y: 272
},
{
x: 84,
y: 160
}
],
collisionArea: [
{
x: 0,
y: 187
},
{
x: 112,
y: 299
},
{
x: 196,
y: 272
},
{
x: 196,
y: 192
},
{
x: 196,
y: 192
},
{
x: 84,
y: 80
},
{
x: 0,
y: 108
},
],
offset: {
x: 0,
y: 80
},
size: {
x: 197,
y: 220
},
// zIndex is deturmined by adding pos.y and zIndexOffset
zIndexOffset: -20,
init: function( x, y, settings ) {
this.animSheet = new ig.AnimationSheet( 'media/obstacles-large.png', 200, 300 );
this.parent( this.pos.x, this.pos.y, settings );
this.addAnim( 'idle', 1, [0] );
this.currentAnim = this.anims.idle;
this.zIndex = this.pos.y + this.zIndexOffset;
ig.game.sortEntitiesDeferred();
},
update: function() {
this.currentAnim.alpha = 1;
this.parent();
this.unitColliding = false;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment