The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'!
https://forums.lestoria.net
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.
83 lines
1.8 KiB
83 lines
1.8 KiB
#define OLC_PGE_APPLICATION
|
|
#include "olcPixelGameEngine.h"
|
|
#include "olcUTIL_Camera2D.h"
|
|
#define OLC_PGEX_TRANSFORMEDVIEW
|
|
#include "olcPGEX_TransformedView.h"
|
|
|
|
using namespace olc;
|
|
using namespace olc::utils;
|
|
|
|
const vi2d WINDOW_SIZE={24*8,24*8};
|
|
|
|
struct Player{
|
|
vf2d pos;
|
|
float moveSpd;
|
|
Player(){};
|
|
Player(vf2d pos,float moveSpd):
|
|
pos(pos),moveSpd(moveSpd){};
|
|
};
|
|
|
|
class Crawler : public olc::PixelGameEngine
|
|
{
|
|
const vi2d WORLD_SIZE={64,64};
|
|
Camera2D camera;
|
|
TileTransformedView view;
|
|
Player player=Player{{},100};
|
|
|
|
public:
|
|
Crawler()
|
|
{
|
|
sAppName = "Crawler Concept";
|
|
}
|
|
|
|
public:
|
|
bool OnUserCreate() override
|
|
{
|
|
camera=Camera2D{WINDOW_SIZE};
|
|
camera.SetMode(olc::utils::Camera2D::Mode::LazyFollow);
|
|
camera.SetTarget(player.pos);
|
|
camera.SetWorldBoundary({0,0},WORLD_SIZE*24);
|
|
camera.EnableWorldBoundary(true);
|
|
view=TileTransformedView{GetScreenSize(),{1,1}};
|
|
return true;
|
|
}
|
|
|
|
bool OnUserUpdate(float fElapsedTime) override
|
|
{
|
|
if(GetKey(RIGHT).bHeld){
|
|
player.pos.x+=fElapsedTime*player.moveSpd;
|
|
}
|
|
if(GetKey(LEFT).bHeld){
|
|
player.pos.x-=fElapsedTime*player.moveSpd;
|
|
}
|
|
if(GetKey(UP).bHeld){
|
|
player.pos.y-=fElapsedTime*player.moveSpd;
|
|
}
|
|
if(GetKey(DOWN).bHeld){
|
|
player.pos.y+=fElapsedTime*player.moveSpd;
|
|
}
|
|
|
|
camera.Update(fElapsedTime);
|
|
view.SetWorldOffset(camera.GetViewPosition());
|
|
//view.HandlePanAndZoom();
|
|
// called once per frame
|
|
Clear(BLACK);
|
|
for (int x = view.GetTopLeftTile().x/24; x <= view.GetBottomRightTile().x/24; x++){
|
|
for (int y = view.GetTopLeftTile().y/24; y <= view.GetBottomRightTile().y/24; y++){
|
|
view.DrawRect(vi2d{x,y}*24,{24,24},DARK_GREY);
|
|
}
|
|
}
|
|
view.DrawCircle(player.pos,8);
|
|
return true;
|
|
}
|
|
};
|
|
|
|
|
|
int main()
|
|
{
|
|
Crawler demo;
|
|
if (demo.Construct(WINDOW_SIZE.x, WINDOW_SIZE.y, 4, 4))
|
|
demo.Start();
|
|
|
|
return 0;
|
|
} |