Skip to content

Instantly share code, notes, and snippets.

@wgaylord
Last active September 15, 2023 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wgaylord/af4bcdadbce8d2c61a2b509aeaca6d38 to your computer and use it in GitHub Desktop.
Save wgaylord/af4bcdadbce8d2c61a2b509aeaca6d38 to your computer and use it in GitHub Desktop.
Memory Allocator game.
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
#include <ctime>
bool CheckBounds(int mouseX, int mouseY, int top, int left, int width, int height);
struct item {
int size;
int startingIndex;
int id;
int lifespan;
int removalTime;
olc::Pixel color;
};
std::string seed = "";
std::string scores = "";
#if defined(OLC_PLATFORM_EMSCRIPTEN)
#define OLC_SOUNDWAVE
#include "olcSoundWaveEngine.h"
#include <emscripten/fetch.h>
void downloadSucceeded(emscripten_fetch_t * fetch) {
scores = fetch -> data;
emscripten_fetch_close(fetch);
}
void downloadFailed(emscripten_fetch_t * fetch) {
emscripten_fetch_close(fetch); // Also free data on failure.
}
void postScore(std::string name, int score) {
emscripten_fetch_attr_t attr;
emscripten_fetch_attr_init( & attr);
strcpy(attr.requestMethod, "GET");
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY | EMSCRIPTEN_FETCH_REPLACE;
attr.onsuccess = downloadSucceeded;
attr.onerror = downloadFailed;
emscripten_fetch( & attr, ("redacted");
}
#else
void postScore(std::string name, int score) {
scores = "Your Score:\n " + name + " " + std::to_string(score);
}
#endif
class Example: public olc::PixelGameEngine
{
olc::Sprite MainMenuBackgrounds[5];
olc::Sprite MainGameBackgrounds[5];
olc::Sprite DirectionsBackground;
olc::Sprite Directions[5];
olc::Sprite GameOver;
olc::Sprite PostScore;
olc::Sprite StartButton;
olc::Sprite StartButtonPressed;
olc::Sprite NextButton;
olc::Sprite NextButtonPressed;
olc::Sprite BackButton;
olc::Sprite BackButtonPressed;
olc::Sprite PostButton;
olc::Sprite PostButtonPressed;
olc::Sprite DontPostButton;
olc::Sprite DontPostButtonPressed;
olc::Sprite PlayAgainButton;
olc::Sprite PlayAgainButtonPressed;
int dirctionStage = 0;
int GameState = 0;
std::vector < item > MemoryObjects;
item CurrentMemoryObject;
int score = 0;
int Value = 100;
bool valueReady = true;
int EndTime = time(0);
std::string name = "<BLANK>";
bool MainSoundStarted = false;
bool RushSoundStarted = false;
int start = time(0);
#if defined(OLC_PLATFORM_EMSCRIPTEN)
olc::sound::WaveEngine engine;
olc::sound::Wave mainWave;
olc::sound::Wave rushWave;
#endif
bool enterSeed = false;
int actualSeed = time(0);
public:
Example()
{
sAppName = "Example";
}
public:
bool OnUserCreate() override
{
MainMenuBackgrounds[0] = olc::Sprite("./assets/main_menu_backgrounds/0.png");
MainMenuBackgrounds[1] = olc::Sprite("./assets/main_menu_backgrounds/1.png");
MainMenuBackgrounds[2] = olc::Sprite("./assets/main_menu_backgrounds/2.png");
MainMenuBackgrounds[3] = olc::Sprite("./assets/main_menu_backgrounds/3.png");
MainMenuBackgrounds[4] = olc::Sprite("./assets/main_menu_backgrounds/4.png");
StartButton = olc::Sprite("./assets/buttons/start.png");
StartButtonPressed = olc::Sprite("./assets/buttons/start_pressed.png");
NextButton = olc::Sprite("./assets/buttons/next.png");
NextButtonPressed = olc::Sprite("./assets/buttons/next_pressed.png");
BackButton = olc::Sprite("./assets/buttons/back.png");
BackButtonPressed = olc::Sprite("./assets/buttons/back_pressed.png");
PostButton = olc::Sprite("./assets/buttons/post.png");
PostButtonPressed = olc::Sprite("./assets/buttons/post_pressed.png");
DontPostButton = olc::Sprite("./assets/buttons/dont_post.png");
DontPostButtonPressed = olc::Sprite("./assets/buttons/dont_post_pressed.png");
PlayAgainButton = olc::Sprite("./assets/buttons/play_again.png");
PlayAgainButtonPressed = olc::Sprite("./assets/buttons/play_again_pressed.png");
GameOver = olc::Sprite("./assets/game_over.png");
PostScore = olc::Sprite("./assets/main_menu_backgrounds/0.png");
Directions[0] = olc::Sprite("./assets/directions/0.png");
Directions[1] = olc::Sprite("./assets/directions/1.png");
Directions[2] = olc::Sprite("./assets/directions/2.png");
Directions[3] = olc::Sprite("./assets/directions/3.png");
Directions[4] = olc::Sprite("./assets/directions/4.png");
DirectionsBackground = olc::Sprite("./assets/directions/background.png");
MainGameBackgrounds[0] = olc::Sprite("./assets/main_game_backgrounds/0.png");
MainGameBackgrounds[1] = olc::Sprite("./assets/main_game_backgrounds/1.png");
MainGameBackgrounds[2] = olc::Sprite("./assets/main_game_backgrounds/2.png");
MainGameBackgrounds[3] = olc::Sprite("./assets/main_game_backgrounds/3.png");
MainGameBackgrounds[4] = olc::Sprite("./assets/main_game_backgrounds/4.png");
#if defined(OLC_PLATFORM_EMSCRIPTEN)
rushWave.LoadAudioWaveform("./assets/8bitDungeonBoss.wav");
mainWave.LoadAudioWaveform("./assets/8bitDungeonLevel.wav");
engine.InitialiseAudio(44100, 2);
engine.SetOutputVolume(0.5);
#endif
srand(actualSeed);
return true;
}
bool OnUserUpdate(float fElapsedTime) override
{
SetPixelMode(olc::Pixel::ALPHA); // Dont draw pixels which have any transparency
switch (GameState) {
case 0:
DrawMainMenu(fElapsedTime);
return true;
case 1:
DrawDirections(fElapsedTime);
return true;
case 2:
DrawGame(fElapsedTime);
return true;
case 3:
DrawPostScore(fElapsedTime);
return true;
case 4:
DrawGameOver(fElapsedTime);
return true;
}
return true;
}
void DrawMainMenu(float fElapsedTime) {
int animationIndex = (time(0) % 4);
DrawSprite({
0,
0
}, & MainMenuBackgrounds[animationIndex]);
if (CheckBounds(GetMouseX(), GetMouseY(), 110, 120, 100, 50)) {
DrawSprite({
110,
120
}, & StartButtonPressed);
if (GetMouse(0).bPressed)
{
GameState = 1;
if (seed != "") {
srand(stoi(seed));
actualSeed = stoi(seed);
}
}
} else {
DrawSprite({
110,
120
}, & StartButton);
}
if (GetKey(olc::Key::S).bPressed) {
enterSeed = true;
}
if (enterSeed) {
std::string temp = GetNumKey();
printf("%s", temp.c_str());
if (temp == "BACK" && name.length() > 0) {
seed = seed.substr(0, seed.length() - 1);
} else {
if (seed.length() < 10 and temp != "BACK") {
seed += temp;
}
}
DrawString({
30,
85
}, "Seed: ", olc::BLACK);
DrawString({
75,
85
}, seed, olc::BLACK);
DrawLine({
75,
93
}, {
160,
93
}, olc::BLACK);
}
}
void DrawPostScore(float fElapsedTime) {
DrawSprite({
0,
0
}, & PostScore);
if (seed != "") {
DrawString({
200,
230
}, "Seed: " + seed);
}
std::string temp = GetTypedKey();
printf("%s", temp.c_str());
if (temp == "BACK" && name.length() > 0) {
name = name.substr(0, name.length() - 1);
} else {
if (name.length() < 10 and temp != "BACK") {
name += temp;
}
}
DrawString({
30,
85
}, "Name: ", olc::BLACK);
DrawString({
75,
85
}, name, olc::BLACK);
DrawLine({
75,
93
}, {
160,
93
}, olc::BLACK);
DrawString({
20,
100
}, "Score: ", olc::BLACK);
DrawString({
75,
100
}, std::to_string(score), olc::BLACK);
if (CheckBounds(GetMouseX(), GetMouseY(), 210, 160, 100, 50) && name.length() > 0) {
DrawSprite({
210,
160
}, & PostButtonPressed);
if (GetMouse(0).bPressed)
{
postScore(name, score);
GameState = 4;
}
} else {
DrawSprite({
210,
160
}, & PostButton);
}
if (CheckBounds(GetMouseX(), GetMouseY(), 10, 160, 100, 50)) {
DrawSprite({
10,
160
}, & DontPostButtonPressed);
if (GetMouse(0).bPressed)
{
scores = "Your Score:\n" + std::to_string(score);
GameState = 4;
}
} else {
DrawSprite({
10,
160
}, & DontPostButton);
}
}
void DrawGameOver(float fElapsedTime) {
int animationIndex = time(0) % 5;
DrawSprite({
0,
0
}, & GameOver);
if (seed != "") {
DrawString({
200,
230
}, "Seed: " + seed);
}
DrawString({
65,
85
}, scores, olc::BLACK);
if (CheckBounds(GetMouseX(), GetMouseY(), 115, 200, 100, 50)) {
DrawSprite({
115,
200
}, & PlayAgainButtonPressed);
if (GetMouse(0).bPressed)
{
scores = "";
dirctionStage = 4;
GameState = 1;
MemoryObjects.clear();
if (seed != "") {
srand(actualSeed);
}
CurrentMemoryObject.startingIndex = 0;
score = 0;
Value = 100;
valueReady = true;
EndTime = time(0);
name = "<BLANK>";
MainSoundStarted = false;
RushSoundStarted = false;
start = time(0);
}
} else {
DrawSprite({
115,
200
}, & PlayAgainButton);
}
}
void DrawGame(float fElapsedTime) {
int remainingTime = EndTime - time(0);
#if defined(OLC_PLATFORM_EMSCRIPTEN)
if (!MainSoundStarted and(time(0) - start) > 2) {
engine.PlayWaveform( & mainWave);
MainSoundStarted = true;
}
if (!RushSoundStarted and remainingTime < 30) {
engine.StopAll();
engine.PlayWaveform( & rushWave);
RushSoundStarted = true;
}
#endif
bool filled[320];
int animationIndex = (time(0) % 4);
DrawSprite({
0,
0
}, & MainGameBackgrounds[animationIndex]);
if (seed != "") {
DrawString({
200,
230
}, "Seed: " + seed);
}
DrawRect({
5,
5
}, {
180,
225
}, olc::BLACK);
for (int y = 0; y < 320; y += 1) {
DrawMemoryCell(y, olc::GREY);
filled[y] = false;
}
if (time(0) % 2 == 0 && valueReady) {
Value -= 10;
valueReady = false;
}
if (time(0) % 2 == 1) {
valueReady = true;
}
if (Value < 0) {
Value = 0;
}
int IndexToRemove = -1;
for (unsigned int i = 0; i < MemoryObjects.size(); i++)
{
item obj = MemoryObjects[i];
//printf("%d %d %d\n", time(0), obj.removalTime, obj.removalTime < time(0));
if (obj.removalTime < time(0)) {
IndexToRemove = i;
}
if (obj.startingIndex >= 0) {
for (int x = 0; x < obj.size; x += 1) {
DrawMemoryCell(obj.startingIndex + x, obj.color);
filled[obj.startingIndex + x] = true;
}
}
}
int mouseIndex = GetMouseCellIndex();
if (mouseIndex >= 0) {
bool NotOkay = false;
for (int x = 0; x < CurrentMemoryObject.size; x += 1) {
NotOkay = NotOkay || filled[mouseIndex + x];
}
if (!NotOkay and!(mouseIndex + CurrentMemoryObject.size > 320)) {
for (int x = 0; x < CurrentMemoryObject.size; x += 1) {
DrawMemoryCell(mouseIndex + x, CurrentMemoryObject.color);
}
}
if (!NotOkay && GetMouse(0).bHeld and!(mouseIndex + CurrentMemoryObject.size > 320)) {
CurrentMemoryObject.startingIndex = mouseIndex;
CurrentMemoryObject.removalTime = time(0) + CurrentMemoryObject.lifespan;
MemoryObjects.push_back(CurrentMemoryObject);
score += Value;
for (int x = 0; x < CurrentMemoryObject.size; x += 1) {
DrawMemoryCell(mouseIndex + x, CurrentMemoryObject.color);
}
}
}
if (MemoryObjects.size() > 0 && IndexToRemove != -1) {
MemoryObjects.erase(MemoryObjects.begin() + IndexToRemove);
}
if (CurrentMemoryObject.startingIndex != -1) {
CurrentMemoryObject = MakeRandomItem();
Value = 25 * CurrentMemoryObject.size;
}
if (EndTime - time(0) < 0) {
GameState = 3;
#if defined(OLC_PLATFORM_EMSCRIPTEN)
engine.StopAll();
#endif
}
if (remainingTime < 30) {
DrawString({
205,
200
}, "Time Remaining", olc::BLACK);
DrawString({
230,
210
}, std::to_string(remainingTime) + "s", olc::RED);
} else {
DrawString({
205,
200
}, "Time Remaining", olc::BLACK);
DrawString({
230,
210
}, std::to_string((int) floor(remainingTime / 60)) + "m" + std::to_string(remainingTime % 60) + "s", olc::BLACK);
}
DrawString({
205,
20
}, "Next Size: " + std::to_string(CurrentMemoryObject.size), olc::BLACK);
DrawString({
205,
50
}, "Object Value", olc::BLACK);
DrawString({
230,
60
}, std::to_string(Value), olc::BLACK);
DrawString({
205,
80
}, "Current Score", olc::BLACK);
DrawString({
230,
90
}, std::to_string(score), olc::BLACK);
}
void DrawMemoryCell(int index, olc::Pixel color) {
int x = index % 16;
int y = floor(index / 16);
DrawRect({
8 + (x * 11),
8 + (11 * y)
}, {
9,
9
}, olc::BLACK);
FillRect({
9 + (x * 11),
9 + (11 * y)
}, {
8,
8
}, color);
}
int GetMouseCellIndex() {
for (int index = 0; index < 320; index += 1) {
int x = index % 16;
int y = floor(index / 16);
if (CheckBounds(GetMouseX(), GetMouseY(), 8 + (x * 11), 8 + (11 * y), 9, 9)) {
return index;
}
}
return -1;
}
int lifespans[12] = {
5,
10,
12,
14,
16,
18,
20,
22,
24,
26,
28,
30
};
item MakeRandomItem() {
item t;
t.color = RandomColor();
t.size = (rand() % 24) + 1;
t.startingIndex = -1;
t.lifespan = lifespans[rand() % 12];
return t;
}
olc::Pixel RandomColor() {
switch (rand() % 18) {
case 0:
return olc::RED;
case 1:
return olc::DARK_RED;
case 2:
return olc::VERY_DARK_RED;
case 3:
return olc::YELLOW;
case 4:
return olc::DARK_YELLOW;
case 5:
return olc::VERY_DARK_YELLOW;
case 6:
return olc::GREEN;
case 7:
return olc::DARK_GREEN;
case 8:
return olc::VERY_DARK_GREEN;
case 9:
return olc::CYAN;
case 10:
return olc::DARK_CYAN;
case 11:
return olc::VERY_DARK_CYAN;
case 12:
return olc::BLUE;
case 13:
return olc::DARK_BLUE;
case 14:
return olc::VERY_DARK_BLUE;
case 15:
return olc::MAGENTA;
case 16:
return olc::DARK_MAGENTA;
case 17:
return olc::VERY_DARK_MAGENTA;
}
return olc::BLACK;
}
void DrawDirections(float fElapsedTime) {
DrawSprite({
0,
0
}, & DirectionsBackground);
DrawString({
280,
220
}, std::to_string(dirctionStage) + "/4", olc::BLACK);
DrawRect({
5,
5
}, {
180,
225
}, olc::BLACK);
for (int y = 0; y < 20; y += 1) {
for (int x = 0; x < 16; x += 1) {
DrawRect({
8 + (x * 11),
8 + (11 * y)
}, {
9,
9
}, olc::BLACK);
FillRect({
9 + (x * 11),
9 + (11 * y)
}, {
8,
8
}, olc::GREY);
}
}
if (dirctionStage == 0 || dirctionStage == 1) {
DrawString({
205,
20
}, "Next Size: " + std::to_string(9), olc::BLACK);
DrawString({
205,
50
}, "Object Value", olc::BLACK);
DrawString({
230,
60
}, std::to_string(25 * 9), olc::BLACK);
DrawString({
205,
80
}, "Current Score", olc::BLACK);
DrawString({
230,
90
}, std::to_string(0), olc::BLACK);
}
if (dirctionStage == 2) {
DrawString({
205,
20
}, "Next Size: " + std::to_string(5), olc::BLACK);
DrawString({
205,
50
}, "Object Value", olc::BLACK);
DrawString({
230,
60
}, std::to_string(5 * 25), olc::BLACK);
DrawString({
205,
80
}, "Current Score", olc::BLACK);
DrawString({
230,
90
}, std::to_string(25 * 9), olc::BLACK);
}
if (dirctionStage == 3) {
DrawString({
205,
20
}, "Next Size: " + std::to_string(5), olc::BLACK);
DrawString({
205,
50
}, "Object Value", olc::BLACK);
DrawString({
230,
60
}, std::to_string(5 * 25), olc::BLACK);
DrawString({
205,
80
}, "Current Score", olc::BLACK);
DrawString({
230,
90
}, std::to_string(25 * 9), olc::BLACK);
}
if (dirctionStage == 4) {
DrawString({
205,
20
}, "Next Size: " + std::to_string(3), olc::BLACK);
DrawString({
205,
50
}, "Object Value", olc::BLACK);
DrawString({
230,
60
}, std::to_string(3 * 25), olc::BLACK);
DrawString({
205,
80
}, "Current Score", olc::BLACK);
DrawString({
230,
90
}, std::to_string(25 * 14), olc::BLACK);
}
if (dirctionStage == 2 || dirctionStage == 3) {
for (int x = 0; x < 9; x += 1) {
DrawMemoryCell(0 + x, olc::BLUE);
}
}
if (dirctionStage == 4) {
for (int x = 0; x < 9; x += 1) {
DrawMemoryCell(0 + x, olc::BLUE);
}
for (int x = 0; x < 5; x += 1) {
DrawMemoryCell(9 + x, olc::RED);
}
}
if (dirctionStage < 4) {
if (CheckBounds(GetMouseX(), GetMouseY(), 210, 110, 100, 50)) {
DrawSprite({
210,
110
}, & NextButtonPressed);
if (GetMouse(0).bPressed)
{
dirctionStage += 1;
}
} else {
DrawSprite({
210,
110
}, & NextButton);
}
} else {
if (CheckBounds(GetMouseX(), GetMouseY(), 210, 110, 100, 50)) {
DrawSprite({
210,
110
}, & StartButtonPressed);
if (GetMouse(0).bPressed)
{
dirctionStage += 1;
if (dirctionStage > 4) {
GameState = 2;
EndTime = time(0) + 180;
}
}
} else {
DrawSprite({
210,
110
}, & StartButton);
}
}
if (dirctionStage > 0) {
if (CheckBounds(GetMouseX(), GetMouseY(), 210, 165, 100, 50)) {
DrawSprite({
210,
165
}, & BackButtonPressed);
if (GetMouse(0).bPressed)
{
dirctionStage -= 1;
}
} else {
DrawSprite({
210,
165
}, & BackButton);
}
}
DrawSprite({
0,
0
}, & Directions[dirctionStage]);
switch (dirctionStage) {
case 0:
DrawString({
30,
20
}, "Current Object Size\nHow many cells\nthe object takes up\n\nCurrent point value\nof the object.\n\nYour Score.", olc::BLACK);
return;
case 1:
DrawString({
163,
17
}, "These are cells\nthey hold objects.\n\nThere are 16\ncells per row.", olc::BLACK);
return;
case 2:
DrawString({
127,
44
}, "This is an Object.\nThe goal of the game\nis to place as many\nas you can to get\nthere value added to\nyour score.\nThis Object is\n9 cells in size.", olc::BLACK);
return;
case 3:
DrawString({
125,
44
}, "You place Objects by\nclicking cells.\nOver time the value\nof Objects decrease.\nObjects will\nrandomly be 'freed'\nover time giving you\nmore space.", olc::BLACK);
return;
case 4:
DrawString({
45,
64
}, "That is all there\nis to the game.\nYou have 3 min to\nget as high of\nscore as possible.", olc::BLACK);
return;
}
}
std::string GetNumKey() {
if (GetKey(olc::Key::NP0).bPressed || GetKey(olc::Key::K0).bPressed) return "0";
if (GetKey(olc::Key::NP1).bPressed || GetKey(olc::Key::K1).bPressed) return "1";
if (GetKey(olc::Key::NP2).bPressed || GetKey(olc::Key::K2).bPressed) return "2";
if (GetKey(olc::Key::NP3).bPressed || GetKey(olc::Key::K3).bPressed) return "3";
if (GetKey(olc::Key::NP4).bPressed || GetKey(olc::Key::K4).bPressed) return "4";
if (GetKey(olc::Key::NP5).bPressed || GetKey(olc::Key::K5).bPressed) return "5";
if (GetKey(olc::Key::NP6).bPressed || GetKey(olc::Key::K6).bPressed) return "6";
if (GetKey(olc::Key::NP7).bPressed || GetKey(olc::Key::K7).bPressed) return "7";
if (GetKey(olc::Key::NP8).bPressed || GetKey(olc::Key::K8).bPressed) return "8";
if (GetKey(olc::Key::NP9).bPressed || GetKey(olc::Key::K9).bPressed) return "9";
if (GetKey(olc::Key::BACK).bPressed) return "BACK";
return "";
}
std::string GetTypedKey() {
if (GetKey(olc::Key::A).bPressed) return "A";
if (GetKey(olc::Key::B).bPressed) return "B";
if (GetKey(olc::Key::C).bPressed) return "C";
if (GetKey(olc::Key::D).bPressed) return "D";
if (GetKey(olc::Key::E).bPressed) return "E";
if (GetKey(olc::Key::F).bPressed) return "F";
if (GetKey(olc::Key::G).bPressed) return "G";
if (GetKey(olc::Key::H).bPressed) return "H";
if (GetKey(olc::Key::I).bPressed) return "I";
if (GetKey(olc::Key::J).bPressed) return "J";
if (GetKey(olc::Key::K).bPressed) return "K";
if (GetKey(olc::Key::L).bPressed) return "L";
if (GetKey(olc::Key::M).bPressed) return "M";
if (GetKey(olc::Key::N).bPressed) return "N";
if (GetKey(olc::Key::O).bPressed) return "O";
if (GetKey(olc::Key::P).bPressed) return "P";
if (GetKey(olc::Key::Q).bPressed) return "Q";
if (GetKey(olc::Key::R).bPressed) return "R";
if (GetKey(olc::Key::S).bPressed) return "S";
if (GetKey(olc::Key::T).bPressed) return "T";
if (GetKey(olc::Key::U).bPressed) return "U";
if (GetKey(olc::Key::V).bPressed) return "V";
if (GetKey(olc::Key::W).bPressed) return "W";
if (GetKey(olc::Key::X).bPressed) return "X";
if (GetKey(olc::Key::Y).bPressed) return "Y";
if (GetKey(olc::Key::Z).bPressed) return "Z";
if (GetKey(olc::Key::NP0).bPressed || GetKey(olc::Key::K0).bPressed) return "0";
if (GetKey(olc::Key::NP1).bPressed || GetKey(olc::Key::K1).bPressed) return "1";
if (GetKey(olc::Key::NP2).bPressed || GetKey(olc::Key::K2).bPressed) return "2";
if (GetKey(olc::Key::NP3).bPressed || GetKey(olc::Key::K3).bPressed) return "3";
if (GetKey(olc::Key::NP4).bPressed || GetKey(olc::Key::K4).bPressed) return "4";
if (GetKey(olc::Key::NP5).bPressed || GetKey(olc::Key::K5).bPressed) return "5";
if (GetKey(olc::Key::NP6).bPressed || GetKey(olc::Key::K6).bPressed) return "6";
if (GetKey(olc::Key::NP7).bPressed || GetKey(olc::Key::K7).bPressed) return "7";
if (GetKey(olc::Key::NP8).bPressed || GetKey(olc::Key::K8).bPressed) return "8";
if (GetKey(olc::Key::NP9).bPressed || GetKey(olc::Key::K9).bPressed) return "9";
if (GetKey(olc::Key::BACK).bPressed) return "BACK";
return "";
}
};
bool CheckBounds(int mouseX, int mouseY, int left, int top, int width, int height) {
return (mouseY > top && mouseY < top + height) && (mouseX > left && mouseX < left + width);
}
int main()
{
Example demo;
if (demo.Construct(320, 240, 4, 4))
demo.Start();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment