hermet pushed a commit to branch master.

http://git.enlightenment.org/games/etypers.git/commit/?id=45e4eedb76811f03381a555bb627b0e71a5e3189

commit 45e4eedb76811f03381a555bb627b0e71a5e3189
Author: Hermet Park <her...@hermet.pe.kr>
Date:   Sat Feb 13 14:51:09 2016 +0900

    display a total score when game is over.
---
 data/theme/etypers.edc | 50 ++++++++++++++++++++++++++++++++++++++++++++++----
 src/bin/etypers.c      | 26 +++++++++++++++++++-------
 2 files changed, 65 insertions(+), 11 deletions(-)

diff --git a/data/theme/etypers.edc b/data/theme/etypers.edc
index 350a15c..3c86424 100644
--- a/data/theme/etypers.edc
+++ b/data/theme/etypers.edc
@@ -140,7 +140,7 @@ collections {
                rel1.to: "level";
             }
          }
-         part { name: "correct";
+         part { name: "accuracy";
             type: TEXT;
             scale: 1;
             description { state: "default" 0.0;
@@ -157,7 +157,7 @@ collections {
                rel1.relative: 0 1;
             }
          }
-         part { name: "correct_value";
+         part { name: "accuracy_value";
             type: TEXT;
             scale: 1;
             description { state: "default" 0.0;
@@ -172,7 +172,7 @@ collections {
                align: 0 0 ;
                rel1.relative: 1 0;
                rel1.offset: 5 0;
-               rel1.to: "correct";
+               rel1.to: "accuracy";
             }
          }
          part { name: "input_clipper";
@@ -230,7 +230,7 @@ collections {
                    size: 30;
                    min: 0 0;
                    max: 1 0;
-                   align: 0.5 0.5;
+                   align: 0.5 0.4;
                    text: "Game Over";
                }
                color: 0 0 0 0;
@@ -241,6 +241,44 @@ collections {
                color: 100 100 100 255;
             }
          }
+         text { "total_score";
+            scale: 1;
+            desc { "default";
+               text {
+                  font: "Sans:style=Bold";
+                  size: 20;
+                  min: 0 0;
+                  max: 1 0;
+                  align: 0.5 0.5;
+                  text: "Your score: 100";
+               }
+               color: 0 0 0 0;
+               align: 0.5 0.5;
+            }
+            desc { "gameover";
+               inherit: "default" 0.0;
+               color: 100 100 100 255;
+            }
+         }
+         text { "exit_guide";
+            scale: 1;
+            desc { "default";
+               text {
+                  font: "Sans:style=Bold";
+                  size: 12;
+                  min: 0 0;
+                  max: 1 0;
+                  align: 0.5 0.6;
+                  text: "Press ESC key";
+               }
+               color: 0 0 0 0;
+               align: 0.5 0.6;
+            }
+            desc { "gameover";
+               inherit: "default" 0.0;
+               color: 100 100 100 255;
+            }
+         }
       }
       programs {
          program { name: "sky_anim1";
@@ -290,6 +328,8 @@ collections {
             action: STATE_SET "gameover" 0.0;
             target: "effect_overlay";
             target: "gameover";
+            target: "total_score";
+            target: "exit_guide";
             transition: LINEAR 1.0;
          }
          program { name: "gamereset";
@@ -299,6 +339,8 @@ collections {
             target: "effect_overlay";
             target: "effect_overlay";
             target: "gameover";
+            target: "total_score";
+            target: "exit_guide";
          }
       }
    }
diff --git a/src/bin/etypers.c b/src/bin/etypers.c
index bad7531..bd27730 100644
--- a/src/bin/etypers.c
+++ b/src/bin/etypers.c
@@ -35,6 +35,7 @@ typedef struct _AppData
    float hit_try_cnt;
    float text_scale;
    unsigned long combo;
+   unsigned long accuracy;
    Evas_Coord bound_w;
    Evas_Coord bound_h;
    Evas_Coord_Rectangle defense_rect;
@@ -333,7 +334,7 @@ game_reset(AppData *appdata)
    elm_object_text_set(appdata->entry, "");
    elm_object_part_text_set(appdata->ly, "level_value", "1");
    elm_object_part_text_set(appdata->ly, "score_value", "0");
-   elm_object_part_text_set(appdata->ly, "correct_value", "100%");
+   elm_object_part_text_set(appdata->ly, "accuracy_value", "100%");
 
    remove_all_enemies(appdata);
    reset_defense_wall(appdata);
@@ -344,6 +345,7 @@ game_reset(AppData *appdata)
    appdata->hit_cnt = 0.0f;
    appdata->hit_try_cnt = 0.0f;
    appdata->combo = 0;
+   appdata->accuracy = 100;
 }
 
 static void
@@ -351,6 +353,15 @@ game_over(AppData *appdata)
 {
    ecore_animator_freeze(appdata->animator);
    elm_object_signal_emit(appdata->ly, "elm,state,gameover", "etypers");
+
+   //score
+   double score = ((double) appdata->score) * appdata->level *
+      ((double) appdata->accuracy);
+
+   char buf[1024];
+   snprintf(buf, sizeof(buf), "%d", (int) score);
+
+   elm_object_part_text_set(appdata->ly, "total_score", buf);
    appdata->state = GameOver;
 }
 
@@ -518,15 +529,17 @@ combo(AppData *appdata, Enemy *enemy, int combo)
 }
 
 static void
-update_correctness(AppData *appdata, Eina_Bool hit)
+update_accuracy(AppData *appdata, Eina_Bool hit)
 {
    appdata->hit_try_cnt += 1.0f;
    if (hit) appdata->hit_cnt += 1.0f;
 
    char buf[10];
-   int correctness = (int) ((appdata->hit_cnt / appdata->hit_try_cnt) * 
100.0f);
-   snprintf(buf, sizeof(buf), "%3d%%", correctness);
-   elm_object_part_text_set(appdata->ly, "correct_value", buf);
+   int accuracy = (int) ((appdata->hit_cnt / appdata->hit_try_cnt) * 100.0f);
+   snprintf(buf, sizeof(buf), "%3d%%", accuracy);
+   elm_object_part_text_set(appdata->ly, "accuracy_value", buf);
+
+   appdata->accuracy = accuracy;
 }
 
 static void
@@ -570,7 +583,7 @@ enemies_kill(AppData *appdata, Evas_Object *obj, const char 
*input_text,
         appdata->combo = 0;
      }
 
-   update_correctness(appdata, hit);
+   update_accuracy(appdata, hit);
 
    elm_object_text_set(obj, NULL);
 
@@ -1014,7 +1027,6 @@ app_init(AppData *appdata)
    defense_wall_init(appdata);
 
    appdata->state = Ready;
-   appdata->level = 1;
    appdata->bound_w = DEFAULT_WIN_W;
    appdata->bound_h = DEFAULT_WIN_H;
 

-- 


Reply via email to