Skip to content

Commit 7ce27d1

Browse files
committed
Merge remote-tracking branch 'origin/aside'
2 parents a404bf0 + de2414f commit 7ce27d1

File tree

10 files changed

+192
-75
lines changed

10 files changed

+192
-75
lines changed

res/jars/commons-lang3-3.1.jar

308 KB
Binary file not shown.

src/com/redomar/game/Game.java

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import javax.swing.JFrame;
1313
import javax.swing.JOptionPane;
1414

15+
import org.apache.commons.lang3.text.WordUtils;
16+
1517
import com.redomar.game.entities.Player;
1618
import com.redomar.game.entities.PlayerMP;
1719
import com.redomar.game.gfx.Screen;
@@ -28,35 +30,37 @@ public class Game extends Canvas implements Runnable {
2830
private static final long serialVersionUID = 1L;
2931

3032
// Setting the size and name of the frame/canvas
31-
public static final int WIDTH = 160;
32-
public static final int HEIGHT = (WIDTH / 3 * 2);
33-
public static final int SCALE = 3;
34-
public static final String NAME = "Game";
35-
public static Game game;
33+
private static final int WIDTH = 160;
34+
private static final int HEIGHT = (WIDTH / 3 * 2);
35+
private static final int SCALE = 3;
36+
private static final String NAME = "Game";
37+
private static Game game;
3638
private static int Jdata_Host;
3739
private static String Jdata_UserName = "";
3840
private static String Jdata_IP = "127.0.0.1";
3941

4042
private JFrame frame;
4143

42-
public boolean running = false;
43-
public int tickCount = 0;
44+
private boolean running = false;
45+
private int tickCount = 0;
4446

4547
private BufferedImage image = new BufferedImage(WIDTH, HEIGHT,
4648
BufferedImage.TYPE_INT_RGB);
4749
private int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer())
4850
.getData();
4951
private int[] colours = new int[6 * 6 * 6];
5052

53+
private BufferedImage image2 = new BufferedImage(WIDTH, HEIGHT - 30, BufferedImage.TYPE_INT_RGB);
5154
private Screen screen;
5255
private InputHandler input;
5356
private WindowHandler window;
5457
private LevelHandler level;
5558
private Player player;
5659
private Music music = new Music();
57-
public Thread musicThread = new Thread(music);
60+
private Thread musicThread = new Thread(music);
61+
private String nowPlaying = "Playing Music";
5862

59-
public boolean notActive = true;
63+
private boolean notActive = true;
6064

6165
private GameClient socketClient;
6266
private GameServer socketServer;
@@ -78,7 +82,7 @@ public Game() {
7882
}
7983

