From ccb55f766ed92775e81904e4540845d58bc2c9e9 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Sun, 15 Aug 2021 00:08:47 +0200 Subject: [PATCH] add score --- README.md | 1 + chi-tor.wren | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4e7bfb6..d4aa63a 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,4 @@ Limitation: the player must cheat - [ ] win state - [ ] update itch page - [ ] other cheats? +- [ ] explicit goal? diff --git a/chi-tor.wren b/chi-tor.wren index e87eb81..75b89b6 100644 --- a/chi-tor.wren +++ b/chi-tor.wren @@ -163,6 +163,7 @@ class Enemy { hit() { _alive = false + Game.score = Game.score + 1 } } @@ -239,6 +240,7 @@ class Player { die() { _alive = false + Game.state = Game.gameover } } @@ -417,7 +419,6 @@ class World { if (collide(bx, by, _player.bw, _player.bh, e.x, e.y, e.w, e.h)) { _player.die() _vfx.add(Explosion.new(_player.x, _player.y)) - Game.state = Game.gameover } } } @@ -487,6 +488,9 @@ class Game is TIC{ static pause { "pause" } static gameover { "gameover" } + static score { __score } + static score=(s) { __score = s } + construct new() { _t=0 _x=96 @@ -496,6 +500,7 @@ class Game is TIC{ _p_buttons = [] _p_index = 0 _c_index = 0 + __score = 0 } TIC() { @@ -504,6 +509,13 @@ class Game is TIC{ _t=_t+1 } + OVR() { + if (Game.state == Game.game) { + TIC.print("SCORE: %(__score)", 0, 0, Color.white, true) + TIC.print("GOAL: 12", 120, 0, Color.white, true) + } + } + update() { if (Game.state == Game.title) { if (TIC.btnp(4)) {