Skip to content

Commit eccadb9

Browse files
author
raytr
committed
Final Update. Added powerups + updated testmap
1 parent 4fb9380 commit eccadb9

39 files changed

+301
-70
lines changed

Diff for: TestMap.csv

+34-34
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
2-
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
3-
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
4-
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
5-
, , ,w, , , , , , ,w, , , , , , ,w, , , , , ,w, , , , ,w,w,w,w,w,w,w,w,w, , , , ,
6-
, , ,w, , , , , , ,w, , , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , ,
7-
, , ,w, , , , , , ,w, , , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , ,
8-
, , , , , , , , , , , , , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , ,
9-
, , , , , , , , , , , , , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , ,
10-
, , , , , , , , , , , , , , , , ,w,w,w,w,w,w,w, , , , , , , , ,w, , , , , , , , ,
11-
, , , , , , , , , , , , , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , ,
12-
, , , , , , , , , , , , , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , ,
13-
, ,w, , , , , , , , ,w, , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , ,
14-
, , ,w, , , , , , ,w, , , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , ,
15-
, , , ,w,w,w,w,w,w, , , , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , ,
16-
, , , , , , , , , , , , , , , , ,w, , , , , ,w, , , , ,w,w,w,w,w,w,w,w,w, , , , ,
17-
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
18-
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
19-
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
20-
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
21-
, , , , , , , , , , ,w,w,w, ,w, ,w, ,w, , , , ,w, ,w, ,w,w,w,w, ,w, , , ,w, ,w,w,w,w, , , , ,
22-
, , , , , , , , , , ,w, , , ,w, ,w, , ,w, , ,w, , ,w, ,w, , ,w, ,w,w, , ,w, ,w, , , , , , , ,
23-
, , , , , , , , , , ,w,w,w, ,w, ,w, , , ,w,w, , , ,w, ,w, , ,w, ,w, ,w, ,w, ,w, , , , , , , ,
24-
, , , , , , , , , , ,w, , , ,w, ,w, , , ,w,w, , , ,w, ,w,w,w,w, ,w, , ,w,w, ,w, ,w,w, , , , ,
25-
, , , , , , , , , , ,w, , , ,w, ,w, , ,w, , ,w, , ,w, ,w, , ,w, ,w, , , ,w, ,w, , ,w, , , , ,
26-
, , , , , , , , , , ,w, , , ,w,w,w, ,w, , , , ,w, ,w, ,w, , ,w, ,w, , , ,w, ,w,w,w,w, , , , ,
27-
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
28-
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
29-
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,w, , , , , , , , , , , ,
30-
, , , , , ,w, , , , , , , , , , , , , ,w, , , , , , , , , , , , , , , , , , , , , ,w, , , , ,
31-
, , , , , ,w, , , , , , , , , , , , , , ,w, , , , , , , , , , , , , , , , ,w, , , ,w, , , , ,
32-
, , , , , ,w, , , , ,w,w,w,w,w, , , , , , ,w, , , , , , ,w, , , ,w, , , , , , , , ,w, , , , ,
33-
, , , , , ,w, , , , , , , , , , , , , , , , ,w, , , , ,w, , , , , , , , , , , , , , , , , , ,
34-
, , , , , ,w, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,w, , , , , , ,
1+
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
2+
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
3+
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
4+
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
5+
, , ,w, , , , , , ,w, , , , , , ,w, , , , , ,w, , , , ,w,w,w,w,w,w,w,w,w, , , , , , , , , ,
6+
, , ,w, , , , , , ,w, , , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , , , , , , ,
7+
, , ,w, , , , , , ,w, , , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , , , , , , ,
8+
, , , , , , , , , , , , , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , , , , , , ,
9+
, , , , , , , , , , , , , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , , , , , , ,
10+
, , , , , , , , , , , , , , , , ,w,w,w,w,w,w,w, , , , , , , , ,w, , , , , , , , , , , , , ,
11+
, , , , , , , , , , , , , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , , , , , , ,
12+
, , , , , , , , , , , , , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , , , , , , ,
13+
, ,w, , , , , , , , ,w, , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , , , , , , ,
14+
, , ,w, , , , , , ,w, , , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , , , , , , ,
15+
, , , ,w,w,w,w,w,w, , , , , , , ,w, , , , , ,w, , , , , , , , ,w, , , , , , , , , , , , , ,
16+
, , , , , , , , , , , , , , , , ,w, , , , , ,w, , , , ,w,w,w,w,w,w,w,w,w, , , , , , , , , ,
17+
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
18+
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
19+
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
20+
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
21+
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
22+
, , , , ,w, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
23+
, , , , , ,w, , , , , , , , , , , , , , ,w, , , , , , , , , , , , , ,w, , , , , , , , , , ,
24+
, , , , , , ,w, , , , , , , , , , , , ,w, , , , , , , , , , , , , , , ,w, , , , , , , , , ,
25+
, , , , , , , ,w, , , , , , , , , , ,w, , , , , , , , , , , , , , , , , ,w, , , , , , , , ,
26+
, , , , , , , , , , , , , , , , , , , , , , , ,w, , , , , , , , , , , , , ,w, , , , , , , ,
27+
, , , , , , , , , , , , , , , , , , , , , , , , ,w, , , , , , , , , , , , ,w, , , , , , , ,
28+
, , , , , , , , , , , , , , , , , , , , , , , , , ,w, , , , , , , , , , , ,w, , , , , , , ,
29+
, , , , , , , ,w, , , , , , , , , , , , , , , , , , ,w, , , , , , , , , , ,w, , , , , , , ,
30+
, , , , , , , ,w, , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,w, , , , , , , ,
31+
, , , , , , , ,w, , , , , , , , , , , , ,w, , , , , , , , , , , , , , , , , , , , , , , , ,
32+
, , , , , , , ,w, , , , , , , , , , , ,w, , , , , , , , , , ,w,w,w,w,w, , , , , , , , , , ,
33+
, , , , , , , ,w, , , , , , , , , , ,w, , , , , , , , , , , , , , , , , , , , , , , , , , ,
34+
, , , , , , , , , , , , , , , , , ,w, , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Diff for: out/production/ShootingGame/game/client/Game$1.class

