Skip to content

Instantly share code, notes, and snippets.

@felipemanga
Created July 3, 2020 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipemanga/20b414879d8cfaf94318b0d0b12ce20c to your computer and use it in GitHub Desktop.
Save felipemanga/20b414879d8cfaf94318b0d0b12ce20c to your computer and use it in GitHub Desktop.
Hiragana Flash in PINES
if( file("hiragana.res", 0) != 1 ){
console("Could not find resources!");
} else {
init();
}
const list = [
"a","e","i","o","u","n",
"chi","fu","ha","he","hi","ho",
"ka","ke","ki","ko","ku","ma",
"me","mi","mo","mu","na","ne",
"ni","no","nu","ra","re","ri",
"ro","ru","sa","se","shi","so",
"su","ta","te","to","tsu","wa",
"we","wo","ya","yo","yu","ba",
"be","bi","bo","bu","da","de",
"do","ga","ge","gi","go","gu",
"ja","ji","jo","ju","pa","pe",
"pi","po","pu","za","ze","zo",
"zu","bya","byo","byu","cha",
"cho","chu","gya","gyo","gyu",
"hya","hyo","hyu","kya","kyo",
"kyu","mya","myo","myu","nya",
"nyo","nyu","pya","pyo","pyu",
"rya","ryo","ryu","sha","sho",
"shu"
];
const UI = file("interface", 0);
const rightEmote = builtin("happyEmote");
const wrongEmote = builtin("dohEmote");
const boredEmote = builtin("boredEmote");
const words = [0,0,0,0];
var X;
var Y;
var stateTime = 0;
var level = 0;
var streak = 0;
var maxStreak = 0;
var num = 0;
var img = null;
var state = nop;
var nextState = null;
var emote = rightEmote;
const spriteX = 80;
const spriteY = 16;
const waitColor = 23;
const rightColor = 7;
const wrongColor = 175;
const bgColor = 17;
var spriteColor = bgColor;
var targetColor = waitColor;
function nop(){}
function pick(){
let newnum = random(0, level);
if(newnum == num) newnum = random(0, level);
num = newnum;
img = file(list[num], img);
for(var i in words){
words[i] = random(0, level);
}
words[random(0, 4)] = num;
targetColor = waitColor;
state = tween;
nextState = waitForInput;
stateTime = 0;
W = 0;
}
function wrongFeedback(){
if(stateTime == 0) stateTime = 60;
else if(--stateTime == 0){
targetColor = bgColor;
nextState = pick;
state = tween;
}
color(172);
if(words[0] == num){
cursor(25 + 2, 25 + 4);
print(list[words[0]]);
}
if(words[1] == num){
cursor(25 + 2, 73 + 4);
print(list[words[1]]);
}
if(words[2] == num){
cursor(5 + 2, 49 + 4);
print(list[words[2]]);
}
if(words[3] == num){
cursor(44 + 2, 49 + 4);
print(list[words[3]]);
}
}
function waitForInput(){
let choice = -1;
if(stateTime == 0) stateTime = 60;
else if(--stateTime == 0) choice = 4;
if(justPressed("UP")){
choice = 0;
} else if(justPressed("DOWN")){
choice = 1;
} else if(justPressed("LEFT")){
choice = 2;
} else if(justPressed("RIGHT")){
choice = 3;
}
if(choice > -1){
if((choice != 4) && (words[choice] == num)){
if(++level > length(list)) level = length(list) - 1;
if(++streak > maxStreak){
maxStreak = streak;
emote = rightEmote;
}
highscore(streak);
nextState = pick;
state = tween;
targetColor = bgColor;
}else{
if(--level < 0) level = 0;
streak = 0;
targetColor = wrongColor;
nextState = wrongFeedback;
state = tween;
stateTime = 0;
emote = boredEmote;
}
W = 0;
} else {
color(22);
cursor(25 + 2, 25 + 4);
print(list[words[0]]);
cursor(25 + 2, 73 + 4);
print(list[words[1]]);
cursor(5 + 2, 49 + 4);
print(list[words[2]]);
cursor(44 + 2, 49 + 4);
print(list[words[3]]);
}
}
function tween(){
if(W--) return;
W = 1;
var block = spriteColor >> 3;
var lum = spriteColor & 7;
var tblock = targetColor >> 3;
var tlum = targetColor & 7;
if(block != tblock){
if(lum > 0) --spriteColor;
else spriteColor = tblock << 3;
} else {
if(lum < tlum) ++spriteColor;
else if(lum == tlum) state = nextState;
else --spriteColor;
}
}
function init(){
fill(bgColor);
color(10);
pick();
}
function update(){
color(18 - 7);
sprite(0, 0, UI);
if(emote == wrongEmote)
color(91);
else
color(0);
sprite(96, 146, emote);
cursor(116, 148);
color(22);
printNumber(streak);
state();
color(spriteColor - 7);
sprite(spriteX, spriteY, img);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment