A repository that sets up a C++ Project with the olcPixelGameEngine already loaded.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

78 lines
1.9 KiB

#define OLC_PGE_APPLICATION
#include <iostream>
#include "pixelGameEngine.h" // use this for drawing stuff to screen
using namespace olc;
class BallGame : public olc::PixelGameEngine
{
public:
BallGame()
{
sAppName = "Example";
}
public:
std::vector<int> data;
int TILE_WIDTH=16;
int TILE_HEIGHT=16;
int tileOffsetX=0;
int tileOffsetY=0;
int TV_WIDTH=TILE_WIDTH*8;
int TV_HEIGHT=TILE_HEIGHT*7;
int MAP_WIDTH=256;
int MAP_HEIGHT=240;
int TV_POSX=256/4;
int TV_POSY=240/4;
bool OnUserCreate() override
{
SetPixelMode(olc::Pixel::ALPHA);
ConsoleCaptureStdOut(true);
// Called once at the start, so create things here
for (int i=0;i<256*240;i++) {
data.push_back(rand()%255);
}
return true;
}
bool OnUserUpdate(float fElapsedTime) override
{
if (GetKey(olc::RIGHT).bPressed) {
tileOffsetX=std::clamp(tileOffsetX+1,0,MAP_WIDTH);
}
if (GetKey(olc::LEFT).bPressed) {
tileOffsetX=std::clamp(tileOffsetX-1,0,MAP_WIDTH);
}
if (GetKey(olc::UP).bPressed) {
tileOffsetY=std::clamp(tileOffsetY-1,0,MAP_HEIGHT);
}
if (GetKey(olc::DOWN).bPressed) {
tileOffsetY=std::clamp(tileOffsetY+1,0,MAP_HEIGHT);
}
for (int x=0;x<TV_WIDTH/TILE_WIDTH;x++) {
for (int y=0;y<TV_HEIGHT/TILE_HEIGHT;y++) {
int tileID=data[(tileOffsetY+y)*MAP_WIDTH+tileOffsetX+x];
FillRect({x*TILE_WIDTH+TV_POSX,y*TILE_HEIGHT+TV_POSY},{TILE_WIDTH,TILE_HEIGHT},olc::Pixel(tileID,tileID,tileID,255));
DrawStringDecal({x*TILE_WIDTH+TV_POSX,y*TILE_HEIGHT+TV_POSY},std::to_string(tileID),(tileID<128)?olc::WHITE:olc::BLACK,{0.5,0.5});
}
}
return true;
}
};
int main()
{
BallGame game;
if (game.Construct(256, 240, 4, 4))
game.Start();
return 0;
}
//--------------------------------------------------------------------------------------------------
// END OF FILE
//--------------------------------------------------------------------------------------------------