Skip to content

Commit 78adad5

Browse files
committed
Merge remote-tracking branch 'origin/aside'
2 parents 5f3b33f + b501218 commit 78adad5

File tree

14 files changed

+178
-166
lines changed

14 files changed

+178
-166
lines changed

src/com/redomar/game/Game.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.redomar.game.net.GameClient;
2828
import com.redomar.game.net.GameServer;
2929
import com.redomar.game.net.packets.Packet00Login;
30+
import com.redomar.game.script.PrintTypes;
3031
import com.redomar.game.script.Printing;
3132

3233
public class Game extends Canvas implements Runnable {
@@ -47,9 +48,9 @@ public class Game extends Canvas implements Runnable {
4748
private static boolean npc = false;
4849
private static int map = 0;
4950

50-
private JFrame frame;
51+
private static JFrame frame;
5152

52-
private boolean running = false;
53+
private static boolean running = false;
5354
private int tickCount = 0;
5455

5556
private BufferedImage image = new BufferedImage(WIDTH, HEIGHT,
@@ -73,7 +74,7 @@ public class Game extends Canvas implements Runnable {
7374
private boolean notActive = true;
7475
private boolean noAudioDevice = false;
7576
private int trigger = 0;
76-
private GameClient socketClient;
77+
private static GameClient socketClient;
7778
private GameServer socketServer;
7879
private Printing print = new Printing();
7980

@@ -144,7 +145,7 @@ public static void npcKill() {
144145
}
145146

146147
public synchronized void start() {
147-
running = true;
148+
Game.setRunning(true);
148149
new Thread(this, "GAME").start();
149150

150151
if (getJdata_Host() == 0) {
@@ -157,7 +158,7 @@ public synchronized void start() {
157158
}
158159

159160
public synchronized void stop() {
160-
running = false;
161+
Game.setRunning(false);
161162
}
162163

163164
public void run() {
@@ -172,7 +173,7 @@ public void run() {
172173

173174
init();
174175

175-
while (running) {
176+
while (Game.isRunning()) {
176177
long now = System.nanoTime();
177178
delta += (now - lastTime) / nsPerTick;
178179
lastTime = now;
@@ -251,7 +252,7 @@ public void render() {
251252
notActive = false;
252253
} else {
253254
// System.out.println("[GAME] Canceled music option");
254-
print.print(" Canceled music option", 1);
255+
print.print(" Canceled music option", PrintTypes.GAME);
255256
input.setPlayMusic(false);
256257
}
257258
}
@@ -284,6 +285,8 @@ public void render() {
284285
"Welcome "
285286
+ WordUtils.capitalizeFully(player
286287
.getSantizedUsername()), 3, getHeight() - 17);
288+
g.setColor(Color.ORANGE);
289+
g.drawString("Press Q to quit", (getWidth()/2)-("Press Q to quit".length()*3), getHeight() -17);
287290
g.setColor(Color.YELLOW);
288291
g.drawString(time.getTime(), (getWidth() - 58), (getHeight() - 3));
289292
g.setColor(Color.WHITE);
@@ -324,20 +327,20 @@ public static void main(String[] args) {
324327
new Menu().start();
325328
}
326329

327-
public JFrame getFrame() {
328-
return frame;
330+
public static JFrame getFrame() {
331+
return Game.frame;
329332
}
330333

331-
public void setFrame(JFrame frame) {
332-
this.frame = frame;
334+
public static void setFrame(JFrame frame) {
335+
Game.frame = frame;
333336
}
334337

335-
public GameClient getSocketClient() {
338+
public static GameClient getSocketClient() {
336339
return socketClient;
337340
}
338341

339342
public void setSocketClient(GameClient socketClient) {
340-
this.socketClient = socketClient;
343+
Game.socketClient = socketClient;
341344
}
342345

343346
public static Player getPlayer() {
@@ -396,6 +399,14 @@ public static void setGame(Game game) {
396399
Game.game = game;
397400
}
398401

402+
public static boolean isRunning() {
403+
return running;
404+
}
405+
406+
public static void setRunning(boolean running) {
407+
Game.running = running;
408+
}
409+
399410
public static boolean isChangeLevel() {
400411
return changeLevel;
401412
}

src/com/redomar/game/InputHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ public void toggleKey(int keyCode, boolean isPressed) {
9292
System.out.println("[GAME] Dummy has been despawned");
9393
}
9494
}
95+
if (keyCode == KeyEvent.VK_Q){
96+
Game.getLevel().removeEntity(Game.getPlayer().getSantizedUsername());
97+
Game.setRunning(false);
98+
Game.getFrame().dispose();
99+
System.exit(1);
100+
}
95101
}
96102

97103
public int getMap() {

src/com/redomar/game/WindowHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
public class WindowHandler implements WindowListener {
99

10+
@SuppressWarnings("unused")
1011
private final Game game;
1112

1213
public WindowHandler(Game game) {
1314
this.game = game;
14-
this.game.getFrame().addWindowListener(this);
15+
Game.getFrame().addWindowListener(this);
1516
}
1617

1718
@Override
@@ -28,7 +29,7 @@ public void windowClosed(WindowEvent event) {
2829
public void windowClosing(WindowEvent event) {
2930
Packet01Disconnect packet = new Packet01Disconnect(Game.getPlayer()
3031
.getUsername());
31-
packet.writeData(this.game.getSocketClient());
32+
packet.writeData(Game.getSocketClient());
3233
}
3334

3435
@Override

src/com/redomar/game/entities/Dummy.java

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class Dummy extends Mob {
1313
private int xa = 0;
1414
private int ya = 0;
1515
private boolean[] swimType;
16+
private int[] swimColour;
1617

1718
private Swim swim;
1819

@@ -57,70 +58,24 @@ public void render(Screen screen) {
5758
int xOffset = getX() - modifier / 2;
5859
int yOffset = getY() - modifier / 2 - 4;
5960

60-
if (isSwimming) {
61+
if (isSwimming || isMagma || isMuddy) {
62+
swimColour = getSwim().waveCols(isSwimming, isMagma, isMuddy);
63+
6164
int waterColour = 0;
6265
yOffset += 4;
6366

6467
colour = Colours.get(-1, 111, -1, faceCol);
6568

6669
if (tickCount % 60 < 15) {
67-
waterColour = Colours.get(-1, -1, 255, -1);
70+
waterColour = Colours.get(-1, -1, swimColour[0], -1);
6871
} else if (15 <= tickCount % 60 && tickCount % 60 < 30) {
6972
yOffset--;
70-
waterColour = Colours.get(-1, 225, 115, -1);
73+
waterColour = Colours.get(-1, swimColour[1], swimColour[2], -1);
7174
} else if (30 <= tickCount % 60 && tickCount % 60 < 45) {
72-
waterColour = Colours.get(-1, 115, -1, 225);
75+
waterColour = Colours.get(-1, swimColour[2], -1, swimColour[1]);
7376
} else {
7477
yOffset--;
75-
waterColour = Colours.get(-1, -1, 225, 115);
76-
}
77-
78-
screen.render(xOffset, yOffset + 3, 31 + 31 * 32, waterColour,
79-
0x00, 1);
80-
screen.render(xOffset + 8, yOffset + 3, 31 + 31 * 32, waterColour,
81-
0x01, 1);
82-
}
83-
84-
if (isMagma) {
85-
int waterColour = 0;
86-
yOffset += 4;
87-
88-
colour = Colours.get(-1, 111, -1, faceCol);
89-
90-
if (tickCount % 60 < 15) {
91-
waterColour = Colours.get(-1, -1, 541, -1);
92-
} else if (15 <= tickCount % 60 && tickCount % 60 < 30) {
93-
yOffset--;
94-
waterColour = Colours.get(-1, 521, 510, -1);
95-
} else if (30 <= tickCount % 60 && tickCount % 60 < 45) {
96-
waterColour = Colours.get(-1, 510, -1, 521);
97-
} else {
98-
yOffset--;
99-
waterColour = Colours.get(-1, -1, 521, 510);
100-
}
101-
102-
screen.render(xOffset, yOffset + 3, 31 + 31 * 32, waterColour,
103-
0x00, 1);
104-
screen.render(xOffset + 8, yOffset + 3, 31 + 31 * 32, waterColour,
105-
0x01, 1);
106-
}
107-
108-
if (isMuddy) {
109-
int waterColour = 0;
110-
yOffset += 4;
111-
112-
colour = Colours.get(-1, 111, -1, faceCol);
113-
114-
if (tickCount % 60 < 15) {
115-
waterColour = Colours.get(-1, -1, 422, -1);
116-
} else if (15 <= tickCount % 60 && tickCount % 60 < 30) {
117-
yOffset--;
118-
waterColour = Colours.get(-1, 410, 321, -1);
119-
} else if (30 <= tickCount % 60 && tickCount % 60 < 45) {
120-
waterColour = Colours.get(-1, 321, -1, 410);
121-
} else {
122-
yOffset--;
123-
waterColour = Colours.get(-1, -1, 410, 321);
78+
waterColour = Colours.get(-1, -1, swimColour[1], swimColour[2]);
12479
}
12580

12681
screen.render(xOffset, yOffset + 3, 31 + 31 * 32, waterColour,

src/com/redomar/game/entities/Player.java

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class Player extends Mob {
2020
private int tickCount = 0;
2121
private String userName;
2222
private boolean[] swimType;
23+
private int[] swimColour;
2324

2425
public static String guestPlayerName = customeName.setName("Player ");
2526

@@ -56,7 +57,8 @@ public void tick() {
5657
Packet02Move packet = new Packet02Move(this.getUsername(),
5758
this.getX(), this.getY(), this.numSteps, this.isMoving,
5859
this.movingDir);
59-
packet.writeData(Game.getGame().getSocketClient());
60+
Game.getGame();
61+
packet.writeData(Game.getSocketClient());
6062

6163
} else {
6264
isMoving = false;
@@ -97,70 +99,24 @@ public void render(Screen screen) {
9799
Game.setChangeLevel(true);
98100
}
99101

100-
if (isSwimming) {
102+
if(isSwimming || isMagma || isMuddy){
103+
swimColour = getSwim().waveCols(isSwimming, isMagma, isMuddy);
104+
101105
int waterColour = 0;
102106
yOffset += 4;
103107

104108
colour = Colours.get(-1, 111, -1, 310);
105109

106110
if (tickCount % 60 < 15) {
107-
waterColour = Colours.get(-1, -1, 255, -1);
111+
waterColour = Colours.get(-1, -1, swimColour[0], -1);
108112
} else if (15 <= tickCount % 60 && tickCount % 60 < 30) {
109113
yOffset--;
110-
waterColour = Colours.get(-1, 225, 115, -1);
114+
waterColour = Colours.get(-1, swimColour[1], swimColour[2], -1);
111115
} else if (30 <= tickCount % 60 && tickCount % 60 < 45) {
112-
waterColour = Colours.get(-1, 115, -1, 225);
116+
waterColour = Colours.get(-1, swimColour[2], -1, swimColour[1]);
113117
} else {
114118
yOffset--;
115-
waterColour = Colours.get(-1, -1, 225, 115);
116-
}
117-
118-
screen.render(xOffset, yOffset + 3, 31 + 31 * 32, waterColour,
119-
0x00, 1);
120-
screen.render(xOffset + 8, yOffset + 3, 31 + 31 * 32, waterColour,
121-
0x01, 1);
122-
}
123-
124-
if (isMagma) {
125-
int waterColour = 0;
126-
yOffset += 4;
127-
128-
colour = Colours.get(-1, 111, -1, 310);
129-
130-
if (tickCount % 60 < 15) {
131-
waterColour = Colours.get(-1, -1, 541, -1);
132-
} else if (15 <= tickCount % 60 && tickCount % 60 < 30) {
133-
yOffset--;
134-
waterColour = Colours.get(-1, 521, 510, -1);
135-
} else if (30 <= tickCount % 60 && tickCount % 60 < 45) {
136-
waterColour = Colours.get(-1, 510, -1, 521);
137-
} else {
138-
yOffset--;
139-
waterColour = Colours.get(-1, -1, 521, 510);
140-
}
141-
142-
screen.render(xOffset, yOffset + 3, 31 + 31 * 32, waterColour,
143-
0x00, 1);
144-
screen.render(xOffset + 8, yOffset + 3, 31 + 31 * 32, waterColour,
145-
0x01, 1);
146-
}
147-
148-
if (isMuddy) {
149-
int waterColour = 0;
150-
yOffset += 4;
151-
152-
colour = Colours.get(-1, 111, -1, 310);
153-
154-
if (tickCount % 60 < 15) {
155-
waterColour = Colours.get(-1, -1, 422, -1);
156-
} else if (15 <= tickCount % 60 && tickCount % 60 < 30) {
157-
yOffset--;
158-
waterColour = Colours.get(-1, 410, 321, -1);
159-
} else if (30 <= tickCount % 60 && tickCount % 60 < 45) {
160-
waterColour = Colours.get(-1, 321, -1, 410);
161-
} else {
162-
yOffset--;
163-
waterColour = Colours.get(-1, -1, 410, 321);
119+
waterColour = Colours.get(-1, -1, swimColour[1], swimColour[2]);
164120
}
165121

166122
screen.render(xOffset, yOffset + 3, 31 + 31 * 32, waterColour,

src/com/redomar/game/entities/efx/Swim.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,33 @@ public class Swim {
77
private static LevelHandler level;
88
private int x;
99
private int y;
10+
private int[] swimCols = new int[3];
1011

1112
public Swim(LevelHandler level, int x, int y) {
1213
Swim.level = level;
1314
this.x = x;
1415
this.y = y;
1516
}
17+
18+
public int[] waveCols(boolean isSwimming, boolean isMagma, boolean isMuddy){
19+
20+
if(isSwimming){
21+
swimCols[0] = 255;
22+
swimCols[1] = 255;
23+
swimCols[2] = 115;
24+
}
25+
if(isMagma){
26+
swimCols[0] = 541;
27+
swimCols[1] = 521;
28+
swimCols[2] = 510;
29+
}
30+
if(isMuddy){
31+
swimCols[0] = 422;
32+
swimCols[1] = 410;
33+
swimCols[2] = 321;
34+
}
35+
return swimCols;
36+
}
1637

1738
public boolean water(boolean isSwimming) {
1839
if (level.getTile(x >> 3, y >> 3).getId() == 4) {

src/com/redomar/game/level/LevelHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
import javax.imageio.ImageIO;
1111

12+
import com.redomar.game.Game;
1213
import com.redomar.game.entities.Entity;
1314
import com.redomar.game.entities.PlayerMP;
1415
import com.redomar.game.gfx.Screen;
1516
import com.redomar.game.level.tiles.Tile;
17+
import com.redomar.game.net.packets.Packet01Disconnect;
1618

1719
public class LevelHandler {
1820

@@ -164,6 +166,8 @@ public void removeEntity(String username) {
164166
index++;
165167
}
166168
this.getEntities().remove(index);
169+
Packet01Disconnect packet = new Packet01Disconnect(Game.getPlayer().getUsername());
170+
packet.writeData(Game.getSocketClient());
167171
}
168172

169173
private int getPlayerMPIndex(String username) {

0 commit comments

Comments
 (0)