8084
public void init() {
81-
game = this;
85+
setGame(this);
8286
int index = 0;
8387
for (int r = 0; r < 6; r++) {
8488
for (int g = 0; g < 6; g++) {
@@ -174,7 +178,7 @@ public void run() {
174178
}
175179

176180
public void tick() {
177-
tickCount++;
181+
setTickCount(getTickCount() + 1);
178182
getLevel().tick();
179183
}
180184

@@ -185,8 +189,8 @@ public void render() {
185189
return;
186190
}
187191

188-
int xOffset = getPlayer().x - (screen.width / 2);
189-
int yOffset = getPlayer().y - (screen.height / 2);
192+
int xOffset = getPlayer().x - (screen.getWidth() / 2);
193+
int yOffset = getPlayer().y - (screen.getHeight() / 2);
190194

191195
getLevel().renderTiles(screen, xOffset, yOffset);
192196

@@ -199,9 +203,9 @@ public void render() {
199203

200204
getLevel().renderEntities(screen);
201205

202-
for (int y = 0; y < screen.height; y++) {
203-
for (int x = 0; x < screen.width; x++) {
204-
int colourCode = screen.pixels[x + y * screen.width];
206+
for (int y = 0; y < screen.getHeight(); y++) {
207+
for (int x = 0; x < screen.getWidth(); x++) {
208+
int colourCode = screen.getPixels()[x + y * screen.getWidth()];
205209
if (colourCode < 255) {
206210
pixels[x + y * WIDTH] = colours[colourCode];
207211
}
@@ -212,18 +216,27 @@ public void render() {
212216
int musicOption = JOptionPane.showConfirmDialog(this, "You are about to turn on music and can be VERY loud", "Music Options", 2, 2);
213217
if (musicOption == 0){
214218
musicThread.start();
215-
notActive = false;
219+
notActive = false;
216220
} else {
217221
System.out.println("Canceled");
218222
input.PlayMusic = false;
219223
}
220224
}
221225

222-
223226
Graphics g = bs.getDrawGraphics();
224227

225228
g.drawRect(0, 0, getWidth(), getHeight());
226-
g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
229+
g.drawImage(image, 0, 0, getWidth(), getHeight()-30, null);
230+
// Font.render("Hi", screen, 0, 0, Colours.get(-1, -1, -1, 555), 1);
231+
g.drawImage(image2, 0, getHeight()-30, getWidth(), getHeight(), null);
232+
g.setColor(Color.WHITE);
233+
g.drawString("Welcome "+WordUtils.capitalizeFully(player.getUsername()), 0, getHeight()-19);
234+
if (notActive == true){
235+
g.drawString("MUSIC is OFF | press 'M' to start", 0, getHeight()-8);
236+
} else{
237+
g.drawString("MUSIC is ON | You cannot turn off the music", 0, getHeight()-8);
238+
g.drawString(nowPlaying, (getWidth() - nowPlaying.length()) - (120 + nowPlaying.length()), getHeight() - 20 );
239+
}
227240
g.dispose();
228241
bs.show();
229242
}
@@ -251,15 +264,15 @@ public static void main(String[] args) {
251264
Thread.sleep(750);
252265
splash.setProgress(92, "Aquring data: Multiplayer");
253266
Thread.sleep(200);
254-
Jdata_Host = JOptionPane.showConfirmDialog(game, "Do you want to be the HOST?");
267+
Jdata_Host = JOptionPane.showConfirmDialog(getGame(), "Do you want to be the HOST?");
255268
if (Jdata_Host == 1){
256-
Jdata_IP = JOptionPane.showInputDialog(game, "Enter the name \nleave blank for local");
269+
Jdata_IP = JOptionPane.showInputDialog(getGame(), "Enter the name \nleave blank for local");
257270
}
258271
Thread.sleep(200);
259272
splash.setProgress(95, "Aquring data: Username");
260273
Thread.sleep(200);
261274
splash.setProgress(96, "Initalizing as Server:Host");
262-
Jdata_UserName = JOptionPane.showInputDialog(game, "Enter a name");
275+
Jdata_UserName = JOptionPane.showInputDialog(getGame(), "Enter a name");
263276
splash.setProgress(97, "Connecting as" + Jdata_UserName);
264277
Thread.sleep(500);
265278
splash.splashOff();
@@ -310,4 +323,28 @@ public void setWindow(WindowHandler window) {
310323
this.window = window;
311324
}
312325

326+
public String getNowPlaying() {
327+
return nowPlaying;
328+
}
329+
330+
public void setNowPlaying(String nowPlaying) {
331+
this.nowPlaying = nowPlaying;
332+
}
333+
334+
public int getTickCount() {
335+
return tickCount;
336+
}
337+
338+
public void setTickCount(int tickCount) {
339+
this.tickCount = tickCount;
340+
}
341+
342+
public static Game getGame() {
343+
return game;
344+
}
345+
346+
public static void setGame(Game game) {
347+
Game.game = game;
348+
}
349+
313350
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void tick() {
4646
isMoving = true;
4747

4848
Packet02Move packet = new Packet02Move(this.getUsername(), this.x, this.y, this.numSteps, this.isMoving, this.movingDir);
49-
packet.writeData(Game.game.getSocketClient());
49+
packet.writeData(Game.getGame().getSocketClient());
5050

5151
} else {
5252
isMoving = false;

src/com/redomar/game/gfx/Screen.java

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22

33
public class Screen {
44

5-
public static final int MAP_WIDTH = 64;
6-
public static final int MAP_WIDTH_MASK = MAP_WIDTH - 1;
5+
private static final int MAP_WIDTH = 64;
6+
private static final int MAP_WIDTH_MASK = MAP_WIDTH - 1;
77

8-
public static final byte BIT_MIRROR_X = 0x01;
9-
public static final byte BIT_MIRROR_Y = 0x02;
8+
private static final byte BIT_MIRROR_X = 0x01;
9+
private static final byte BIT_MIRROR_Y = 0x02;
1010

11-
public int[] pixels;
11+
private int[] pixels;
1212

13-
public int xOffset = 0;
14-
public int yOffset = 0;
13+
private int xOffset = 0;
14+
private int yOffset = 0;
1515

16-
public int width;
17-
public int height;
16+
private int width;
17+
private int height;
1818

19-
public SpriteSheet sheet;
19+
private SpriteSheet sheet;
2020

2121
public Screen(int width, int height, SpriteSheet sheet) {
2222

23-
this.width = width;
24-
this.height = height;
23+
this.setWidth(width);
24+
this.setHeight(height);
2525
this.sheet = sheet;
2626

27-
pixels = new int[width * height];
27+
setPixels(new int[width * height]);
2828
}
2929

3030
public void render(int xPos, int yPos, int tile, int colour, int mirrorDir,
@@ -38,7 +38,7 @@ public void render(int xPos, int yPos, int tile, int colour, int mirrorDir,
3838
int scaleMap = scale - 1;
3939
int xTile = tile % 32;
4040
int yTile = tile / 32;
41-
int tileOffset = (xTile << 3) + (yTile << 3) * sheet.width;
41+
int tileOffset = (xTile << 3) + (yTile << 3) * sheet.getWidth();
4242

4343
for (int y = 0; y < 8; y++) {
4444
int ySheet = y;
@@ -59,23 +59,23 @@ public void render(int xPos, int yPos, int tile, int colour, int mirrorDir,
5959
int xPixel = x + xPos + (x * scaleMap) - ((scaleMap << 3) / 2);
6060

6161
int col = (colour >> (sheet.pixels[xSheet + ySheet
62-
* sheet.width + tileOffset] * 8)) & 255;
62+
* sheet.getWidth() + tileOffset] * 8)) & 255;
6363
if (col < 255) {
6464

6565
for (int yScale = 0; yScale < scale; yScale++) {
6666

67-
if (yPixel + yScale < 0 | yPixel + yScale >= height) {
67+
if (yPixel + yScale < 0 | yPixel + yScale >= getHeight()) {
6868
continue;
6969
}
7070

7171
for (int xScale = 0; xScale < scale; xScale++) {
7272

73-
if (xPixel + xScale < 0 | xPixel + xScale >= width) {
73+
if (xPixel + xScale < 0 | xPixel + xScale >= getWidth()) {
7474
continue;
7575
}
7676

77-
pixels[(xPixel + xScale) + (yPixel + yScale)
78-
* width] = col;
77+
getPixels()[(xPixel + xScale) + (yPixel + yScale)
78+
* getWidth()] = col;
7979
}
8080
}
8181

@@ -89,4 +89,32 @@ public void setOffset(int xOffset, int yOffset) {
8989
this.xOffset = xOffset;
9090
this.yOffset = yOffset;
9191
}
92+
93+
public static int getMapWidthMask() {
94+
return MAP_WIDTH_MASK;
95+
}
96+
97+
public int getWidth() {
98+
return width;
99+
}
100+
101+
public void setWidth(int width) {
102+
this.width = width;
103+
}
104+
105+
public int[] getPixels() {
106+
return pixels;
107+
}
108+
109+
public void setPixels(int[] pixels) {
110+
this.pixels = pixels;
111+
}
112+
113+
public int getHeight() {
114+
return height;
115+
}
116+
117+
public void setHeight(int height) {
118+
this.height = height;
119+
}
92120
}

src/com/redomar/game/gfx/SpriteSheet.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
public class SpriteSheet {
99

10-
public String path;
11-
public int width;
12-
public int height;
10+
private String path;
11+
private int width;
12+
private int height;
1313

1414
public int[] pixels;
1515

@@ -26,11 +26,11 @@ public SpriteSheet(String path) {
2626
return;
2727
}
2828

29-
this.path = path;
30-
this.width = image.getWidth();
29+
this.setPath(path);
30+
this.setWidth(image.getWidth());
3131
this.height = image.getHeight();
3232

33-
pixels = image.getRGB(0, 0, width, height, null, 0, width);
33+
pixels = image.getRGB(0, 0, getWidth(), height, null, 0, getWidth());
3434

3535
for (int i = 0; i < pixels.length; i++) {
3636
pixels[i] = (pixels[i] & 0xff) / 64; // removes alpha (transparency)
@@ -40,4 +40,20 @@ public SpriteSheet(String path) {
4040
// System.out.println(pixels[i]);
4141
}
4242
}
43+
44+
public String getPath() {
45+
return path;
46+
}
47+
48+
public void setPath(String path) {
49+
this.path = path;
50+
}
51+
52+
public int getWidth() {
53+
return width;
54+
}
55+
56+
public void setWidth(int width) {
57+
this.width = width;
58+
}
4359
}

0 commit comments

Comments
 (0)