-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadme.txt
153 lines (125 loc) · 4.81 KB
/
readme.txt
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
Final Project PBO
Game Flappy Bird
Pada game ini player harus mengarahkan karakter untuk melewati rintangan tanpa terjatuh dengan hati-hati. 'Karakter' akan lompat ketika ditekan dan akan jatuh bebas jika tidak ditekan. Jika player dapat mengenai objek tertentu maka akan dapat tambahan poin. Game akan berakhir jika 'karakter' mengenai rintangan atau jatuh. Skor tertinggi player akan dicatat.
sumber referensi : https://github.com/FunGameDeveloperFGD/JavaGame_FlappyBird
Aspek OOP yang diterapkan :
1. Casting/Conversion (src/main/GamePanel.java)
//casting
if (backgroundBox.x + backgroundBox.getWidth() <= 0) {
backgroundBox.x = (int) (backgroundBox.x + backgroundBox.getWidth());
}
if (floorBox.x + floorBox.getWidth() <= 0) {
floorBox.x = (int) (floorBox.x + floorBox.getWidth());
}
2. Constructor (src/main/Game.java, src/main/Obstacle)
public Obstacle(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
topPipe = new Rectangle(x, y, width, height);
bottomPipe = new Rectangle(x, height + distance, width, height);
}
3. Overriding (src/main/GamePanel.java)
@Override
public void run() {
try {
requestFocus();
start();
while (isRunning) {
update();
draw();
Thread.sleep(1000 / 60);
}
} catch (Exception e) {
e.printStackTrace();
}
}
4. Inheritance (src/main/GamePanel.java)
//inheritance
public class GamePanel extends JPanel implements Runnable, MouseListener{
5. Exception Handling (src/main/GamePanel.java)
public void start() {
//exception handling
try {
view = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_RGB);
background = ImageIO.read(getClass().getResource("/assets/background.png"));
floor = ImageIO.read(getClass().getResource("/assets/floor.png"));
tapToStartTheGame = ImageIO.read(getClass().getResource("/assets/tap_to_start_the_game.png"));
BufferedImage fly = ImageIO.read(getClass().getResource("/assets/flappy_sprite_sheet.png"));
topPipe = ImageIO.read(getClass().getResource("/assets/top_pipe.png"));
bottomPipe = ImageIO.read(getClass().getResource("/assets/bottom_pipe.png"));
flyBirdAmin = new BufferedImage[3];
for (int i = 0; i < 3; i++) {
flyBirdAmin[i] = fly.getSubimage(i * 17, 0, 17, 12);
}
bird = flyBirdAmin[0];
DISTORTION = (SIZE / background.getHeight());
obstacles = new Obstacle[4];
startPositionObstacles();
int widthTapStartGame = tapToStartTheGame.getWidth() * DISTORTION;
int heightTapStartGame = tapToStartTheGame.getHeight() * DISTORTION;
tapToStartTheGameBox = new Rectangle(
(SIZE / 2) - (widthTapStartGame / 2),
(SIZE / 2) - (heightTapStartGame / 2),
widthTapStartGame,
heightTapStartGame
);
flappyBox = new Rectangle(
0,
0,
bird.getWidth() * DISTORTION,
bird.getHeight() * DISTORTION
);
backgroundBox = new Rectangle(
0,
0,
background.getWidth() * DISTORTION,
background.getHeight() * DISTORTION
);
floorBox = new Rectangle(
0,
SIZE - (floor.getHeight() * DISTORTION),
floor.getWidth() * DISTORTION,
floor.getHeight() * DISTORTION
);
startPositionFlappy();
font = new Font("TimesRoman", Font.BOLD, 16 * DISTORTION);
} catch (Exception e) {
e.printStackTrace();
}
}
6. GUI (src/main/GameWindow.java)
public class GameWindow {
//GUI
private JFrame w;
public GameWindow(GamePanel gamePanel){
w = new JFrame();
w.setResizable(false);
w.add(gamePanel);
w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
w.pack();
w.setLocationRelativeTo(null);
w.setVisible(true);
}
}
7. Input Output (src/GamePanel.java)
//input
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
direction = Direction.Up;
}
@Override
public void mouseReleased(MouseEvent e) {
inGame = true;
direction = Direction.Down;
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}