0 Bytes
Binary file not shown.

Diff for: out/production/ShootingGame/game/client/Game$2.class

0 Bytes
Binary file not shown.

Diff for: out/production/ShootingGame/game/client/Game$3.class

0 Bytes
Binary file not shown.

Diff for: out/production/ShootingGame/game/client/Game$4.class

17 Bytes
Binary file not shown.

Diff for: out/production/ShootingGame/game/client/Game.class

271 Bytes
Binary file not shown.
157 Bytes
Binary file not shown.
761 Bytes
Binary file not shown.
1.38 KB
Binary file not shown.

Diff for: out/production/ShootingGame/game/client/Sprite.class

-1 Bytes
Binary file not shown.
104 Bytes
Binary file not shown.
143 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
1.23 KB
Binary file not shown.
129 Bytes
Binary file not shown.
736 Bytes
Binary file not shown.
407 Bytes
Binary file not shown.
420 Bytes
Binary file not shown.
970 Bytes
Binary file not shown.
1.09 KB
Binary file not shown.
110 Bytes
Binary file not shown.
Binary file not shown.
115 Bytes
Binary file not shown.
Binary file not shown.

Diff for: src/game/client/Game.java

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package game.client;
22

33
import game.client.net.ClientReceivePacketHandler;
4+
import game.shared.GameLoop;
45
import game.shared.net.NetManager;
56
import game.shared.net.Packet;
67
import game.shared.net.PacketSuccessFailHandler;
@@ -27,6 +28,7 @@
2728

2829
public class Game {
2930
private Playfield playfield = new Playfield(this);
31+
private GameLoop gameLoop;
3032
private BorderPane mainPane;
3133
private ChatBox chatBox;
3234
private final NetManager nh;
@@ -93,6 +95,11 @@ public void handle(MouseEvent event) {
9395
mainPane.requestFocus();
9496
}
9597
});
98+
99+
//Start our gameLoop
100+
gameLoop = new GameLoop(new ClientGameLoopRunnable(this,playfield),60);
101+
gameLoop.start();
102+
96103
stage.setScene(scene);
97104
stage.show();
98105

