[gcompris] Wordlist new XML properties for gletters & wordsgame



commit b522c04b797c17de644bfae3671a3fea22cf1eae
Author: GunChleoc <fios foramnagaidhlig net>
Date:   Sun May 12 17:24:41 2013 +0100

    Wordlist new XML properties for gletters & wordsgame
    
    - Wordlist levels have 3 new, optional parameters:
    -- fallspeed: how fast the words fall
    -- speed: how fast a new item is dropped after the last one
    -- sublevels: how many items are in the level
    
    - gletters:
    -- use the new parameters
    -- display bonus at end of level
    
    - wordsgame:
    -- use the new parameters
    -- display bonus at end of level
    -- levels now start with a defined speed + fallspeed
       when the user clicks through the levels

 src/gcompris/board_config_wordlist.c               |    2 +-
 src/gcompris/wordlist.c                            |   37 ++++++++++-
 src/gcompris/wordlist.h                            |   15 +++--
 src/gletters-activity/gletters.c                   |   47 +++++++++-----
 .../resources/gletters/default-gd.xml              |   62 ++++++++++++------
 .../resources/gletters/upper-gd.xml                |   29 ++++++---
 .../resources/wordsgame/default-gd.xml             |   14 ++--
 src/wordsgame-activity/wordsgame.c                 |   65 ++++++++++++++------
 8 files changed, 189 insertions(+), 82 deletions(-)
---
diff --git a/src/gcompris/board_config_wordlist.c b/src/gcompris/board_config_wordlist.c
index 1b8255c..66e72e3 100644
--- a/src/gcompris/board_config_wordlist.c
+++ b/src/gcompris/board_config_wordlist.c
@@ -164,7 +164,7 @@ static void _button_clicked(GtkWidget *w, gpointer data)
        gtk_text_buffer_get_start_iter(buffer, &start_iter);
        gtk_text_buffer_get_end_iter(buffer, &end_iter);
        text = gtk_text_buffer_get_slice(buffer, &start_iter, &end_iter, TRUE);
-       gc_wordlist_set_wordlist(u->wordlist, level, text);
+       gc_wordlist_set_wordlist(u->wordlist, level, -1,-1,-1, text);
        g_free(text);
        gc_wordlist_save(u->wordlist);
        _combo_lang_changed(u->combo_lang, u);
diff --git a/src/gcompris/wordlist.c b/src/gcompris/wordlist.c
index 66eb5d6..1c6682c 100644
--- a/src/gcompris/wordlist.c
+++ b/src/gcompris/wordlist.c
@@ -65,6 +65,9 @@ GcomprisWordlist
   xmlNodePtr node;
   xmlNodePtr wordsNode;
   guint level;
+  guint speed;
+  guint fallspeed;
+  guint sublevels;
 
   GcomprisWordlist     *wordlist;
   xmlChar              *text;
@@ -85,8 +88,7 @@ GcomprisWordlist
       g_free(filename);
       return NULL;
     }
-
-  g_warning("Wordlist found %s\n", xmlfilename);
+  g_message("Wordlist found %s\n", xmlfilename);
 
   xmldoc = xmlParseFile(xmlfilename);
 
@@ -176,14 +178,36 @@ GcomprisWordlist
     }
 
     level=-1;
+    speed=-1;
+    fallspeed=-1;
+    sublevels=-1;
     text = xmlGetProp ( node,
                    (const xmlChar *) "value");
     if (text) {
            level = atoi((gchar *) text);
            xmlFree (text);
     }
+    // todo
+    text = xmlGetProp ( node,
+                   (const xmlChar *) "speed");
+    if (text) {
+           speed = atoi((gchar *) text);
+           xmlFree (text);
+    }
+    text = xmlGetProp ( node,
+                   (const xmlChar *) "fallspeed");
+    if (text) {
+           fallspeed = atoi((gchar *) text);
+           xmlFree (text);
+    }
+    text = xmlGetProp ( node,
+                   (const xmlChar *) "sublevels");
+    if (text) {
+           sublevels = atoi((gchar *) text);
+           xmlFree (text);
+    }
     text = xmlNodeGetContent ( wordsNode);
