hermet pushed a commit to branch master.

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

commit e251e6ca38dfebc7054eabbf1f64d51c245e84c7
Author: Hermet Park <her...@hermet.pe.kr>
Date:   Sat Feb 13 03:22:57 2016 +0900

    + random item
---
 src/bin/etypers.c | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 168 insertions(+), 9 deletions(-)

diff --git a/src/bin/etypers.c b/src/bin/etypers.c
index ce20c21..027fcec 100644
--- a/src/bin/etypers.c
+++ b/src/bin/etypers.c
@@ -1,13 +1,14 @@
 #include <Elementary.h>
 
+#define _DROP_DIST_WEIGHT 25
 #define DEFAULT_WIN_W ELM_SCALE_SIZE(400)
 #define DEFAULT_WIN_H ELM_SCALE_SIZE(600)
 #define NEW_ENEMY_DURATION_SEC 5
 #define LEVEL_INC_WEIGHT 0.01
-#define DROP_DIST_WEIGHT 25
 #define DEFENSE_WALL_CNT 15
 #define WALL_COLOR 100, 100, 100, 170
 #define MINUS_SCORE 25
+#define ITEM_TIME 10
 
 typedef enum _GameState
 {
@@ -40,8 +41,13 @@ typedef struct _AppData
    Evas_Object *entry;
    Evas_Object *table;
    Evas_Object *popup;
+   Evas_Object *check;
    GameState state;
+   Ecore_Timer *timer;
    Ecore_Animator *animator;
+
+   Eina_Bool item;
+   Eina_Bool item_time;
 } AppData;
 
 typedef struct _Enemy
@@ -52,9 +58,36 @@ typedef struct _Enemy
    float y;
    float w;
    float h;
+   Eina_Bool item;
 } Enemy;
 
+#define ITEM_NAMES_CNT 75
+static char *ITEM_NAMES[ITEM_NAMES_CNT] = { "hermet", "raster", "cedric",
+"zmike", "tasn", "ami", "antognolli", "beber", "bu5hm4n", "captainigloo",
+"andreas", "asdfuser", "beber", "barbieri", "ceolin", "davemds", "demarchi",
+"devilhorns", "englebass", "etrunko", "eunue", "felipealmeida", "furrymyad",
+"garik", "glima", "gl-lee", "herdsman", "huchi", "illogict", "jackdanielz",
+"jaehwan", "jaehyun", "jayji", "jeyzu", "jihoon", "jpeg", "jypark", "kimcinoo",
+"kuuko", "kwo", "leif", "maxerba", "mej", "mekius", "morlenxus", "ngc891",
+"nikawhite", "okra", "onefang", "princeamd", "q66", "raoul", "ravenlock",
+"rimmed", "ryuan", "sachiel", "sanghyeonlee", "sanjeev", "savio", "seoz",
+"slomo", "sohyun", "spacegrapher", "stanluk" "stenfan", "sung", 
"thanatermesis",
+"thiep", "uartie", "ulisses", "vapier", "woohyun", "yakov", "yoz", 
"zehortigoza"};
+
+#define ITEM_TYPE_CNT 4
+typedef enum _ItemType
+{
+  RECOVER_ITEM = 0,
+  MOVE_FORWARD,
+  REMOVE_ALL,
+  STOP_ALL
+} ItemType;
+
+double DROP_DIST_WEIGHT = 25;
+
 static void reset_defense_wall(AppData *appdata);
+static void enemy_kill(AppData *appdata, Enemy *enemy);
+static void combo(AppData *appdata, Enemy *enemy, int combo);
 
 static double
 level_handicap_forenemy_add(double level)
@@ -83,7 +116,7 @@ remove_all_enemies(AppData *appdata)
 
 static Enemy *
 enemy_new(Evas_Object *parent, const char *str, Evas_Coord x, Evas_Coord y,
-           Evas_Coord max_w, Evas_Coord max_h)
+           Evas_Coord max_w, Evas_Coord max_h, Eina_Bool item)
 {
    Enemy *enemy = calloc(1, sizeof(Enemy));
    if (!enemy) return NULL;
@@ -99,7 +132,22 @@ enemy_new(Evas_Object *parent, const char *str, Evas_Coord 
x, Evas_Coord y,
    evas_object_smart_member_add(entry, parent);
 
    elm_entry_editable_set(entry, EINA_FALSE);
-   elm_object_text_set(entry, str);
+
+   //Item Enemy
+   if (item)
+     {
+        enemy->item = EINA_TRUE;
+        int idx = rand() % ITEM_NAMES_CNT;
+        elm_object_text_set(entry, ITEM_NAMES[idx]);
+        Elm_Transit *t = elm_transit_add();
+        elm_transit_effect_color_add(t, 255, 255, 255, 255, 0, 0, 0, 255);
+        elm_transit_auto_reverse_set(t, EINA_TRUE);
+        elm_transit_repeat_times_set(t, -1);
+        elm_transit_duration_set(t, 0.25);
+        elm_transit_object_add(t, entry);
+        elm_transit_go(t);
+     }
+   else elm_object_text_set(entry, str);
 
    //Prevent the text cutting out by the window bound
    Evas_Coord tb_w, tb_h;
@@ -127,7 +175,8 @@ enemy_add(AppData *appdata)
    char *word = eina_array_data_get(appdata->words_array,(rand() % words_cnt));
    Enemy *enemy = enemy_new(appdata->bx, word,
                             (rand() % appdata->bound_w), 0, appdata->bound_w,
-                            appdata->bound_h);
+                            appdata->bound_h, appdata->item_time);
+   appdata->item_time = EINA_FALSE;
    appdata->enemies = eina_inlist_append(appdata->enemies,
                                          (Eina_Inlist *) enemy);
    appdata->interval_time = appdata->last_frame_time;
@@ -139,6 +188,69 @@ enemy_kill_transit_del_cb(void *data, Elm_Transit *transit)
    evas_object_del(data);
 }
 
+static Eina_Bool
+recover_wall_anim_cb(void *data)
+{
+   AppData *appdata = data;
+   Eina_List *l;
+   Evas_Object *obj;
+   EINA_LIST_FOREACH(appdata->defense_wall, l, obj)
+     {
+        Elm_Transit *transit = elm_transit_add();
+        elm_transit_object_add(transit, obj);
+        elm_transit_effect_color_add(transit, 255, 255, 255, 255, WALL_COLOR);
+        elm_transit_duration_set(transit, 0.25);
+        elm_transit_go(transit);
+     }
+   return ECORE_CALLBACK_CANCEL;
+}
+
+static void
+recover_wall(AppData *appdata)
+{
+   reset_defense_wall(appdata);
+   ecore_animator_add(recover_wall_anim_cb, appdata);
+}
+
+static Eina_Bool
+move_forward_timer_cb(void *data)
+{
+   DROP_DIST_WEIGHT = _DROP_DIST_WEIGHT;
+   return ECORE_CALLBACK_CANCEL;
+}
+
+static void
+move_forward(AppData *appdata)
+{
+   DROP_DIST_WEIGHT = 10 * _DROP_DIST_WEIGHT;
+   ecore_timer_add(0.5, move_forward_timer_cb, appdata);
+}
+
+static void
+remove_all(AppData *appdata)
+{
+   Eina_Inlist *l;
+   Enemy *enemy;
+   const char *enemy_text;
+
+   EINA_INLIST_FOREACH_SAFE(appdata->enemies, l, enemy)
+     {
+        enemy_text = elm_object_text_get(enemy->entry);
+        if (!enemy_text) continue;
+        appdata->combo++;
+        if (appdata->combo > 1)
+          combo(appdata, enemy, appdata->combo);
+        enemy_kill(appdata, enemy);
+     }
+}
+
+static void
+stop_all(AppData *appdata)
+{
+   DROP_DIST_WEIGHT = -20 * _DROP_DIST_WEIGHT;
+   ecore_timer_add(0.5, move_forward_timer_cb, appdata);
+}
+
 static void
 enemy_kill(AppData *appdata, Enemy *enemy)
 {
@@ -147,6 +259,26 @@ enemy_kill(AppData *appdata, Enemy *enemy)
    Evas_Object *entry = enemy->entry;
    appdata->enemies = eina_inlist_remove(appdata->enemies,
                                          EINA_INLIST_GET(enemy));
+   if (enemy->item)
+     {
+        recover_wall(appdata);
+        int idx = rand() % ITEM_TYPE_CNT;
+        switch (idx)
+          {
+           case RECOVER_ITEM:
+              recover_wall(appdata);
+              break;
+           case MOVE_FORWARD:
+              move_forward(appdata);
+              break;
+           case REMOVE_ALL:
+              remove_all(appdata);
+              break;
+           case STOP_ALL:
+              stop_all(appdata);
+              break;
+          }
+     }
 
    //Kill Effect
    Elm_Transit *transit = elm_transit_add();
@@ -215,7 +347,7 @@ game_over(AppData *appdata)
 
 void remove_wall_transit_del_cb(void *data, Elm_Transit *transit)
 {
-   evas_object_hide(data);
+   evas_object_del(data);
 }
 
 void remove_wall(Evas_Object *wall)
@@ -223,7 +355,7 @@ void remove_wall(Evas_Object *wall)
    Elm_Transit *transit = elm_transit_add();
    if (!transit)
      {
-        evas_object_hide(wall);
+        evas_object_del(wall);
         return;
      }
 
@@ -263,7 +395,7 @@ Eina_Bool collision_check(AppData *appdata, Enemy *enemy)
 }
 
 static Eina_Bool
