-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexample.cpp
140 lines (115 loc) · 4.39 KB
/
example.cpp
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
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
#define OLC_PGE_GAMEPAD
#include "olcPGEX_Gamepad.h"
class Test : public olc::PixelGameEngine {
bool OnUserCreate() override {
olc::GamePad::init();
return true;
}
olc::GamePad *gamepad = nullptr;
bool OnUserUpdate(float fElapsedTime) override {
Clear(olc::BLACK);
if (gamepad == nullptr || !gamepad->stillConnected) {
DrawString(10, 10, "Press the select button on a gamepad!");
gamepad = olc::GamePad::selectWithButton(olc::GPButtons::SELECT);
return true;
}
if (!gamepad->getButton(olc::GPButtons::L2).bHeld) {
FillRect(10, 10, 30, 10, olc::WHITE * gamepad->getAxis(olc::GPAxes::TL));
DrawRect(10, 10, 30, 10, olc::RED);
} else {
FillRect(10, 10, 30, 10, olc::WHITE * gamepad->getAxis(olc::GPAxes::TL));
DrawRect(10, 10, 30, 10, olc::BLUE);
}
if (!gamepad->getButton(olc::GPButtons::L1).bHeld) {
DrawRect(10, 30, 30, 10);
} else {
FillRect(10, 30, 30, 10);
}
if (!gamepad->getButton(olc::GPButtons::R2).bHeld) {
FillRect(360, 10, 30, 10, olc::WHITE * gamepad->getAxis(olc::GPAxes::TR));
DrawRect(360, 10, 30, 10, olc::RED);
} else {
FillRect(360, 10, 30, 10, olc::WHITE * gamepad->getAxis(olc::GPAxes::TR));
DrawRect(360, 10, 30, 10, olc::BLUE);
}
if (!gamepad->getButton(olc::GPButtons::R1).bHeld) {
DrawRect(360, 30, 30, 10);
} else {
FillRect(360, 30, 30, 10);
}
if (!gamepad->getButton(olc::GPButtons::FACE_U).bHeld) {
DrawCircle(360, 70, 10);
} else {
FillCircle(360, 70, 10);
}
if (gamepad->getButton(olc::GPButtons::FACE_U).bPressed) {
gamepad->startVibration(1);
} else if (gamepad->getButton(olc::GPButtons::FACE_U).bReleased) {
gamepad->stopVibration();
}
if (!gamepad->getButton(olc::GPButtons::FACE_L).bHeld) {
DrawCircle(345, 85, 10);
} else {
FillCircle(345, 85, 10);
}
if (!gamepad->getButton(olc::GPButtons::FACE_R).bHeld) {
DrawCircle(375, 85, 10);
} else {
FillCircle(375, 85, 10);
}
if (!gamepad->getButton(olc::GPButtons::FACE_D).bHeld) {
DrawCircle(360, 100, 10);
} else {
FillCircle(360, 100, 10);
}
if (!gamepad->getButton(olc::GPButtons::DPAD_U).bHeld) {
DrawRect(50, 100, 10, 10);
} else {
FillRect(50, 100, 10, 10);
}
if (!gamepad->getButton(olc::GPButtons::DPAD_D).bHeld) {
DrawRect(50, 120, 10, 10);
} else {
FillRect(50, 120, 10, 10);
}
if (!gamepad->getButton(olc::GPButtons::DPAD_L).bHeld) {
DrawRect(40, 110, 10, 10);
} else {
FillRect(40, 110, 10, 10);
}
if (!gamepad->getButton(olc::GPButtons::DPAD_R).bHeld) {
DrawRect(60, 110, 10, 10);
} else {
FillRect(60, 110, 10, 10);
}
if (!gamepad->getButton(olc::GPButtons::SELECT).bHeld) {
DrawRect(150, 30, 30, 10);
} else {
FillRect(150, 30, 30, 10);
}
if (!gamepad->getButton(olc::GPButtons::START).bHeld) {
DrawRect(200, 30, 30, 10);
} else {
FillRect(200, 30, 30, 10);
}
DrawLine(80, 115, gamepad->getAxis(olc::GPAxes::DX) * 10 + 80, gamepad->getAxis(olc::GPAxes::DY) * 10 + 115);
if (gamepad->getButton(olc::GPButtons::L3).bHeld) {
FillCircle(20 + gamepad->getAxis(olc::GPAxes::LX) * 10, 70 + gamepad->getAxis(olc::GPAxes::LY) * 10, 10);
} else {
DrawCircle(20 + gamepad->getAxis(olc::GPAxes::LX) * 10, 70 + gamepad->getAxis(olc::GPAxes::LY) * 10, 10);
}
if (gamepad->getButton(olc::GPButtons::R3).bHeld) {
FillCircle(320 + gamepad->getAxis(olc::GPAxes::RX) * 10, 100 + gamepad->getAxis(olc::GPAxes::RY) * 10, 10);
} else {
DrawCircle(320 + gamepad->getAxis(olc::GPAxes::RX) * 10, 100 + gamepad->getAxis(olc::GPAxes::RY) * 10, 10);
}
return true;
}
};
int main() {
Test test;
test.Construct(640, 480, 1, 1, false, true);
test.Start();
}