SMX_PGE/sample/PGEX_SMX_Example.cpp

78 lines
1.9 KiB
C++
Raw Normal View History

2023-06-16 18:51:30 -05:00
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
2023-06-16 19:33:55 -05:00
#include "PGEX_SMX.h"
2023-06-16 18:51:30 -05:00
using namespace olc;
2017-12-14 20:02:36 -06:00
2023-06-16 18:51:30 -05:00
class SMX_PGE : public olc::PixelGameEngine
2017-12-14 20:02:36 -06:00
{
2023-06-16 19:33:55 -05:00
PGEX_SMX smx;
2023-06-16 18:44:07 -07:00
bool paused = false;
int mode = 0;
vf2d playerPos = { 0,0 };
2017-12-14 20:02:36 -06:00
public:
2023-06-16 18:51:30 -05:00
SMX_PGE()
2017-12-14 20:02:36 -06:00
{
2023-06-16 19:33:55 -05:00
sAppName = "SMX PGE";
2017-12-14 20:02:36 -06:00
}
2023-06-16 18:51:30 -05:00
public:
bool OnUserCreate() override
2017-12-14 20:02:36 -06:00
{
2023-06-16 18:51:30 -05:00
// Called once at the start, so create things here
return true;
}
2017-12-14 20:02:36 -06:00
2023-06-16 18:51:30 -05:00
bool OnUserUpdate(float fElapsedTime) override
{
2023-06-16 18:45:54 -07:00
smx.GetPanel(RIGHT, 0).bHeld;
2023-06-16 18:44:07 -07:00
if (GetKey(RIGHT).bPressed) {
mode = (mode + 1) % 3;
}
switch (mode) {
case 0: {
if (GetKey(SPACE).bPressed) {
paused = !paused;
}
// called once per frame
if (!paused) {
for (int x = 0; x < ScreenWidth(); x++)
for (int y = 0; y < ScreenHeight(); y++)
Draw(x, y, olc::Pixel(rand() % 255, rand() % 255, rand() % 255));
}
}break;
case 1: {
Clear(DARK_CYAN);
DrawRect({ 1,1 }, { 9,18 }, RED);
}break;
case 2: {
Clear(VERY_DARK_BLUE);
FillCircle(playerPos, 3,VERY_DARK_GREY);
DrawCircle(playerPos, 3);
if (GetKey(W).bHeld) {
playerPos.y -= 5*fElapsedTime;
}
if (GetKey(A).bHeld) {
playerPos.x -= 5 * fElapsedTime;
}
if (GetKey(S).bHeld) {
playerPos.y += 5 * fElapsedTime;
}
if (GetKey(D).bHeld) {
playerPos.x += 5 * fElapsedTime;
}
}break;
}
2023-06-16 18:51:30 -05:00
return true;
2017-12-14 20:02:36 -06:00
}
};
2023-06-16 18:51:30 -05:00
2017-12-14 20:02:36 -06:00
int main()
{
2023-06-16 18:51:30 -05:00
SMX_PGE demo;
2023-06-16 19:33:55 -05:00
if (demo.Construct(12, 21, 50, 50))
2023-06-16 18:51:30 -05:00
demo.Start();
2017-12-14 20:02:36 -06:00
return 0;
}