Merged branch utf8.
[neverball] / ball / st_play.c
index b413f6b..6bb5487 100644 (file)
@@ -1,4 +1,4 @@
-/*   
+/*
  * Copyright (C) 2003 Robert Kooima
  *
  * NEVERBALL is  free software; you can redistribute  it and/or modify
 #include "st_shared.h"
 
 #include "st_play.h"
-#include "st_fail.h"
 #include "st_goal.h"
+#include "st_fall_out.h"
+#include "st_time_out.h"
 #include "st_over.h"
+#include "st_pause.h"
 
 /*---------------------------------------------------------------------------*/
 
 static int view_rotate;
 
-/*---------------------------------------------------------------------------*/
-
-static int abort_play(void)
+static int pause_or_exit(void)
 {
-   if (curr_lg()->mode == MODE_SINGLE)
-       return 0;
-   else
-       return goto_state(&st_over);
+    if (SDL_GetModState() & KMOD_SHIFT)
+    {
+        level_stat(GAME_NONE, curr_clock(), curr_coins());
+        level_stop();
+        config_clr_grab();
+        
+        return goto_state(&st_over);
+    }
+    return goto_pause();
 }
 
+/*---------------------------------------------------------------------------*/
+
 static int play_ready_enter(void)
 {
     int id;
@@ -51,7 +58,7 @@ static int play_ready_enter(void)
     }
 
     audio_play(AUD_READY, 1.0f);
-    config_set_grab();
+    config_set_grab(1);
 
     return id;
 }
@@ -75,6 +82,14 @@ static int play_ready_click(int b, int d)
     return (b < 0 && d == 1) ? goto_state(&st_play_loop) : 1;
 }
 
+static int play_ready_keybd(int c, int d)
+{
+    if (d)
+        if (config_tst_d(CONFIG_KEY_PAUSE, c))
+            goto_pause();
+    return 1;
+}
+
 static int play_ready_buttn(int b, int d)
 {
     if (d)
@@ -82,7 +97,7 @@ static int play_ready_buttn(int b, int d)
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
             return goto_state(&st_play_loop);
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
-            return abort_play();
+            return pause_or_exit();
     }
     return 1;
 }
@@ -101,6 +116,8 @@ static int play_set_enter(void)
 
     audio_play(AUD_SET, 1.f);
 
+    clear_pause();
+
     return id;
 }
 
@@ -115,6 +132,7 @@ static void play_set_timer(int id, float dt)
 
     game_step_fade(dt);
     gui_timer(id, dt);
+    audio_timer(dt);
 }
 
 static int play_set_click(int b, int d)
@@ -127,6 +145,14 @@ static int play_set_click(int b, int d)
     return 1;
 }
 
+static int play_set_keybd(int c, int d)
+{
+    if (d)
+        if (config_tst_d(CONFIG_KEY_PAUSE, c))
+            goto_pause();
+    return 1;
+}
+
 static int play_set_buttn(int b, int d)
 {
     if (d)
@@ -134,17 +160,26 @@ static int play_set_buttn(int b, int d)
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
             return goto_state(&st_play_loop);
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
-            return abort_play();
+            return pause_or_exit();
     }
     return 1;
 }
 
 /*---------------------------------------------------------------------------*/
 
