-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
100 lines (75 loc) · 1.88 KB
/
main.c
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
/* Pong Ultimate
*
* main.c
* Created by: S. Harrison
* Date: 15-09-2018
*/
#include "constants.h"
#include "pong.h"
Ball ball;
int batOffset = 20;
Scoreboard scoreboard;
Bat batLeft, batRight;
char scoreboard_text[100] = "";
Line lineTop, lineBottom, lineMiddle;
int main() {
initialize();
while(1) {
update();
draw();
display();
}
return 0;
}
void initialize() {
// setup initalizers
initializeScreen();
initializePad();
initializeDebugFont();
// define the background colour
setBackgroundColor(createColor(50, 50, 50));
// define the 'playing field'
lineTop = createLine(createColor(255, 255, 255), 0, 10, SCREEN_WIDTH, 10);
lineBottom = createLine(createColor(255, 255, 255), 0, SCREEN_HEIGHT - 20, SCREEN_WIDTH, SCREEN_HEIGHT - 20);
lineMiddle = createLine(createColor(150, 150, 150), SCREEN_WIDTH / 2, 0, SCREEN_WIDTH / 2, SCREEN_HEIGHT);
// define the bat objects
batLeft = createBat(batOffset);
batRight = createBat(SCREEN_WIDTH - batOffset);
// define the ball
ball = createBall();
// define the scoreboard
scoreboard = createScoreboard();
}
void update() {
// update based on controller input
padUpdate();
// check for Player 1 input
if (padCheck(Pad1Up)) {
batLeft = moveBat(batLeft, -2);
}
if (padCheck(Pad1Down)) {
batLeft = moveBat(batLeft, 2);
}
// check for Player 2 input
// dual input checks
if (padCheck(Pad1Start) || padCheck(Pad2Start)) {
ball = kickBall(ball);
}
// move the ball
ball = moveBall(ball, batLeft, batRight);
// update the scoreboard
sprintf(scoreboard_text, "%d:%d", scoreboard.score_left, scoreboard.score_right);
}
void draw() {
// draw the 'playing field'
drawLine(lineTop);
drawLine(lineBottom);
drawLine(lineMiddle);
// draw the 'bat' objects
drawBat(batLeft);
drawBat(batRight);
// draw the 'ball' object
drawBall(ball);
// draw the scoreboard
FntPrint(scoreboard_text);
}