add win state
This commit is contained in:
parent
6d77ee84f1
commit
ccbdf0913e
|
@ -14,3 +14,5 @@ Limitation: the player must cheat
|
||||||
- [ ] update itch page
|
- [ ] update itch page
|
||||||
- [ ] other cheats?
|
- [ ] other cheats?
|
||||||
- [ ] explicit goal?
|
- [ ] explicit goal?
|
||||||
|
- [ ] bug: respawn killed enemies
|
||||||
|
- [ ] bug: bullets collide with bg?
|
||||||
|
|
36
chi-tor.wren
36
chi-tor.wren
|
@ -163,7 +163,11 @@ class Enemy {
|
||||||
|
|
||||||
hit() {
|
hit() {
|
||||||
_alive = false
|
_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 {
|
class World {
|
||||||
|
endReached { _world_x >= 210 }
|
||||||
|
|
||||||
construct new() {
|
construct new() {
|
||||||
_t = 0
|
_t = 0
|
||||||
_stars = []
|
_stars = []
|
||||||
|
@ -357,7 +363,7 @@ class World {
|
||||||
// medium stars
|
// medium stars
|
||||||
var width = 10
|
var width = 10
|
||||||
var spaceBetween = width * 10
|
var spaceBetween = width * 10
|
||||||
var speed = 0.1
|
var speed = 0.5
|
||||||
var mediumTick = (spaceBetween + width) / speed
|
var mediumTick = (spaceBetween + width) / speed
|
||||||
if (_t % mediumTick == 0) {
|
if (_t % mediumTick == 0) {
|
||||||
var dir = -1
|
var dir = -1
|
||||||
|
@ -370,7 +376,7 @@ class World {
|
||||||
|
|
||||||
// Map scrolling
|
// Map scrolling
|
||||||
if (Game.state == Game.game) {
|
if (Game.state == Game.game) {
|
||||||
if (_world_x < 210) {
|
if (!endReached) {
|
||||||
if (_t % _world_scroll_speed == 0) {
|
if (_t % _world_scroll_speed == 0) {
|
||||||
_world_x = _world_x + 1
|
_world_x = _world_x + 1
|
||||||
}
|
}
|
||||||
|
@ -482,6 +488,22 @@ class World {
|
||||||
}
|
}
|
||||||
|
|
||||||
_player.draw()
|
_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 { __score }
|
||||||
static score=(s) { __score = s }
|
static score=(s) { __score = s }
|
||||||
|
static goal { __goal }
|
||||||
|
|
||||||
construct new() {
|
construct new() {
|
||||||
_t=0
|
_t=0
|
||||||
|
@ -506,6 +529,7 @@ class Game is TIC{
|
||||||
_p_index = 0
|
_p_index = 0
|
||||||
_c_index = 0
|
_c_index = 0
|
||||||
__score = 0
|
__score = 0
|
||||||
|
__goal = 30
|
||||||
_t_delay = 0
|
_t_delay = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,8 +544,8 @@ class Game is TIC{
|
||||||
Game.state == Game.gameover) {
|
Game.state == Game.gameover) {
|
||||||
TIC.print("SCORE: %(__score)", 1, 1, Color.black, true)
|
TIC.print("SCORE: %(__score)", 1, 1, Color.black, true)
|
||||||
TIC.print("SCORE: %(__score)", 0, 0, Color.white, true)
|
TIC.print("SCORE: %(__score)", 0, 0, Color.white, true)
|
||||||
TIC.print("GOAL: 12", 121, 1, Color.black, true)
|
TIC.print("GOAL: %(__goal)", 121, 1, Color.black, true)
|
||||||
TIC.print("GOAL: 12", 120, 0, Color.white, true)
|
TIC.print("GOAL: %(__goal)", 120, 0, Color.white, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Game.state == Game.gameover) {
|
if (Game.state == Game.gameover) {
|
||||||
|
@ -550,6 +574,7 @@ class Game is TIC{
|
||||||
} else if (Game.state == Game.gameover) {
|
} else if (Game.state == Game.gameover) {
|
||||||
if (_t_delay > 10) {
|
if (_t_delay > 10) {
|
||||||
if (TIC.btnp(4)) {
|
if (TIC.btnp(4)) {
|
||||||
|
_world = World.new()
|
||||||
newGame()
|
newGame()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -583,7 +608,6 @@ class Game is TIC{
|
||||||
}
|
}
|
||||||
|
|
||||||
newGame() {
|
newGame() {
|
||||||
_world = World.new()
|
|
||||||
__state = Game.game
|
__state = Game.game
|
||||||
__score = 0
|
__score = 0
|
||||||
_t_delay = 0
|
_t_delay = 0
|
||||||
|
|
Loading…
Reference in a new issue