2 * Copyright (C) 2003 Robert Kooima
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
29 /*---------------------------------------------------------------------------*/
31 /* The level currently playing */
32 static struct level_game current_level_game;
34 /*---------------------------------------------------------------------------*/
36 int level_replay(const char *filename)
38 return demo_replay_init(filename, ¤t_level_game);
41 static struct level single_level; /* a level without set */
43 int level_play_go(void)
44 /* Start to play the current level */
46 struct level_game *lg = ¤t_level_game;
48 const struct level *l;
51 l = get_level(lg->level);
55 lg->goal = (mode == MODE_PRACTICE) ? 0 : l->goal;
56 lg->time = (mode == MODE_PRACTICE) ? 0 : l->time;
58 /* clear other fields */
59 lg->state = GAME_NONE;
62 lg->coin_rank = lg->goal_rank = lg->time_rank =
63 lg->score_rank = lg-> times_rank = 3;
66 return demo_play_init(USER_REPLAY_FILE, l, lg);
70 void level_play_single(const char *filename)
71 /* Prepare to play a single level */
73 struct level *l = &single_level;
75 current_level_game.mode = MODE_SINGLE;
76 current_level_game.level = 0;
78 strncpy(l->file, filename, MAXSTR);
87 void level_play(int i, int m)
88 /* Prepare to play a level sequence from the `i'th level */
90 current_level_game.mode = m;
91 current_level_game.level = i;
93 current_level_game.score = 0;
94 current_level_game.balls = 3;
95 current_level_game.times = 0;
98 /*---------------------------------------------------------------------------*/
100 const struct level_game * curr_lg(void)
102 return ¤t_level_game;
105 int count_extra_balls(int old_score, int coins)
107 int modulo = old_score % 100;
108 int sum = modulo + coins;
112 void level_stop(int state, int clock, int coins)
113 /* Stop the current playing level */
115 struct level_game * lg = ¤t_level_game;
117 int timer = (mode == MODE_PRACTICE || mode == MODE_SINGLE) ? clock : lg->time - clock;
123 /* Performs challenge mode opperations */
124 if (mode == MODE_CHALLENGE)
129 /* sum coins an earn extra balls */
130 if (state == GAME_GOAL)
132 lg->balls += count_extra_balls(lg->score, coins);
137 if (state == GAME_TIME || state == GAME_FALL)
141 /* Update high-scores and next level */
142 if (state == GAME_GOAL && curr_set())
143 set_finish_level(lg, config_simple_get_s(CONFIG_PLAYER));
147 /* stop demo recording */
153 int mode = current_level_game.mode;
154 int balls = current_level_game.balls;
155 return (mode == MODE_CHALLENGE) && (balls <= 0);
158 void level_next(void)
160 current_level_game.level = current_level_game.next_level;
163 void level_update_player_name(void)
165 score_change_name(¤t_level_game, config_simple_get_s(CONFIG_PLAYER));
168 /*---------------------------------------------------------------------------*/