-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClientAnimation.java~
More file actions
executable file
·223 lines (198 loc) · 8.93 KB
/
ClientAnimation.java~
File metadata and controls
executable file
·223 lines (198 loc) · 8.93 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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.io.*;
import javax.imageio.*;
import java.awt.image.*;
public class ClientAnimation extends JPanel implements ActionListener{
//properties
static Map currentMap;
static UserInterface UI; //create a new user interface to thread
static Thread UI_Thread;
static String [] playerClass = {"NA", "NA", "NA", "NA"};
int intPlayerNumber;
int characterSelected = 0;
int imgX;
int imgY;
Timer timer;
Timer timerAtk;
Timer shortTimer = null;
int intSAnim = 0; //These replace the boolean variables for slow and fast
int intFAnim = 2;
int intAtkAnim = 0;
int intSlowAnimate = 0;
int mouseButton = 0; //mouse button
//========================================
//--Player Sprites--
static BufferedImage MageImg = null;
static BufferedImage BuffImg = null;
static BufferedImage ThiefImg = null;
static BufferedImage DoctorImg = null;
BufferedImage EnemySharkImg = null;
int intCharacter = 0;
public void actionPerformed (ActionEvent evt) {
if (evt.getSource() == timer) {
//for slower animation
//intSlowAnimate Counts to 2, if its at 1: nothing happens, if its at 2:then the animation switch is triggered. Then the count is reset back to 0
intSlowAnimate++;
if (intSlowAnimate%2 == 0){
if(intSAnim == 1){
intSAnim = 0;
intSlowAnimate =0;
}else if(intSAnim == 0){
intSAnim = 1;
}
}
//for regular animation
//intFAnim switches on the timer
if (intFAnim == 3){
intFAnim = 2;
}else if (intFAnim == 2){
intFAnim = 3;
}
}
if(evt.getSource() == shortTimer){
mouseButton = 0; //reset mouse button after somebody clicks
shortTimer.stop();
}
if (evt.getSource() == timerAtk){
if(intAtkAnim ==0){
intAtkAnim=1;
}else{
timerAtk.stop();
}
}
}
//methods
public void paintComponent (Graphics g) {
//EXTRAS!
//Anti Aliasing
super.paintComponent(g);
Graphics2D graphics2D = (Graphics2D) g;
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setColor (Color.BLACK);
g.fillRect (0, 0, 2000, 2000);
//Setting image coordinates
imgX = -ClientMain.intPlayerData [intPlayerNumber][0] + 640;
imgY = -ClientMain.intPlayerData [intPlayerNumber][1] + 360;
if (imgX > 0) {
imgX = 0;
}else if (imgX < -currentMap.MapImg.getWidth() + 1280) {
imgX = -currentMap.MapImg.getWidth() + 1280;
}
if (imgY > 0) {
imgY = 0;
}else if (imgY < -currentMap.MapImg.getHeight() + 720) {
imgY = -currentMap.MapImg.getHeight() + 720;
}
//drawing the map background
g.drawImage (currentMap.MapImg, 0, 0, 1300, 740, -imgX, -imgY, -imgX + 1300, -imgY + 740, null);
//drawing player
for (int intCount = 0; intCount < 4; intCount ++) {
int intRow = 0;
int intCol = 0;
int intPlayerX = imgX + ClientMain.intPlayerData [intCount][0] - 45;
int intPlayerY = imgY + ClientMain.intPlayerData [intCount][1] - 45;
intRow = (ClientMain.intPlayerData [intCount][2] + 45 - (ClientMain.intPlayerData [intCount][2] + 45)%90)/90;
if (ClientMain.intPlayerData [intCount][3] == 0) {
intCol = intSAnim;
}else {
intCol = intFAnim;
}
double timeSinceAtk1 = (System.nanoTime()-ClientMain.longPlayerCooldown[intCount][0])/1e6;
double timeSinceAtk2 = (System.nanoTime()-ClientMain.longPlayerCooldown[intCount][1])/1e6;
//shows most attack animation
if(timeSinceAtk1 < timeSinceAtk2){
if(timeSinceAtk2 > 0 && timeSinceAtk2 < Integer.parseInt(UI.strDataStats[characterSelected][4]) ){
intCol = 5;
}
if(timeSinceAtk1 > 0 && timeSinceAtk1 < Integer.parseInt(UI.strDataStats[characterSelected][2]) ){
intCol = 4;
}
}else{
if(timeSinceAtk1 > 0 && timeSinceAtk1 < Integer.parseInt(UI.strDataStats[characterSelected][2]) ){
intCol = 4;
}
if(timeSinceAtk2 > 0 &&timeSinceAtk2 < Integer.parseInt(UI.strDataStats[characterSelected][4]) ){
intCol = 5;
}
}
if (intPlayerX > 0 && intPlayerY > 0) {
if (playerClass [intCount].equals ("mage")) {
g.drawImage (MageImg, intPlayerX, intPlayerY, intPlayerX + 90, intPlayerY + 90, 90 * intCol, 90 * intRow, 90 * intCol + 90, 90 * intRow + 90, null);
}else if (playerClass [intCount].equals ("buff")) {
g.drawImage (BuffImg, intPlayerX, intPlayerY, intPlayerX + 90, intPlayerY + 90, 90 * intCol, 90 * intRow, 90 * intCol + 90, 90 * intRow + 90, null);
}else if(playerClass [intCount].equals ("thief")){
g.drawImage (ThiefImg, intPlayerX, intPlayerY, intPlayerX + 90, intPlayerY + 90, 90 * intCol, 90 * intRow, 90 * intCol + 90, 90 * intRow + 90, null);
}else if(playerClass [intCount].equals ("doctor")){
g.drawImage (DoctorImg, intPlayerX, intPlayerY, intPlayerX + 90, intPlayerY + 90, 90 * intCol, 90 * intRow, 90 * intCol + 90, 90 * intRow + 90, null);
}
}
}
//g.setColor (Color.GREEN);
if(ClientMain.longEnemyData != null){
for (int Count = 0; Count < ClientMain.longEnemyData.length; Count ++) {
//flash if enemy is hit
Double timeSinceEnemyWasHit = (System.nanoTime()-ClientMain.longEnemyData[Count][3])/1e6;
int flashSpeed = 30;
if( timeSinceEnemyWasHit > 0 && timeSinceEnemyWasHit < flashSpeed || timeSinceEnemyWasHit > flashSpeed*3 && timeSinceEnemyWasHit < flashSpeed*4 || timeSinceEnemyWasHit > flashSpeed*6 && timeSinceEnemyWasHit < flashSpeed * 6 || timeSinceEnemyWasHit > flashSpeed*8 && timeSinceEnemyWasHit < flashSpeed*9){
//invisible (flashing enemy hit animation)
}else{
//draw shark
if(ClientMain.longEnemyData[Count][2] >= 90 && ClientMain.longEnemyData[Count][2] <= 270){
//facing left
if(intSAnim == 1){
g.drawImage (EnemySharkImg, imgX+(int)ClientMain.longEnemyData[Count][0]-45, imgY+(int)(ClientMain.longEnemyData [Count][1])-45, imgX+(int)ClientMain.longEnemyData[Count][0]+45, imgY+(int)(ClientMain.longEnemyData [Count][1])+45, 0, 0, 90, 90, null);
}else{
g.drawImage (EnemySharkImg, imgX+(int)ClientMain.longEnemyData[Count][0]-45, imgY+(int)(ClientMain.longEnemyData [Count][1])-45, imgX+(int)ClientMain.longEnemyData[Count][0]+45, imgY+(int)(ClientMain.longEnemyData [Count][1])+45, 90, 0, 180, 90, null);
}
}else{
//facing right
if(intSAnim == 1){
g.drawImage (EnemySharkImg, imgX+(int)ClientMain.longEnemyData[Count][0]-45, imgY+(int)(ClientMain.longEnemyData [Count][1])-45, imgX+(int)ClientMain.longEnemyData[Count][0]+45, imgY+(int)(ClientMain.longEnemyData [Count][1])+45, 0, 90, 90, 180, null);
}else{
g.drawImage (EnemySharkImg, imgX+(int)ClientMain.longEnemyData[Count][0]-45, imgY+(int)(ClientMain.longEnemyData [Count][1])-45, imgX+(int)ClientMain.longEnemyData[Count][0]+45, imgY+(int)(ClientMain.longEnemyData [Count][1])+45, 90, 90, 180, 180, null);
}
}
//g.fillOval (imgX + (int)ClientMain.longEnemyData [Count][0] - 30, imgY + (int)(ClientMain.longEnemyData [Count][1]) - 30, 60, 60);
}
}
}
//update mininmap with player choordinates
currentMap.updateMinimap(ClientMain.intPlayerData, playerClass, intPlayerNumber);
//update UserInterface class
if(UI != null){
UI.mouseButton = this.mouseButton;
//draw User Interface
g.drawImage(UI.UIRender, 0, 0, null);
}
}
//constructor
public ClientAnimation (String currentMapFile) throws IOException{
super(true);
timer = new Timer(450, this);
timer.start();
timerAtk = new Timer(150, this);
//Initialize user interface
UI = new UserInterface();
UI_Thread = new Thread(UI);
shortTimer = new Timer(50, this);
currentMap = new Map (currentMapFile + ".csv");
try{
currentMap.renderMap();
currentMap.renderMinimap();
currentMap.renderBoundMap();
MageImg = ImageIO.read(new File("Mageimg.png"));
BuffImg = ImageIO.read(new File("BuffImg.png"));
ThiefImg = ImageIO.read(new File("ThiefImg.png"));
DoctorImg = ImageIO.read(new File("DoctorImg.png"));
EnemySharkImg = ImageIO.read(new File("EnemySharkImg.png"));
}catch(Exception e){
System.out.println("Render map error: " + e);
}
//start rendering the UI
UI_Thread.start();
}
}