Bridges-C++ 3.5.0-dev2-1-ge3e57bf
Bridges(C++ API)
GameBase3D.h
Go to the documentation of this file.
1#ifndef GAME_BASE_3D_H
2#define GAME_BASE_3D_H
3
4#include "SocketConnection.h"
5#include "GameGrid.h"
6#include "Bridges.h"
7#include "Scene.h"
8
9namespace bridges {
10 namespace game {
22 class GameBase3D {
23 private:
25
26 GameGrid gg;
27
28 bool firsttime = true;
29
30 bool bquit = false;
31 std::unique_ptr<SocketConnection> sockcon;
32
33 Scene *scene;
34 // we keep this object locally to prevent users from creating a
35 // a whole bunch of Scene objects
36 // Scene scene;
37
38 protected:
39 bool debug = false;
40
48 GameBase3D(int assignmentID, std::string username, std::string apikey)
49 : bridges(assignmentID, username, apikey) {
50
51 bridges.setServer("games");
52
53 sockcon = std::make_unique<SocketConnection>(bridges);
54
55 // set up the default 3D scene
56 float position[] = {0., 0., 0.};
57 scene = new Scene("fps", 90, position);
58 }
59
60 virtual ~GameBase3D() = default;
61
66 virtual void initialize () = 0;
67
72
73 virtual void gameLoop () = 0;
74
83 sockcon->registerKeyListener(p);
84 }
85
90 void render() {
91 if (firsttime) {
92 bridges.setJSONFlag(debug);
93
94 bridges.setDataStructure(current_scene);
95
96 bridges.visualize();
97
98 firsttime = false;
99 }
100 sockcon->sendSceneDataToServer(current_scene);
101 }
102
107 void quit() {
108 bquit = true;
109 }
110
114 void setTitle(std::string title) {
115 bridges.setTitle(title);
116 }
117
121 void setDescription(std::string desc) {
122 bridges.setDescription(desc);
123 }
124
125 public:
126 // current scene object
128
129 // accessors
130 void addScene(Scene& sc) {
131 current_scene = sc;
132 }
133
135 return current_scene;
136 }
137
138 bool gameover() const {
139 return bquit;
140 }
141 };
142 }
143}
144
145#endif
This class contains methods to connect and transmit a user's data structure representation to the Bri...
Definition: Bridges.h:51
Definition: Scene.h:14
This class extends the GameBase class to 3D environments.
Definition: GameBase3D.h:22
void render()
Renders the game.
Definition: GameBase3D.h:90
virtual ~GameBase3D()=default
void registerKeyListener(KeypressListener *p)
register a new KeypressListener
Definition: GameBase3D.h:82
void quit()
calling this function causes the game to end.
Definition: GameBase3D.h:107
void setTitle(std::string title)
Set the title of the game.
Definition: GameBase3D.h:114
bool gameover() const
Definition: GameBase3D.h:138
Scene current_scene
Definition: GameBase3D.h:127
virtual void gameLoop()=0
This function is called once per frame of the game.
void setDescription(std::string desc)
Set a short description of the game.
Definition: GameBase3D.h:121
GameBase3D(int assignmentID, std::string username, std::string apikey)
Protected construction prevens direct creation.
Definition: GameBase3D.h:48
Scene getCurrentScene()
Definition: GameBase3D.h:134
void addScene(Scene &sc)
Definition: GameBase3D.h:130
bool debug
Definition: GameBase3D.h:39
virtual void initialize()=0
This function is called once when the game starts.
This is a class in BRIDGES for representing an (n x n)game grid.
Definition: GameGrid.h:398
This is meant to be an internal class, not something that the library user will use....
Definition: SocketConnection.h:34
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4