New play mode. be happy.
authormrtout <mrtout@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Sun, 19 Feb 2006 23:29:30 +0000 (23:29 +0000)
committermrtout <mrtout@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Sun, 19 Feb 2006 23:29:30 +0000 (23:29 +0000)
git-svn-id: https://s.snth.net/svn/neverball/trunk@96 78b8d119-cf0a-0410-b17c-f493084dd1d7

ball/game.c
ball/level.c
ball/level.h
ball/st_goal.c
ball/st_play.c
ball/st_save.c
ball/st_start.c
share/config.c
share/config.h

index cabd47e..f803a2c 100644 (file)
@@ -103,7 +103,10 @@ int game_init(const char *file_name,
               const char *back_name,
               const char *grad_name, int t, int e)
 {
-    clock = (float) t / 100.f;
+    if (level_mode() == MODE_FREE)
+       clock = 0.f;
+    else
+        clock = (float) t / 100.f;
 
     if (game_state)
         game_free();
@@ -610,7 +613,9 @@ static void game_update_time(float dt, int b)
 
    /* The ticking clock. */
 
-    if (b)
+    if (b==2)
+       clock += dt;
+    else if (b)
     {
         if (clock < 600.f)
             clock -= dt;
index 1e76dec..62f44d8 100644 (file)
@@ -423,8 +423,8 @@ static int level_play_go(void)
 /* Start to play the current level */
 {
     status = GAME_NONE;
-    coins = 0;
-    goal  = level_v[level].goal;
+    coins  = 0;
+    goal   = (mode == MODE_FREE) ? 0 : level_v[level].goal;
     
     return demo_play_init(USER_REPLAY_FILE,
                           level_v[level].file,
@@ -433,7 +433,7 @@ static int level_play_go(void)
                           level_v[level].song,
                           level_v[level].shot,
                           level_v[level].time,
-                          level_auto_opened() ? 0 : goal, score, coins, balls);
+                          goal, score, coins, balls);
 }
 
 int level_play(const char *filename, int i, int m)
@@ -472,12 +472,6 @@ int level_last(void)
     return (level + 1 == count);
 }
 
