add double points cheat

This commit is contained in:
Fabien Freling 2021-08-14 23:01:12 +02:00
parent 0934981061
commit 350970b695

View file

@ -28,24 +28,31 @@ class D {
static down { 1 } static down { 1 }
static left { 2 } static left { 2 }
static right { 3 } static right { 3 }
static toRot(dir) {
if (dir == D.up) {
return 0
}
if (dir == D.right) {
return 1
}
if (dir == D.down) {
return 2
}
if (dir == D.left) {
return 3
}
return -1
}
} }
var CheatSeq = [D.up, D.up, D.left, D.right, D.up, D.down] class Cheat {
static seq { [D.up, D.up, D.left, D.right, D.up, D.down] }
static enabled { __enabled }
static enabled=(b) { __enabled = b }
var DirRot = Fn.new {|dir| static doublePoints { __double_points }
if (dir == D.up) { static doublePoints=(b) { __double_points = b }
return 0
}
if (dir == D.right) {
return 1
}
if (dir == D.down) {
return 2
}
if (dir == D.left) {
return 3
}
return -1
} }
class Star { class Star {
@ -75,7 +82,7 @@ class HintPlanet {
_x = x _x = x
_y = y _y = y
_scrollSpeed = scrollSpeed _scrollSpeed = scrollSpeed
_rot = DirRot.call(dir) _rot = D.toRot(dir)
_size = 32 _size = 32
} }
@ -344,8 +351,8 @@ class World {
var mediumTick = (spaceBetween + width) / speed var mediumTick = (spaceBetween + width) / speed
if (_t % mediumTick == 0) { if (_t % mediumTick == 0) {
var dir = -1 var dir = -1
if (_hint_planet_i < CheatSeq.count) { if (_hint_planet_i < Cheat.seq.count) {
dir = CheatSeq[_hint_planet_i] dir = Cheat.seq[_hint_planet_i]
} }
_stars.add(HintPlanet.new(W, R.int(16,H-32), speed, dir)) _stars.add(HintPlanet.new(W, R.int(16,H-32), speed, dir))
_hint_planet_i = _hint_planet_i + 1 _hint_planet_i = _hint_planet_i + 1
@ -480,7 +487,7 @@ class Game is TIC{
_world = World.new() _world = World.new()
_p_buttons = [] _p_buttons = []
_p_index = 0 _p_index = 0
_d_enabled = false _c_index = 0
} }
TIC() { TIC() {
@ -494,40 +501,49 @@ class Game is TIC{
if (TIC.btnp(4)) { if (TIC.btnp(4)) {
_state = Game.game _state = Game.game
} }
} else if (state == Game.game) { } else if (state == Game.game) {
if (TIC.btnp(5)) { if (TIC.btnp(5)) {
_state = Game.pause _state = Game.pause
_p_buttons = List.filled(10, -1) _p_buttons = List.filled(10, -1)
_p_index = 0 _p_index = 0
} }
} else if (state == Game.pause) { } else if (state == Game.pause) {
if (TIC.btnp(5)) { if (TIC.btnp(5)) {
_state = Game.game _state = Game.game
} }
for (k in 0..3) { if (!Cheat.enabled) {
if (TIC.btnp(k)) { for (k in 0..3) {
_p_buttons[_p_index % _p_buttons.count] = k if (TIC.btnp(k)) {
_p_index = _p_index + 1 _p_buttons[_p_index % _p_buttons.count] = k
_p_index = _p_index + 1
}
}
if (cheatFound()) {
Cheat.enabled = true
}
} else {
if (TIC.btnp(4)) {
Cheat.doublePoints = !Cheat.doublePoints
} }
} }
if (cheatFound()) {
_d_enabled = true
}
} }
_world.update(state) _world.update(state)
} }
cheatFound() { cheatFound() {
var end = _p_index var end = _p_index
var start = (end - CheatSeq.count) var start = (end - Cheat.seq.count)
if (start < 0) { if (start < 0) {
return false return false
} }
for (i in 0...CheatSeq.count) { for (i in 0...Cheat.seq.count) {
var dir = _p_buttons[(start + i) % _p_buttons.count] var dir = _p_buttons[(start + i) % _p_buttons.count]
var cheat = CheatSeq[i] var cheat = Cheat.seq[i]
if (dir != cheat) { if (dir != cheat) {
return false return false
} }
@ -550,7 +566,7 @@ class Game is TIC{
} 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)
if (!_d_enabled) { if (!Cheat.enabled) {
TIC.print("debug mode: disabled", 60, H - 10, Color.white) TIC.print("debug mode: disabled", 60, H - 10, Color.white)
var end = _p_index var end = _p_index
@ -558,11 +574,19 @@ class Game is TIC{
for (i in start...end) { for (i in start...end) {
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 rot = DirRot.call(dir) var rot = D.toRot(dir)
var sprId = 84 var sprId = 84
TIC.spr(sprId, 5 + pos * 10, H - 20, 0, 1, 0, rot) TIC.spr(sprId, 5 + pos * 10, H - 20, 0, 1, 0, rot)
} }
} else { } else {
var h = H/4 + 20
TIC.spr(116, 50, h - 1, 0)
TIC.print("double points:", 60, h, Color.white)
if (Cheat.doublePoints) {
TIC.print("ON", 140, h, Color.green)
} else {
TIC.print("OFF", 140, h, Color.red)
}
TIC.print("debug mode: enabled", 60, H - 10, Color.white) TIC.print("debug mode: enabled", 60, H - 10, Color.white)
} }
} }
@ -600,6 +624,7 @@ class Game is TIC{
// 113:2222222222222222222222222222222222222222022222220000222200000000 // 113:2222222222222222222222222222222222222222022222220000222200000000
// 114:2222222222222222222222222222222222222222222222202222000000000000 // 114:2222222222222222222222222222222222222222222222202222000000000000
// 115:2222200022220000222000002200000020000000000000000000000000000000 // 115:2222200022220000222000002200000020000000000000000000000000000000
// 116:00c0000000cc000000ccc00000cccc0000ccc00000cc000000c0000000000000
// </TILES> // </TILES>
// <SPRITES> // <SPRITES>