2024-05-15 11:39:51 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "gl2d/gl2d.h"
|
|
|
|
#include <glad/glad.h>
|
2024-05-15 12:35:20 +02:00
|
|
|
#include "shader.h"
|
|
|
|
#include "camera.h"
|
2024-05-15 11:39:51 +02:00
|
|
|
#include "glm/vec2.hpp"
|
2024-05-15 12:35:20 +02:00
|
|
|
#include <texture.h>
|
|
|
|
#include "renderer.h"
|
|
|
|
#include "skyBox.h"
|
2024-05-15 11:39:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
class GameInput
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
class Button
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
bool isPressed() { return pressed; };
|
|
|
|
bool isHeld() { return held; }
|
|
|
|
bool isReleased() { return released; }
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
friend GameInput;
|
|
|
|
|
|
|
|
bool held = 0;
|
|
|
|
bool pressed = 0;
|
|
|
|
bool released = 0;
|
|
|
|
|
|
|
|
void setPress()
|
|
|
|
{
|
|
|
|
pressed = true;
|
|
|
|
held = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setRelease()
|
|
|
|
{
|
|
|
|
released = true;
|
|
|
|
held = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void resetInput()
|
|
|
|
{
|
|
|
|
released = 0;
|
|
|
|
pressed = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-05-15 12:35:20 +02:00
|
|
|
enum keys
|
2024-05-15 11:39:51 +02:00
|
|
|
{
|
2024-05-15 12:35:20 +02:00
|
|
|
FRONT,
|
2024-05-15 11:39:51 +02:00
|
|
|
BACK,
|
|
|
|
LEFT,
|
|
|
|
RIGHT,
|
|
|
|
LEFT_CLICK,
|
|
|
|
RIGHT_CLICK,
|
|
|
|
DOWN,
|
|
|
|
UP,
|
|
|
|
C,
|
|
|
|
P,
|
|
|
|
BUTTONS_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
Button getKey(int k) const
|
|
|
|
{
|
2024-05-15 12:35:20 +02:00
|
|
|
if(k < 0 || k >= BUTTONS_COUNT)
|
2024-05-15 11:39:51 +02:00
|
|
|
{
|
|
|
|
return Button{};
|
|
|
|
}
|
|
|
|
|
|
|
|
return buttons[k];
|
|
|
|
}
|
|
|
|
|
2024-05-15 12:35:20 +02:00
|
|
|
void setKeyPress(int k)
|
2024-05-15 11:39:51 +02:00
|
|
|
{
|
|
|
|
if (k < 0 || k >= BUTTONS_COUNT)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
buttons[k].setPress();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setKeyRelease(int k)
|
|
|
|
{
|
|
|
|
if (k < 0 || k >= BUTTONS_COUNT)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
buttons[k].setRelease();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void resetInputsThisFrame()
|
|
|
|
{
|
2024-05-15 12:35:20 +02:00
|
|
|
for(int i=0; i< BUTTONS_COUNT; i++)
|
2024-05-15 11:39:51 +02:00
|
|
|
{
|
|
|
|
buttons[i].resetInput();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void resetInputsToZero()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < BUTTONS_COUNT; i++)
|
|
|
|
{
|
|
|
|
buttons[i].setRelease();
|
|
|
|
buttons[i].resetInput();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int getMousePosX() const
|
|
|
|
{
|
|
|
|
return mousePosX;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getMousePosY() const
|
|
|
|
{
|
|
|
|
return mousePosY;
|
|
|
|
}
|
|
|
|
|
|
|
|
glm::ivec2 getMousePos() const
|
|
|
|
{
|
|
|
|
return glm::ivec2(mousePosX, mousePosY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMousePosition(int x, int y)
|
|
|
|
{
|
|
|
|
mousePosX = x;
|
|
|
|
mousePosY = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
Button buttons[BUTTONS_COUNT];
|
|
|
|
int mousePosX;
|
|
|
|
int mousePosY;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2024-05-15 12:35:20 +02:00
|
|
|
|
2024-05-15 11:39:51 +02:00
|
|
|
class Game
|
|
|
|
{
|
|
|
|
public:
|
2024-05-15 12:35:20 +02:00
|
|
|
|
2024-05-15 11:39:51 +02:00
|
|
|
Game(int screenW, int screenH) { onCreate(screenW, screenH); }
|
|
|
|
~Game() { onDestroy(); }
|
|
|
|
|
2024-05-15 12:35:20 +02:00
|
|
|
void onUpdate(float deltaTime, const GameInput &input);
|
2024-05-15 11:39:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
void updateWindowMetrics(int screenW, int screenH);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
void onCreate(int screenW, int screenH);
|
|
|
|
|
|
|
|
void onDestroy() {};
|
|
|
|
|
|
|
|
gl2d::Renderer2D renderer2d;
|
|
|
|
gl2d::Font font;
|
|
|
|
int screenW, screenH;
|
|
|
|
|
2024-05-15 12:35:20 +02:00
|
|
|
Camera *camera = 0;
|
|
|
|
bool isCreativeCamera = 0;
|
|
|
|
|
|
|
|
ChunksRenderer renderer;
|
|
|
|
|
|
|
|
ChunkManager chunkManager;
|
|
|
|
|
|
|
|
gl2d::Texture arrowTexture;
|
|
|
|
|
|
|
|
SkyBox skyBox;
|
2024-05-15 11:39:51 +02:00
|
|
|
|
|
|
|
};
|