File: game_state.c

package info (click to toggle)
rockdodger 0.9.2-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,220 kB
  • ctags: 756
  • sloc: ansic: 5,374; makefile: 159; sh: 21
file content (94 lines) | stat: -rw-r--r-- 1,902 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <assert.h>
#include "game_state.h"
#include "rockdodger_globals.h"
#include "highscore_io.h"
#include "ship.h"
#include "sound.h"

void dead_pause() {
  play_tune(1);
  initialshield = 150;
  xship = 10;
  yship = ysize / 2;
  xvel = 2;
  yvel = 0;
  shieldlevel = 3 * W;
  laserlevel = 3 * W;
}


void handle_state_timeout(void) {
  //Ignore any state timeout in GAME PLAY mode.
  if(state == GAME_PLAY) return;
  // Count down the game loop timer, and change state when it gets to zero or less;
  if((state_timeout -= movementrate * 3) < 0) {
    switch (state) {
    case DEAD_PAUSE:
      // Create a new ship and start all over again
      state = GAME_PLAY;
      dead_pause();
      break;
    case GAME_OVER:
      state = HIGH_SCORE_ENTRY;
      game_over();
      break;
    case HIGH_SCORE_DISPLAY:
      state = TITLE_PAGE;
      state_timeout = 500.0;
      break;
    case HIGH_SCORE_ENTRY:
      // state = TITLE_PAGE;
      // play_tune(1);
      // state_timeout=100.0;
      break;
    case TITLE_PAGE:
      state = current_edition == EDITION_greeblies ? HIGH_SCORE_DISPLAY : DEMO;
      state_timeout = 400.0;
      sfx_enabled = 0;
      reset_ship_state();
      break;
    case DEMO:
      state = HIGH_SCORE_DISPLAY;
      state_timeout = 222.365;
      break;
    case SETUP:
      state = TITLE_PAGE;
      state_timeout = 500.0;
      break;
    case GAME_PLAY:
    case RESTART_GAME:
      assert(0); //Never happens.
      break;
    case GAME_PAUSED:
    case QUIT_GAME:
      break;
    }
  }
}


void pausegame() {
  switch(state) {
  case GAME_PLAY:
    state = GAME_PAUSED;
    break;
  case GAME_PAUSED:
    state = GAME_PLAY;
    break;
  default:
    assert(0);
  }
}


void reset_ship_state() {
  nships = 4;
  clear_score();
  xvel = 0;
  yvel = 0;
  xship = 10;
  yship = ysize / 2;
  shieldlevel = 3 * W;
  laserlevel = 3 * W;
  initialshield = 150;
}