add pause

master
Fabien Freling 2021-08-13 18:20:25 +02:00
parent 86a60e94f6
commit 353c5fbb3c
1 changed files with 55 additions and 1 deletions

View File

@ -259,6 +259,10 @@ class World {
}
update(state) {
if (state == Game.pause) {
return
}
if (_player.alive) {
if (state == Game.game) {
@ -413,6 +417,7 @@ class Game is TIC{
state { _state }
static title { "title" }
static game { "game" }
static pause { "pause" }
construct new() {
_t=0
@ -420,6 +425,9 @@ class Game is TIC{
_y=24
_state = Game.title
_world = World.new()
_p_buttons = []
_p_index = 0
_d_enabled = false
}
TIC() {
@ -441,9 +449,26 @@ class Game is TIC{
update() {
if (state == Game.title) {
if (TIC.btn(4)) {
if (TIC.btnp(4)) {
_state = Game.game
}
} else if (state == Game.game) {
if (TIC.btnp(5)) {
_state = Game.pause
_p_buttons = List.filled(10, -1)
_p_index = 0
}
} else if (state == Game.pause) {
if (TIC.btnp(5)) {
_state = Game.game
}
for (k in 0..3) {
if (TIC.btnp(k)) {
_p_buttons[_p_index % _p_buttons.count] = k
_p_index = _p_index + 1
}
}
}
_world.update(state)
}
@ -454,6 +479,33 @@ class Game is TIC{
_world.draw(state)
} else if (state == Game.game) {
_world.draw(state)
} else if (state == Game.pause) {
TIC.print("PAUSE", 90, H/4, Color.white, false, 2)
TIC.print("debug mode: disabled", 60, H - 10, Color.white)
var end = _p_index
var start = (end - 10).max(0)
//System.print("start: %(start)")
System.print("c: %(_p_index - start)")
var c = 0
for (i in start...end) {
//System.print("%(_p_buttons) i: %(i%_p_buttons.count)")
var pos = i - start
var dir = _p_buttons[i % _p_buttons.count]
var sprId = 84
if (dir == 0) { // up
TIC.spr(sprId, 5 + pos * 10, H - 20, 0)
}
if (dir == 1) { // down
TIC.spr(sprId, 5 + pos * 10, H - 20, 0, 1, 2)
}
if (dir == 2) { // left
TIC.spr(sprId, 5 + pos * 10, H - 20, 0, 1, 0, 3)
}
if (dir == 3) { // right
TIC.spr(sprId, 5 + pos * 10, H - 20, 0, 1, 0, 1)
}
}
}
}
}
@ -479,10 +531,12 @@ class Game is TIC{
// 081:1112222221222222222222222222222222222222222222222222222222222222
// 082:2222222222222222222222222222222222222222222222222222222222222222
// 083:2222200022222000222222002222220022222200222222202222222022222220
// 084:0000000000022000002222000222222022222222000220000002200000022000
// 096:0222222202222222022222220022222200222222002222220002222200022222
// 097:2222222222222222222222222222222222222222222222222222222222222222
// 098:2222222222222222222222222222222222222222222222222222222222222222
// 099:2222222022222220222222202222220022222200222222002222200022222000
// 100:0000000000066000006666000666666066666666000660000006600000066000
// 112:0002222200002222000002220000002200000002000000000000000000000000
// 113:2222222222222222222222222222222222222222022222220000222200000000
// 114:2222222222222222222222222222222222222222222222202222000000000000