-    gc_wordlist_set_wordlist(wordlist, level, (const gchar*)text);
+    gc_wordlist_set_wordlist(wordlist, level, speed, fallspeed, sublevels, (const gchar*)text);
     xmlFree(text);
 
     node = node->next;
@@ -300,7 +324,9 @@ gc_wordlist_free(GcomprisWordlist *wordlist)
   g_free (wordlist);
 }
 
-void gc_wordlist_set_wordlist(GcomprisWordlist *wordlist, guint level, const gchar*text)
+void gc_wordlist_set_wordlist(GcomprisWordlist *wordlist,
+                                                         guint level, gint speed, gint fallspeed, gint 
sublevels,
+                                                         const gchar*text)
 {
        LevelWordlist *lw;
        GSList *words=NULL;
@@ -336,6 +362,9 @@ void gc_wordlist_set_wordlist(GcomprisWordlist *wordlist, guint level, const gch
 
        level_words->words = words;
        level_words->level = level;
+       level_words->speed = speed;
+       level_words->fallspeed = fallspeed;
+       level_words->sublevels = sublevels;
 
        wordlist->number_of_level++;
        wordlist->levels_words = g_slist_append( wordlist->levels_words, level_words);
diff --git a/src/gcompris/wordlist.h b/src/gcompris/wordlist.h
index fe75d5f..960e536 100644
--- a/src/gcompris/wordlist.h
+++ b/src/gcompris/wordlist.h
@@ -21,6 +21,9 @@
 
 typedef struct {
   gint level;
+  gint speed;
+  gint fallspeed;
+  gint sublevels;
   GSList *words;
 } LevelWordlist;
 
@@ -29,15 +32,17 @@ typedef struct {
   gchar         *name;
   gchar         *description;
   gchar         *locale;
-  guint                 number_of_level;
+  guint                     number_of_level;
   /* LevelWordlist list */
-  GSList         *levels_words;
+  GSList               *levels_words;
 } GcomprisWordlist;
 
 GcomprisWordlist *gc_wordlist_get_from_file(const gchar *fileformat, ...);
 LevelWordlist   *gc_wordlist_get_levelwordlist(GcomprisWordlist *wordlist, guint level);
 void              gc_wordlist_free(GcomprisWordlist *wordlist);
-gchar           *gc_wordlist_random_word_get(GcomprisWordlist *wordlist, guint level);
-void             gc_wordlist_set_wordlist(GcomprisWordlist *wordlist, guint level, const gchar*words);
-void             gc_wordlist_save(GcomprisWordlist *wordlist);
+gchar            *gc_wordlist_random_word_get(GcomprisWordlist *wordlist, guint level);
+void              gc_wordlist_set_wordlist(GcomprisWordlist *wordlist,
+                                                                          guint level, gint speed, gint 
fallspeed, gint sublevels,
+                                                                          const gchar*text);
+void              gc_wordlist_save(GcomprisWordlist *wordlist);
 #endif
diff --git a/src/gletters-activity/gletters.c b/src/gletters-activity/gletters.c
index 53bedf3..9aecd6e 100644
--- a/src/gletters-activity/gletters.c
+++ b/src/gletters-activity/gletters.c
@@ -78,15 +78,15 @@ static GcomprisBoard *gcomprisBoard = NULL;
  */
 
 #define FALL_RATE_BASE 40
-#define FALL_RATE_MULT 10
+#define FALL_RATE_MULT 80
 
 /* these constants control how often letters are dropped
  * the base rate is fixed
  * the increment governs increase per level
  */
 
-#define DROP_RATE_BASE 1000
-#define DROP_RATE_MULT 1000
+#define DROP_RATE_BASE 5000
+#define DROP_RATE_MULT 100
 
 static gint dummy_id = 0;
 static gint drop_items_id = 0;
@@ -122,8 +122,8 @@ static void          player_win(LettersItem *item);
 static void             player_lose(void);
 
 
-static  gint              fallSpeed = 0;
-static  gint               speed = 0;
+static  gint             fallSpeed = 0;
+static  gint             speed = 0;
 
 static GooCanvasItem *preedit_text = NULL;
 
@@ -518,16 +518,25 @@ static void gletters_next_level_unlocked()
 {
   int l;
 
+  LevelWordlist *levellist = gc_wordlist_get_levelwordlist(gc_wordlist, gcomprisBoard->level);
   // get number of letters available
-  l=g_slist_length(gc_wordlist_get_levelwordlist(gc_wordlist, gcomprisBoard->level)->words);
+  l=g_slist_length(levellist->words);
 
   g_message("wordlist length for level %d is %d\n",
            gcomprisBoard->level,
            l);
-  l = l/3 + (gcomprisBoard->level)/3; // make sure the level doesn't get too long
-  // set sublevels
-  gcomprisBoard->number_of_sublevel = (DEFAULT_SUBLEVEL>l?DEFAULT_SUBLEVEL:l);
 
+  /* set sublevels */
+  if (levellist->sublevels > 0)
+  {
+      gcomprisBoard->number_of_sublevel = levellist->sublevels;
+  }
+  else
+  {
+        /* If level length is not set in XML, make sure the level doesn't get too long */
+        l = l/3 + (gcomprisBoard->level)/3;
+        gcomprisBoard->number_of_sublevel = (DEFAULT_SUBLEVEL>l?DEFAULT_SUBLEVEL:l);
+  }
   gc_score_start(SCORESTYLE_NOTE,
                 BOARDWIDTH - 195,
                 BOARDHEIGHT - 30,
@@ -560,14 +569,15 @@ static void gletters_next_level_unlocked()
  */
 static void setSpeed(guint level)
 {
-  speed= ((gint) FALL_RATE_BASE)+(((gint) FALL_RATE_MULT)*level);
-  fallSpeed= (gint) DROP_RATE_BASE+(DROP_RATE_MULT*level);
+    LevelWordlist *levellist = gc_wordlist_get_levelwordlist(gc_wordlist, level);
+    speed = (levellist->speed >= 0) ? (gint) levellist->speed : ((gint) FALL_RATE_BASE)+(((gint) 
FALL_RATE_MULT)/level);
+    fallSpeed = (levellist->fallspeed >= 0) ? (gint) levellist->fallspeed : (gint) 
DROP_RATE_BASE+(DROP_RATE_MULT*level);
 }
 
 /* set initial values for the next level */
 static void gletters_next_level()
 {
-  gcomprisBoard->sublevel = 0;
+  gcomprisBoard->sublevel = 1;
 #if GLIB_CHECK_VERSION(2, 31, 0)
   g_mutex_lock (&items_lock);
 #else
@@ -730,9 +740,9 @@ static GooCanvasItem *gletters_create_item(GooCanvasItem *parent)
   guint i;
   if(word)
   {
-      /* Check if letter has already been used. Cap at 6 tries, because there 
+         /* Check if letter has already been used. Cap at 20 tries, because there
        * might not be enough letters for all the sublevels */
-      for (i=0;i<6 && word && g_hash_table_lookup(letters_table,word)!=NULL;++i)
+      for (i=0;i<20 && word && g_hash_table_lookup(letters_table,word)!=NULL;++i)
       {
           word = gc_wordlist_random_word_get(gc_wordlist, gcomprisBoard->level);
       }
@@ -888,16 +898,19 @@ static void player_win(LettersItem *item)
 
   if(gcomprisBoard->sublevel > gcomprisBoard->number_of_sublevel)
     {
-
+      /* Give feedback about completed level */
+      gc_bonus_display(TRUE, GC_BONUS_LION);
+      drop_items_id = g_timeout_add (3000,
+                                      (GSourceFunc) gletters_drop_items, NULL);
       /* Try the next level */
       gcomprisBoard->level++;
-      gcomprisBoard->sublevel = 0;
+      gcomprisBoard->sublevel = 1;
       if(gcomprisBoard->level>gcomprisBoard->maxlevel)
        gcomprisBoard->level = gcomprisBoard->maxlevel;
     
       setSpeed(gcomprisBoard->level);
       gletters_next_level_unlocked();
-      gc_sound_play_ogg ("sounds/bonus.wav", NULL);
+      //gc_sound_play_ogg ("sounds/bonus.wav", NULL);
     }
   else
     {
diff --git a/src/gletters-activity/resources/gletters/default-gd.xml 
b/src/gletters-activity/resources/gletters/default-gd.xml
index a1e3d9a..5e7f49e 100644
--- a/src/gletters-activity/resources/gletters/default-gd.xml
+++ b/src/gletters-activity/resources/gletters/default-gd.xml
@@ -1,26 +1,40 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <GCompris>
 <Wordlist name="default-gd" description="Gàidhlig" locale="gd">
-<level value="1">
+<level value="1" sublevels="5">
 a
+e
+i
+o
+u
+</level>
+<level value="2" sublevels="12">
 b
 c
 d
-e
 f
 g
-i
 l
 m
 n
-o
 p
 r
 s
 t
-u
 </level>
-<level value="2">
+<level value="3" sublevels="10">
+1
+2
+3
+4
+5
+6
+7
+8
+9
+0
+</level>
+<level value="4">
 a
 b
 c
@@ -49,26 +63,28 @@ u
 9
 0
 </level>
-<level value="3">
+<level value="5" sublevels="5">
 A
+E
+I
+O
+U
+</level>
+<level value="6" sublevels="12">
 B
 C
 D
-E
 F
 G
-I
 L
 M
 N
-O
 P
 R
 S
 T
-U
 </level>
-<level value="4">
+<level value="7">
 A
 B
 C
@@ -97,7 +113,7 @@ U
 9
 0
 </level>
-<level value="5">
+<level value="8">
 a
 b
 c
@@ -133,7 +149,14 @@ S
 T
 U
 </level>
-<level value="6">
+<level value="9" sublevels="5">
+à
+è
+ì
+ò
+ù
+</level>
+<level value="10" sublevels="12">
 bh
 ch
 dh
@@ -146,13 +169,8 @@ th
 ll
 nn
 rr
-à
-è
-ì
-ò
-ù
 </level>
-<level value="7">
+<level value="11">
 BH
 CH
 DH
@@ -171,7 +189,7 @@ RR
 Ò
 Ù
 </level>
-<level value="8">
+<level value="12">
 bh
 ch
 dh
@@ -207,6 +225,7 @@ RR
 Ò
 Ù
 </level>
+<level value="13">
 a
 b
 c
@@ -285,5 +304,6 @@ RR
 8
 9
 0
+</level>
 </Wordlist>
 </GCompris>
diff --git a/src/gletters-activity/resources/gletters/upper-gd.xml 
b/src/gletters-activity/resources/gletters/upper-gd.xml
index edba9e2..6d39eae 100644
--- a/src/gletters-activity/resources/gletters/upper-gd.xml
+++ b/src/gletters-activity/resources/gletters/upper-gd.xml
@@ -1,14 +1,25 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <GCompris>
 <Wordlist name="default-gd" description="Gàidhlig" locale="gd">
-<level value="1">
+<level value="1" sublevels="5">
 a
 e
 i
 o
 u
 </level>
-<level value="2">
+<level value="2" sublevels="10">
+1
+2
+3
+4
+5
+6
+7
+8
+9
+</level>
+<level value="3">
 a
 e
 i
@@ -25,7 +36,7 @@ u
 8
 9
 </level>
-<level value="3">
+<level value="4" sublevels="12">
 b
 c
 d
@@ -39,7 +50,7 @@ r
 s
 t
 </level>
-<level value="4">
+<level value="5">
 b
 c
 d
@@ -63,7 +74,7 @@ t
 8
 9
 </level>
-<level value="5">
+<level value="6">
 b
 c
 d
@@ -82,14 +93,14 @@ i
 o
 u
 </level>
-<level value="6">
+<level value="7" sublevels="5">
 à
 è
 ì
 ò
 ù
 </level>
-<level value="7">
+<level value="8" sublevels="12">
 bh
 ch
 dh
@@ -103,7 +114,7 @@ ll
 nn
 rr
 </level>
-<level value="8">
+<level value="9">
 à
 è
 ì
@@ -122,7 +133,7 @@ ll
 nn
 rr
 </level>
-<level value="9">
+<level value="10">
 b
 c
 d
diff --git a/src/readingh-activity/resources/wordsgame/default-gd.xml 
b/src/readingh-activity/resources/wordsgame/default-gd.xml
index 6739fde..c465460 100644
--- a/src/readingh-activity/resources/wordsgame/default-gd.xml
+++ b/src/readingh-activity/resources/wordsgame/default-gd.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <GCompris>
 <Wordlist name="default-gd" description="Gàidhlig" locale="gd">
-<level value="1">
+<level value="1" speed="150" fallspeed="7000" sublevels="10">
 ad
 ag
 am
@@ -192,7 +192,7 @@ uat
 uca
 ugh
 </level>
-<level value="2">
+<level value="2" speed="130" fallspeed="6000" sublevels="15">
 achd
 adag
 adan
@@ -662,7 +662,7 @@ umha
 umpa
 urra
 </level>
-<level value="3">
+<level value="3" speed="110" fallspeed="5000" sublevels="20">
 crudh
 abaid
 abair
@@ -1301,7 +1301,7 @@ urras
 usgar
 uspag
 </level>
-<level value="4">
+<level value="4" speed="90" fallspeed="4000" sublevels="25">
 abaich
 abstol
 acainn
@@ -2110,7 +2110,7 @@ umainn
 umhail
 uncail
 </level>
-<level value="5">
+<level value="5" speed="130" fallspeed="6000" sublevels="20">
 àra
 àrd
 àth
@@ -2224,7 +2224,7 @@ tè
 tì
 ùr
 </level>
-<level value="6">
+<level value="6" speed="110" fallspeed="5000" sublevels="25">
 tùdan
 àirde
 àirne
@@ -2650,7 +2650,7 @@ uèir
 ùird
 ùpag
 </level>
-<level value="7">
+<level value="7" speed="100" fallspeed="4000" sublevels="35">
 abachan
 abhagan
 abhainn
diff --git a/src/wordsgame-activity/wordsgame.c b/src/wordsgame-activity/wordsgame.c
index 0cd936f..055e260 100644
--- a/src/wordsgame-activity/wordsgame.c
+++ b/src/wordsgame-activity/wordsgame.c
@@ -95,15 +95,20 @@ static void          player_loose(void);
 #define MAX_SPEED  150
 #define MIN_FALLSPEED  3000
 #define MIN_SPEED  50
-#define DEFAULT_FALLSPEED  7000
-#define DEFAULT_SPEED  150
+#define DEFAULT_FALLSPEED  8000
+#define DEFAULT_SPEED  170
 
+/* Within a level, make faster */
 #define INCREMENT_FALLSPEED  1000
 #define INCREMENT_SPEED  10
 
+/* At start of level, make faster */
+#define ADD_SPEED 20
+#define ADD_FALLSPEED 1000
 
-static  guint32              fallSpeed = 0;
-static  double               speed = 0.0;
+
+static  gint              fallSpeed = 0;
+static  gint              speed = 0;
 
 static GooCanvasItem *preedit_text = NULL;
 
@@ -475,11 +480,40 @@ is_our_board (GcomprisBoard *gcomprisBoard)
 /*-------------------------------------------------------------------------------*/
 /*-------------------------------------------------------------------------------*/
 
+
+
+/*
+ * Set how often and how fast items drop
+ */
+static void setSpeed(guint level)
+{
+    LevelWordlist *levellist = gc_wordlist_get_levelwordlist(gc_wordlist, level);
+    fallSpeed = (levellist->fallspeed >= 0) ? (gint) levellist->fallspeed : DEFAULT_FALLSPEED - 
level*ADD_FALLSPEED;
+    speed = (levellist->speed >= 0) ? (gint) levellist->speed : DEFAULT_SPEED - level*ADD_SPEED;
+
+    if(speed < MIN_SPEED ) speed = MIN_SPEED;
+    if(speed > MAX_SPEED ) speed = MAX_SPEED;
+    if(fallSpeed < MIN_FALLSPEED ) fallSpeed = MIN_FALLSPEED;
+    if(fallSpeed > MAX_FALLSPEED ) fallSpeed = MAX_FALLSPEED;
+}
+
+
 /* Called with items_lock locked */
 static void wordsgame_next_level_unlocked()
 {
-  gcomprisBoard->number_of_sublevel = 10 +
-    ((gcomprisBoard->level-1) * 5);
+    gcomprisBoard->sublevel = 1;
+    setSpeed(gcomprisBoard->level);
+
+    /* set sublevels */
+    LevelWordlist *levellist = gc_wordlist_get_levelwordlist(gc_wordlist, gcomprisBoard->level);
+    if (levellist->sublevels > 0)
+    {
+      gcomprisBoard->number_of_sublevel = levellist->sublevels;
+    }
+    else
+    {
+        gcomprisBoard->number_of_sublevel = 10 + ((gcomprisBoard->level-1) * 5);
+    }
   gc_score_start(SCORESTYLE_NOTE,
                 BOARDWIDTH - 195,
                 BOARDHEIGHT - 30,
@@ -499,14 +533,6 @@ static void wordsgame_next_level_unlocked()
   items=g_ptr_array_new();
   items2del=g_ptr_array_new();
 
-
-  /* Increase speed only after 5 levels */
-  if(gcomprisBoard->level > 5)
-    {
-      gint temp = fallSpeed-gcomprisBoard->level*200;
-      if (temp > MIN_FALLSPEED)        fallSpeed=temp;
-    }
-
   pause_board(FALSE);
 }
 
@@ -787,14 +813,19 @@ static void player_win(LettersItem *item)
   if(gcomprisBoard->sublevel > gcomprisBoard->number_of_sublevel)
     {
 
+      /* Give feedback about completed level */
+      //gc_sound_play_ogg ("sounds/bonus.wav", NULL);
+      gc_bonus_display(TRUE, GC_BONUS_LION);
+      drop_items_id = g_timeout_add (3000,
+                                      (GSourceFunc) wordsgame_drop_items, NULL);
+
       /* Try the next level */
       gcomprisBoard->level++;
-      gcomprisBoard->sublevel = 0;
+      gcomprisBoard->sublevel = 1;
       if(gcomprisBoard->level>gcomprisBoard->maxlevel)
        gcomprisBoard->level = gcomprisBoard->maxlevel;
 
       wordsgame_next_level_unlocked();
-      gc_sound_play_ogg ("sounds/bonus.wav", NULL);
     }
   else
     {
@@ -802,9 +833,7 @@ static void player_win(LettersItem *item)
       /* Drop a new item now to speed up the game */
       if(items->len==0)
         {
-
          if ((fallSpeed-=INCREMENT_FALLSPEED) < MIN_FALLSPEED) fallSpeed+=INCREMENT_FALLSPEED;
-
          if ((speed-=INCREMENT_SPEED) < MIN_SPEED) speed+=INCREMENT_SPEED;
 
           if (drop_items_id) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]