Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Elsombrero

Hi, I'm trying to understand the mechanics of why and how this code works. It's to detect if the AI is near an edge or not and to turn in the opposite direction if there's no collision tile. Thanks in advance.

update: function(){
                 //near edge detection
                 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;
                    }
                    var xdir = this.flip ? -1 : 1;
                    this.vel.x = this.speed * xdir;
                    this.currentAnim.flip.x = this.flip;
                    this.parent();
             },

1 decade ago by Elsombrero

Also if it helps the code is from the example game Resident Raver in Introducing Html5 games with ImpactJS. I feel it doesn't go into much depth about what his code actually does, only in certain parts. I use the class reference though and it's quite helpful in conjunction with the book.

1 decade ago by Elsombrero

I checked out the class reference and the getTile function is straight forward but i don't understand this part. The adding of the flip ternary part.

ig.game.collisionMap.getTile( 
                 this.pos.x + (this.flip ? +4 : this.size.x -4), 
                    this.pos.y + this.size.y+1
                 )

1 decade ago by Elsombrero

Never mind the question lol I feel dumb for asking now, I got it.
Page 1 of 1
« first « previous next › last »