PGE Engine
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
scene.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_H
20 #define SCENE_H
21 
22 #include <SDL2/SDL_opengl.h>
23 #include <SDL2/SDL_keycode.h>
24 #include <SDL2/SDL_scancode.h>
25 #include <SDL2/SDL_events.h>
26 #include <common_features/fader.h>
27 #include <common_features/rectf.h>
28 #include <script/lua_engine.h>
29 #include <scenes/_base/gfx_effect.h>
30 
31 #include <functional>
32 #include <QList>
33 
34 #include <chrono>
35 
36 class Scene
37 {
38  void construct();
39 public:
40  void updateTickValue();
41 
42  enum TypeOfScene
43  {
44  _Unknown=0,
45  Loading,
46  Title,
47  Level,
48  World,
49  Credits,
50  GameOver
51  };
52 
53  Scene();
54  Scene(TypeOfScene _type);
55  virtual ~Scene();
56  virtual void onKeyInput(int key);
57  virtual void onKeyboardPressed(SDL_Scancode scancode);
58  virtual void onKeyboardPressedSDL(SDL_Keycode sdl_key, Uint16 modifier);
59  virtual void onKeyboardReleased(SDL_Scancode scancode);
60  virtual void onKeyboardReleasedSDL(SDL_Keycode sdl_key, Uint16 modifier);
61  virtual void onMouseMoved(SDL_MouseMotionEvent &mmevent);
62  virtual void onMousePressed(SDL_MouseButtonEvent &mbevent);
63  virtual void onMouseReleased(SDL_MouseButtonEvent &mbevent);
64  virtual void onMouseWheel(SDL_MouseWheelEvent &wheelevent);
65  virtual void processEvents();
66  virtual LuaEngine* getLuaEngine();
67 
68  virtual void update();
69  virtual void updateLua();
70  virtual void render();
71  virtual void renderMouse();
72  virtual int exec(); //scene's loop
73  TypeOfScene type();
74 
75  void addRenderFunction(const std::function<void()>& renderFunc);
76  void clearRenderFunctions();
77 
78  virtual bool isVizibleOnScreen(PGE_RectF &rect);
79  virtual bool isVizibleOnScreen(double x, double y, double w, double h);
80 
81  bool isExiting();
82  bool doShutDown();
83  /**************Fader**************/
84  bool isOpacityFadding();
85  void setFade(int speed, float target, float step);
86  PGE_Fader fader;
87  /**************Fader**************/
88 
89  /* Effects engine */
90  typedef QList<Scene_Effect> SceneEffectsArray;
91  SceneEffectsArray WorkingEffects;
105  void launchStaticEffect(long effectID, float startX, float startY, int animationLoops, int delay, float velocityX, float velocityY, float gravity, int direction=0, Scene_Effect_Phys phys=Scene_Effect_Phys());
106 
120  void launchStaticEffectC(long effectID, float startX, float startY, int animationLoops, int delay, float velocityX, float velocityY, float gravity, int direction=0, Scene_Effect_Phys phys=Scene_Effect_Phys());
121  void processEffects(float ticks);
122  /* Effects engine */
123 
124  QString errorString();
125 
126 protected:
127  bool running;
128  bool _doShutDown;
129  bool doExit;
130  int uTick;
131  float uTickf;
132 
133  /************waiting timer************/
134  typedef std::chrono::high_resolution_clock StClock;
135  typedef std::chrono::high_resolution_clock::time_point StTimePt;
136  void wait(float ms);
137  /************waiting timer************/
138  QString _errorString;
139 private:
140  TypeOfScene sceneType;
141  float dif;
142 
143  QVector<std::function<void()> > renderFunctions;
144 };
145 
146 #endif // SCENE_H
Definition: gfx_effect.h:27
Definition: fader.h:22
virtual void onKeyboardPressed(SDL_Scancode scancode)
Triggering when pressed any key on keyboard.
Definition: scene.cpp:69
void launchStaticEffect(long effectID, float startX, float startY, int animationLoops, int delay, float velocityX, float velocityY, float gravity, int direction=0, Scene_Effect_Phys phys=Scene_Effect_Phys())
launchStaticEffect Starts static effect by ID at position X,Y relative to left-top corner of effect p...
Definition: gfx_effect.cpp:107
virtual void onKeyboardReleasedSDL(SDL_Keycode sdl_key, Uint16 modifier)
Triggering when pressed any key on keyboard.
Definition: scene.cpp:78
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
void launchStaticEffectC(long effectID, float startX, float startY, int animationLoops, int delay, float velocityX, float velocityY, float gravity, int direction=0, Scene_Effect_Phys phys=Scene_Effect_Phys())
launchStaticEffectC Starts static effect by ID at position X,Y relative to center of effect picture ...
Definition: gfx_effect.cpp:25
virtual void onKeyboardReleased(SDL_Scancode scancode)
Triggering when pressed any key on keyboard.
Definition: scene.cpp:75
Definition: rectf.h:26
virtual void onKeyInput(int key)
Triggering when pressed game specific key.
Definition: scene.cpp:66
virtual void onKeyboardPressedSDL(SDL_Keycode sdl_key, Uint16 modifier)
Triggering when pressed any key on keyboard.
Definition: scene.cpp:72