More docstring clean-up. Renamed REPLAY_VERSION to DEMO_VERSION.
[neverball] / ball / st_play.c
index 362b328..c665640 100644 (file)
@@ -1,4 +1,4 @@
-/*   
+/*
  * Copyright (C) 2003 Robert Kooima
  *
  * NEVERBALL is  free software; you can redistribute  it and/or modify
 #include "hud.h"
 #include "game.h"
 #include "demo.h"
-#include "level.h"
+#include "levels.h"
 #include "audio.h"
 #include "config.h"
+#include "st_shared.h"
 
 #include "st_play.h"
-#include "st_fail.h"
-#include "st_goal.h"
+#include "st_play_end.h"
 #include "st_over.h"
 
 /*---------------------------------------------------------------------------*/
@@ -31,11 +31,19 @@ static int view_rotate;
 
 /*---------------------------------------------------------------------------*/
 
+static int abort_play(void)
+{
+   if (curr_lg()->mode == MODE_SINGLE)
+       return 0;
+   else
+       return goto_state(&st_over);
+}
+
 static int play_ready_enter(void)
 {
     int id;
 
-    if ((id = gui_label(0, "Ready?", GUI_LRG, GUI_ALL, 0, 0)))
+    if ((id = gui_label(0, _("Ready?"), GUI_LRG, GUI_ALL, 0, 0)))
     {
         gui_layout(id, 0, 0);
         gui_pulse(id, 1.2f);
@@ -47,17 +55,6 @@ static int play_ready_enter(void)
     return id;
 }
 
-static void play_ready_leave(int id)
-{
-    gui_delete(id);
-}
-
-static void play_ready_paint(int id, float st)
-{
-    game_draw(0, st);
-    gui_paint(id);
-}
-
 static void play_ready_timer(int id, float dt)
 {
     float t = time_state();
@@ -77,11 +74,6 @@ 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)
-{
-    return (d && c == SDLK_ESCAPE) ? goto_state(&st_over) : 1;
-}
-
 static int play_ready_buttn(int b, int d)
 {
     if (d)
@@ -89,7 +81,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 goto_state(&st_over);
+            return abort_play();
     }
     return 1;
 }
@@ -100,7 +92,7 @@ static int play_set_enter(void)
 {
     int id;
 
-    if ((id = gui_label(0, "Set?", GUI_LRG, GUI_ALL, 0, 0)))
+    if ((id = gui_label(0, _("Set?"), GUI_LRG, GUI_ALL, 0, 0)))
     {
         gui_layout(id, 0, 0);
         gui_pulse(id, 1.2f);
@@ -111,17 +103,6 @@ static int play_set_enter(void)
     return id;
 }
 
-static void play_set_leave(int id)
-{
-    gui_delete(id);
-}
-
-static void play_set_paint(int id, float st)
-{
-    game_draw(0, st);
-    gui_paint(id);
-}
-
 static void play_set_timer(int id, float dt)
 {
     float t = time_state();
@@ -145,11 +126,6 @@ static int play_set_click(int b, int d)
     return 1;
 }
 
-static int play_set_keybd(int c, int d)
-{
-    return (d && c == SDLK_ESCAPE) ? goto_state(&st_over) : 1;
-}
-
 static int play_set_buttn(int b, int d)
 {
     if (d)
@@ -157,18 +133,20 @@ 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 goto_state(&st_over);
+            return abort_play();
     }
     return 1;
 }
 
 /*---------------------------------------------------------------------------*/
 
+static int nohud = 0;
+
 static int play_loop_enter(void)
 {
     int id;
 
-    if ((id = gui_label(0, "GO!", GUI_LRG, GUI_ALL, gui_blu, gui_grn)))
+    if ((id = gui_label(0, _("GO!"), GUI_LRG, GUI_ALL, gui_blu, gui_grn)))
     {
         gui_layout(id, 0, 0);
         gui_pulse(id, 1.2f);
@@ -179,18 +157,20 @@ static int play_loop_enter(void)
     game_set_fly(0.f);
     view_rotate = 0;
 
-    return id;
-}
+    hud_view_pulse(config_get_d(CONFIG_CAMERA));
 
-static void play_loop_leave(int id)
-{
-    gui_delete(id);
+    nohud = 0;
+
+    hud_update(0);
+
+    return id;
 }
 
 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);
@@ -207,17 +187,19 @@ static void play_loop_timer(int id, float dt)
 
     float g[3] = { 0.0f, -9.8f, 0.0f };
 
+    int state, state_value;
+
     at = (7 * at + dt) / 8;
 
     gui_timer(id, at);
     hud_timer(at);
     game_set_rot(view_rotate * k);
 
-    switch (game_step(g, at, 1))
+    state = game_step(g, at, &state_value);
+    if (state)
     {
-    case GAME_TIME: 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;
+        level_stop(state, state_value, curr_clock(), curr_coins());
+        goto_state(&st_play_end);
     }
 
     game_step_fade(dt);
@@ -277,10 +259,18 @@ static int play_loop_keybd(int c, int d)
             view_rotate = 0;
     }
 
-    if (d && c == SDLK_ESCAPE)
-        goto_state(&st_over);
     if (d && c == SDLK_F12)
-        goto_state(&st_look);
+        return goto_state(&st_look);
+
+    if (d && c == SDLK_F6)
+        nohud = !nohud;
+
+    /* Cheat */
+    if (d && c == SDLK_c && config_get_d(CONFIG_CHEAT))
+    {
+        level_stop(GAME_GOAL, 0, curr_clock(), curr_coins());
+        return goto_state(&st_play_end);
+    }
     return 1;
 }
 
@@ -289,7 +279,10 @@ static int play_loop_buttn(int b, int d)
     if (d == 1)
     {
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
-            return goto_state(&st_over);
+        {
+            level_stop(GAME_NONE, 0, curr_clock(), curr_coins());
+            return abort_play();
+        }
 
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
             view_rotate = +1;
@@ -359,8 +352,16 @@ 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_ESCAPE) goto_state(&st_play_loop);
-    if (d && c == SDLK_F12)    goto_state(&st_play_loop);
+    if (d && c == SDLK_F12)
+        return goto_state(&st_play_loop);
+
+    return 1;
+}
+
+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 1;
 }
@@ -369,33 +370,33 @@ static int look_keybd(int c, int d)
 
 struct state st_play_ready = {
     play_ready_enter,
-    play_ready_leave,
-    play_ready_paint,
+    shared_leave,
+    shared_paint,
     play_ready_timer,
     NULL,
     NULL,
     play_ready_click,
-    play_ready_keybd,
+    NULL,
     play_ready_buttn,
     1, 0
 };
 
 struct state st_play_set = {
     play_set_enter,
-    play_set_leave,
-    play_set_paint,
+    shared_leave,
+    shared_paint,
     play_set_timer,
     NULL,
     NULL,
     play_set_click,
-    play_set_keybd,
+    NULL,
     play_set_buttn,
     1, 0
 };
 
 struct state st_play_loop = {
     play_loop_enter,
-    play_loop_leave,
+    shared_leave,
     play_loop_paint,
     play_loop_timer,
     play_loop_point,
@@ -415,6 +416,6 @@ struct state st_look = {
     NULL,
     NULL,
     look_keybd,
-    NULL,
+    look_buttn,
     0, 0
 };