Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

Languages: Tetris in French and Chinese

Mason Chen485071132d57
diff --git a/games/tetris/lang/fr.txt b/games/tetris/lang/fr.txt
new file mode 100644
index 00000000..4a10cedd
--- /dev/null
+++ b/games/tetris/lang/fr.txt
@@ -0,0 +1,32 @@
+# Tetris in French: the English text as in the source, a tab, the translation (see tools/lang.py).
+# The calculator's font: 32 big or 45 small letters across; the panels' labels 8 big ones.
+NEXT SUIVANT
+HOLD RÉSERVE
+BEST RECORD
+SCORE SCORE
+LEVEL NIVEAU
+LINES LIGNES
+\n HOW TO PLAY\n\n - <LEFT> and <RIGHT> to move\n - <DOWN> for soft drop\n - <UP> for hard drop\n - <OK> & <TOOLBOX> to rotate left and right\n - <BACKSPACE> (<clear>) to hold the tetri\n - <BACK> to pause\n\n Every full line disappears\n Get more points by clearing\n multiple lines at once !\n The level increases every 10 lines.\n You lose when the stack reaches the top. \n Hold the tetri to keep it for later ! \n COMMENT JOUER\n\n - <GAUCHE> et <DROITE> : déplacer\n - <BAS> : descente rapide\n - <HAUT> : chute directe\n - <OK> et <BOÎTE À OUTILS> : tourner\n - <EFFACER> (<clear>) : réserver\n - <RETOUR> : pause\n\n Une ligne pleine disparaît.\n Plus de points en effaçant\n plusieurs lignes d'un coup !\n Le niveau monte toutes les 10 lignes.\n Perdu si la pile atteint le haut.\n Réserve une pièce pour plus tard !
+Ghost Piece Pièce fantôme
+Yes Oui
+No Non
+Starting Level Niveau de départ
+High Score Meilleur score
+Replay Rejouer
+Menu Menu
+Quit game Quitter
+ GAME OVER PERDU !
+ NEW HIGH SCORE! RECORD BATTU !
+Quit game? Quitter ?
+Current Score Score actuel
+Current Level Niveau actuel
+Play Jouer
+Settings Réglages
+How to Play Comment jouer
+Exit Quitter
+Continue Continuer
+New Game Nouvelle partie
+Overwrite save? Écraser la partie ?
+Resume Reprendre
+Menu : <Back> Menu : <Retour>
+SETTINGS RÉGLAGES
diff --git a/games/tetris/lang/zh.txt b/games/tetris/lang/zh.txt
new file mode 100644
index 00000000..9982924c
--- /dev/null
+++ b/games/tetris/lang/zh.txt
@@ -0,0 +1,33 @@
+# Tetris in Chinese: the English text as in the source, a tab, the translation (see tools/lang.py).
+# A Chinese letter takes two cells of the calculator's font (32 big or 45 small cells across);
+# the panels' labels 8 big cells.
+NEXT 下一个
+HOLD 暂存
+BEST 最高分
+SCORE 得分
+LEVEL 等级
+LINES 行数
+\n HOW TO PLAY\n\n - <LEFT> and <RIGHT> to move\n - <DOWN> for soft drop\n - <UP> for hard drop\n - <OK> & <TOOLBOX> to rotate left and right\n - <BACKSPACE> (<clear>) to hold the tetri\n - <BACK> to pause\n\n Every full line disappears\n Get more points by clearing\n multiple lines at once !\n The level increases every 10 lines.\n You lose when the stack reaches the top. \n Hold the tetri to keep it for later ! \n 玩法说明\n\n - 左/右方向键:左右移动\n - 下方向键:加速下落\n - 上方向键:直接落下\n - <OK>/<工具箱>:向左/向右旋转\n - <退格>(<clear>):暂存方块\n - <返回>:暂停\n\n 填满一行即可消除,\n 一次消除多行得分更高!\n 每消除 10 行升一级。\n 方块堆到顶部即失败。\n 暂存的方块可留待以后使用!
+Ghost Piece 显示落点
+Yes 是
+No 否
+Starting Level 起始等级
+High Score 最高分
+Replay 再来一局
+Menu 菜单
+Quit game 退出游戏
+ GAME OVER 游戏结束
+ NEW HIGH SCORE! 新纪录!
+Quit game? 退出游戏?
+Current Score 当前得分
+Current Level 当前等级
+Play 开始游戏
+Settings 设置
+How to Play 玩法说明
+Exit 退出
+Continue 继续游戏
+New Game 新游戏
+Overwrite save? 覆盖存档?
+Resume 继续
+Menu : <Back> 菜单:<返回>
+SETTINGS 设置
diff --git a/games/tetris/numworks_utils/build.rs b/games/tetris/numworks_utils/build.rs
index bc4b027d..24b8a365 100644
--- a/games/tetris/numworks_utils/build.rs
+++ b/games/tetris/numworks_utils/build.rs
@@ -1,6 +1,14 @@
use std::process::Command;
fn main() {
+ // NumPlay's language builds (tools/lang.py) turn NP_TEXT_EXTRA on in the common header: the
+ // code for letters beyond ASCII is only built then (cfg np_text_extra)
+ println!("cargo::rerun-if-changed=../../common/np_text.h");
+ println!("cargo::rustc-check-cfg=cfg(np_text_extra)");
+ let header = std::fs::read_to_string("../../common/np_text.h").unwrap_or_default();
+ if header.contains("#define NP_TEXT_EXTRA 1") {
+ println!("cargo::rustc-cfg=np_text_extra");
+ }
// The C helpers (files, app lifetime) read the calculator's memory directly:
// they are only built for the calculator. Other targets (the simulator
// build of NumPlay) provide the same functions.
diff --git a/games/tetris/numworks_utils/src/lib.rs b/games/tetris/numworks_utils/src/lib.rs
index 04bcb9bf..51b037f7 100644
--- a/games/tetris/numworks_utils/src/lib.rs
+++ b/games/tetris/numworks_utils/src/lib.rs
@@ -1,6 +1,15 @@
#![no_std]
#![no_main]
+/// A text players read, NUL-terminated for the calculator. NumPlay's language builds put each
+/// one's translation in its place (tools/lang.py, games/tetris/lang/<code>.txt).
+#[macro_export]
+macro_rules! T {
+ ($s:literal) => {
+ concat!($s, "\0")
+ };
+}
+
pub mod app;
pub mod eadk;
pub mod graphical;
diff --git a/games/tetris/numworks_utils/src/menu.rs b/games/tetris/numworks_utils/src/menu.rs
index 77bc636c..5bd2754e 100644
--- a/games/tetris/numworks_utils/src/menu.rs
+++ b/games/tetris/numworks_utils/src/menu.rs
@@ -36,13 +36,13 @@ pub enum StartMenuAction<T> {
Exit,
}
-const CHOICES_NO_SAVE: &[&str] = &["Play\0", "Settings\0", "How to Play\0", "Exit\0"];
+const CHOICES_NO_SAVE: &[&str] = &[T!("Play"), T!("Settings"), T!("How to Play"), T!("Exit")];
const CHOICES_WITH_SAVE: &[&str] = &[
- "Continue\0",
- "New Game\0",
- "Settings\0",
- "How to Play\0",
- "Exit\0",
+ T!("Continue"),
+ T!("New Game"),
+ T!("Settings"),
+ T!("How to Play"),
+ T!("Exit"),
];
/// Asks a yes/no question; No is selected first, and Back answers No.
@@ -85,7 +85,7 @@ pub fn confirm_dialog(prompt: &str, cfg: &ColorConfig) -> bool {
let choice = selection(
cfg,
&MenuConfig {
- choices: &["No\0", "Yes\0"],
+ choices: &[T!("No"), T!("Yes")],
rect_margins: (35, 0), // 35px padding on left and right inside the 200px box
dimensions: (dialog_w - 4, LARGE_CHAR_HEIGHT + 4),
offset: (0, btn_y_offset),
@@ -217,7 +217,7 @@ fn start_menu_single_slot<T: GameSave>(
return StartMenuAction::Continue(save, None);
}
1 => {
- if confirm_dialog("Overwrite save?\0", cfg) {
+ if confirm_dialog(T!("Overwrite save?"), cfg) {
delete_save(filename, None);
fading(FADING_TIME);
return StartMenuAction::NewGame(None);
@@ -236,7 +236,7 @@ fn start_menu_single_slot<T: GameSave>(
controls(controls_text, cfg);
}
_ => {
- if confirm_dialog("Quit game?\0", cfg) {
+ if confirm_dialog(T!("Quit game?"), cfg) {
fading(FADING_TIME);
return StartMenuAction::Exit;
}
@@ -261,7 +261,7 @@ fn start_menu_single_slot<T: GameSave>(
controls(controls_text, cfg);
}
_ => {
- if confirm_dialog("Quit game?\0", cfg) {
+ if confirm_dialog(T!("Quit game?"), cfg) {
fading(FADING_TIME);
return StartMenuAction::Exit;
}
@@ -337,7 +337,7 @@ pub fn pause_menu(cfg: &ColorConfig, y_offset: i16) -> u8 {
selection(
cfg,
&MenuConfig {
- choices: &["Resume\0", "Menu\0", "Quit game\0"],
+ choices: &[T!("Resume"), T!("Menu"), T!("Quit game")],
rect_margins: (20, 10),
dimensions: (
SCREEN_WIDTH * 2 / 5,
@@ -484,7 +484,7 @@ fn draw_selection_string(
fn controls(text: &str, cfg: &ColorConfig) -> u8 {
wait_for_vblank();
fill_screen(cfg.bckgrd);
- let back_text = "Menu : <Back> \0";
+ let back_text = T!("Menu : <Back> ");
draw_string_cfg(
back_text,
Point::new(
diff --git a/games/tetris/numworks_utils/src/menu/settings.rs b/games/tetris/numworks_utils/src/menu/settings.rs
index 484662e1..dc86b65e 100644
--- a/games/tetris/numworks_utils/src/menu/settings.rs
+++ b/games/tetris/numworks_utils/src/menu/settings.rs
@@ -147,8 +147,8 @@ fn draw_settings_page(
// visual things
display::wait_for_vblank();
fill_screen(cfg.bckgrd);
- draw_centered_string("SETTINGS\0", 5u16, true, cfg, false);
- let back_text = "Menu : <Back> \0";
+ draw_centered_string(T!("SETTINGS"), 5u16, true, cfg, false);
+ let back_text = T!("Menu : <Back> ");
draw_string_cfg(
back_text,
Point::new(
diff --git a/games/tetris/numworks_utils/src/utils.rs b/games/tetris/numworks_utils/src/utils.rs
index e0f29cb9..f67e4b86 100644
--- a/games/tetris/numworks_utils/src/utils.rs
+++ b/games/tetris/numworks_utils/src/utils.rs
@@ -27,12 +27,26 @@ pub fn get_centered_text_x_coordo(string: &str, large: bool) -> u16 {
}
}
+/// The cells a text takes in the calculator's fixed-width font. In a language build (see build.rs),
+/// an accented letter takes one and a Chinese one two (NumPlay draws those in two cells).
+pub fn text_cells(string: &str) -> u16 {
+ if cfg!(np_text_extra) {
+ string
+ .chars()
+ .filter(|c| *c >= ' ')
+ .map(|c| if c as u32 >= 0x2E80 { 2 } else { 1 })
+ .sum()
+ } else {
+ string
+ .chars()
+ .filter(|p| p.is_ascii_alphanumeric() || *p == ' ' || p.is_ascii_punctuation())
+ .count() as u16
+ }
+}
+
/// Returns the size IN PIXELS, on the screen, of the given string
pub fn get_string_pixel_size(string: &str, large: bool) -> u16 {
- string
- .chars()
- .filter(|p| p.is_ascii_alphanumeric() || *p == ' ' || p.is_ascii_punctuation())
- .count() as u16
+ text_cells(string)
* (if large {
LARGE_CHAR_WIDTH
} else {
diff --git a/games/tetris/tetris/build.rs b/games/tetris/tetris/build.rs
index 48d66e83..291b1223 100644
--- a/games/tetris/tetris/build.rs
+++ b/games/tetris/tetris/build.rs
@@ -3,6 +3,14 @@ use std::process::Command;
const TILESIZE: u16 = 12;
fn main() {
+ // in NumPlay's language builds (tools/lang.py: NP_TEXT_EXTRA on in the common header), the
+ // code for letters beyond ASCII (cfg np_text_extra)
+ println!("cargo::rerun-if-changed=../../common/np_text.h");
+ println!("cargo::rustc-check-cfg=cfg(np_text_extra)");
+ let header = std::fs::read_to_string("../../common/np_text.h").unwrap_or_default();
+ if header.contains("#define NP_TEXT_EXTRA 1") {
+ println!("cargo::rustc-cfg=np_text_extra");
+ }
// Turn icon.png into icon.nwi
println!("cargo:rerun-if-changed=src/data/icon.png");
let output = Command::new("nwlink")
diff --git a/games/tetris/tetris/src/data/tetris_controls.txt b/games/tetris/tetris/src/data/tetris_controls.txt
deleted file mode 100644
index d474a2eb..00000000
--- a/games/tetris/tetris/src/data/tetris_controls.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-
- HOW TO PLAY
-
- - <LEFT> and <RIGHT> to move
- - <DOWN> for soft drop
- - <UP> for hard drop
- - <OK> & <TOOLBOX> to rotate left and right
- - <BACKSPACE> (<clear>) to hold the tetri
- - <BACK> to pause
-
- Every full line disappears
- Get more points by clearing
- multiple lines at once !
- The level increases every 10 lines.
- You lose when the stack reaches the top.
- Hold the tetri to keep it for later !
\ No newline at end of file
diff --git a/games/tetris/tetris/src/game_tetris.rs b/games/tetris/tetris/src/game_tetris.rs
index fc72b0cf..0b38bf12 100644
--- a/games/tetris/tetris/src/game_tetris.rs
+++ b/games/tetris/tetris/src/game_tetris.rs
@@ -12,6 +12,7 @@ use numworks_utils::{
},
storage::save::{delete_save, write_save, SaveSlotMode},
utils::{randint, LARGE_CHAR_HEIGHT},
+ T,
};
use crate::{
@@ -40,18 +41,21 @@ fn vis_addon() {
draw_tetrimino(&tetri, false);
}
+/// The "How to Play" page (one line per line of the screen, 45 small letters wide).
+const CONTROLS: &str = T!("\n HOW TO PLAY\n\n - <LEFT> and <RIGHT> to move\n - <DOWN> for soft drop\n - <UP> for hard drop\n - <OK> & <TOOLBOX> to rotate left and right\n - <BACKSPACE> (<clear>) to hold the tetri\n - <BACK> to pause\n\n Every full line disappears\n Get more points by clearing\n multiple lines at once !\n The level increases every 10 lines.\n You lose when the stack reaches the top. \n Hold the tetri to keep it for later ! ");
+
pub fn start() {
let mut opt: [&mut Setting; 3] = [
&mut Setting {
- name: "Ghost Piece\0",
+ name: T!("Ghost Piece"),
choice: 0,
values: Vec::from_slice(&[1, 0]).unwrap(),
- texts: Vec::from_slice(&["Yes\0", "No\0"]).unwrap(),
+ texts: Vec::from_slice(&[T!("Yes"), T!("No")]).unwrap(),
user_modifiable: true,
fixed_values: true,
},
&mut Setting {
- name: "Starting Level\0",
+ name: T!("Starting Level"),
choice: 0,
values: Vec::from_slice(&[1, 1, 9]).unwrap(),
texts: Vec::new(),
@@ -59,7 +63,7 @@ pub fn start() {
fixed_values: false,
},
&mut Setting {
- name: "High Score\0",
+ name: T!("High Score"),
choice: 0,
values: Vec::from_slice(&[0, 0, 999999]).unwrap(),
texts: Vec::new(),
@@ -74,7 +78,7 @@ pub fn start() {
&mut opt,
&COLOR_CONFIG,
vis_addon,
- include_str!("./data/tetris_controls.txt"),
+ CONTROLS,
"tetris",
SaveSlotMode::Single,
);
@@ -187,7 +191,7 @@ const LEFT_ROTATION_KEY: u32 = key::OK;
const HOLD_KEY: u32 = key::BACKSPACE;
const DEATH_MENU: MenuConfig = MenuConfig {
- choices: &["Replay\0", "Menu\0", "Quit game\0"],
+ choices: &[T!("Replay"), T!("Menu"), T!("Quit game")],
rect_margins: (20, 10),
dimensions: (CASE_SIZE * (PLAYFIELD_WIDTH + 2), CASE_SIZE * 10),
offset: (0, 60),
@@ -433,11 +437,11 @@ pub fn game(
}
if death {
delete_save("tetris", None); // Deletes record immediately
- draw_centered_string(" GAME OVER \0", 10, true, &COLOR_CONFIG, true);
+ draw_centered_string(T!(" GAME OVER "), 10, true, &COLOR_CONFIG, true);
if score > *high_score {
*high_score = score;
draw_centered_string(
- " NEW HIGH SCORE! \0",
+ T!(" NEW HIGH SCORE! "),
10 + LARGE_CHAR_HEIGHT + 2,
true,
&COLOR_CONFIG,
@@ -445,7 +449,7 @@ pub fn game(
);
}
let mut action = selection(&COLOR_CONFIG, &DEATH_MENU, false);
- if action == 2 && !confirm_dialog("Quit game?\0", &COLOR_CONFIG) {
+ if action == 2 && !confirm_dialog(T!("Quit game?"), &COLOR_CONFIG) {
action = 1; // not quitting: back to the Tetris menu
}
// Ensure the save is deleted regardless of selection option chosen
@@ -534,7 +538,7 @@ pub fn game(
// Quit game asks first; saying no comes back to the pause menu
let action = loop {
let a = pause_menu(&COLOR_CONFIG, 0);
- if a != 2 || confirm_dialog("Quit game?\0", &COLOR_CONFIG) {
+ if a != 2 || confirm_dialog(T!("Quit game?"), &COLOR_CONFIG) {
break a;
}
redraw();
diff --git a/games/tetris/tetris/src/tetris_save.rs b/games/tetris/tetris/src/tetris_save.rs
index 901fb495..2da2386a 100644
--- a/games/tetris/tetris/src/tetris_save.rs
+++ b/games/tetris/tetris/src/tetris_save.rs
@@ -1,7 +1,10 @@
use heapless::Vec;
-use numworks_utils::storage::{
- save::{GameSave, SaveField, MAX_SAVE_FIELDS},
- MAX_STORAGE_VALUES,
+use numworks_utils::{
+ storage::{
+ save::{GameSave, SaveField, MAX_SAVE_FIELDS},
+ MAX_STORAGE_VALUES,
+ },
+ T,
};
use crate::{
@@ -38,13 +41,13 @@ impl GameSave for TetrisSave {
fn describe_fields(&self) -> Vec<SaveField, MAX_SAVE_FIELDS> {
let mut fields = Vec::new();
let _ = fields.push(SaveField {
- name: "Current Score\0",
+ name: T!("Current Score"),
min: 0,
max: 999999,
value: self.raw[20],
});
let _ = fields.push(SaveField {
- name: "Current Level\0",
+ name: T!("Current Level"),
min: 1,
max: 20,
value: (self.raw[21] & 0xFFFF),
diff --git a/games/tetris/tetris/src/ui_tetris.rs b/games/tetris/tetris/src/ui_tetris.rs
index d4a27379..0b074f74 100644
--- a/games/tetris/tetris/src/ui_tetris.rs
+++ b/games/tetris/tetris/src/ui_tetris.rs
@@ -6,7 +6,8 @@ use numworks_utils::{
},
graphical::{draw_string_cfg, tiling::Tileset},
include_bytes_align_as,
- utils::{string_from_u32, LARGE_CHAR_WIDTH},
+ utils::{string_from_u32, text_cells, LARGE_CHAR_WIDTH},
+ T,
};
use crate::{
@@ -60,7 +61,11 @@ fn draw_panel(x: u16, y: u16) {
/// Draws a label centred in a panel, `row` lines below its top.
fn draw_label(text: &str, panel_x: u16, panel_y: u16, row: u16) {
- let chars = text.trim_end_matches('\0').chars().count() as u16;
+ let chars = if cfg!(np_text_extra) {
+ text_cells(text)
+ } else {
+ text.trim_end_matches('\0').chars().count() as u16
+ };
let x = panel_x + (PANEL_W - chars * LARGE_CHAR_WIDTH) / 2;
draw_string_cfg(
text,
@@ -105,12 +110,12 @@ pub fn draw_stable_ui(level: u16, level_lines: u16, score: u32, high_score: u32)
draw_panel(LEFT_X, BOTTOM_Y);
draw_panel(RIGHT_X, TOP_Y);
draw_panel(RIGHT_X, BOTTOM_Y);
- draw_label("NEXT\0", LEFT_X, TOP_Y, 0);
- draw_label("HOLD\0", LEFT_X, BOTTOM_Y, 0);
- draw_label("BEST\0", RIGHT_X, TOP_Y, 0);
- draw_label("SCORE\0", RIGHT_X, TOP_Y, 2);
- draw_label("LEVEL\0", RIGHT_X, BOTTOM_Y, 0);
- draw_label("LINES\0", RIGHT_X, BOTTOM_Y, 2);
+ draw_label(T!("NEXT"), LEFT_X, TOP_Y, 0);
+ draw_label(T!("HOLD"), LEFT_X, BOTTOM_Y, 0);
+ draw_label(T!("BEST"), RIGHT_X, TOP_Y, 0);
+ draw_label(T!("SCORE"), RIGHT_X, TOP_Y, 2);
+ draw_label(T!("LEVEL"), RIGHT_X, BOTTOM_Y, 0);
+ draw_label(T!("LINES"), RIGHT_X, BOTTOM_Y, 2);
wait_for_vblank();
draw_score(high_score, true);