Skip to content

Commit e8030c9

Browse files
committed
Mid-stage of shooting projectiles
Imporvements on entities
2 parents 4318696 + 8323f7b commit e8030c9

File tree

12 files changed

+329
-15
lines changed

12 files changed

+329
-15
lines changed

src/com/redomar/game/Game.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.redomar.game.entities.Dummy;
1818
import com.redomar.game.entities.Player;
1919
import com.redomar.game.entities.PlayerMP;
20+
import com.redomar.game.entities.Vendor;
2021
import com.redomar.game.gfx.Screen;
2122
import com.redomar.game.gfx.SpriteSheet;
2223
import com.redomar.game.level.LevelHandler;
@@ -76,6 +77,7 @@ public class Game extends Canvas implements Runnable {
7677
private LevelHandler level;
7778
private Player player;
7879
private Dummy dummy;
80+
private Vendor vendor;
7981
private Music music = new Music();
8082
private Font font = new Font();
8183
private Thread musicThread = new Thread(music, "MUSIC");
@@ -138,6 +140,9 @@ public void init() {
138140

139141
// socketClient.sendData("ping".getBytes());
140142
loginPacket.writeData(getSocketClient());
143+
144+
game.setVendor(new Vendor(getLevel(), "Vendor", 215, 215, 304, 543));
145+
getLevel().addEntity(getVendor());
141146
}
142147

143148
public void setMap(String Map_str) {
@@ -161,7 +166,7 @@ public void setMap(String Map_str) {
161166

162167
public static void npcSpawn() {
163168
if (isNpc() == true) {
164-
game.setDummy(new Dummy(Game.getLevel(), "h", 215, 215, 500, 543));
169+
game.setDummy(new Dummy(Game.getLevel(), "Dummy", 100, 150, 500, 543));
165170
game.level.addEntity(Game.getDummy());
166171
}
167172
}
@@ -295,11 +300,16 @@ public void render() {
295300
}
296301

297302
if (changeLevel == true) {
303+
print.print("Teleported into new world", PrintTypes.GAME);
298304
if (getMap() == 1) {
299305
setMap("/levels/water_level.png");
306+
getLevel().removeEntity(getDummy()); setNpc(false);
307+
getLevel().removeEntity(getVendor());
300308
setMap(2);
301309
} else if (getMap() == 2) {
302310
setMap("/levels/custom_level.png");
311+
getLevel().removeEntity(getDummy()); setNpc(false);
312+
getLevel().addEntity(getVendor());
303313
setMap(1);
304314
}
305315
changeLevel = false;
@@ -495,6 +505,14 @@ public void setDummy(Dummy dummy) {
495505
this.dummy = dummy;
496506
}
497507

508+
public Vendor getVendor() {
509+
return vendor;
510+
}
511+
512+
public void setVendor(Vendor vendor) {
513+
this.vendor = vendor;
514+
}
515+
498516
public static String getJdata_IP() {
499517
return Jdata_IP;
500518
}

src/com/redomar/game/InputHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ public void toggleKey(int keyCode, boolean isPressed) {
9595
// }
9696
if (Game.getMap() == 2) {
9797
Game.setChangeLevel(true);
98-
Game.getLevel().removeEntity(Game.getDummy());
9998
Game.setNpc(false);
10099
}
101100
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class Dummy extends Mob {
2626

2727
public Dummy(LevelHandler level, String name, int x, int y, int shirtCol,
2828
int faceCol) {
29-
super(level, "h", x, y, speed, collisionBoders);
29+
super(level, name, x, y, speed, collisionBoders);
3030
this.faceCol = faceCol;
3131
this.shirtCol = shirtCol;
3232
this.colour = Colours.get(-1, 111, shirtCol, faceCol);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
public abstract class Entity {
77

88
protected double x, y;
9+
protected String name;
910
protected LevelHandler level;
1011

1112
public Entity(LevelHandler level) {
@@ -35,4 +36,12 @@ public double getY() {
3536
public void setY(int y) {
3637
this.y = y;
3738
}
39+
40+
public String getName() {
41+
return name;
42+
}
43+
44+
public void setName(String name) {
45+
this.name = name;
46+
}
3847
}

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
public abstract class Mob extends Entity {
1515

16-
protected String name;
1716
protected Random random = new Random();
1817
protected double speed;
1918
protected int numSteps = 0;
@@ -29,7 +28,7 @@ public abstract class Mob extends Entity {
2928
* [0] Contains the <strong>xMin</strong><br>
3029
* [1] Contains the <strong>xMax</strong><br>
3130
* [2] Contains the <strong>yMin</strong><br>
32-
* [3] Contains the <strong>yMax
31+
* [3] Contains the <strong>yMax</strong>
3332
*/
3433
protected int[] collisionBoders = new int[4];
3534

@@ -205,6 +204,25 @@ protected void followMovementAI(int x, int y, int px, int py, double xa,
205204
ya-=speed;
206205
moveMob(xa, ya, mob);
207206
}
207+
208+
protected double[] randomMovementAI(double x, double y, double xa, double ya, int tick) {
209+
if (tick % (random.nextInt(50) + 30) == 0) {
210+
xa = random.nextInt(3) - 1;
211+
ya = random.nextInt(3) - 1;
212+
if (random.nextInt(4) == 0) {
213+
xa = 0;
214+
ya = 0;
215+
}
216+
}
217+
if(x <= 180){
218+
xa = 1;
219+
ya = -1;
220+
}
221+
double move[] = new double[2];
222+
move[0] = xa;
223+
move[1] = ya;
224+
return move;
225+
}
208226

209227
protected void moveMob(double xa, double ya, Mob mob) {
210228
if (xa != 0 || ya != 0) {

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.redomar.game.Game;
44
import com.redomar.game.InputHandler;
55
import com.redomar.game.entities.efx.Swim;
6+
import com.redomar.game.entities.projectiles.Projectile;
7+
import com.redomar.game.entities.projectiles.Small;
68
import com.redomar.game.gfx.Colours;
79
import com.redomar.game.gfx.Screen;
810
import com.redomar.game.level.LevelHandler;
@@ -25,6 +27,7 @@ public class Player extends Mob {
2527
private boolean[] swimType;
2628
private int[] swimColour;
2729
private static int[] collisionBoders = {-2, 8, 0, 7};
30+
private int fireRate = 0;
2831

2932
public static String guestPlayerName = customeName.setName("Player ");
3033

@@ -36,6 +39,7 @@ public Player(LevelHandler level, int x, int y, InputHandler input,
3639
this.faceCol = faceCol;
3740
this.shirtCol = shirtCol;
3841
this.colour = Colours.get(-1, 111, shirtCol, faceCol);
42+
fireRate = Small.FIRE_RATE;
3943
}
4044

4145
public void tick() {
@@ -57,11 +61,24 @@ public void tick() {
5761
}
5862
}
5963

60-
if (Game.getMouse().getButton() == 1){
61-
double dx = Game.getMouse().getX() - 480/2;
62-
double dy = Game.getMouse().getY() - 320/2;
63-
double dir = Math.atan2(dy, dx);
64-
shoot(x, y, dir);
64+
if(fireRate > 0) fireRate--;
65+
66+
if (Game.getMouse().getButton() == 1 && fireRate <= 0){
67+
if(!swim.isActive(swimType)){
68+
double dx = Game.getMouse().getX() - 480/2;
69+
double dy = Game.getMouse().getY() - 320/2;
70+
double dir = Math.atan2(dy, dx);
71+
shoot(x, y, dir);
72+
fireRate = Small.FIRE_RATE;
73+
}
74+
}
75+
76+
for (int i = 0; i < projectiles.size(); i++) {
77+
Projectile p = projectiles.get(i);
78+
if(p.isRemoved()){
79+
projectiles.remove(i);
80+
Game.getLevel().removeProjectileEntities(p);
81+
}
6582
}
6683

6784
if (xa != 0 || ya != 0) {
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
package com.redomar.game.entities;
2+
3+
import java.util.List;
4+
5+
import com.redomar.game.entities.efx.Swim;
6+
import com.redomar.game.gfx.Colours;
7+
import com.redomar.game.gfx.Screen;
8+
import com.redomar.game.level.LevelHandler;
9+
import com.redomar.game.level.Node;
10+
11+
public class Vendor extends Mob {
12+
13+
private int colour, shirtCol, faceCol; // = Colours.get(-1, 111, 240, 310);
14+
private int tickCount = 0;
15+
private int tick = 0;
16+
private double xa = 0;
17+
private double ya = 0;
18+
private double[] movement;
19+
private boolean[] swimType;
20+
private int[] swimColour;
21+
private static double speed = 0.75;
22+
private List<Node> path = null;
23+
private int time = 0;
24+
private static int[] collisionBoders = {0, 7, 0, 7};
25+
26+
private Swim swim;
27+
28+
public Vendor(LevelHandler level, String name, int x, int y, int shirtCol,
29+
int faceCol) {
30+
super(level, name, x, y, speed, collisionBoders);
31+
this.faceCol = faceCol;
32+
this.shirtCol = shirtCol;
33+
this.colour = Colours.get(-1, 111, shirtCol, faceCol);
34+
}
35+
36+
public void tick() {
37+
38+
tick++;
39+
movement = randomMovementAI(x, y, xa, ya, tick);
40+
41+
this.xa = movement[0];
42+
this.ya = movement[1];
43+
44+
moveMob(xa, ya, this);
45+
46+
setSwim(new Swim(level, (int) getX(), (int) getY()));
47+
swimType = getSwim().swimming(isSwimming, isMagma, isMuddy);
48+
isSwimming = swimType[0];
49+
isMagma = swimType[1];
50+
isMuddy = swimType[2];
51+
52+
tickCount++;
53+
54+
}
55+
56+
public void render(Screen screen) {
57+
setTime(getTime() + 1);
58+
int xTile = 8;
59+
int yTile = 28;
60+
int walkingSpeed = 4;
61+
int flipTop = (numSteps >> walkingSpeed) & 1;
62+
int flipBottom = (numSteps >> walkingSpeed) & 1;
63+
64+
if (movingDir == 1) {
65+
xTile += 2;
66+
if (!isMoving || swim.isActive(swimType)){
67+
yTile -= 2;
68+
}
69+
} else if (movingDir == 0 && !isMoving || movingDir == 0 && swim.isActive(swimType)) {
70+
yTile -= 2;
71+
} else if (movingDir > 1) {
72+
xTile += 4 + ((numSteps >> walkingSpeed) & 1) * 2;
73+
flipTop = (movingDir - 1) % 2;
74+
if(!isMoving){
75+
xTile = 4;
76+
}
77+
}
78+
79+
int modifier = 8 * scale;
80+
int xOffset = (int) getX() - modifier / 2;
81+
int yOffset = (int) getY() - modifier / 2 - 4;
82+
83+
if (isSwimming || isMagma || isMuddy) {
84+
swimColour = getSwim().waveCols(isSwimming, isMagma, isMuddy);
85+
86+
int waterColour = 0;
87+
yOffset += 4;
88+
89+
colour = Colours.get(-1, 111, -1, faceCol);
90+
91+
if (tickCount % 60 < 15) {
92+
waterColour = Colours.get(-1, -1, swimColour[0], -1);
93+
} else if (15 <= tickCount % 60 && tickCount % 60 < 30) {
94+
yOffset--;
95+
waterColour = Colours.get(-1, swimColour[1], swimColour[2], -1);
96+
} else if (30 <= tickCount % 60 && tickCount % 60 < 45) {
97+
waterColour = Colours.get(-1, swimColour[2], -1, swimColour[1]);
98+
} else {
99+
yOffset--;
100+
waterColour = Colours.get(-1, -1, swimColour[1], swimColour[2]);
101+
}
102+
103+
screen.render(xOffset, yOffset + 3, 31 + 31 * 32, waterColour,
104+
0x00, 1);
105+
screen.render(xOffset + 8, yOffset + 3, 31 + 31 * 32, waterColour,
106+
0x01, 1);
107+
}
108+
109+
screen.render((xOffset + (modifier * flipTop)), yOffset,
110+
(xTile + yTile * 32), colour, flipTop, scale);
111+
screen.render((xOffset + modifier - (modifier * flipTop)), yOffset,
112+
((xTile + 1) + yTile * 32), colour, flipTop, scale);
113+
if (!isSwimming && !isMagma && !isMuddy) {
114+
screen.render((xOffset + (modifier * flipBottom)),
115+
(yOffset + modifier), (xTile + (yTile + 1) * 32), colour,
116+
flipBottom, scale);
117+
screen.render((xOffset + modifier - (modifier * flipBottom)),
118+
(yOffset + modifier), ((xTile + 1) + (yTile + 1) * 32),
119+
colour, flipBottom, scale);
120+
colour = Colours.get(-1, 111, shirtCol, faceCol);
121+
}
122+
}
123+
124+
public Swim getSwim() {
125+
return swim;
126+
}
127+
128+
public void setSwim(Swim swim) {
129+
this.swim = swim;
130+
}
131+
132+
public List<Node> getPath() {
133+
return path;
134+
}
135+
136+
public void setPath(List<Node> path) {
137+
this.path = path;
138+
}
139+
140+
public int getTime() {
141+
return time;
142+
}
143+
144+
public void setTime(int time) {
145+
this.time = time;
146+
}
147+
}

0 commit comments

Comments
 (0)