enable cheat code

This commit is contained in:
Fabien Freling 2021-08-13 18:33:33 +02:00
parent 353c5fbb3c
commit 97513db0b6

View file

@ -23,6 +23,13 @@ class Color {
static white { 12 } static white { 12 }
} }
class D {
static up { 0 }
static down { 1 }
static left { 2 }
static right { 3 }
}
class Star { class Star {
construct new(x, y, size, scrollSpeed, color) { construct new(x, y, size, scrollSpeed, color) {
_x = x _x = x
@ -428,6 +435,7 @@ class Game is TIC{
_p_buttons = [] _p_buttons = []
_p_index = 0 _p_index = 0
_d_enabled = false _d_enabled = false
_cheat_seq = [D.up, D.up, D.left, D.right, D.up, D.down]
} }
TIC() { TIC() {
@ -469,10 +477,30 @@ class Game is TIC{
_p_index = _p_index + 1 _p_index = _p_index + 1
} }
} }
if (cheatFound()) {
_d_enabled = true
}
} }
_world.update(state) _world.update(state)
} }
cheatFound() {
var end = _p_index
var start = (end - _cheat_seq.count)
if (start < 0) {
return false
}
for (i in 0..._cheat_seq.count) {
var dir = _p_buttons[(start + i) % _p_buttons.count]
var cheat = _cheat_seq[i]
if (dir != cheat) {
return false
}
}
return true
}
draw() { draw() {
TIC.cls(0) TIC.cls(0)
if (state == Game.title) { if (state == Game.title) {
@ -481,30 +509,31 @@ class Game is TIC{
_world.draw(state) _world.draw(state)
} else if (state == Game.pause) { } else if (state == Game.pause) {
TIC.print("PAUSE", 90, H/4, Color.white, false, 2) TIC.print("PAUSE", 90, H/4, Color.white, false, 2)
TIC.print("debug mode: disabled", 60, H - 10, Color.white)
var end = _p_index if (!_d_enabled) {
var start = (end - 10).max(0) TIC.print("debug mode: disabled", 60, H - 10, Color.white)
//System.print("start: %(start)")
System.print("c: %(_p_index - start)") var end = _p_index
var c = 0 var start = (end - 10).max(0)
for (i in start...end) { for (i in start...end) {
//System.print("%(_p_buttons) i: %(i%_p_buttons.count)") var pos = i - start
var pos = i - start var dir = _p_buttons[i % _p_buttons.count]
var dir = _p_buttons[i % _p_buttons.count] var sprId = 84
var sprId = 84 if (dir == D.up) {
if (dir == 0) { // up TIC.spr(sprId, 5 + pos * 10, H - 20, 0)
TIC.spr(sprId, 5 + pos * 10, H - 20, 0) }
} if (dir == D.down) {
if (dir == 1) { // down TIC.spr(sprId, 5 + pos * 10, H - 20, 0, 1, 2)
TIC.spr(sprId, 5 + pos * 10, H - 20, 0, 1, 2) }
} if (dir == D.left) {
if (dir == 2) { // left TIC.spr(sprId, 5 + pos * 10, H - 20, 0, 1, 0, 3)
TIC.spr(sprId, 5 + pos * 10, H - 20, 0, 1, 0, 3) }
} if (dir == D.right) {
if (dir == 3) { // right TIC.spr(sprId, 5 + pos * 10, H - 20, 0, 1, 0, 1)
TIC.spr(sprId, 5 + pos * 10, H - 20, 0, 1, 0, 1) }
} }
} else {
TIC.print("debug mode: enabled", 60, H - 10, Color.white)
} }
} }
} }