@@ -127,17 +134,6 @@ public Player addPlayer(int playerNum, String name) {
127134

128135
playerList.add(newPlayer);
129136
return newPlayer;
130-
/*
131-
Sprite newSprite = new Sprite();
132-
newSprite.setName(newPlayer.getName());
133-
newSprite.setId(newPlayer.getPlayerId());
134-
newPlayer.setSprite(newSprite);
135-
playfield.addSprite(newSprite);
136-
if (playerNum == this.getPlayerNum()){
137-
playfield.bindCameraToSprite(newSprite);
138-
}
139-
140-
*/
141137

142138
}
143139
public Player getClientPlayer(){
@@ -176,7 +172,7 @@ private void close(){
176172
PacketSuccessFailHandler psfh = new PacketSuccessFailHandler() {
177173
@Override
178174
public void run(InetSocketAddress addr) {
179-
playfield.stop();
175+
gameLoop.stopRunning();
180176
nh.stop();
181177
}
182178
};

Diff for: src/game/client/GameCamera.java

+7
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,11 @@ public double getX() {
3737
public double getY() {
3838
return pc.getTranslateY();
3939
}
40+
41+
public double getScreenHeight() {
42+
return screenHeight;
43+
}
44+
public double getScreenWidth() {
45+
return screenWidth;
46+
}
4047
}

Diff for: src/game/client/Playfield.java

+36-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package game.client;
22

33
import game.shared.GameLoop;
4+
import javafx.geometry.VPos;
45
import javafx.scene.Node;
56
import javafx.scene.SubScene;
67
import javafx.scene.canvas.Canvas;
78
import javafx.scene.canvas.GraphicsContext;
89
import javafx.scene.layout.VBox;
910
import javafx.scene.paint.Color;
1011
import javafx.scene.shape.ArcType;
12+
import javafx.scene.text.Font;
13+
import javafx.scene.text.TextAlignment;
1114

1215
import java.util.ArrayList;
1316
import java.util.HashMap;
1417
import java.util.List;
18+
import java.util.Timer;
1519
import java.util.concurrent.ConcurrentHashMap;
1620

1721

@@ -25,9 +29,10 @@ public class Playfield {
2529
private GameCamera gameCamera = new GameCamera();
2630
private double width;
2731
private double height;
28-
private double canvasWidth = 2000;
29-
private double canvasHeight = 2000;
30-
private GameLoop gameLoop;
32+
private double canvasWidth = 1000;
33+
private double canvasHeight = 1000;
34+
private boolean drawWinMsg = false;
35+
private String winningPlayer;
3136
private Game g;
3237
public Playfield(Game g){
3338
this.g = g;
@@ -46,9 +51,6 @@ public void init(double width, double height){
4651
gameCamera.init(subScene,width,height);
4752
body = subScene;
4853

49-
//Start our gameLoop
50-
gameLoop = new GameLoop(new ClientGameLoopRunnable(g,this),60);
51-
gameLoop.start();
5254
}
5355
public void bindCameraToSprite(Sprite s){
5456
gameCamera.bindSprite(s);
@@ -63,10 +65,20 @@ public void draw(){
6365
if (canvasWidth != gameArea.getWidth()) gameArea.setWidth(canvasWidth);
6466
if (canvasHeight != gameArea.getHeight()) gameArea.setHeight(canvasHeight);
6567
clear();
66-
createBorder();
6768
for (Sprite s : spriteMap.values()){
6869
s.draw(gc);
6970
}
71+
createBorder();
72+
if (drawWinMsg){
73+
System.out.println("HELLO");
74+
gc.setTextAlign(TextAlignment.CENTER);
75+
gc.setTextBaseline(VPos.CENTER);
76+
gc.setFill(Color.DARKORANGE);
77+
gc.setFont(Font.font ("Arial", 64));
78+
gc.fillText(winningPlayer + " WON THE ROUND!",
79+
gameCamera.getScreenWidth()/2 + gameCamera.getX(),
80+
gameCamera.getScreenHeight()/2 + gameCamera.getY() - 100);
81+
}
7082
}
7183

7284
private void createBorder() {
@@ -95,9 +107,6 @@ public List<Sprite> getSpriteList() {
95107
return new ArrayList<>(spriteMap.values());
96108
}
97109

98-
public void stop() {
99-
gameLoop.stopRunning();
100-
}
101110

102111
public Sprite getCameraBoundedSprite() {
103112
return gameCamera.getBoundedSprite();
@@ -117,4 +126,21 @@ public void setCanvasHeight(float height) {
117126
public void setCanvasWidth(float width) {
118127
canvasWidth = width;
119128
}
129+
130+
public void displayWinMsg(Player p) {
131+
drawWinMsg = true;
132+
winningPlayer = p.getName();
133+
Timer t = new java.util.Timer();
134+
t.schedule(
135+
new java.util.TimerTask() {
136+
@Override
137+
public void run() {
138+
// close the thread
139+
drawWinMsg = false;
140+
t.cancel();
141+
}
142+
},
143+
5000
144+
);
145+
}
120146
}

Diff for: src/game/client/Sprite.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public void setRotation(float angle) {
199199
public void setRemoteAngle(float angle) {
200200
this.remoteAngle = angle;
201201
}
202-
public void setRGBColor(int r,int g, int b,int opacity){
202+
public void setRGBColor(int r,int g, int b,double opacity){
203203
this.color = new Color(r,g,b,opacity);
204204
}
205205
}

Diff for: src/game/client/SpriteFactory.java

+12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ public static Sprite createSprite(EntityCreateMsg ecm){
2727
newSprite.setWidth(50);
2828
newSprite.setHeight(50);
2929
break;
30+
case HP_POWERUP:
31+
newSprite.setRGBColor(0,1,0,1);
32+
newSprite.setName("HP");
33+
newSprite.setWidth(50);
34+
newSprite.setHeight(50);
35+
break;
36+
case SHOT_POWERUP:
37+
newSprite.setRGBColor(0,0,1,0.4);
38+
newSprite.setName("SHOT++");
39+
newSprite.setWidth(50);
40+
newSprite.setHeight(50);
41+
break;
3042
default:
3143
break;
3244
}

Diff for: src/game/client/net/ClientReceivePacketHandler.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import game.shared.net.messages.*;
99
import game.shared.net.Message;
1010
import game.shared.net.Packet;
11-
import javafx.application.Platform;
1211

1312
public class ClientReceivePacketHandler implements ReceivePacketHandler {
1413
final Game g;
@@ -47,7 +46,8 @@ public void handleReceive(Packet packet) {
4746
case CHAT_MESSAGE:
4847
playerNum = ((ChatMsg) m).getPlayerNum();
4948
String msg = ((ChatMsg) m).getMsg();
50-
g.getChatBox().addMsg(playerNum, msg, false);
49+
if (playerNum != -1)g.getChatBox().addMsg(playerNum, msg, false);
50+
else g.getChatBox().addMsg(playerNum, msg, true);
5151
break;
5252
case ENTITY_CREATE:
5353
EntityCreateMsg ecm = (EntityCreateMsg) m;
@@ -81,6 +81,10 @@ public void handleReceive(Packet packet) {
8181
PlayerStateMsg psm = (PlayerStateMsg)m;
8282
Player player = g.getPlayer(psm.getPlayerNum());
8383
player.setScore(psm.getScore());
84+
break;
85+
case PLAYER_WIN:
86+
PlayerWinMsg pwm = (PlayerWinMsg)m;
87+
g.getPlayfield().displayWinMsg(g.getPlayer(pwm.getPlayerNum()));
8488

8589
break;
8690
default:

Diff for: src/game/server/GameServer.java

+51-9
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ public class GameServer {
1919
private int playerNumCounter = 0;
2020
private final int port;
2121
private List<Entity> entityList = new CopyOnWriteArrayList<>();
22+
private List<Entity> powerUpList = new ArrayList<Entity>();
2223
private List<Entity> bulletList = new ArrayList<Entity>();
2324
private final Map<Integer, Player> playerNumPlayerMap = new HashMap<>();
24-
private GameMap gameMap = new GameMap(new ArrayList<Entity>(),2000,2000);
25+
private GameMap gameMap = new GameMap(new ArrayList<Entity>(),1000,1000);
2526

2627
public GameServer(int port) {
2728
this.port = port;
@@ -34,22 +35,53 @@ public void init() {
3435
gl = new GameLoop(new Runnable() {
3536
@Override
3637
public void run() {
38+
//Check win condition
39+
boolean winnerFound = false;
40+
for (Player p : playerNumPlayerMap.values()){
41+
if (p.getScore() > 4){
42+
nh.sendMessage(PlayerWinMsg.encode(p.getId()));
43+
winnerFound = true;
44+
break;
45+
}
46+
}
47+
if (winnerFound) {
48+
for (Player p : playerNumPlayerMap.values()) {
49+
do {
50+
p.setX(Math.random() * gameMap.getWidth());
51+
p.setY(Math.random() * gameMap.getHeight());
52+
} while (p.collides(gameMap.getWalls()));
53+
p.setHp(100);
54+
p.setShootCooldownUpdateTicks(10);
55+
p.setScore(0);
56+
}
57+
}
58+
3759

38-
//Add new bullets
39-
List<Entity> newBullets = new ArrayList<Entity>();
60+
//Add new entities
61+
List<Entity> newEntities = new ArrayList<Entity>();
4062
for (Player p : playerNumPlayerMap.values()){
4163
if (p.canShoot()){
4264
Bullet b = new Bullet(p);
4365
b.setVx(b.getVx() * Math.cos(p.getAngle()));
4466
b.setVy(b.getVy() * Math.sin(p.getAngle()));
4567
b.setX(p.getX() + p.getWidth()/2 - b.getWidth()/2);
4668
b.setY(p.getY() + p.getHeight()/2 - b.getHeight()/2);
47-
newBullets.add(b);
69+
bulletList.add(b);
70+
newEntities.add(b);
4871
}
4972
}
73+
while (powerUpList.size() < 5){
74+
double random = Math.random();
75+
Powerup myPowerup = random > 0.5 ? new HealthPowerup() : new ShotPowerup();
76+
do {
77+
myPowerup.setX(Math.random() * (gameMap.getWidth() - myPowerup.getWidth()) );
78+
myPowerup.setY(Math.random() * (gameMap.getHeight() - myPowerup.getHeight()) );
79+
}while(myPowerup.collides(gameMap.getWalls()));
80+
powerUpList.add(myPowerup);
81+
newEntities.add(myPowerup);
82+
}
5083

51-
addEntities(newBullets);
52-
bulletList.addAll(newBullets);
84+
addEntities(newEntities);
5385

5486
List<Entity> toRemove = new ArrayList<Entity>();
5587
for (Player p : playerNumPlayerMap.values()){
@@ -71,6 +103,16 @@ public void run() {
71103
}
72104
}
73105
}
106+
107+
for (Entity pw : powerUpList){
108+
if (pw.collides(p)){
109+
Powerup pwu = (Powerup) pw;
110+
pwu.applyEffect(p);
111+
toRemove.add(pw);
112+
}
113+
if (pw.getX() + pw.getWidth() > gameMap.getWidth()) pw.setX(gameMap.getWidth() - pw.getWidth());
114+
if (pw.getY() + pw.getHeight() > gameMap.getHeight()) pw.setY(gameMap.getHeight() - pw.getHeight());
115+
}
74116
if (p.getX() < 0) p.setX(0);
75117
if (p.getY() < 0) p.setY(0);
76118
if (p.getX() + p.getWidth() > gameMap.getWidth()) p.setX(gameMap.getWidth() - p.getWidth());
@@ -82,13 +124,13 @@ public void run() {
82124
toRemove.add(b);
83125
}
84126
}
127+
85128
bulletList.removeAll(toRemove);
129+
powerUpList.removeAll(toRemove);
130+
86131
//Send entity remove messages
87132
removeEntities(toRemove);
88133

89-
90-
91-
92134
//Send entity state messages
93135
List<Message> entityStateMsgs = new ArrayList<Message>();
94136

0 commit comments

Comments
 (0)