180 lines
3.9 KiB
C++
Executable File
180 lines
3.9 KiB
C++
Executable File
#pragma once
|
|
|
|
#include <string>
|
|
|
|
#include "utils/Random.hpp"
|
|
|
|
struct Vector2;
|
|
struct Color;
|
|
struct Rectangle;
|
|
struct Texture;
|
|
struct RenderTexture;
|
|
struct Camera2D;
|
|
|
|
#ifdef PANDA_INCLUDE_TYPE
|
|
|
|
struct Vector2 {
|
|
float x;
|
|
float y;
|
|
};
|
|
|
|
struct Color {
|
|
unsigned char r;
|
|
unsigned char g;
|
|
unsigned char b;
|
|
unsigned char a;
|
|
};
|
|
|
|
struct Rectangle {
|
|
float x;
|
|
float y;
|
|
float width;
|
|
float height;
|
|
}
|
|
|
|
struct Texture {
|
|
unsigned int id;
|
|
int width;
|
|
int height;
|
|
int mipmaps;
|
|
int format;
|
|
}
|
|
|
|
struct RenderTexture {
|
|
unsigned int id;
|
|
Texture texture;
|
|
Texture depth;
|
|
}
|
|
|
|
struct Camera2D {
|
|
Vector2 offset;
|
|
Vector2 target;
|
|
float rotation;
|
|
float zoom;
|
|
}
|
|
|
|
#endif
|
|
|
|
namespace panda
|
|
{
|
|
struct TextureAtlasItem
|
|
{
|
|
int x;
|
|
int y;
|
|
int w;
|
|
int h;
|
|
float px;
|
|
float py;
|
|
};
|
|
|
|
class Scene {
|
|
public:
|
|
Scene() {}
|
|
virtual ~Scene() {}
|
|
virtual void Preload() {}
|
|
virtual void Update() {}
|
|
|
|
bool preloaded = false;
|
|
};
|
|
|
|
struct Sprite {
|
|
Texture *texture;
|
|
|
|
void SetPivot(Vector2 ratio);
|
|
void SetPivotRatio(Vector2 ratio);
|
|
void SetFlip(bool x, bool y);
|
|
void SetFlipX(bool x);
|
|
void SetFlipY(bool y);
|
|
|
|
Vector2 GetPivot() const;
|
|
Vector2 GetPivotFlip() const;
|
|
bool GetFlipX() const;
|
|
bool GetFlipY() const;
|
|
|
|
private:
|
|
bool flipX = false;
|
|
bool flipY = false;
|
|
float pivotX = 0.0f;
|
|
float pivotY = 0.0f;
|
|
float pivotX_flip = 0.0f;
|
|
float pivotY_flip = 0.0f;
|
|
|
|
void CalculatePivotFlip();
|
|
};
|
|
|
|
struct Matrix {
|
|
float a = 1.0f;
|
|
float b = 0.0f;
|
|
float c = 0.0f;
|
|
float d = 1.0f;
|
|
float tx = 0.0f;
|
|
float ty = 0.0f;
|
|
|
|
void identity();
|
|
void translate(float dx, float dy);
|
|
void rotate(float radian);
|
|
void scale(float sx, float sy);
|
|
|
|
void concat(Matrix m);
|
|
};
|
|
|
|
class App {
|
|
public:
|
|
void CreateWindow(int w, int h, const char *str);
|
|
|
|
void AppUpdate();
|
|
void SetScene(Scene* scene);
|
|
Scene* GetScene();
|
|
|
|
private:
|
|
Scene* _scene_current = nullptr;
|
|
};
|
|
|
|
// ############################################################################################
|
|
|
|
// # Graphic
|
|
|
|
// ### GUI
|
|
void GuiInit();
|
|
void GuiDestroy();
|
|
void GuiBegin();
|
|
void GuiEnd();
|
|
void GuiThemeSetup();
|
|
|
|
// ### atlas
|
|
bool LoadTextureAtlas(const char *image_path, const char *ini_path, std::string AtlasKey);
|
|
bool UnloadTextureAtlas(std::string AtlasKey);
|
|
void DrawTextureAtlas(std::string AtlasKey, std::string key, int x, int y);
|
|
void DrawTextureAtlasPro(std::string AtlasKey, std::string key, int x, int y, Color color, bool flipX = false, bool flipY = false);
|
|
|
|
// ### gridmap
|
|
// Draw GridMap using cam, use this inside BeginMode2D
|
|
void DrawGridMap(Texture texture, Camera2D cam);
|
|
// This is quick version without cam, does not support zoom
|
|
void DrawGridMapQuick(Texture texture, Vector2 offset);
|
|
Texture LoadDefaultGridMap();
|
|
|
|
// ### draw
|
|
void DrawTextureTiled(Texture texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint);
|
|
void DrawRenderTexture(const RenderTexture &buffer, const float &x, const float &y, const Color &color);
|
|
|
|
// ## sprite
|
|
void DrawSprite(const panda::Sprite &sprite, const float &x, const float &y, const Color &color);
|
|
void DrawSpriteV(const panda::Sprite &sprite, const Vector2 &pos, const Color &color);
|
|
void DrawSpriteEx(const panda::Sprite &sprite, const Vector2 &pos, const Vector2 &scale, const float &rotation, const Color &color);
|
|
Vector2 GetPointInSprite(const Vector2 &point, const panda::Sprite &sprite, const Vector2 &pos, const Vector2 &scale, const float &rotation);
|
|
|
|
// ### texture utils
|
|
Rectangle GetTextureRect(const Texture &tex, bool flipX, bool flipY);
|
|
|
|
// Utils
|
|
Random &GetDefaultRandom();
|
|
|
|
// Euclidean Distance
|
|
double distance(const Vector2 &p1, const Vector2 &p2);
|
|
double distanceSqrt(const Vector2 &p1, const Vector2 &p2);
|
|
|
|
// Manhattan Distance
|
|
double distanceManhattan(const Vector2 &p1, const Vector2 &p2);
|
|
}
|