Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Problem with enemies grup and battle sytem


Mizukage
 Share

Recommended Posts

game: function()

    this.enemies = {        name: 'Retard Farmer - [very week]',        hp: 50,        attack: Math.floor(Math.random() * 8) + 5,        exp: 50,        gold: 5    }

Here enemies is a object 

 

 

 

create: function()

        enemies = this.game.add.group();        for (var i = 0; i < 10; i++) {            enemies.create(360 + Math.random() * 600, 300 + Math.random() * 600, 'monsterLvl1');            enemies.scale.setTo(1.4);        }

So here I have enemies, but they are group and dont have a sprites or body (problem with immovable = true;)

 

 

 

 

update: function () 

        this.game.physics.arcade.overlap(playerSprite, enemies, fightEngine, null, this);        this.game.physics.arcade.overlap(playerSprite, enemies); function fightEngine(player, enemy) {                        //Freeze enemy during collision, cant be defined on this .create not sprite            //enemy.body.immovable = true;                        //Trying to freze player during fight            playerSprite.body.immovable = true;                        //var playerDmg = (player.str/10)*(player.weapon.attack + player.lvl);            if (this.enemies.hp > 0) {                //Wait 1 sec here!!                this.enemies.hp -= this.playerDmg;                console.log('Enemy get ' + this.playerDmg);                //is he dead?                if (this.enemies.hp <= 0) {                    //get grind stuff                    this.player.gold += this.enemies.gold;                    this.player.exp += this.enemies.exp;                    //delete the enemy object                    enemy.kill();                    console.log('"'+this.enemies.name+'"'+' is dead.');                    this.lvlUpCheck(this.player);                    this.barUpdate();                    //Restore life for nest enemies clone                     this.enemies.hp = 50;                    //Wait 1 sec here!!                                    } else {                                        //Wait 1 sec here!!                    this.player.hp -= this.enemies.attack;                    console.log('You lost ' + this.enemies.attack + ' life');                    //have you been killed?                    if (this.player.hp <= 0) {                        console.log('You are dead');                        //Dead() fdunction and transfer to another game instance dead.js                    }                                    }            }                     };

 

There is a problem with pause after any attacks, for make it more turn based. I put comments "Wait 1 sec here!!" I have no idea how to do that??

 

 

And if I wall create another type of enemy like a enemiesLvl2 than how can I call them in my function fightEngine(player, enemy) ??
Now I neet to use 'this.enemies' inside a fightEngine() it is stick.... If player collide with enemies than fightEngine must use enemies object, when collide with enemiesLvl2 than use enemiesLvl2 object values..

 

I dont want to create fightEngine function for each one enemy types

Link to comment
Share on other sites

The way you've written it now, your "fightEngine" function will run every tick of the game engine, around 60 times a second.

 

If you want something to happen every second instead, you want a timer. You probably don't want to drive this off the physics collisions, though -- it should probably be single events like keypresses instead of "continuous" events like collisions.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...