Skip to content

Commit 4afb725

Browse files
committed
#22 Code formatting
1 parent a13a109 commit 4afb725

File tree

17 files changed

+71
-107
lines changed

17 files changed

+71
-107
lines changed

src/com/redomar/game/Launcher.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
import com.redomar.game.menu.Menu;
44

5-
public class Launcher
6-
{
7-
public static void main(String[] args)
8-
{
5+
public class Launcher {
6+
public static void main(String[] args) {
97
new Menu().start();
108
}
119
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
public class Colours {
44

55
public static int get(int colour1, int colour2, int colour3, int colour4) {
6-
return (get(colour4) << 24) + (get(colour3) << 16)
7-
+ (get(colour2) << 8) + (get(colour1));
6+
return (get(colour4) << 24) + (get(colour3) << 16) + (get(colour2) << 8) + (get(colour1));
87
}
98

109
private static int get(int colour) {

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

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,19 @@ public class Screen {
77

88
private static final byte BIT_MIRROR_X = 0x01;
99
private static final byte BIT_MIRROR_Y = 0x02;
10-
10+
private final SpriteSheet sheet;
1111
private int[] pixels;
12-
1312
private int xOffset = 0;
1413
private int yOffset = 0;
15-
1614
private int width;
1715
private int height;
1816

19-
private SpriteSheet sheet;
20-
2117
/**
2218
* Constructs the draw area
23-
* @param width width of the screen
19+
*
20+
* @param width width of the screen
2421
* @param height height of the screen
25-
* @param sheet Sprite-sheet selector. Constructed Spritesheet needs to be here,
22+
* @param sheet Sprite-sheet selector. Constructed sprite sheet needs to be here,
2623
* Sprite-sheet cp requires path only.
2724
*/
2825
public Screen(int width, int height, SpriteSheet sheet) {
@@ -34,23 +31,24 @@ public Screen(int width, int height, SpriteSheet sheet) {
3431
setPixels(new int[width * height]);
3532
}
3633

34+
@SuppressWarnings("unused")
3735
public static int getMapWidthMask() {
3836
return MAP_WIDTH_MASK;
3937
}
4038

4139

4240
/**
43-
* Rendering sprites from Spritesheet onto the game world.
44-
* Render contstucter requires
45-
* @param xPos X Postion of subject
46-
* @param yPos Y Postion of subject
47-
* @param tile tile location. e.g 7 * 32 + 1 is the oblong bullet on the 7th row 2nd colomn
48-
* @param colour Using established colouring nomanclature. i.e. use com.redomar.game.gfx.Colours
49-
* @param mirrorDir flip Direction: 0x01 flip verticle, 0x02 flip horizontal.
50-
* @param scale Scale
41+
* Rendering sprites from sprite sheet onto the game world.
42+
* Render constructor requires
43+
*
44+
* @param xPos X Position of subject
45+
* @param yPos Y Position of subject
46+
* @param tile tile location. e.g 7 * 32 + 1 is the oblong bullet on the 7th row 2nd column
47+
* @param colour Using established colouring nomenclature. i.e. use com.redomar.game.gfx.Colours
48+
* @param mirrorDir flip Direction: 0x01 flip vertical, 0x02 flip horizontal.
49+
* @param scale Scale
5150
*/
52-
public void render(int xPos, int yPos, int tile, int colour, int mirrorDir,
53-
int scale) {
51+
public void render(int xPos, int yPos, int tile, int colour, int mirrorDir, int scale) {
5452
xPos -= xOffset;
5553
yPos -= yOffset;
5654

@@ -80,26 +78,22 @@ public void render(int xPos, int yPos, int tile, int colour, int mirrorDir,
8078

8179
int xPixel = x + xPos + (x * scaleMap) - ((scaleMap << 3) / 2);
8280

83-
int col = (colour >> (sheet.pixels[xSheet + ySheet
84-
* sheet.getWidth() + tileOffset] * 8)) & 255;
81+
int col = (colour >> (sheet.pixels[xSheet + ySheet * sheet.getWidth() + tileOffset] * 8)) & 255;
8582
if (col < 255) {
8683

8784
for (int yScale = 0; yScale < scale; yScale++) {
8885

89-
if (yPixel + yScale < 0
90-
| yPixel + yScale >= getHeight()) {
86+
if (yPixel + yScale < 0 | yPixel + yScale >= getHeight()) {
9187
continue;
9288
}
9389

9490
for (int xScale = 0; xScale < scale; xScale++) {
9591

96-
if (xPixel + xScale < 0
97-
| xPixel + xScale >= getWidth()) {
92+
if (xPixel + xScale < 0 | xPixel + xScale >= getWidth()) {
9893
continue;
9994
}
10095

101-
getPixels()[(xPixel + xScale) + (yPixel + yScale)
102-
* getWidth()] = col;
96+
getPixels()[(xPixel + xScale) + (yPixel + yScale) * getWidth()] = col;
10397
}
10498
}
10599

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
package com.redomar.game.gfx;
22

3+
import javax.imageio.ImageIO;
34
import java.awt.image.BufferedImage;
45
import java.io.IOException;
5-
6-
import javax.imageio.ImageIO;
6+
import java.util.Objects;
77

88
public class SpriteSheet {
99

10+
public int[] pixels;
1011
private String path;
1112
private int width;
12-
private int height;
13-
14-
public int[] pixels;
1513

1614
public SpriteSheet(String path) {
1715
BufferedImage image = null;
1816

1917
try {
20-
image = ImageIO.read(SpriteSheet.class.getResourceAsStream(path));
18+
image = ImageIO.read(Objects.requireNonNull(SpriteSheet.class.getResourceAsStream(path)));
2119
} catch (IOException e) {
2220
e.printStackTrace();
2321
}
@@ -28,19 +26,17 @@ public SpriteSheet(String path) {
2826

2927
this.setPath(path);
3028
this.setWidth(image.getWidth());
31-
this.height = image.getHeight();
29+
int height = image.getHeight();
3230

3331
pixels = image.getRGB(0, 0, width, height, null, 0, width);
3432

3533
for (int i = 0; i < pixels.length; i++) {
3634
pixels[i] = (pixels[i] & 0xff) / 64; // removes alpha (transparency)
3735
}
3836

39-
for (int i = 0; i < 8; i++) {
40-
// System.out.println(pixels[i]);
41-
}
4237
}
4338

39+
@SuppressWarnings("unused")
4440
public String getPath() {
4541
return path;
4642
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ public List<Entity> getEntities(Entity e, int radius) {
286286
}
287287

288288

289-
290289
public int getWidth() {
291290
return width;
292291
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class Node {
88
public Node parent;
99
public double fCost, gCost, hCost;
1010

11-
public Node(Vector2i tile, Node parent, double gCost, double hCost){
11+
public Node(Vector2i tile, Node parent, double gCost, double hCost) {
1212
this.tile = tile;
1313
this.parent = parent;
1414
this.gCost = gCost;

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,20 @@
22

33
public class AnimatedTile extends BasicTile {
44

5-
private int[][] animationTileCoords;
5+
private final int[][] animationTileCoords;
66
private int currentAnimationIndex;
77
private long lastIterationTime;
8-
private int animationSwitchDelay;
8+
private final int animationSwitchDelay;
99

1010
/**
11-
*
12-
* @param id Unique ID for the Tile
13-
* @param animationCoords A 2D array of all x,y-coordinates in Integers.
14-
* @param tileColour Colours from the SpriteSheet.
15-
* @param levelColour Colours to be displayed in the Game World.
11+
* @param id Unique ID for the Tile
12+
* @param animationCoords A 2D array of all x,y-coordinates in Integers.
13+
* @param tileColour Colours from the SpriteSheet.
14+
* @param levelColour Colours to be displayed in the Game World.
1615
* @param animationSwitchDelay Length of time to be delayed to the next frame from the 2D array.
1716
*/
18-
public AnimatedTile(int id, int[][] animationCoords, int tileColour,
19-
int levelColour, int animationSwitchDelay) {
20-
super(id, animationCoords[0][0], animationCoords[0][1], tileColour,
21-
levelColour);
17+
public AnimatedTile(int id, int[][] animationCoords, int tileColour, int levelColour, int animationSwitchDelay) {
18+
super(id, animationCoords[0][0], animationCoords[0][1], tileColour, levelColour);
2219
this.animationTileCoords = animationCoords;
2320
this.currentAnimationIndex = 0;
2421
this.lastIterationTime = System.currentTimeMillis();
@@ -28,8 +25,7 @@ public AnimatedTile(int id, int[][] animationCoords, int tileColour,
2825
public void tick() {
2926
if ((System.currentTimeMillis() - lastIterationTime) >= (animationSwitchDelay)) {
3027
lastIterationTime = System.currentTimeMillis();
31-
currentAnimationIndex = (currentAnimationIndex + 1)
32-
% animationTileCoords.length;
28+
currentAnimationIndex = (currentAnimationIndex + 1) % animationTileCoords.length;
3329
this.tileId = (animationTileCoords[currentAnimationIndex][0] + (animationTileCoords[currentAnimationIndex][1] * 32));
3430
}
3531
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ public class BasicSolidTile extends BasicTile {
55
/**
66
* This is a solid tile, but does not emit any light. This tile does not have any animations.
77
*
8-
* @param id Unique ID for the Tile
9-
* @param x Specifies the x-coordinate from the SpriteSheet, measured in 8 pixels. Must be 0 - 31
10-
* @param y Specifies the y-coordinate from the SpriteSheet, measured in 8 pixels. Must be 0 - 31
11-
* @param tileColour Colours from the SpriteSheet.
8+
* @param id Unique ID for the Tile
9+
* @param x Specifies the x-coordinate from the SpriteSheet, measured in 8 pixels. Must be 0 - 31
10+
* @param y Specifies the y-coordinate from the SpriteSheet, measured in 8 pixels. Must be 0 - 31
11+
* @param tileColour Colours from the SpriteSheet.
1212
* @param levelColour Colours to be displayed in the Game World.
1313
*/
1414
public BasicSolidTile(int id, int x, int y, int tileColour, int levelColour) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ public class BasicTile extends Tile {
1111
/**
1212
* This is a tile that does not emit light, nor is sold. This tile does not have any animations.
1313
*
14-
* @param id Unique ID for the Tile
15-
* @param x Specifies the x-coordinate from the SpriteSheet, measured in 8 pixels. Must be 0 - 31
16-
* @param y Specifies the y-coordinate from the SpriteSheet, measured in 8 pixels. Must be 0 - 31
17-
* @param tileColour Colours from the SpriteSheet.
14+
* @param id Unique ID for the Tile
15+
* @param x Specifies the x-coordinate from the SpriteSheet, measured in 8 pixels. Must be 0 - 31
16+
* @param y Specifies the y-coordinate from the SpriteSheet, measured in 8 pixels. Must be 0 - 31
17+
* @param tileColour Colours from the SpriteSheet.
1818
* @param levelColour Colours to be displayed in the Game World.
1919
*/
2020
public BasicTile(int id, int x, int y, int tileColour, int levelColour) {

src/com/redomar/game/lib/Font.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,20 @@ public class Font {
66

77
private static java.awt.Font arial;
88
private static java.awt.Font segoe;
9-
private static String chars = "" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ "
10-
+ "0123456789.,:;'\"!?$%()-=+/ ";
9+
private static final String chars = "" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ " + "0123456789.,:;'\"!?$%()-=+/ ";
1110

1211
public Font() {
1312
Font.setArial(new java.awt.Font("Arial", java.awt.Font.BOLD, 14));
1413
Font.setSegoe(new java.awt.Font("Segoe UI", java.awt.Font.BOLD, 14));
1514
}
1615

17-
public static void render(String msg, Screen screen, int x, int y,
18-
int colour, int scale) {
16+
public static void render(String msg, Screen screen, int x, int y, int colour, int scale) {
1917
msg = msg.toUpperCase();
2018

2119
for (int i = 0; i < msg.length(); i++) {
2220
int charIndex = chars.indexOf(msg.charAt(i));
2321
if (charIndex >= 0) {
24-
screen.render(x + (i * 8), y, charIndex + 30 * 32, colour,
25-
0x00, scale);
22+
screen.render(x + (i * 8), y, charIndex + 30 * 32, colour, 0x00, scale);
2623
}
2724
}
2825
}

0 commit comments

Comments
 (0)