aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2020-04-01 18:14:18 -0500
committerJeffrey Armstrong <jeff@approximatrix.com>2020-04-01 18:14:18 -0500
commit0496bfb6bf86784242246b218b4d663367ee0e7b (patch)
tree2087d72f45d4b4f816edbc0cb458e6eb7433b160
parentca1dd8dfa3fbb0ca8f947b003b9e52bc2a686968 (diff)
downloadgemworm-0496bfb6bf86784242246b218b4d663367ee0e7b.zip
gemworm-0496bfb6bf86784242246b218b4d663367ee0e7b.tar.gz
Initial work on capturing initials if a high score is achieved. Lots broken with form handling, though.
-rw-r--r--scores.c22
-rw-r--r--scores.h3
-rw-r--r--worm.c30
-rw-r--r--wormst.rscbin2210 -> 2204 bytes
4 files changed, 54 insertions, 1 deletions
diff --git a/scores.c b/scores.c
index f840692..11a983f 100644
--- a/scores.c
+++ b/scores.c
@@ -126,3 +126,25 @@ char *get_score_at(int pos, int *score)
*score = scores[pos].score;
return scores[pos].initials;
}
+
+int is_high_score(int score)
+{
+ return (score > scores[9].score);
+}
+
+void add_high_score(const char *initials, int score)
+{
+int i,j;
+
+ for(i=0;i<10;i++) {
+ if(score > scores[i].score) {
+ for(j=8;j>=i;j--) {
+ scores[j+1].score = scores[j].score;
+ memcpy(scores[j+1].initials, scores[j].initials, 3);
+ }
+ scores[i].score = score;
+ memcpy(scores[i].initials, initials, 3);
+ break;
+ }
+ }
+}
diff --git a/scores.h b/scores.h
index 05f53f0..1d36fbe 100644
--- a/scores.h
+++ b/scores.h
@@ -5,4 +5,7 @@ void load_scores(const char *fullpath);
void save_scores(const char *fullpath);
char *get_score_at(int pos, int *score);
+int is_high_score(int score);
+void add_high_score(const char *initials, int score);
+
#endif /* SCORES_HEADERS */
diff --git a/worm.c b/worm.c
index dd1af07..ebe6089 100644
--- a/worm.c
+++ b/worm.c
@@ -78,6 +78,7 @@ GRECT app_wdw; /* xywh of working area */
OBJECT FAR *app_menu;
OBJECT FAR *about_box;
OBJECT FAR *scores_box;
+OBJECT FAR *newscore_box;
#ifdef PCGEM
#define RCS_FILE "wormpc.rsc"
@@ -104,6 +105,28 @@ GRECT box,origin;
return;
}
+void hndl_high_score(int score)
+{
+int res;
+GRECT box,origin;
+
+TEDINFO *eted;
+
+ form_center(newscore_box, &box.g_x, &box.g_y, &box.g_w, &box.g_h);
+ objc_draw(newscore_box,0,2,box.g_x, box.g_y, box.g_w, box.g_h);
+ res = form_do(newscore_box,0);
+
+ if(res == BOK) {
+ /* save! */
+ eted = (TEDINFO *)(newscore_box[TINITIALS].ob_spec.index);
+
+ add_high_score((char *)eted->te_ptext, score);
+ }
+
+ form_dial(FMD_FINISH,0,0,0,0,box.g_x, box.g_y, box.g_w, box.g_h);
+ return;
+}
+
short score_positions[] = {THI1, THI2, THI3, THI4, THI5, THI6, THI7, THI8, THI9, THI10};
void hndl_scores()
@@ -214,6 +237,7 @@ WORD txtwidth,txtheight;
rsrc_gaddr(R_TREE,ABOUT,&about_box);
rsrc_gaddr(R_TREE,HISCORES,&scores_box);
+ rsrc_gaddr(R_TREE,NEWSCORE,&newscore_box);
/* Make the application name nicer on Atari GEM */
#ifndef PCGEM
@@ -535,7 +559,11 @@ EVMULT_OUT evout;
wind_update(END_UPDATE);
if(palive == DEAD || falive == DEAD) {
- form_alert(1,"[3][You've Died!|Good try, though...][Reset]");
+ if(is_high_score(player->score)) {
+ hndl_high_score(player->score);
+ save_scores(argv[0]);
+ } else
+ form_alert(1,"[3][You've Died!|Good try, though...][Reset]");
reset_player(player);
playing = 0;
menu_ienable(app_menu, MPAUSE, 0);
diff --git a/wormst.rsc b/wormst.rsc
index 9bfb313..7969965 100644
--- a/wormst.rsc
+++ b/wormst.rsc
Binary files differ