Game project: Money!

I did a small update on the game-thing: the play­er is now able to col­lect mon­ey (or dia­monds, or burg­ers, or any­thing) coole minecraft maps zumen. These will be used in the in-game shops to, well, buy stuff.

One issue I had was that I want­ed to make the coins col­lect­ed per­sis­tent: for exam­ple, if you grab all the coins to get in stage 1, vis­it a cou­ple of oth­er stages, then go back to stage 1, you won’t find any coin any­more – because you already picked all of them when you first vis­it­ed herun­ter­laden. If you need 500 coins (dia­monds, burg­er, etc.) to buy some­thing, going to the same lev­el again and again won’t help.

At first, I was not too sure about how to imple­ment this fea­ture cre­ative cloud dateien herun­ter­laden.
After a cou­ple of dis­cus­sions with a friend should I say, a patient one?), I set­tled for the fol­low­ing approach (which is not exact­ly what he rec­om­mend­ed, but which kin­da works for me):

I start with the BasicGame object, which allows to keep things stored between dif­fer­ent states free cut pat­tern Christ­mas. In the boot state, I cre­at­ed some­thing look­ing like this:

BasicGame = {  
  vis­it­edLevels: []
};

Every time I load a new lev­el, I check if the vis­it­edLevels key is either emp­ty, or match­es some­thing exist­ing face­book win­dows.
If it is emp­ty of there is not match, I set a val­ue alreadyVis­it­ed to false, and cre­ate a new key:

BasicGame.visitedLevels.push({
  lev­el­Name: ‘theLevel­Name’,
  coins: []
})

Now every time the play­er grabs a coin, I add its coor­di­nates in the coins array:

for (var i=0; i<BasicGame.visitedLevels.length; i++){
  if (BasicGame.visitedLevels[i].levelName == this.currentLevel) {
    BasicGame.visitedLevels[i].coins.push(
      {x: coin.cameraOffset.x, y:coin.cameraOffset.y}
    );
  }
}

(not sure if using cam­eraOff­set is the prop­er way, but that’s the only val­ue that matched the one I grabbed from the tilemap) insta­gram sto­ry stick­er herun­ter­laden.

After a cou­ple of coins col­lect­ed, the BasicGame object starts to look like:

BasicGame = {
  vis­it­edLevels: [
    {
      lev­el­Name: ‘theLevel­Name’,
      coins: [
        {x: 2, y: 6},
        {x: 100, y: 82}
      ]
    }
  ]
};

Then when I cre­ate my lev­el and add the coins, I check first if alreadyVis­it­ed is false land­wirtschafts sim­u­la­tor 2017 mods kosten­los herun­ter­laden.
If it is true, I com­pare each coin coor­di­nates with what I have stored in the BasicGame object for the cur­rent lev­el. I only add the coin if there is no match house musik kosten­los down­load­en.

cre­ate­Coins: func­tion() {
  this.coins = this.add.group();
  var coinArr = this.findObjectsByType(‘coin’, this.map, ‘object­sLay­er’);
  var coin;
  coinArr.forEach(function(element) {
    if (this.alreadyVisited){
      var coin­WasTak­en = false;
      for (var i=0; i<BasicGame.visitedLevels.length; i++) {
        if (BasicGame.visitedLevels[i].levelName == this.currentLevel) {
          for (var j=0; j<BasicGame.visitedLevels[i].coins.length; j++) {
            console.log(BasicGame.visitedLevels[i].coins[j]);
            if(BasicGame.visitedLevels[i].coins[j].x == element.x && BasicGame.visitedLevels[i].coins[j].y == element.y) {
              coin­WasTak­en = true;
            }
          }
        }
      }
      if (!coin­WasTak­en) {
        coin = new Coin(this.game, element.x, element.y, this.map);
        this.coins.add(coin);
      }
    } else {
      coin = new Coin(this.game, element.x, element.y, this.map);
      this.coins.add(coin);
    }
    //console.log(element);
  }, this);
}

It works, but I would be curi­ous to know if there are oth­er solu­tions, or maybe a more “stan­dard” way to achieve the same thing mod­el invi­ta­tion cards for free. Com­ments & crit­ics wel­come!

2 Comments