Skip to content

Commit 2c8a5fd

Browse files
committed
Updated code structure
formatted the code structure to get align code and to get rid of extra empty lines
1 parent 4f043ce commit 2c8a5fd

File tree

18 files changed

+318
-275
lines changed

18 files changed

+318
-275
lines changed

src/com/redomar/game/Game.java

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@
2929
import com.redomar.game.net.packets.Packet00Login;
3030
import com.redomar.game.script.Printing;
3131

32-
3332
public class Game extends Canvas implements Runnable {
34-
33+
3534
// Setting the size and name of the frame/canvas
3635
private static final long serialVersionUID = 1L;
3736
private static final String game_Version = "v1.6.1 Alpha";
@@ -59,7 +58,8 @@ public class Game extends Canvas implements Runnable {
5958
.getData();
6059
private int[] colours = new int[6 * 6 * 6];
6160

62-
private BufferedImage image2 = new BufferedImage(WIDTH, HEIGHT - 30, BufferedImage.TYPE_INT_RGB);
61+
private BufferedImage image2 = new BufferedImage(WIDTH, HEIGHT - 30,
62+
BufferedImage.TYPE_INT_RGB);
6363
private Screen screen;
6464
private InputHandler input;
6565
private WindowHandler window;
@@ -76,8 +76,7 @@ public class Game extends Canvas implements Runnable {
7676
private GameClient socketClient;
7777
private GameServer socketServer;
7878
private Printing print = new Printing();
79-
80-
79+
8180
public Game() {
8281
setMinimumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
8382
setMaximumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
@@ -113,7 +112,8 @@ public void init() {
113112
setWindow(new WindowHandler(this));
114113
setMap("/levels/custom_level.png");
115114
setMap(1);
116-
Packet00Login loginPacket = new Packet00Login(player.getUsername(), player.getX(), player.getY());
115+
Packet00Login loginPacket = new Packet00Login(player.getUsername(),
116+
player.getX(), player.getY());
117117

118118
if (socketServer != null) {
119119
socketServer.addConnection((PlayerMP) getPlayer(), loginPacket);
@@ -129,24 +129,24 @@ public void setMap(String Map_str) {
129129
getJdata_UserName(), null, -1));
130130
level.addEntity(player);
131131
}
132-
133-
public static void npcSpawn(){
134-
if(isNpc() == true){
132+
133+
public static void npcSpawn() {
134+
if (isNpc() == true) {
135135
game.setDummy(new Dummy(Game.getLevel(), "h", 215, 215, 500, 543));
136136
game.level.addEntity(Game.getDummy());
137137
}
138138
}
139-
140-
public static void npcKill(){
141-
if(isNpc() == false){
139+
140+
public static void npcKill() {
141+
if (isNpc() == false) {
142142
game.level.removeEntity(Game.getDummy());
143143
}
144144
}
145145

146146
public synchronized void start() {
147147
running = true;
148148
new Thread(this, "GAME").start();
149-
149+
150150
if (getJdata_Host() == 0) {
151151
socketServer = new GameServer(this);
152152
socketServer.start();
@@ -240,67 +240,80 @@ public void render() {
240240
}
241241
}
242242
}
243-
244-
if (noAudioDevice == false){
245-
if (input.isPlayMusic() == true && notActive == true){
246-
int musicOption = JOptionPane.showConfirmDialog(this, "You are about to turn on music and can be VERY loud", "Music Options", 2, 2);
247-
if (musicOption == 0){
243+
244+
if (noAudioDevice == false) {
245+
if (input.isPlayMusic() == true && notActive == true) {
246+
int musicOption = JOptionPane.showConfirmDialog(this,
247+
"You are about to turn on music and can be VERY loud",
248+
"Music Options", 2, 2);
249+
if (musicOption == 0) {
248250
musicThread.start();
249251
notActive = false;
250252
} else {
251-
//System.out.println("[GAME] Canceled music option");
253+
// System.out.println("[GAME] Canceled music option");
252254
print.print(" Canceled music option", 1);
253255
input.setPlayMusic(false);
254256
}
255-
}
257+
}
256258
}
257-
258-
if (isChangeLevel() == true && getTickCount() % 60 == 0){
259+
260+
if (isChangeLevel() == true && getTickCount() % 60 == 0) {
259261
Game.setChangeLevel(true);
260262
setChangeLevel(false);
261263
}
262-
263-
if (changeLevel == true){
264-
if(getMap() == 1){
265-
setMap("/levels/water_level.png");
264+
265+
if (changeLevel == true) {
266+
if (getMap() == 1) {
267+
setMap("/levels/water_level.png");
266268
setMap(2);
267-
}else if(getMap() == 2){
269+
} else if (getMap() == 2) {
268270
setMap("/levels/custom_level.png");
269271
setMap(1);
270272
}
271273
changeLevel = false;
272274
}
273-
275+
274276
Graphics g = bs.getDrawGraphics();
275277
g.drawRect(0, 0, getWidth(), getHeight());
276-
g.drawImage(image, 0, 0, getWidth(), getHeight()-30, null);
277-
// Font.render("Hi", screen, 0, 0, Colours.get(-1, -1, -1, 555), 1);
278-
g.drawImage(image2, 0, getHeight()-30, getWidth(), getHeight(), null);
278+
g.drawImage(image, 0, 0, getWidth(), getHeight() - 30, null);
279+
// Font.render("Hi", screen, 0, 0, Colours.get(-1, -1, -1, 555), 1);
280+
g.drawImage(image2, 0, getHeight() - 30, getWidth(), getHeight(), null);
279281
g.setColor(Color.WHITE);
280282
g.setFont(font.getSegoe());
281-
g.drawString("Welcome "+WordUtils.capitalizeFully(player.getSantizedUsername()), 3, getHeight()-17);
283+
g.drawString(
284+
"Welcome "
285+
+ WordUtils.capitalizeFully(player
286+
.getSantizedUsername()), 3, getHeight() - 17);
282287
g.setColor(Color.YELLOW);
283-
g.drawString(time.getTime(), (getWidth() - 58), (getHeight()-3));
288+
g.drawString(time.getTime(), (getWidth() - 58), (getHeight() - 3));
284289
g.setColor(Color.WHITE);
285-
if(noAudioDevice == true){
290+
if (noAudioDevice == true) {
286291
g.setColor(Color.RED);
287-
g.drawString("MUSIC is OFF | no audio device for playback", 3, getHeight()-3);
292+
g.drawString("MUSIC is OFF | no audio device for playback", 3,
293+
getHeight() - 3);
288294
trigger++;
289-
if(trigger == 25){
290-
JOptionPane.showMessageDialog(this, "No Audio device found", "Audio Issue", 0);
295+
if (trigger == 25) {
296+
JOptionPane.showMessageDialog(this, "No Audio device found",
297+
"Audio Issue", 0);
291298
}
292-
} else if (notActive == true){
299+
} else if (notActive == true) {
293300
g.setColor(Color.RED);
294-
g.drawString("MUSIC is OFF | press 'M' to start", 3, getHeight()-3);
295-
} else{
301+
g.drawString("MUSIC is OFF | press 'M' to start", 3,
302+
getHeight() - 3);
303+
} else {
296304
g.setColor(Color.GREEN);
297-
g.drawString("MUSIC is ON | You cannot turn off the music", 3, getHeight()-3);
305+
g.drawString("MUSIC is ON | You cannot turn off the music", 3,
306+
getHeight() - 3);
298307
g.setColor(Color.WHITE);
299-
setNowPlaying(WordUtils.capitalize(music.getSongName()[music.getSongNumber()].substring(7, (music.getSongName()[music.getSongNumber()].length() - 4))));
300-
if (getNowPlaying().startsWith("T")){
301-
g.drawString(nowPlaying, getWidth() - (nowPlaying.length() * 9) + 12, getHeight() - 17);
308+
setNowPlaying(WordUtils.capitalize(music.getSongName()[music
309+
.getSongNumber()].substring(7,
310+
(music.getSongName()[music.getSongNumber()].length() - 4))));
311+
if (getNowPlaying().startsWith("T")) {
312+
g.drawString(nowPlaying, getWidth() - (nowPlaying.length() * 9)
313+
+ 12, getHeight() - 17);
302314
} else {
303-
g.drawString(nowPlaying, getWidth() - (nowPlaying.length() * 9) + 8, getHeight() - 17);
315+
g.drawString(nowPlaying, getWidth() - (nowPlaying.length() * 9)
316+
+ 8, getHeight() - 17);
304317
}
305318
}
306319
g.dispose();

src/com/redomar/game/InputHandler.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,32 +61,32 @@ public void toggleKey(int keyCode, boolean isPressed) {
6161
if (keyCode == KeyEvent.VK_D || keyCode == KeyEvent.VK_RIGHT) {
6262
getRight().toggle(isPressed);
6363
}
64-
if (keyCode == KeyEvent.VK_M){
64+
if (keyCode == KeyEvent.VK_M) {
6565
this.setPlayMusic(true);
6666
}
67-
if (keyCode == KeyEvent.VK_Z){
68-
// if (map == 0){
69-
// Game.getGame().setMap("/levels/water_level.png");
70-
// map++;
71-
// } else{
72-
// Game.getGame().setMap("/levels/custom_level.png");
73-
// map--;
74-
// }
75-
if(Game.getMap() == 2){
67+
if (keyCode == KeyEvent.VK_Z) {
68+
// if (map == 0){
69+
// Game.getGame().setMap("/levels/water_level.png");
70+
// map++;
71+
// } else{
72+
// Game.getGame().setMap("/levels/custom_level.png");
73+
// map--;
74+
// }
75+
if (Game.getMap() == 2) {
7676
Game.setChangeLevel(true);
7777
Game.getLevel().removeEntity(Game.getDummy());
7878
Game.setNpc(false);
7979
}
8080
}
81-
if (keyCode == KeyEvent.VK_N){
82-
if(Game.isNpc() == false){
81+
if (keyCode == KeyEvent.VK_N) {
82+
if (Game.isNpc() == false) {
8383
Game.setNpc(true);
8484
Game.npcSpawn();
8585
System.out.println("[GAME] Dummy has been spawned");
8686
}
8787
}
88-
if (keyCode == KeyEvent.VK_K){
89-
if(Game.isNpc() == true){
88+
if (keyCode == KeyEvent.VK_K) {
89+
if (Game.isNpc() == true) {
9090
Game.setNpc(false);
9191
Game.npcKill();
9292
System.out.println("[GAME] Dummy has been despawned");

src/com/redomar/game/WindowHandler.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,50 @@
55

66
import com.redomar.game.net.packets.Packet01Disconnect;
77

8-
public class WindowHandler implements WindowListener{
8+
public class WindowHandler implements WindowListener {
99

1010
private final Game game;
11-
12-
public WindowHandler(Game game){
11+
12+
public WindowHandler(Game game) {
1313
this.game = game;
1414
this.game.getFrame().addWindowListener(this);
1515
}
16-
16+
1717
@Override
1818
public void windowActivated(WindowEvent event) {
19-
19+
2020
}
2121

2222
@Override
2323
public void windowClosed(WindowEvent event) {
24-
24+
2525
}
2626

2727
@Override
2828
public void windowClosing(WindowEvent event) {
29-
Packet01Disconnect packet = new Packet01Disconnect(Game.getPlayer().getUsername());
29+
Packet01Disconnect packet = new Packet01Disconnect(Game.getPlayer()
30+
.getUsername());
3031
packet.writeData(this.game.getSocketClient());
3132
}
3233

3334
@Override
3435
public void windowDeactivated(WindowEvent event) {
35-
36+
3637
}
3738

3839
@Override
3940
public void windowDeiconified(WindowEvent event) {
40-
41+
4142
}
4243

4344
@Override
4445
public void windowIconified(WindowEvent event) {
45-
46+
4647
}
4748

4849
@Override
4950
public void windowOpened(WindowEvent event) {
50-
51+
5152
}
5253

5354
}

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,46 @@
55
import com.redomar.game.gfx.Screen;
66
import com.redomar.game.level.LevelHandler;
77

8-
public class Dummy extends Mob{
9-
10-
private int colour, shirtCol, faceCol; //= Colours.get(-1, 111, 240, 310);
8+
public class Dummy extends Mob {
9+
10+
private int colour, shirtCol, faceCol; // = Colours.get(-1, 111, 240, 310);
1111
private int tickCount = 0;
1212
private int xa = 0;
1313
private int ya = 0;
14-
15-
public Dummy(LevelHandler level, String name, int x, int y, int shirtCol, int faceCol) {
14+
15+
public Dummy(LevelHandler level, String name, int x, int y, int shirtCol,
16+
int faceCol) {
1617
super(level, "h", x, y, 1);
1718
this.faceCol = faceCol;
1819
this.shirtCol = shirtCol;
1920
this.colour = Colours.get(-1, 111, shirtCol, faceCol);
2021
}
21-
22+
2223
public void tick() {
23-
24-
followMovementAI(getX(), getY(), Game.getPlayer().getX(), Game.getPlayer().getY(), xa, ya, this);
24+
25+
followMovementAI(getX(), getY(), Game.getPlayer().getX(), Game
26+
.getPlayer().getY(), xa, ya, this);
2527

2628
if (level.getTile(this.getX() >> 3, this.getY() >> 3).getId() == 4) {
2729
isSwimming = true;
2830
}
2931

30-
if (isSwimming && level.getTile(this.getX() >> 3, this.getY() >> 3).getId() != 4) {
32+
if (isSwimming
33+
&& level.getTile(this.getX() >> 3, this.getY() >> 3).getId() != 4) {
3134
isSwimming = false;
3235
}
3336

3437
if (level.getTile(this.getX() >> 3, this.getY() >> 3).getId() == 12) {
3538
isMagma = true;
3639
}
37-
38-
if (isMagma && level.getTile(this.getX() >> 3, this.getY() >> 3).getId() != 12){
40+
41+
if (isMagma
42+
&& level.getTile(this.getX() >> 3, this.getY() >> 3).getId() != 12) {
3943
isMagma = false;
4044
}
4145

4246
tickCount++;
43-
47+
4448
}
4549

4650
public void render(Screen screen) {
@@ -84,7 +88,7 @@ public void render(Screen screen) {
8488
screen.render(xOffset + 8, yOffset + 3, 31 + 31 * 32, waterColour,
8589
0x01, 1);
8690
}
87-
91+
8892
if (isMagma) {
8993
int waterColour = 0;
9094
yOffset += 4;
@@ -102,7 +106,7 @@ public void render(Screen screen) {
102106
yOffset--;
103107
waterColour = Colours.get(-1, -1, 521, 510);
104108
}
105-
109+
106110
screen.render(xOffset, yOffset + 3, 31 + 31 * 32, waterColour,
107111
0x00, 1);
108112
screen.render(xOffset + 8, yOffset + 3, 31 + 31 * 32, waterColour,

0 commit comments

Comments
 (0)