forked from notEpsilon/concurrent_project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGamePanel.java
More file actions
97 lines (82 loc) · 2.19 KB
/
GamePanel.java
File metadata and controls
97 lines (82 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
public class GamePanel extends JPanel {
int x;
int y;
int controller;
Goal goal;
Player[] p4;
Thread[] players;
Football football;
InfoPanel infoPanel;
public GamePanel(InfoPanel infoPanel) {
setBackground(new Color(0,100,0));
this.infoPanel = infoPanel;
this.controller = 0;
}
public void createGameEntities() {
p4 = new Player[] {
new Player(this, 130, 375, Color.MAGENTA),
new Player(this, 90, 375, Color.BLACK),
new Player(this, 50, 375, Color.RED),
new Player(this, 10, 375, Color.ORANGE)
};
players = new Thread[] {
new Thread(p4[0]),
new Thread(p4[1]),
new Thread(p4[2]),
new Thread(p4[3])
};
for (int i = 0; i < players.length; i++)
players[i].start();
goal = new Goal(this,150,5);
}
public void kickBall() {
if (football != null) {
if(football.gety() < 0){
football = new Football(this, infoPanel, p4[controller].getPlayer(), this.goal);
football.start();
this.controller = (this.controller + 1) % 4;
}
}
else {
football = new Football(this, infoPanel, p4[controller].getPlayer(), this.goal);
football.start();
this.controller = (this.controller + 1) % 4;
}
}
public void startGoal() {
goal = new Goal(this,150,5);
goal.start();
}
public void drawGameEntities() {
if (players[0] != null && goal != null) {
for (int i = 0; i < 4; i++) {
p4[i].draw();
}
goal.draw();
}
}
public void updateGameEntities(int direction) {
if (p4[controller] == null)
return;
if (direction == 1) {
p4[controller].erase();
p4[controller].moveLeft();
}
else if (direction == 3) {
p4[controller].erase();
p4[controller].moveRight();
}
}
public void setX (int xPos) {
x = xPos;
}
public void setY (int yPos) {
y = yPos;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
}
}