-
Notifications
You must be signed in to change notification settings - Fork 1
/
StartingScene.java
184 lines (162 loc) · 5.91 KB
/
StartingScene.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.ArrayList;
public class StartingScene extends JPanel{
BufferedImage myImage;
Graphics myBuffer;
private Timer t;
public boolean showInfoBook = false;
StartingBackground bckground;
private boolean space;
public int count = 0;
public int playerVelocityX = 0;
public int playerVelocityY = 0;
Player player;
PlayerStats stats;
public boolean increaseVelocityUp = true;
public boolean increaseVelocityDown = true;
public boolean increaseVelocityRight = true;
public boolean increaseVelocityLeft = true;
public int doorNum = 0;
public boolean isOver = false;
MasterGUI f;
ArrayList<Door> doors;
public StartingScene(PlayerStats pStats, MasterGUI master){
doors = new ArrayList<Door>();
doors.add(new Door(147, 145));
doors.add(new Door(800, 145));
doors.add(new Door(1050, 300));
doors.add(new Door(600, 15));
doors.add(new Door(600, 300));
f = master;
myImage = new BufferedImage(700, 700, BufferedImage.TYPE_INT_RGB);
myBuffer = myImage.getGraphics();
myBuffer.setColor(Color.WHITE);
myBuffer.fillRect(0, 0, 700, 700);
bckground = new StartingBackground(0);
player = new Player();
player.style = "still";
stats = pStats;
t = new Timer(5, new AnimationListener());
addKeyListener(new Key());
setFocusable(true);
begin();
}
public void begin(){
t.start();
}
public PlayerStats getStats(){
return stats;
}
public void animate(){
bckground.draw(myBuffer);
bckground.moveBackground((int)(1.5*playerVelocityX));
player.draw(myBuffer, player.style, 100, true, stats.curWeapon(), stats.money, stats.shield);
player.move(playerVelocityX, playerVelocityY);
for(int i = 0; i < doors.size(); i++){
doors.get(i).draw(myBuffer, bckground.referenceX);
}
checkDoorText(player.rectX, player.rectY);
stats.setDamage(stats.getWeaponDamage(stats.curWeapon()));
if(showInfoBook){
stats.drawInfoBook(myBuffer);
}
repaint();
}
public void checkDoorText(int playerX, int playerY){
for(int i = 0; i < doors.size(); i++){
if(doors.get(i).nextToADoor(playerX, playerY, bckground.referenceX)){
myBuffer.setFont(new Font("Purisa", Font.BOLD, 15));
myBuffer.setColor(Color.WHITE);
myBuffer.drawString("Press 'E' to enter!", doors.get(i).getX()-5-bckground.referenceX, doors.get(i).getY()-5);
}
}
}
public void paintComponent(Graphics g) //The same method as before!
{
g.drawImage(myImage, 0, 0, getWidth(), getHeight(), null); //Draw the buffered image we've stored as a field
}
private class AnimationListener implements ActionListener
{
public void actionPerformed(ActionEvent e) //Gets called over and over by the Timer
{
animate(); //...hence animation!
}
}
private class Key extends KeyAdapter{
public void keyPressed(KeyEvent e){
if(e.getKeyCode() == KeyEvent.VK_RIGHT && increaseVelocityRight){
player.style = "right";
playerVelocityX += 3;
increaseVelocityRight = false;
}
else if(e.getKeyCode() == KeyEvent.VK_LEFT && increaseVelocityLeft){
player.style = "left";
playerVelocityX -= 3;
increaseVelocityLeft = false;
}
else if(e.getKeyCode() == KeyEvent.VK_UP && increaseVelocityUp){
player.style = "up";
playerVelocityY -= 4;
increaseVelocityUp = false;
}
else if(e.getKeyCode() == KeyEvent.VK_DOWN && increaseVelocityDown){
player.style = "down";
playerVelocityY += 4;
increaseVelocityDown = false;
}
else if(e.getKeyCode() == KeyEvent.VK_L){
stats.saveStats();
}
else if(e.getKeyCode() == KeyEvent.VK_I){
showInfoBook = true;
}
else if(e.getKeyCode() == KeyEvent.VK_E){
if(playerVelocityX == 0 && playerVelocityY == 0){
for(int i = 0; i < doors.size(); i++){
if(doors.get(i).nextToADoor(player.rectX, player.rectY, bckground.referenceX)){
if(i == 0){
f.changeStartToTutorial();
}
else if(i == 1){
f.changeStartToArena();
}
else if(i == 2){
f.changeStartToShop();
}
else if(i == 3){
f.changeStartToFarm();
}
else if(i == 4){
f.changeStartToBoss();
}
}
}
}
}
}
public void keyReleased(KeyEvent e){
if(e.getKeyCode() == KeyEvent.VK_RIGHT){
playerVelocityX -= 3;
increaseVelocityRight = true;
}
else if(e.getKeyCode() == KeyEvent.VK_LEFT){
playerVelocityX += 3;
increaseVelocityLeft = true;
}
else if(e.getKeyCode() == KeyEvent.VK_I){
showInfoBook = false;
}
else if(e.getKeyCode() == KeyEvent.VK_UP){
playerVelocityY += 4;
increaseVelocityUp = true;
}
else if(e.getKeyCode() == KeyEvent.VK_DOWN){
playerVelocityY -= 4;
increaseVelocityDown = true;
}
}
}
}