PGE Engine
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
scene_world.h
1 /*
2  * Platformer Game Engine by Wohlstand, a free platform for game making
3  * Copyright (c) 2015 Vitaly Novichkov <admin@wohlnet.ru>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef SCENE_WORLD_H
20 #define SCENE_WORLD_H
21 
22 #include <QString>
23 #include <QList>
24 #include "scene.h"
25 #include <controls/controller.h>
26 #include <PGE_File_Formats/wld_filedata.h>
27 #include <common_features/pge_texture.h>
28 #include <common_features/episode_state.h>
29 #include <common_features/rect.h>
30 #include <common_features/point.h>
31 #include <common_features/event_queue.h>
32 #include <data_configs/config_manager.h>
33 #include <gui/pge_menubox.h>
34 
35 #include "world/wld_tilebox.h"
36 #include "world/wld_player_portrait.h"
37 #include "world/wld_pathopener.h"
38 
39 #include <script/lua_world_engine.h>
40 
42 {
43  int x;
44  int y;
45  PGE_Texture t;
47  int frmH;
48 };
49 
50 class WorldScene : public Scene
51 {
52  friend class PGE_MsgBox;
53  friend class PGE_TextInputBox;
54  friend class PGE_MenuBoxBase;
55  friend class WldPathOpener;
56 public:
57  WorldScene();
58  ~WorldScene();
59 
60  bool init();
61  bool loadConfigs();
62 
63  void onKeyboardPressedSDL(SDL_Keycode sdl_key, Uint16 modifier);
64  LuaEngine* getLuaEngine();
65 
66  void processEvents();
67  void update();
68  void render();
69  int exec();
70 
71  void tickAnimations(float ticks);
72 
73  bool isExit();
74  void setExiting(int delay, int reason);
75 
76  bool loadFile(QString filePath);
77 
78  QString getLastError();
79  void setGameState(EpisodeState *_state);
80 
81 private:
82  bool isInit;
83 
84  Controller * player1Controller;
85  controller_keys controls_1;
86 
87  bool frameSkip;
88 
89  EpisodeState * gameState;
90  QString errorMsg;
91 
92  WorldMapSetup common_setup;
93  WorldData data;
94 
95  bool worldIsContinues;
96  bool lock_controls;
97 
98  PGE_Rect viewportRect;
99 
100  int exitWorldDelay;
101  int exitWorldCode;
102 
103  int numOfPlayers;
104  QList<PlayerState > players;
105 
106  PGE_Texture backgroundTex;
107  QList<PGE_Texture > textures_bank;
108 
109  enum WalkDirections{
110  Walk_Idle=0,
111  Walk_Left,
112  Walk_Right,
113  Walk_Up,
114  Walk_Down
115  };
116  double posX;
117  double posY;
118  int walk_direction;
119  float move_speed;
120  float move_steps_count;
121  void doMoveStep(double &posVal);
122  void setDir(int dr);
123 
124  obj_player mapwalker_setup;
125  PGE_Texture mapwalker_texture;
126  float mapwalker_img_h;
127  SimpleAnimator mapwalker_ani;
128  int mapwalker_offset_x;
129  int mapwalker_offset_y;
130  void mapwalker_refreshDirection();
131 
132 
133  void playMusic(long musicID, QString customMusicFile, bool fade=false, int fadeLen=300);
134  void stopMusic(bool fade=false, int fadeLen=300);
135  bool _playStopSnd;
136  bool _playDenySnd;
137 
138  QString currentMusicFile;
139 
140  void jump();
141  bool jumpTo;
142  PGE_Point jumpToXY;
143 
144  /************Printable stuff****************/
145  long health;
146  long lives;
147  long stars;
148  long points;
149  long coins;
150  QString levelTitle;
151  /*******************************************/
152  bool allow_left;
153  bool allow_up;
154  bool allow_right;
155  bool allow_down;
156  void updateAvailablePaths();
157  void updateCenter();
158  void fetchSideNodes(bool &side, QVector<WorldNode *> &nodes, float cx, float cy);
159  void initElementsVisibility();
160  void saveElementsVisibility();
161 
162  bool pathOpeningInProcess;
163  WldPathOpener pathOpener;
164 
165  QVector<WorldScene_misc_img > imgs;
166  QVector<WorldScene_Portrait > portraits;
167 
168  TileBox _indexTable;
169  QList<WldTileItem > wld_tiles;
170  QList<WldSceneryItem > wld_sceneries;
171  QList<WldPathItem > wld_paths;
172  QList<WldLevelItem > wld_levels;
173  QList<WldMusicBoxItem > wld_musicboxes;
174  EventQueue<WorldScene > wld_events;
175 
176  QList<WorldNode > wldItems;
177  QVector<WorldNode * > _itemsToRender;
178 
179 
180  /*****************Pause Menu*******************/
181  enum PauseMenuItems_Menu1
182  {
183  PAUSE_Continue=0,
184  PAUSE_SaveCont,
185  PAUSE_SaveQuit,
186  PAUSE_Exit
187  };
188  enum PauseMenuItems_Menu2
189  {
190  PAUSE_2_Continue=0,
191  PAUSE_2_Exit
192  };
193  int _pauseMenuID;
194  bool isPauseMenu;
195  PGE_MenuBox _pauseMenu;
196  bool _pauseMenu_opened;
197  void initPauseMenu1();
198  void initPauseMenu2();
199  void processPauseMenu();
200  /*****************Pause Menu**end**************/
201 
202  int debug_render_delay;
203  int debug_phys_delay;
204  int debug_event_delay;
205  int debug_total_delay;
206 
207  LuaWorldEngine luaEngine;
208 };
209 
210 #endif // SCENE_WORLD_H
Control key map structure. Contains a "is pressed" states of all available control keys...
Definition: control_keys.h:25
Definition: setup_wld_scene.h:18
Definition: lua_world_engine.h:8
Definition: pge_texture.h:32
Definition: rect.h:26
Definition: wld_filedata.h:95
Definition: pge_msgbox.h:38
Definition: pge_menubox.h:24
Definition: obj_player.h:103
The Controller class provides proxy interface between controllable objects array and physical control...
Definition: controller.h:32
Definition: scene.h:36
This class should have basic functions for interacting with lua To run the lua engine you have to con...
Definition: lua_engine.h:27
Definition: simple_animator.h:28
void onKeyboardPressedSDL(SDL_Keycode sdl_key, Uint16 modifier)
Triggering when pressed any key on keyboard.
Definition: scene_world.cpp:1165
Definition: scene_world.h:50
Definition: wld_tilebox.h:132
Definition: point.h:23
Definition: pge_textinputbox.h:38
Definition: episode_state.h:47
Definition: wld_pathopener.h:28
bool loadConfigs()
Definition: scene_world.cpp:416
Definition: pge_menuboxbase.h:43
Definition: scene_world.h:41