-_animator_cb(void *data)
+main_animator_cb(void *data)
 {
    //FIXME: Sometimes this func is called abnormally. Need to check.
    AppData *appdata = data;
@@ -315,6 +447,7 @@ _animator_cb(void *data)
 static void
 app_release(AppData *appdata)
 {
+   ecore_timer_del(appdata->timer);
    ecore_animator_del(appdata->animator);
 
    remove_all_enemies(appdata);
@@ -532,14 +665,31 @@ game_resume(AppData *appdata)
    ecore_animator_thaw(appdata->animator);
 }
 
+static Eina_Bool
+item_timer_cb(void *data)
+{
+   AppData *appdata = data;
+   if (!appdata->state == Playing) return ECORE_CALLBACK_RENEW;
+
+   appdata->item_time = EINA_TRUE;
+
+   return ECORE_CALLBACK_RENEW;
+}
+
 static void
 game_level_cb(void *data, Evas_Object *obj, void *event_info)
 {
    AppData *appdata = evas_object_data_get(obj, "appdata");
+
+   appdata->item = elm_check_state_get(appdata->check);
+
    evas_object_del(appdata->popup);
    appdata->popup = NULL;
    appdata->level = (int)(uintptr_t) data;
 
+
+   if (appdata->item) ecore_timer_add(ITEM_TIME, item_timer_cb, appdata);
+
    game_reset(appdata);
    appdata->state = Playing;
    game_resume(appdata);
@@ -567,11 +717,13 @@ game_start_cb(void *data, Evas_Object *obj, void 
*event_info)
    evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
    evas_object_show(box);
 
+   //Label
    Evas_Object *label = elm_label_add(box);
    elm_object_text_set(label, "Start Level");
    evas_object_show(label);
    elm_box_pack_end(box, label);
 
+   //List
    Evas_Object *list = elm_list_add(box);
    elm_list_mode_set(list, ELM_LIST_EXPAND);
    elm_scroller_policy_set(list, ELM_SCROLLER_POLICY_OFF,
@@ -600,13 +752,20 @@ game_start_cb(void *data, Evas_Object *obj, void 
*event_info)
 
    elm_list_go(list);
    evas_object_show(list);
-
    elm_box_pack_end(box, list);
 
+   //Item
+   Evas_Object *check = elm_check_add(box);
+   elm_check_state_set(check, EINA_TRUE);
+   elm_object_text_set(check, "Random Item");
+   evas_object_show(check);
+   elm_box_pack_end(box, check);
+
    elm_object_content_set(notify, box);
    evas_object_show(notify);
 
    appdata->popup = notify;
+   appdata->check = check;
 }
 
 static void
@@ -827,7 +986,7 @@ app_init(AppData *appdata)
    appdata->bound_w = DEFAULT_WIN_W;
    appdata->bound_h = DEFAULT_WIN_H;
 
-   appdata->animator = ecore_animator_add(_animator_cb, appdata);
+   appdata->animator = ecore_animator_add(main_animator_cb, appdata);
 
    game_pause(appdata);
 

-- 


Reply via email to