refactor game state
This commit is contained in:
parent
d788900650
commit
ac098d2310
47
chi-tor.wren
47
chi-tor.wren
|
@ -177,7 +177,7 @@ class Player {
|
|||
_bw = 12
|
||||
_bh = 10
|
||||
|
||||
_speed = 1
|
||||
_speed = 2
|
||||
_bullets = []
|
||||
_alive = true
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ class World {
|
|||
|
||||
// init background
|
||||
for (i in 0..W) {
|
||||
update(Game.title)
|
||||
update()
|
||||
}
|
||||
|
||||
_remap = Fn.new {|tile, x, y|
|
||||
|
@ -318,14 +318,14 @@ class World {
|
|||
TIC.mset(x, y, 0)
|
||||
}
|
||||
|
||||
update(state) {
|
||||
if (state == Game.pause) {
|
||||
update() {
|
||||
if (Game.state == Game.pause) {
|
||||
return
|
||||
}
|
||||
|
||||
if (_player.alive) {
|
||||
|
||||
if (state == Game.game) {
|
||||
if (Game.state == Game.game) {
|
||||
_player.update()
|
||||
}
|
||||
|
||||
|
@ -364,7 +364,7 @@ class World {
|
|||
}
|
||||
|
||||
// Map scrolling
|
||||
if (state == Game.game) {
|
||||
if (Game.state == Game.game) {
|
||||
if (_t % _world_scroll_speed == 0) {
|
||||
_world_x = _world_x + 1
|
||||
}
|
||||
|
@ -417,6 +417,7 @@ 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -459,7 +460,7 @@ class World {
|
|||
return false
|
||||
}
|
||||
|
||||
draw(state) {
|
||||
draw() {
|
||||
for (s in _stars) {
|
||||
s.draw()
|
||||
}
|
||||
|
@ -479,16 +480,18 @@ class World {
|
|||
}
|
||||
|
||||
class Game is TIC{
|
||||
state { _state }
|
||||
static state { __state }
|
||||
static state=(s) { __state = s }
|
||||
static title { "title" }
|
||||
static game { "game" }
|
||||
static pause { "pause" }
|
||||
static gameover { "gameover" }
|
||||
|
||||
construct new() {
|
||||
_t=0
|
||||
_x=96
|
||||
_y=24
|
||||
_state = Game.title
|
||||
__state = Game.title
|
||||
_world = World.new()
|
||||
_p_buttons = []
|
||||
_p_index = 0
|
||||
|
@ -502,21 +505,21 @@ class Game is TIC{
|
|||
}
|
||||
|
||||
update() {
|
||||
if (state == Game.title) {
|
||||
if (Game.state == Game.title) {
|
||||
if (TIC.btnp(4)) {
|
||||
_state = Game.game
|
||||
__state = Game.game
|
||||
}
|
||||
|
||||
} else if (state == Game.game) {
|
||||
} else if (Game.state == Game.game) {
|
||||
if (TIC.btnp(5)) {
|
||||
_state = Game.pause
|
||||
__state = Game.pause
|
||||
_p_buttons = List.filled(10, -1)
|
||||
_p_index = 0
|
||||
}
|
||||
|
||||
} else if (state == Game.pause) {
|
||||
} else if (Game.state == Game.pause) {
|
||||
if (TIC.btnp(5)) {
|
||||
_state = Game.game
|
||||
__state = Game.game
|
||||
}
|
||||
|
||||
if (!Cheat.enabled) {
|
||||
|
@ -537,7 +540,7 @@ class Game is TIC{
|
|||
}
|
||||
}
|
||||
|
||||
_world.update(state)
|
||||
_world.update()
|
||||
}
|
||||
|
||||
cheatFound() {
|
||||
|
@ -558,17 +561,19 @@ class Game is TIC{
|
|||
|
||||
draw() {
|
||||
TIC.cls(0)
|
||||
if (state == Game.title) {
|
||||
_world.draw(state)
|
||||
if (Game.state == Game.title) {
|
||||
_world.draw()
|
||||
TIC.print("Chi-Tor", W/4, H/4, Color.white, false, 3)
|
||||
TIC.print("Chi-Tor", W/4-1, H/4-1, Color.red, false, 3)
|
||||
TIC.print("Z", W/5, 4*H/5, Color.red)
|
||||
TIC.print(": shoot", W/5+8, 4*H/5, Color.white)
|
||||
TIC.print("X", W/5, 4*H/5+10, Color.red)
|
||||
TIC.print(": pause", W/5+8, 4*H/5+10, Color.white)
|
||||
} else if (state == Game.game) {
|
||||
_world.draw(state)
|
||||
} else if (state == Game.pause) {
|
||||
|
||||
} else if (Game.state == Game.game) {
|
||||
_world.draw()
|
||||
|
||||
} else if (Game.state == Game.pause) {
|
||||
TIC.print("PAUSE", 90, H/4, Color.white, false, 2)
|
||||
|
||||
if (!Cheat.enabled) {
|
||||
|
|
Loading…
Reference in a new issue