Skip to content

Commit 250b5f6

Browse files
committed
Edited code positionings
1 parent a4d843d commit 250b5f6

File tree

16 files changed

+165
-128
lines changed

16 files changed

+165
-128
lines changed

src/com/redomar/game/Game.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,17 @@ public void init() {
8181
screen = new Screen(WIDTH, HEIGHT, new SpriteSheet("/sprite_sheet.png"));
8282
input = new InputHandler(this);
8383
level = new LevelHandler("/levels/water_level.png");
84-
84+
8585
player = new PlayerMP(level, 100, 100, input,
8686
JOptionPane.showInputDialog(this, "Enter a name"), null, -1);
87-
88-
level.addEntity(player);
87+
88+
level.addEntity(player);
8989
Packet00Login loginPacket = new Packet00Login(player.getUsername());
90-
90+
9191
if (socketServer != null) {
9292
socketServer.addConnection((PlayerMP) player, loginPacket);
9393
}
94-
94+
9595
// socketClient.sendData("ping".getBytes());
9696
loginPacket.writeData(socketClient);
9797
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ public void move(int xa, int ya) {
5050
public abstract boolean hasCollided(int xa, int ya);
5151

5252
protected boolean isSolid(int xa, int ya, int x, int y) {
53-
54-
if(level == null){
53+
54+
if (level == null) {
5555
return false;
5656
}
57-
57+
5858
Tile lastTile = level.getTile((this.x + x) >> 3, (this.y + y) >> 3);
59-
Tile newtTile = level.getTile((this.x + x + xa) >> 3, (this.y + y + ya) >> 3);
60-
61-
if(!lastTile.equals(newtTile) && newtTile.isSolid()){
59+
Tile newtTile = level.getTile((this.x + x + xa) >> 3,
60+
(this.y + y + ya) >> 3);
61+
62+
if (!lastTile.equals(newtTile) && newtTile.isSolid()) {
6263
return true;
6364
}
6465

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

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public class Player extends Mob {
1313
private int tickCount = 0;
1414
private String userName;
1515

16-
public Player(LevelHandler level, int x, int y, InputHandler input, String userName) {
16+
public Player(LevelHandler level, int x, int y, InputHandler input,
17+
String userName) {
1718
super(level, "Player", x, y, 1);
1819
this.input = input;
1920
this.userName = userName;
@@ -23,7 +24,7 @@ public void tick() {
2324
int xa = 0;
2425
int ya = 0;
2526

26-
if(input != null){
27+
if (input != null) {
2728
if (input.up.isPressed()) {
2829
ya--;
2930
}
@@ -44,15 +45,15 @@ public void tick() {
4445
} else {
4546
isMoving = false;
4647
}
47-
48+
4849
if (level.getTile(this.x >> 3, this.y >> 3).getId() == 4) {
4950
isSwimming = true;
5051
}
5152

5253
if (isSwimming && level.getTile(this.x >> 3, this.y >> 3).getId() != 4) {
5354
isSwimming = false;
5455
}
55-
56+
5657
tickCount++;
5758
}
5859

@@ -73,13 +74,13 @@ public void render(Screen screen) {
7374
int modifier = 8 * scale;
7475
int xOffset = x - modifier / 2;
7576
int yOffset = y - modifier / 2 - 4;
76-
77-
if(isSwimming){
77+
78+
if (isSwimming) {
7879
int waterColour = 0;
7980
yOffset += 4;
80-
81+
8182
colour = Colours.get(-1, 111, -1, 310);
82-
83+
8384
if (tickCount % 60 < 15) {
8485
waterColour = Colours.get(-1, -1, 255, -1);
8586
} else if (15 <= tickCount % 60 && tickCount % 60 < 30) {
@@ -91,21 +92,32 @@ public void render(Screen screen) {
9192
yOffset--;
9293
waterColour = Colours.get(-1, -1, 225, 115);
9394
}
94-
95-
screen.render(xOffset, yOffset + 3, 31 + 31 * 32, waterColour, 0x00, 1);
96-
screen.render(xOffset + 8, yOffset + 3, 31 + 31 * 32, waterColour, 0x01, 1);
95+
96+
screen.render(xOffset, yOffset + 3, 31 + 31 * 32, waterColour,
97+
0x00, 1);
98+
screen.render(xOffset + 8, yOffset + 3, 31 + 31 * 32, waterColour,
99+
0x01, 1);
97100
}
98101

99-
screen.render((xOffset + (modifier * flipTop)), yOffset, (xTile + yTile * 32), colour, flipTop, scale);
100-
screen.render((xOffset + modifier - (modifier * flipTop)), yOffset, ((xTile + 1) + yTile * 32), colour, flipTop, scale);
101-
if(!isSwimming){
102-
screen.render((xOffset + (modifier * flipBottom)), (yOffset + modifier), (xTile + (yTile + 1) * 32), colour, flipBottom, scale);
103-
screen.render((xOffset + modifier - (modifier * flipBottom)), (yOffset + modifier), ((xTile + 1) + (yTile + 1) * 32), colour, flipBottom, scale);
104-
colour = Colours.get(-1, 111, 240, 310);;
102+
screen.render((xOffset + (modifier * flipTop)), yOffset,
103+
(xTile + yTile * 32), colour, flipTop, scale);
104+
screen.render((xOffset + modifier - (modifier * flipTop)), yOffset,
105+
((xTile + 1) + yTile * 32), colour, flipTop, scale);
106+
if (!isSwimming) {
107+
screen.render((xOffset + (modifier * flipBottom)),
108+
(yOffset + modifier), (xTile + (yTile + 1) * 32), colour,
109+
flipBottom, scale);
110+
screen.render((xOffset + modifier - (modifier * flipBottom)),
111+
(yOffset + modifier), ((xTile + 1) + (yTile + 1) * 32),
112+
colour, flipBottom, scale);
113+
colour = Colours.get(-1, 111, 240, 310);
114+
;
105115
}
106-
107-
if(userName != null){
108-
Font.render(userName, screen, xOffset - ((userName.length() - 1) / 2 * 8), yOffset - 10, Colours.get(-1, -1, -1, 555), 1);
116+
117+
if (userName != null) {
118+
Font.render(userName, screen, xOffset
119+
- ((userName.length() - 1) / 2 * 8), yOffset - 10,
120+
Colours.get(-1, -1, -1, 555), 1);
109121
}
110122
}
111123

@@ -141,8 +153,8 @@ public boolean hasCollided(int xa, int ya) {
141153

142154
return false;
143155
}
144-
145-
public String getUsername(){
156+
157+
public String getUsername() {
146158
return this.userName;
147159
}
148160

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,27 @@
55
import com.redomar.game.InputHandler;
66
import com.redomar.game.level.LevelHandler;
77

8-
public class PlayerMP extends Player{
9-
8+
public class PlayerMP extends Player {
9+
1010
public InetAddress ipAddess;
1111
public int port;
1212

13-
public PlayerMP(LevelHandler level, int x, int y, InputHandler input, String userName, InetAddress ipAddress, int port) {
13+
public PlayerMP(LevelHandler level, int x, int y, InputHandler input,
14+
String userName, InetAddress ipAddress, int port) {
1415
super(level, x, y, input, userName);
1516
this.ipAddess = ipAddress;
1617
this.port = port;
1718
}
18-
19-
public PlayerMP(LevelHandler level, int x, int y, String userName, InetAddress ipAddress, int port) {
19+
20+
public PlayerMP(LevelHandler level, int x, int y, String userName,
21+
InetAddress ipAddress, int port) {
2022
super(level, x, y, null, userName);
2123
this.ipAddess = ipAddress;
2224
this.port = port;
2325
}
24-
26+
2527
@Override
26-
public void tick(){
28+
public void tick() {
2729
super.tick();
2830
}
2931

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ public void render(int xPos, int yPos, int tile, int colour, int mirrorDir,
7373
if (xPixel + xScale < 0 | xPixel + xScale >= width) {
7474
continue;
7575
}
76-
77-
pixels[(xPixel + xScale) + (yPixel + yScale) * width] = col;
76+
77+
pixels[(xPixel + xScale) + (yPixel + yScale)
78+
* width] = col;
7879
}
7980
}
8081

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public SpriteSheet(String path) {
3737
}
3838

3939
for (int i = 0; i < 8; i++) {
40-
//System.out.println(pixels[i]);
40+
// System.out.println(pixels[i]);
4141
}
4242
}
4343
}

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,34 @@ private void loadLevelFromFile() {
4848
}
4949

5050
private void loadTiles() {
51-
int[] tileColours = this.image.getRGB(0, 0, width, height, null, 0, width);
51+
int[] tileColours = this.image.getRGB(0, 0, width, height, null, 0,
52+
width);
5253
for (int y = 0; y < height; y++) {
5354
for (int x = 0; x < width; x++) {
5455
tileCheck: for (Tile t : Tile.tiles) {
55-
if(t != null && t.getLevelColour() == tileColours[x+y*width]){
56-
this.tiles[x+y*width] = t.getId();
56+
if (t != null
57+
&& t.getLevelColour() == tileColours[x + y * width]) {
58+
this.tiles[x + y * width] = t.getId();
5759
break tileCheck;
5860
}
5961
}
6062
}
6163
}
6264
}
63-
65+
6466
@SuppressWarnings("unused")
65-
private void saveLevelToFile(){
67+
private void saveLevelToFile() {
6668
try {
67-
ImageIO.write(image, "png", new File(Level.class.getResource(this.imagePath).getFile()));
69+
ImageIO.write(image, "png",
70+
new File(Level.class.getResource(this.imagePath).getFile()));
6871
} catch (IOException e) {
6972
e.printStackTrace();
7073
}
7174
}
72-
75+
7376
@SuppressWarnings("unused")
74-
private void alterTile(int x, int y, Tile newTile){
75-
this.tiles[x+y*width] = newTile.getId();
77+
private void alterTile(int x, int y, Tile newTile) {
78+
this.tiles[x + y * width] = newTile.getId();
7679
image.setRGB(x, y, newTile.getLevelColour());
7780
}
7881

src/com/redomar/game/level/tiles/AnimatedTile.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@ public class AnimatedTile extends BasicTile {
77
private long lastIterationTime;
88
private int animationSwitchDelay;
99

10-
public AnimatedTile(int id, int[][] animationCoords, int tileColour, int levelColour, int animationSwitchDelay) {
11-
super(id, animationCoords[0][0], animationCoords[0][1], tileColour, levelColour);
12-
this.animationTileCoords = animationCoords;
13-
this.currentAnimationIndex = 0;
14-
this.lastIterationTime = System.currentTimeMillis();
15-
this.animationSwitchDelay = animationSwitchDelay;
16-
}
10+
public AnimatedTile(int id, int[][] animationCoords, int tileColour,
11+
int levelColour, int animationSwitchDelay) {
12+
super(id, animationCoords[0][0], animationCoords[0][1], tileColour,
13+
levelColour);
14+
this.animationTileCoords = animationCoords;
15+
this.currentAnimationIndex = 0;
16+
this.lastIterationTime = System.currentTimeMillis();
17+
this.animationSwitchDelay = animationSwitchDelay;
18+
}
1719

18-
public void tick() {
19-
if ((System.currentTimeMillis() - lastIterationTime) >= (animationSwitchDelay)) {
20-
lastIterationTime = System.currentTimeMillis();
21-
currentAnimationIndex = (currentAnimationIndex + 1) % animationTileCoords.length;
22-
this.tileId = (animationTileCoords[currentAnimationIndex][0] + (animationTileCoords[currentAnimationIndex][1] * 32));
23-
}
24-
}
20+
public void tick() {
21+
if ((System.currentTimeMillis() - lastIterationTime) >= (animationSwitchDelay)) {
22+
lastIterationTime = System.currentTimeMillis();
23+
currentAnimationIndex = (currentAnimationIndex + 1)
24+
% animationTileCoords.length;
25+
this.tileId = (animationTileCoords[currentAnimationIndex][0] + (animationTileCoords[currentAnimationIndex][1] * 32));
26+
}
27+
}
2528
}

src/com/redomar/game/level/tiles/BasicSolidTile.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.redomar.game.level.tiles;
22

3-
4-
public class BasicSolidTile extends BasicTile{
3+
public class BasicSolidTile extends BasicTile {
54

65
public BasicSolidTile(int id, int x, int y, int tileColour, int levelColour) {
76
super(id, x, y, tileColour, levelColour);

src/com/redomar/game/level/tiles/BasicTile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ public void tick() {
2121
public void render(Screen screen, LevelHandler level, int x, int y) {
2222
screen.render(x, y, tileId, tileColour, 0x00, 1);
2323
}
24-
24+
2525
}

0 commit comments

Comments
 (0)