From 09349810610808d5ab03261f30d3dca2b1a976f9 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Fri, 13 Aug 2021 19:27:34 +0200 Subject: [PATCH] display hint in planets --- chi-tor.wren | 75 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/chi-tor.wren b/chi-tor.wren index 87209e8..7484959 100644 --- a/chi-tor.wren +++ b/chi-tor.wren @@ -30,6 +30,24 @@ class D { static right { 3 } } +var CheatSeq = [D.up, D.up, D.left, D.right, D.up, D.down] + +var DirRot = Fn.new {|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 +} + class Star { construct new(x, y, size, scrollSpeed, color) { _x = x @@ -52,6 +70,31 @@ class Star { } } +class HintPlanet { + construct new(x, y, scrollSpeed, dir) { + _x = x + _y = y + _scrollSpeed = scrollSpeed + _rot = DirRot.call(dir) + _size = 32 + } + + update() { + _x = _x - _scrollSpeed + } + + draw() { + TIC.spr(64, _x - _size / 2, _y - _size / 2, 0, 1, 0, 0, _size / TileSize, _size / TileSize) + if (_rot != -1) { + TIC.spr(68, _x - 2, _y - 4, 0, 1, 0, _rot) + } + } + + expired { + _x + _size / 2 < 0 + } +} + class Bullet { construct new(x, y) { _x = x @@ -71,7 +114,6 @@ class Bullet { } draw() { - //TIC.rect(_x, _y, _w, _h, 4) TIC.spr(288, _x, _y - 4, 0) } @@ -232,6 +274,7 @@ class World { _world_y = 0 _w_offset_x = 0 _world_scroll_speed = 60 / 2 + _hint_planet_i = 0 // init background for (i in 0..W) { @@ -250,9 +293,7 @@ class World { collect(list) { var i = 0 while (i < list.count) { - //System.print("%(list[i])") if (list[i].expired) { - //System.print("remove element from list") list.removeAt(i) } else { i = i + 1 @@ -302,7 +343,12 @@ class World { var speed = 0.1 var mediumTick = (spaceBetween + width) / speed if (_t % mediumTick == 0) { - _stars.add(Star.new(W, R.int(0,H-20), width, speed, 13)) + var dir = -1 + if (_hint_planet_i < CheatSeq.count) { + dir = CheatSeq[_hint_planet_i] + } + _stars.add(HintPlanet.new(W, R.int(16,H-32), speed, dir)) + _hint_planet_i = _hint_planet_i + 1 } // Map scrolling @@ -435,7 +481,6 @@ class Game is TIC{ _p_buttons = [] _p_index = 0 _d_enabled = false - _cheat_seq = [D.up, D.up, D.left, D.right, D.up, D.down] } TIC() { @@ -476,13 +521,13 @@ class Game is TIC{ cheatFound() { var end = _p_index - var start = (end - _cheat_seq.count) + var start = (end - CheatSeq.count) if (start < 0) { return false } - for (i in 0..._cheat_seq.count) { + for (i in 0...CheatSeq.count) { var dir = _p_buttons[(start + i) % _p_buttons.count] - var cheat = _cheat_seq[i] + var cheat = CheatSeq[i] if (dir != cheat) { return false } @@ -513,19 +558,9 @@ class Game is TIC{ for (i in start...end) { var pos = i - start var dir = _p_buttons[i % _p_buttons.count] + var rot = DirRot.call(dir) var sprId = 84 - if (dir == D.up) { - TIC.spr(sprId, 5 + pos * 10, H - 20, 0) - } - if (dir == D.down) { - TIC.spr(sprId, 5 + pos * 10, H - 20, 0, 1, 2) - } - if (dir == D.left) { - TIC.spr(sprId, 5 + pos * 10, H - 20, 0, 1, 0, 3) - } - if (dir == D.right) { - TIC.spr(sprId, 5 + pos * 10, H - 20, 0, 1, 0, 1) - } + TIC.spr(sprId, 5 + pos * 10, H - 20, 0, 1, 0, rot) } } else { TIC.print("debug mode: enabled", 60, H - 10, Color.white)