Skip to content

Commit

Permalink
demos: space-shooter: Fix high score saving (#217)
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Maškarinec <[email protected]>
  • Loading branch information
marekmaskarinec committed Dec 21, 2024
1 parent 1cc226d commit 198c8b1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
10 changes: 7 additions & 3 deletions demos/space-shooter/enemy.um
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ fn handle*() {
if global::hp == 0 {
if global::score > global::hi {
global::hi = global::score
f := std::fopen("score", "w").item0
fprintf(f, "%d", global::hi)
std::fclose(f)
f, err := std::fopen(th::convPath("data://score"), "w")
if err.code != 0 {
printf("Error: Could not write high score\n")
} else {
fprintf(f, "%d", global::hi)
std::fclose(f)
}
}

enemies = []Enemy{}
Expand Down
4 changes: 2 additions & 2 deletions demos/space-shooter/main.um
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ fn init*() {
sound::init()
global::hp = 10

f, err := std::fopen("score", "r")
if err.code != 0 {
f, err := std::fopen(th::convPath("data://score"), "r")
if err.code == 0 {
fscanf(f, "%d", &global::hi)
std::fclose(f)
}
Expand Down
1 change: 0 additions & 1 deletion demos/space-shooter/score

This file was deleted.

2 changes: 1 addition & 1 deletion umka/th.um
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ var (

fn umth_conv_path(path: str): str
//~~fn convPath
// Expands the path to a platform specific path.
// Evaluate path prefixes and return as a platform native path.
fn convPath*(path: str): str {
//~~
return umth_conv_path(path)
Expand Down

0 comments on commit 198c8b1

Please sign in to comment.