-
Notifications
You must be signed in to change notification settings - Fork 30
/
TransitionTest.java
161 lines (146 loc) · 4.8 KB
/
TransitionTest.java
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package org.newdawn.slick.tests;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.state.transition.BlobbyTransition;
import org.newdawn.slick.state.transition.FadeInTransition;
import org.newdawn.slick.state.transition.FadeOutTransition;
import org.newdawn.slick.state.transition.HorizontalSplitTransition;
import org.newdawn.slick.state.transition.RotateTransition;
import org.newdawn.slick.state.transition.SelectTransition;
import org.newdawn.slick.state.transition.Transition;
import org.newdawn.slick.state.transition.VerticalSplitTransition;
import org.newdawn.slick.util.Log;
/**
* A test to view the different transitions that are currently implemented
*
* @author kevin
*/
public class TransitionTest extends StateBasedGame {
/** The transitions under test */
private Class[][] transitions = new Class[][] {
{null, VerticalSplitTransition.class},
{FadeOutTransition.class, FadeInTransition.class},
{null, RotateTransition.class},
{null, HorizontalSplitTransition.class},
{null, BlobbyTransition.class},
{null, SelectTransition.class},
};
/** The index of the next transition to use */
private int index;
/**
* Test the transitions implemented
*/
public TransitionTest() {
super("Transition Test - Hit Space To Transition");
}
/**
* @see org.newdawn.slick.state.StateBasedGame#initStatesList(org.newdawn.slick.GameContainer)
*/
public void initStatesList(GameContainer container) throws SlickException {
addState(new ImageState(0, "testdata/wallpaper/paper1.png", 1));
addState(new ImageState(1, "testdata/wallpaper/paper2.png", 2));
addState(new ImageState(2, "testdata/bigimage.tga", 0));
}
/**
* Get the next transition pair that we'lluse
*
* @return The pair of transitions used to enter and leave the next state
*/
public Transition[] getNextTransitionPair() {
Transition[] pair = new Transition[2];
try {
if (transitions[index][0] != null) {
pair[0] = (Transition) transitions[index][0].newInstance();
}
if (transitions[index][1] != null) {
pair[1] = (Transition) transitions[index][1].newInstance();
}
} catch (Throwable e) {
Log.error(e);
}
index++;
if (index >= transitions.length) {
index = 0;
}
return pair;
}
/**
* A test state that just displayed one image full scren
*
* @author kevin
*/
private class ImageState extends BasicGameState {
/** The id of this state */
private int id;
/** The next state we'll move to */
private int next;
/** The reference to the image to be displayed */
private String ref;
/** The loaded image */
private Image image;
/**
* Create a new image state
*
* @param id The id of the this state
* @param ref The reference to the image to display
* @param next The next state we'll mvoe to
*/
public ImageState(int id, String ref, int next) {
this.ref = ref;
this.id = id;
this.next = next;
}
/**
* @see org.newdawn.slick.state.BasicGameState#getID()
*/
public int getID() {
return id;
}
/**
* @see org.newdawn.slick.state.GameState#init(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame)
*/
public void init(GameContainer container, StateBasedGame game) throws SlickException {
image = new Image(ref);
}
/**
* @see org.newdawn.slick.state.GameState#render(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.Graphics)
*/
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
image.draw(0,0,800,600);
g.setColor(Color.red);
g.fillRect(-50,200,50,50);
}
/**
* @see org.newdawn.slick.state.GameState#update(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame, int)
*/
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
if (container.getInput().isKeyPressed(Input.KEY_SPACE)) {
Transition[] pair = getNextTransitionPair();
game.enterState(next, pair[0], pair[1]);
}
}
}
/**
* Entry point to our test
*
* @param argv
* The arguments passed to the test
*/
public static void main(String[] argv) {
try {
AppGameContainer container = new AppGameContainer(
new TransitionTest());
container.setDisplayMode(800, 600, false);
container.start();
} catch (SlickException e) {
e.printStackTrace();
}
}
}