1 decade ago
by lilxe
I'm creating a my very first game and i would like to have two entities one that fires on a timer and one that fires when near.
i have been stuck on this for a while and done some research and i cant find much to help me out so any help would be appreciated
thanks =)
1 decade ago
by Joncom
Create two entities. For one of them create a timer:
var timer = new ig.Timer();
For the other one create a method that checks the distance between itself and the player:
var distanceToPlayer = function() {
var player = ig.game.getEntitiesByType( EntityPlayer )[0];
var distance = this.distanceTo( player );
return distance;
}
What specifically are you having trouble with? It would be helpful if you shared what code you do have so far.
Depends on if you want your turret to consider obstacles (meaning, it will only fire if the line of sight is clear) or not.
If not you can just use Euclidian distance between the turret and the player.
if ( Math.round( Math.sqrt( Math.pow(player.pos.x-this.pos.x,2) + Math.pow(player.pos.y-this.pos.y,2) ) ) <= this.lineOfSight ) {
this.shoot();
}
Where "player" is reference to player entity and lineOfSight is a parameter of turret entity that defines the distance from where to start shooting.
But if you are developing a tower defence game as I imagine you just have to check the proximity of every enemy, not the player object.
On the other hand, if you want the turret to consider walls, you also have to check collision map for clear path before allowing the turret to shoot using
trace() method.
1 decade ago
by lilxe
thanks for the help
this is the code i have at the moment
ig.module(
'game.entities.turret'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityTurret = ig.Entity.extend({
size: {x: 10, y:18},
offset: {x: 4, y: 2},
type: ig.Entity.TYPE.B, // Evil enemy group
checkAgainst: ig.Entity.TYPE.A, // Check against friendly
collides: ig.Entity.COLLIDES.PASSIVE,
health:10,
animSheet: new ig.AnimationSheet( 'media/Turret.png', 20, 20),
init: function( x, y, settings ) {
this.parent( x, y, settings );
this.addAnim( 'shoot', 2, [0,1] );
},
check: function( other ) {
other.receiveDamage( 3, this );
}
});
});
this is the basic code i have i know its not much. i dont know how to actually get a group b to shoot. i understand the player shooting, but with the group b i dont really understand the logic. i have been going through Introducing HTML5 Game Development on safari books online and they dont show/tell how to implement the logic. if there is any tutorials that you can recomend to help me out it be much appreciated
Page 1 of 1
« first
« previous
next ›
last »