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.
28 /*---------------------------------------------------------------------------*/
30 /* The level currently playing */
31 static struct level_game current_level_game;
33 /*---------------------------------------------------------------------------*/
35 int level_replay(const char *filename)
37 return demo_replay_init(filename, ¤t_level_game);
40 static struct level single_level; /* a level without set */
42 int level_play_go(void)
43 /* Start to play the current level */
45 struct level_game *lg = ¤t_level_game;
46 const struct level *l = lg->level;
49 lg->goal = (mode == MODE_PRACTICE) ? 0 : l->goal;
50 lg->time = (mode == MODE_PRACTICE) ? 0 : l->time;
52 /* clear other fields */
53 lg->state = GAME_NONE;
56 lg->coin_rank = lg->goal_rank = lg->time_rank =
57 lg->score_rank = lg-> times_rank = 3;
60 return demo_play_init(USER_REPLAY_FILE, l, lg);
64 void level_play_single(const char *filename)
65 /* Prepare to play a single level */
67 struct level *l = &single_level;
76 level_load(filename, l);
78 level_play(l, MODE_SINGLE);
81 void level_play(const struct level *l, int m)
82 /* Prepare to play a level sequence from the `i'th level */
84 current_level_game.mode = m;
85 current_level_game.level = l;
87 current_level_game.score = 0;
88 current_level_game.balls = 3;
89 current_level_game.times = 0;
92 /*---------------------------------------------------------------------------*/
94 const struct level_game * curr_lg(void)
96 return ¤t_level_game;
99 int count_extra_balls(int old_score, int coins)
101 int modulo = old_score % 100;
102 int sum = modulo + coins;
106 void level_stop(int state, int clock, int coins)
107 /* Stop the current playing level */
109 struct level_game * lg = ¤t_level_game;
111 int timer = (mode == MODE_PRACTICE || mode == MODE_SINGLE) ? clock : lg->time - clock;
117 /* Performs challenge mode opperations */
118 if (mode == MODE_CHALLENGE)
123 /* sum coins an earn extra balls */
124 if (state == GAME_GOAL)
126 lg->balls += count_extra_balls(lg->score, coins);
131 if (state == GAME_TIME || state == GAME_FALL)
135 /* Update high-scores and next level */
136 if (state == GAME_GOAL && curr_set())
137 set_finish_level(lg, config_simple_get_s(CONFIG_PLAYER));
139 lg->next_level = NULL;
141 /* stop demo recording */
147 int mode = current_level_game.mode;
148 int balls = current_level_game.balls;
149 return (mode == MODE_CHALLENGE) && (balls <= 0);
152 void level_next(void)
154 struct level_game *lg = ¤t_level_game;
155 lg->level = lg->next_level;
158 void level_update_player_name(void)
160 score_change_name(¤t_level_game, config_simple_get_s(CONFIG_PLAYER));
163 /*---------------------------------------------------------------------------*/