-
Notifications
You must be signed in to change notification settings - Fork 0
/
GamePanel.java
93 lines (72 loc) · 1.83 KB
/
GamePanel.java
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
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import javax.swing.JPanel;
public class GamePanel extends JPanel {
int x;
int y;
Goal goal;
Player player;
Football football;
InfoPanel infoPanel;
SoundManager soundManager;
public GamePanel (InfoPanel infoPanel) {
setBackground(new Color(0,100,0));
this.infoPanel = infoPanel;
this.soundManager = SoundManager.getInstance();
}
public void createGameEntities() {
player = new Player (this, 10, 375);
goal = new Goal(this,150,5);
}
public void kickBall(){
if(football!=null){
if(football.gety()<0){
soundManager.playSound("kick", false);
football = new Football(this,infoPanel,player,this.goal);
football.start();
}
}else{
soundManager.playSound("kick", false);
football = new Football(this,infoPanel,player,this.goal);
football.start();}
}
public void startGoal(){
soundManager.playSound("game_intro", false);
soundManager.playSound("whistle",false);
goal = new Goal(this,150,5);
goal.start();
soundManager.playSound("background",true);
}
public void drawGameEntities() {
if (player != null&&goal!= null){
player.draw();
goal.draw();
}
}
public void updateGameEntities(int direction) {
if (player == null)
return;
if (direction == 1) {
player.erase();
player.moveLeft();
}
else
if (direction == 3) {
player.erase();
player.moveRight();
}
}
public void setX (int xPos) {
x = xPos;
}
public void setY (int yPos) {
y = yPos;
}
public void paintComponent (Graphics g) {
super.paintComponent(g);
}
}