Keresés

Új hozzászólás Aktív témák

  • Speeedfire

    félisten

    válasz Jim-Y #5966 üzenetére

    Egy kis html5 játékon dolgozok phaser motorral. A játékban x időközönként feljönnek ikonok amiket ha felvesz a játékos akkor plusz élet vagy fegyvert kap (legalábbis jelenleg, de ezt bővíteném). Fegyverből is van 11 féle.
    A lényeg az lenne, hogy amikor egy ilyen ikont feldobok, akkor 30% valószínűséggel legyen élet, a maradék 70%-ban pedig fegyver. Jelenleg csak kiveszem a helperTypes tömbből az egyik elemet és abból lesz az ikon. Vagy fegyver vagy élet. Ezt a Helper osztály konstruktora tovább dolgozza. Kb ennyi lenne a lényeg. De nem tudom a 30/70-et hogy tudnám megoldani.

    this.helperTypes = [
    'gun', 'healt'
    ];

    ------------------------------------

    addHelper: function () {
    if (this.game.time.now > this.nextHelper) {
    this.nextHelper = this.game.time.now + this.helperRate;
    var type = game.rnd.integerInRange(0,this.helperTypes.length);
    this.helpers.push(new Helper(this.countHelper, game, this.player, this.helperTypes[type]));
    this.countHelper++;
    }

    },

    ------------------------------------


    var Helper = function (index, game, player, type) {

    var x = game.rnd.integerInRange(game.width/2,game.width-50);
    var y = game.rnd.integerInRange(50,game.height-50);

    this.game = game;
    this.player = player;
    this.type = type;

    this.helper = game.add.sprite(x, y, type);
    this.helper.anchor.set(0.5);
    this.helper.name = index.toString();
    game.physics.enable(this.helper, Phaser.Physics.ARCADE);
    this.helper.scale.setTo(0.25, 0.25);
    this.helper.outOfBoundsKill = true;
    this.helper.checkWorldBounds = true;
    this.helper.body.immovable = false;

    game.physics.arcade.velocityFromRotation(this.helper.rotation, -100, this.helper.body.velocity);

    };

    Helper.prototype = Object.create(Phaser.Sprite.prototype);
    Helper.prototype.constructor = Helper;

    Helper.prototype.update = function () {
    //todo
    };

    Helper.prototype.useIt = function(gameObj) {
    switch(this.type) {
    case 'gun':
    var index = this.game.rnd.integerInRange(1,9);
    gameObj.setWeapon(index);
    break;
    case 'healt':
    var index = this.game.rnd.integerInRange(1,5);
    gameObj.healt += index * 10;
    break;
    default:
    //todo
    break;
    }

    };


    sztanozs:
    Csak gyors összedobtam a példákat, nem figyeltem, hogy pontosan jó-e. :B

    Szerk.: Köszi, bár nem tudom, hogy most akkor ez kell-e számomra vagy sem. :B

Új hozzászólás Aktív témák

Hirdetés