Hi,
In my game called dhoombaby i have one obstacle which is like one hole...when player comes near to that hole...players down animation should take place...but problem is that how can i come to know that player is near to that hole....
In weltmeister i have taken that holes tiles...so in coding how to get that specific tile??? its urgent..can anyone help me???
1 decade ago
by drhayes
You could place an invisible entity around the hole and check for the player's collision to play the animation.
Thanks drhayes very much...now my code is working properly...
now other problem is that when my player is near to enemy i.e cop (in my game) then cop fires bullet on player.....but main problem is when cop is walking right side and player is also coming right side then the cop fire from back...i want when cop and player both are face to face then only cop should fire....what could be the logic behind this??
In my cop.js file i have
{
var x = this.pos.x + 10;
var y = this.pos.y + 30;
if(this.distanceTo(ig.game.player) <= 200 )
{
console.log('angle:' + this.distanceTo(ig.game.player));
ig.game.spawnEntity( EntityBullet1, x, y, {angle: this.angleTo( ig.game.player )} );
}
}
the cop fires when player is near ...but i also want above condition to satisfy...can u help me....
1 decade ago
by Donzo
You will have to check for flip.
First have the enemy character find the player character
with this:
var player = ig.game.getEntityByName('whateverYouNameYourPlayer');
Then do something like this:
if (this.flip == true && player.flip == true){
this.fire();
}
You will have to do all the work to calculate
who needs to be flipped when.
Also,
make sure that the flip property exists and is updated in both entities,
as it is not a core property.
Thanks Donzo...i have used the flip property...now my running code is:
if (this.distanceTo(ig.game.player) <= 200 && this.flip == true && ig.game.player.flip == false )
{
ig.game.spawnEntity( EntityBullet1, x, y, {angle: this.angleTo( ig.game.player )} );
}
Now cop fires in right direction...when both are facing to one another then only cop fires...but i coudn't understand this sentence which u told:-
make sure that the flip property exists and is updated in both entities,
as it is not a core property.
can u explore it ???
1 decade ago
by Donzo
Yes,
the flip property is not part of the
Entity class.
It is added in each individual entity
as you would add any variable:
Thirsty:true;
Right?
1 decade ago
by Joncom
@Donzo: Right.
If you wanted to though, you could add it to the Entity class:
/* entity-extras.js */
ig.Entity.inject({
flip: false
});
Hi ...
Thnaks Donzo and jancom...
Now my game is almost over...just i want that when player completes last level then game over screen should display...i have used this game over screen when player loses all his 3 lives but i also want it when he completes all three levels...how do i come to know that player has completed last level?? Any help?? Required urgently..
Hi..
In my game, i have floating entity by using it player can move forward. But the problem is;floating entity not work out properly. I want my floating entity move little backward and forward in between air by using collision or without collision.
In weltmeister i have this floating entity.
I have some code but this is useful when something is attached with that floating entity like river, on river this code is very useful, it shows like this floating entity really float on river. But now i need this floating entity float in between air and by using it player move forward .
What should i do????
i have this code for entity float on river-
ig.module(
'game.entities.float'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityFloat = ig.Entity.extend({
size: {x: 215, y: 55},
offset: {x: 10, y: 0},
maxVel: {x: 100, y: 100},
friction: {x: 150, y: 0},
type: ig.Entity.TYPE.NONE, // Evil enemy group
checkAgainst: ig.Entity.TYPE.A, // Check against friendly
collides: ig.Entity.COLLIDES.FIXED,
health: 1,
stats: {time: 0, kills: 0, deaths: 0, coin: 0},
speed: 200,
flip: false,
animSheet: new ig.AnimationSheet( 'media/float.png', 232, 57 ),
sfxDie: new ig.Sound( 'media/sounds/blob-die.*' ),
init: function( x, y, settings ) {
this.parent( x, y, settings );
this.addAnim( 'crawl', 0.04, [0,0,0,0,0,0] );
},
update: function() {
// Near an edge? return!
if( !ig.game.collisionMap.getTile(
this.pos.x + (this.flip ? +4 : this.size.x -4),
this.pos.y + this.size.y+1
)
)
{
this.flip = !this.flip;
// We have to move the offset.x around a bit when going
// in reverse direction, otherwise the blob's hitbox will
// be at the tail end.
this.offset.x = this.flip ? 0 : 24;
}
var xdir = this.flip ? -1 : 1;
this.vel.x = this.speed * xdir;
this.currentAnim.flip.x = !this.flip;
this.parent();
},
/*kill: function() {
this.sfxDie.play();
ig.game.stats.kills ++;
console.log('in blob kill');
this.parent();
},
*/
handleMovementTrace: function( res ) {
this.parent( res );
// Collision with a wall? return!
if( res.collision.x ) {
this.flip = !this.flip;
this.offset.x = this.flip ? 0 : 24;
}
},
/*check: function( other ) {
other.receiveDamage( 1, this );
ig.game.spawnEntity(EntityDeathExplosion, this.pos.x, this.pos.y);
}*/
});
});
1 decade ago
by Joncom
Hi Dhoombaby:
Mind editing your post and enclosing your code within double-pounds?
Doing so increases the likelyhood that someone will respond.
Because it is otherwise difficult to read.
##
/* code here */
##
Page 1 of 1
« first
« previous
next ›
last »