add win state

This commit is contained in:
Fabien Freling 2021-08-15 16:28:42 +02:00
parent 6d77ee84f1
commit ccbdf0913e
2 changed files with 32 additions and 6 deletions

View file

@ -14,3 +14,5 @@ Limitation: the player must cheat
- [ ] update itch page
- [ ] other cheats?
- [ ] explicit goal?
- [ ] bug: respawn killed enemies
- [ ] bug: bullets collide with bg?

View file

@ -163,7 +163,11 @@ class Enemy {
hit() {
_alive = false
Game.score = Game.score + 1
var points = 1
if (Cheat.doublePoints) {
points = 2
}
Game.score = Game.score + points
}
}
@ -278,6 +282,8 @@ class Explosion {
}
class World {
endReached { _world_x >= 210 }
construct new() {
_t = 0
_stars = []
@ -357,7 +363,7 @@ class World {
// medium stars
var width = 10
var spaceBetween = width * 10
var speed = 0.1
var speed = 0.5
var mediumTick = (spaceBetween + width) / speed
if (_t % mediumTick == 0) {
var dir = -1
@ -370,7 +376,7 @@ class World {
// Map scrolling
if (Game.state == Game.game) {
if (_world_x < 210) {
if (!endReached) {
if (_t % _world_scroll_speed == 0) {
_world_x = _world_x + 1
}
@ -482,6 +488,22 @@ class World {
}
_player.draw()
if (endReached) {
var w = 80
var h = H/2-10
if (Game.score >= Game.goal) {
TIC.print("YOU WIN", w+1, h+1, Color.black, true, 2)
TIC.print("YOU WIN", w, h, Color.white, true, 2)
} else {
TIC.print("YOU LOSE", w+1, h+1, Color.black, true, 2)
TIC.print("YOU LOSE", w, h, Color.white, true, 2)
var p = Game.goal - Game.score
TIC.print("You need %(p) more points to win", w+1, h + 21, Color.black, false, 1, true)
TIC.print("You need %(p) more points to win", w, h + 20, Color.white, false, 1, true)
}
}
}
}
@ -495,6 +517,7 @@ class Game is TIC{
static score { __score }
static score=(s) { __score = s }
static goal { __goal }
construct new() {
_t=0
@ -506,6 +529,7 @@ class Game is TIC{
_p_index = 0
_c_index = 0
__score = 0
__goal = 30
_t_delay = 0
}
@ -520,8 +544,8 @@ class Game is TIC{
Game.state == Game.gameover) {
TIC.print("SCORE: %(__score)", 1, 1, Color.black, true)
TIC.print("SCORE: %(__score)", 0, 0, Color.white, true)
TIC.print("GOAL: 12", 121, 1, Color.black, true)
TIC.print("GOAL: 12", 120, 0, Color.white, true)
TIC.print("GOAL: %(__goal)", 121, 1, Color.black, true)
TIC.print("GOAL: %(__goal)", 120, 0, Color.white, true)
}
if (Game.state == Game.gameover) {
@ -550,6 +574,7 @@ class Game is TIC{
} else if (Game.state == Game.gameover) {
if (_t_delay > 10) {
if (TIC.btnp(4)) {
_world = World.new()
newGame()
}
}
@ -583,7 +608,6 @@ class Game is TIC{
}
newGame() {
_world = World.new()
__state = Game.game
__score = 0
_t_delay = 0