-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameState.java
More file actions
121 lines (111 loc) · 2.79 KB
/
GameState.java
File metadata and controls
121 lines (111 loc) · 2.79 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import java.awt.Graphics;
import java.awt.Image;
/**
* This class helps to control the state of game and can handle switching
* between game states.
*
* @author John Kurlak (kurlak)
* Weston Thayer (weston5)
* Panhavorn Hok (onehok1)
* @version 12.07.09
*/
public class GameState
{
static final int TITLE_SCREEN = 0;
static final int GAME_PLAY = 1;
static final int DEAD = 2;
static final int LEVEL_COMPLETE = 3;
static final int GAME_PAUSED = 4;
static final int GAME_OVER = 5;
static final int WINNER = 6;
static final int CREDITS = 7;
static final int CONTROLS = 8;
static final int CONTROLS_TWO = 9;
static final int STORY = 10;
static final int STORY_TWO = 11;
static final int MENU = 12;
static final int EXIT = 13;
static final int LEVEL_STARTING = 14;
private static int currentState = TITLE_SCREEN;
private static int loading = 0;
private static int nextState = currentState;
private static int loadingTop = 0;
private static int loadingBottom = 0;
private static Image topImage = Utilities
.loadImage("loading-top.png");
private static Image bottomImage = Utilities
.loadImage("loading-bottom.png");
/**
* This method gets the current state of the game.
*
* @return Returns the current state of the game as an integer
*/
public static int getCurrentState()
{
return currentState;
}
/**
* This method loads a different state with a transition.
*
* @param state The new state to load
*/
public static void loadState(int state)
{
loadingTop = -topImage.getHeight(null);
loadingBottom = Global.WINDOW_HEIGHT;
loading = 1;
nextState = state;
}
/**
* This method loads a different state instantly without a transition.
*
* @param state The new state to load
*/
public static void switchState(int state)
{
currentState = state;
}
/**
* This method determines whether the game is currently transitioning
* between states.
*
* @return Returns true if the game is currently transitioning and false if
* it is not
*/
public static boolean isLoading()
{
return (loading != 0);
}
/**
* This method draws the transition animation.
*
* @param g The graphics object to which we can draw
*/
public static void drawLoad(Graphics g)
{
if (loading == 1 || loading == 2)
{
if (loading == 1)
{
loadingTop += 60;
loadingBottom -= 60;
if (loadingTop >= 0)
{
currentState = nextState;
loading = 2;
}
}
else
{
loadingTop -= 60;
loadingBottom += 60;
if (loadingBottom > Global.WINDOW_HEIGHT)
{
loading = 0;
}
}
g.drawImage(topImage, 0, loadingTop, null);
g.drawImage(bottomImage, 0, loadingBottom, null);
}
}
}