Skip to content

Commit d2b58ec

Browse files
committed
Improved code efficentiancy for player swimming types
1 parent 875778c commit d2b58ec

File tree

2 files changed

+29
-53
lines changed

2 files changed

+29
-53
lines changed

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

Lines changed: 8 additions & 53 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

@@ -97,70 +98,24 @@ public void render(Screen screen) {
9798
Game.setChangeLevel(true);
9899
}
99100

100-
if (isSwimming) {
101+
if(isSwimming || isMagma || isMuddy){
102+
swimColour = getSwim().waveCols(isSwimming, isMagma, isMuddy);
103+
101104
int waterColour = 0;
102105
yOffset += 4;
103106

104107
colour = Colours.get(-1, 111, -1, 310);
105108

106109
if (tickCount % 60 < 15) {
107-
waterColour = Colours.get(-1, -1, 255, -1);
110+
waterColour = Colours.get(-1, -1, swimColour[0], -1);
108111
} else if (15 <= tickCount % 60 && tickCount % 60 < 30) {
109112
yOffset--;
110-
waterColour = Colours.get(-1, 225, 115, -1);
113+
waterColour = Colours.get(-1, swimColour[1], swimColour[2], -1);
111114
} else if (30 <= tickCount % 60 && tickCount % 60 < 45) {
112-
waterColour = Colours.get(-1, 115, -1, 225);
115+
waterColour = Colours.get(-1, swimColour[2], -1, swimColour[1]);
113116
} else {
114117
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);
118+
waterColour = Colours.get(-1, -1, swimColour[1], swimColour[2]);
164119
}
165120

166121
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) {

0 commit comments

Comments
 (0)