-int level_auto_opened(void)
-/* Is the level automatically opened */
-{
-    return mode != MODE_CHALLENGE && level != limit;
-}
-
 int level_exit(const char *filename, int next)
 {
     times_total += level_v[level].time - curr_clock();
@@ -586,7 +580,7 @@ int level_done(int *time_i, int *coin_i)
 int level_score(int n)
 {
     int sound = AUD_COIN;
-    int value = level_auto_opened();
+    int value = 0;
 
     coins += n;
 
index 9396b73..e318980 100644 (file)
@@ -5,6 +5,7 @@
 
 #define MODE_CHALLENGE 1
 #define MODE_TRAINING  2
+#define MODE_FREE      3
 
 const char *level_shot(int);
 const char *level_coin_n(int, int);
index ff319cf..64a7601 100644 (file)
@@ -194,7 +194,8 @@ static int goal_enter(void)
            if (level_mode() != MODE_CHALLENGE)
                 gui_state(jd, _("Retry Level"), GUI_SML, GOAL_SAME, 0);
 
-            if (level_last())
+           if (level_mode() == MODE_FREE) ;
+           else if (level_last())
                 gui_start(jd, _("Finish"),  GUI_SML, GOAL_NEXT, 0);
             else
                 gui_start(jd, _("Next Level"), GUI_SML, GOAL_NEXT, 0);
index 2b7d18d..d456955 100644 (file)
@@ -206,6 +206,7 @@ static void play_loop_timer(int id, float dt)
     static float at = 0;
 
     float g[3] = { 0.0f, -9.8f, 0.0f };
+    int nmf = level_mode() != MODE_FREE;
 
     at = (7 * at + dt) / 8;
 
@@ -213,9 +214,9 @@ static void play_loop_timer(int id, float dt)
     hud_timer(at);
     game_set_rot(view_rotate * k);
 
-    switch (game_step(g, at, 1))
+    switch (game_step(g, at, nmf ? 1 : 2))
     {
-    case GAME_TIME: level_stat(GAME_TIME); goto_state(&st_time_out); break;
+    case GAME_TIME: if (nmf) {level_stat(GAME_TIME); goto_state(&st_time_out);} break;
     case GAME_FALL: level_stat(GAME_FALL); goto_state(&st_fall_out); break;
     case GAME_GOAL: level_stat(GAME_GOAL); goto_state(&st_goal);     break;
     }
index cf1f955..c358624 100644 (file)
@@ -40,6 +40,7 @@ static char filename[MAXNAM];
 static int save_action(int i)
 {
     size_t l = strlen(filename);
+    int next = level_mode() == MODE_CHALLENGE;
 
     audio_play(AUD_MENU, 1.0f);
 
@@ -52,7 +53,7 @@ static int save_action(int i)
             return goto_state(&st_clobber);
         else
         {
-            if (level_exit(filename, 1))
+            if (level_exit(filename, next))
                 return goto_state(&st_level);
            else if (!level_dead() && level_mode() == MODE_CHALLENGE)
                 return goto_state(&st_done);
@@ -61,7 +62,7 @@ static int save_action(int i)
         }
 
     case SAVE_CANCEL:
-        if (level_exit(NULL, 1))
+        if (level_exit(NULL, next))
             return goto_state(&st_level);
        else if (!level_dead() && level_mode() == MODE_CHALLENGE)
             return goto_state(&st_done);
@@ -193,11 +194,12 @@ static int save_buttn(int b, int d)
 
 static int clobber_action(int i)
 {
+    int next = level_mode() == MODE_CHALLENGE;
     audio_play(AUD_MENU, 1.0f);
 
     if (i == SAVE_SAVE)
     {
-            if (level_exit(filename, 1))
+            if (level_exit(filename, next))
                 return goto_state(&st_level);
             else
                 return goto_state(&st_title);
index e9f1711..710e8cd 100644 (file)
@@ -29,6 +29,8 @@
 /*---------------------------------------------------------------------------*/
 
 #define START_BACK -1
+#define START_FREE -2
+#define START_TRAINING -3
 #define START_CHALLENGE 0
 
 static int shot_id;
@@ -39,7 +41,8 @@ static int shot_id;
 
 static void gui_level(int id, char *text, int i)
 {
-    int o = level_opened(i);
+    int m = config_get_d(CONFIG_MODE_FREE);
+    int o = level_opened(i) && (!m || level_opened(i+1));
     int e = level_exists(i);
 
     if      (o) gui_state(id, text, GUI_SML, i, 0);
@@ -51,11 +54,21 @@ static void gui_level(int id, char *text, int i)
 
 static int start_action(int i)
 {
-    int mode = MODE_TRAINING;
+    int mode = config_get_d(CONFIG_MODE_FREE) ? MODE_FREE : MODE_TRAINING;
     audio_play(AUD_MENU, 1.0f);
 
     if (i == START_BACK)
         return goto_state(&st_set);
+    else if (i == START_TRAINING)
+    {
+       config_set_d(CONFIG_MODE_FREE, 0);
+       goto_state(&st_start);
+    }
+    else if (i == START_FREE)
+    {
+       config_set_d(CONFIG_MODE_FREE, 1);
+       goto_state(&st_start);
+    }
     
     if (i == START_CHALLENGE)
     {
@@ -80,6 +93,7 @@ static int start_enter(void)
 {
     int w = config_get_d(CONFIG_WIDTH);
     int h = config_get_d(CONFIG_HEIGHT);
+    int m = config_get_d(CONFIG_MODE_FREE);
 
     int id, jd, kd, ld;
 
@@ -103,6 +117,11 @@ static int start_enter(void)
                gui_state(kd, _("Challenge"), GUI_SML, START_CHALLENGE , 0);
                 if ((ld = gui_harray(kd)))
                 {
+                   gui_state(ld, _("Free Playing"), GUI_SML, START_FREE , m == 1);
+                   gui_state(ld, _("Training"), GUI_SML, START_TRAINING , m == 0);
+               }
+                if ((ld = gui_harray(kd)))
+                {
                     gui_level(ld, "05",  5);
                     gui_level(ld, "04",  4);
                     gui_level(ld, "03",  3);
index 750e47a..8993a37 100644 (file)
@@ -106,6 +106,7 @@ void config_init(void)
     config_set_d(CONFIG_ROTATE_FAST,          DEFAULT_ROTATE_FAST);
     config_set_d(CONFIG_ROTATE_SLOW,          DEFAULT_ROTATE_SLOW);
     config_set_d(CONFIG_LAST_SET,             DEFAULT_LAST_SET);
+    config_set_d(CONFIG_MODE_FREE,            DEFAULT_MODE_FREE);
     config_set_s(CONFIG_PLAYER,               DEFAULT_PLAYER);
     config_set_s(CONFIG_BALL,                 DEFAULT_BALL);
     config_set_s(CONFIG_COIN,                 DEFAULT_COIN);
@@ -199,6 +200,8 @@ void config_load(void)
                     config_set_d(CONFIG_ROTATE_SLOW,          atoi(val));
                 else if (strcmp(key, "last_set")              == 0)
                     config_set_d(CONFIG_LAST_SET,             atoi(val));
+                else if (strcmp(key, "mode")                  == 0)
+                    config_set_d(CONFIG_MODE_FREE,            atoi(val));
 
                 else if (strcmp(key, "key_camera_1")  == 0)
                     config_key(val, CONFIG_KEY_CAMERA_1, DEFAULT_KEY_CAMERA_1);
@@ -307,6 +310,8 @@ void config_save(void)
                 option_d[CONFIG_ROTATE_SLOW]);
         fprintf(fp, "last_set             %d\n",
                 option_d[CONFIG_LAST_SET]);
+        fprintf(fp, "mode                 %d\n",
+                option_d[CONFIG_MODE_FREE]);
 
         fprintf(fp, "key_camera_1         %s\n",
                 SDL_GetKeyName(option_d[CONFIG_KEY_CAMERA_1]));
index 51b0d20..5144c32 100644 (file)
@@ -109,6 +109,7 @@ enum {
     CONFIG_ROTATE_FAST,
     CONFIG_ROTATE_SLOW,
     CONFIG_LAST_SET,
+    CONFIG_MODE_FREE,
 
     CONFIG_OPTION_D_COUNT
 };
@@ -166,6 +167,7 @@ enum {
 #define DEFAULT_ROTATE_SLOW          100
 #define DEFAULT_ROTATE_FAST          200
 #define DEFAULT_LAST_SET             0
+#define DEFAULT_MODE_FREE            0
 #define DEFAULT_PLAYER               _("Player")
 #define DEFAULT_BALL                 "png/ball.png"
 #define DEFAULT_COIN                 _("png/coin.png")