+static int nohud = 0;
+
 static int play_loop_enter(void)
 {
     int id;
 
+    if (is_paused())
+    {
+        clear_pause();
+        view_rotate = 0;
+        return 0;
+    }
+
     if ((id = gui_label(0, _("GO!"), GUI_LRG, GUI_ALL, gui_blu, gui_grn)))
     {
         gui_layout(id, 0, 0);
@@ -156,6 +191,10 @@ static int play_loop_enter(void)
     game_set_fly(0.f);
     view_rotate = 0;
 
+    hud_view_pulse(config_get_d(CONFIG_CAMERA));
+
+    nohud = 0;
+
     hud_update(0);
 
     return id;
@@ -164,7 +203,9 @@ static int play_loop_enter(void)
 static void play_loop_paint(int id, float st)
 {
     game_draw(0, st);
-    hud_paint();
+
+    if (!nohud)
+        hud_paint();
 
     if (time_state() < 1.f)
         gui_paint(id);
@@ -172,8 +213,7 @@ static void play_loop_paint(int id, float st)
 
 static void play_loop_timer(int id, float dt)
 {
-    float k = (((SDL_GetModState() & KMOD_LSHIFT) ||
-                (SDL_GetModState() & KMOD_RSHIFT)) ?
+    float k = ((SDL_GetModState() & KMOD_SHIFT) ?
                (float) config_get_d(CONFIG_ROTATE_FAST) / 100.f:
                (float) config_get_d(CONFIG_ROTATE_SLOW) / 100.f);
 
@@ -181,24 +221,31 @@ static void play_loop_timer(int id, float dt)
 
     float g[3] = { 0.0f, -9.8f, 0.0f };
 
-    int state;
-    
     at = (7 * at + dt) / 8;
 
     gui_timer(id, at);
     hud_timer(at);
     game_set_rot(view_rotate * k);
 
-    state = game_step(g, at, 1);
-    if (state)
+    switch (game_step(g, at, 1))
     {
-       level_stop(state, curr_clock(), curr_coins());
-       switch (state)
-       {
-       case GAME_TIME: goto_state(&st_time_out); break;
-       case GAME_FALL: goto_state(&st_fall_out); break;
-       case GAME_GOAL: goto_state(&st_goal);     break;
-       }
+    case GAME_GOAL:
+        level_stat(GAME_GOAL, curr_clock(), curr_coins());
+        goto_state(&st_goal);
+        break;
+
+    case GAME_FALL:
+        level_stat(GAME_FALL, curr_clock(), curr_coins());
+        goto_state(&st_fall_out);
+        break;
+
+    case GAME_TIME:
+        level_stat(GAME_TIME, curr_clock(), curr_coins());
+        goto_state(&st_time_out);
+        break;
+
+    default:
+        break;
     }
 
     game_step_fade(dt);
@@ -249,6 +296,14 @@ static int play_loop_keybd(int c, int d)
             config_set_d(CONFIG_CAMERA, 2);
             hud_view_pulse(2);
         }
+        if (config_tst_d(CONFIG_KEY_RESTART, c) &&
+            curr_lg()->mode != MODE_CHALLENGE)
+        {
+            level_same();
+            goto_state(&st_play_ready);
+        }
+        if (config_tst_d(CONFIG_KEY_PAUSE, c))
+            goto_pause();
     }
     else
     {
@@ -258,13 +313,15 @@ static int play_loop_keybd(int c, int d)
             view_rotate = 0;
     }
 
-    if (d && c == SDLK_F12)
+    if (d && c == SDLK_F12 && config_cheat())
         return goto_state(&st_look);
-    
-    /* Cheat */
-    if (d && c == SDLK_c && config_get_d(CONFIG_CHEAT))
+
+    if (d && c == SDLK_F6)
+        nohud = !nohud;
+
+    if (d && c == SDLK_c && config_cheat())
     {
-        level_stop(GAME_GOAL, curr_clock(), curr_coins());
+        level_stat(GAME_GOAL, curr_clock(), curr_coins());
         return goto_state(&st_goal);
     }
     return 1;
@@ -275,10 +332,7 @@ static int play_loop_buttn(int b, int d)
     if (d == 1)
     {
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
-       {
-           level_stop(GAME_NONE, curr_clock(), curr_coins());
-            return abort_play();
-       }
+            pause_or_exit();
 
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
             view_rotate = +1;
@@ -349,7 +403,7 @@ static void look_point(int id, int x, int y, int dx, int dy)
 static int look_keybd(int c, int d)
 {
     if (d && c == SDLK_F12)
-       return goto_state(&st_play_loop);
+        return goto_state(&st_play_loop);
 
     return 1;
 }
@@ -357,7 +411,7 @@ static int look_keybd(int c, int d)
 static int look_buttn(int b, int d)
 {
     if (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
-       return goto_state(&st_play_loop);
+        return goto_state(&st_play_loop);
 
     return 1;
 }
@@ -372,7 +426,7 @@ struct state st_play_ready = {
     NULL,
     NULL,
     play_ready_click,
-    NULL,
+    play_ready_keybd,
     play_ready_buttn,
     1, 0
 };
@@ -385,7 +439,7 @@ struct state st_play_set = {
     NULL,
     NULL,
     play_set_click,
-    NULL,
+    play_set_keybd,
     play_set_buttn,
     1, 0
 };