-
Notifications
You must be signed in to change notification settings - Fork 0
/
robotgame.h
111 lines (97 loc) · 3.46 KB
/
robotgame.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef GAME_H
#define GAME_H
#include <vector>
#include <string>
#include <memory>
#include <filesystem>
#include "pge/olcPixelGameEngine.h"
#include "pge/imgui_impl_pge.h"
#include "pge/imgui_stdlib.h"
#include "lua/lua.hpp"
#include "block.h"
#include "programmableblock.h"
#include "buttonblock.h"
#include "diodeblock.h"
#include "motorblock.h"
#include "mapblock.h"
#include "radarblock.h"
#include "uistate.h"
#include "inputstate.h"
#include "map.h"
#include "robot.h"
class IState;
class RobotGame : public olc::PixelGameEngine
{
private:
olc::imgui::PGE_ImGUI pge_imgui;
Map map;
Robot robot;
std::vector<std::shared_ptr<Block>> blocks;
olc::vi2d gridSize = {16, 9};
olc::vi2d infoMenuPos;
const olc::vi2d infoMenuSize = {200, 776};
olc::vi2d blocksMenuPos;
const olc::vi2d blocksMenuSize = {800, 2 * blocksize + 20};
const int uiPadding = 8;
Block* selectedBlock = nullptr;
public:
std::vector<std::pair<int, std::shared_ptr<Block>>> inventory;
float timedelta;
const int tps = 60;
SpriteManager sm;
const int spritesize = 16; // one grid unit image size
const int spritescale = 4; // sprite scaling ratio
const int blocksize = spritesize * spritescale; // one grid unit rendered size
std::map<std::string, std::string> helpFiles;
const std::filesystem::path examplesPath = {"./examples"};
const ImGuiWindowFlags codeEditFlags = ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoNav |
ImGuiWindowFlags_NoScrollWithMouse;
const ImGuiWindowFlags popUpMenuFlags = ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoNav |
ImGuiWindowFlags_NoBringToFrontOnFocus;
const ImGuiWindowFlags infoMenuFlags = popUpMenuFlags | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoScrollbar;
uint8_t connectionsLayer;
uint8_t gridLayer;
uint8_t blocksUILayer;
uint8_t infoUILayer;
uint8_t tempLayer;
uint8_t mapGridLayer;
std::unique_ptr<IState> state;
RobotGame();
bool OnUserCreate() override;
bool OnUserUpdate(float fElapsedTime) override;
void SimTick();
void DrawHelp();
void DrawGrid();
olc::vi2d GetResolution();
Block* GetBlockAt(olc::vi2d pos);
olc::vi2d GetGridAt(olc::vi2d pos);
Block* GetBlockUnderMouse();
Block* GetBlockUnderMouseInv();
void IncrInvCount(const Block* schema, int count);
bool CursorCollide(olc::vi2d pos, olc::vi2d size, olc::vi2d mousepos);
void ClearLayers();
void DrawBlock(Block* block);
void DrawBlockSprite(olc::vi2d pos, Block* block, int scale = -1);
void DrawBlocks();
void DrawBlocksUI();
void ShowDebugWindow();
void PlaceBlock(std::shared_ptr<Block> block);
void RemoveBlock(Block* block);
int InvCount(const Block* schema);
olc::vi2d GetBlockCenter(Block* block);
void DrawConnections();
void SelectBlock(Block* block);
bool CanBePlaced(Block* block, olc::vi2d pos);
void DrawInfoUI();
void DrawUI(void);
void HandleInput();
void UpdateState();
void SimStart();
void SimStop();
};
#endif // GAME_H