Jump to content

Random Located Sprite Collision


FedeCuci
 Share

Recommended Posts

Hi everyone,

I am trying to add collision to sprites that are randomly spawned in the map of the game. 

// New object of class Player the sprite name is 'ship'
player = new Player("keyboardMouse", game.world.centerX, game.world.centerY, 200, 200, "12341",
        game.add.sprite(game.world.randomX, game.world.randomY, 'ship'), //Sprite handler object
        Weapons.sniperWeapon.weapon, // Weapon handler object
        ThrustEmitters.ourEmitter.emitter // Thrust emmiter handler object
    );


// loop to randomly place the sprites
for (var i = 0; i < 200; i++){

    var asteroid_brown = game.add.sprite(game.world.randomX, game.world.randomY, 'asteroid');
    var rock = game.add.sprite(game.world.randomX, game.world.randomY, 'rock');

    }



In theory, I would want to make something like the resources in moomoo.io (trees, rocks, gold etc.) You should be able to add collision so that when the player cannot just travel through them and also when shot at you would get 1 of the specific resource.

Also if this can be done in a better way, how would you do it?

Thanks!

 

reee.mov

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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