Scorer Plugin


start:
  - show room: WITH FADE CONTINUE
  - show deuzi: happy AT CENTER WITH FADE
  - deuzi says: Hello, welcome to (bold)the Scoring Example!(end)
  - var score: 0
  - deuzi says normal: Are you ready to have scoring for your choices?
  - choice:
    - "Yes!":
      - deuzi says happy: That's great!
      - call Scorer: "{score}"
      - wait: 100
      - deuzi says normal: Now you have score box on top right corner!
      - deuzi says happy: As you made a right choice, I give you (bold)+50(end) points.
      - var score: "{score} + 50"
      - call Scorer: "{score}"
    - "Not yet!":
      - deuzi says: Well, scoring is important to keep track of your progress.
      - call Scorer: "{score}"
      - deuzi says happy: So, it here anyway! Look at the top right corner.
      - deuzi says angry: "Your choice not to have the scoring was lazy. (bold)-50(end) points."
      - var score: "{score} - 50"
      - call Scorer: REMOVE
      - call Scorer: "{score}"
  - deuzi says normal: That's it for scoring example.
  - deuzi says happy: Use this example as starting point in your games. Best Wishes!
  - deuzi says normal: If you're new, don't forget to play (bold)the Tutorial(end) game, where me and my friends will show you around the basic features of RenJS.
  - deuzi says happy: And if you already have some experience, you can go ahead and start writing!
  - scene: endGame
									


backgrounds:
  room: assets/backgrounds/room_day.jpg

characters:
  deuzi:
    displayName: Deuzilene
    speechColour: "#ca90cf"
    looks:
      normal: assets/characters/Char3NormalSchool.png
      happy: assets/characters/Char3HappySchool.png
      angry: assets/characters/Char3AngrySchool.png

sfx:
  scoreUpdateSFX: assets/gui/scoreUpdate.mp3

extra:
  image:
    scorer: assets/gui/scorerBox.png
								


class Scorer extends RenJS.Plugin {

    scorer = null;
    text = null;

    async onCall(params) {
      if (params.body == "REMOVE" && this.scorer){
          // remove scorer
          await this.game.screenEffects.transition.FADEOUT(this.scorer)
          this.scorer.destroy();
          this.scorer = null;
          this.game.resolveAction();
          return;
      }
      else if (params.body == "REMOVE WITHNOFADE" && this.scorer){
          // remove scorer
          this.scorer.destroy();
          this.scorer = null;
          this.game.resolveAction();
          return;
      }
        if (this.scorer){
            this.game.managers.audio.playSFX('scoreUpdateSFX');
            // Just change the scorer value
            this.text.text = this.game.managers.logic.parseVars(params.body);
        } else {
            this.scorer = this.game.add.sprite(this.game.world.centerX+350, this.game.world.centerY-250, 'scorer'); //loads scorer gui under extras
            this.game.gui.hud.addChild(this.scorer);
            this.scorer.alpha = 0;
            this.scorer.anchor.set(0.5);
            const style = {...this.game.gui.hud.cHandlers.default.config.text.style};
            const message = this.game.managers.logic.parseVars(params.body);
            this.text = this.game.add.text(0, 0, message, style);
            this.text.anchor.set(0.5);
            this.scorer.addChild(this.text);
            this.game.managers.audio.playSFX('scoreUpdateSFX');
            await this.game.screenEffects.transition.FADEIN(this.scorer);
        }
        this.game.resolveAction();
    }
}

RenJSGame.addPlugin('Scorer',Scorer);
								

Return to the Gallery Download from Github