double-hit-balls/game/main_code.h

212 lines
5.0 KiB
C
Raw Permalink Normal View History

2017-01-10 12:43:06 +00:00
#ifndef MAIN_CODE_H_INCLUDED
#define MAIN_CODE_H_INCLUDED
#ifdef TARGET_ANDROID
#include "android_api.h"
#endif
#ifdef TARGET_WIN32
#define NOMINMAX 1
#include <Windows.h>
#undef NOMINMAX
#endif
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "boost/shared_ptr.hpp"
#include "boost/thread/thread.hpp"
#include "boost/assign.hpp"
#include "boost/bind.hpp"
#include "include/Engine.h"
2017-02-26 23:07:37 +00:00
#include "boost/signals2.hpp"//Signal must be included after asio
2017-01-10 12:43:06 +00:00
#include "gamecode.h"
#include "menucode.h"
#include "creditscode.h"
#include "loadingcode.h"
2018-05-22 12:00:30 +00:00
#include "galaxy_menu.h"
2017-01-10 12:43:06 +00:00
using namespace SE;
2017-11-14 17:04:04 +00:00
extern boost::signals2::signal<void(Vector2f)> OnTapUpSignal;
extern boost::signals2::signal<void(Vector2f)> OnTapUpAfterMoveSignal;
2017-01-10 12:43:06 +00:00
2017-11-14 17:04:04 +00:00
extern boost::signals2::signal<void(Vector2f)> OnTapDownSignal;
extern boost::signals2::signal<void(Vector2f)> OnFlingSignal;
extern boost::signals2::signal<void(Vector2f)> OnScrollSignal;
2017-02-26 23:07:37 +00:00
2017-11-14 17:04:04 +00:00
extern boost::signals2::signal<void()> OnDrawSignal;
2017-01-10 12:43:06 +00:00
extern const std::string CONST_BLOCK_TEXTURE1;
extern const std::string CONST_BLOCK_TEXTURE2;
extern const std::string CONST_BLOCK_TEXTURE3;
extern const std::string CONST_BONUS_GOTHROUGH_TEXTURE;
extern const std::string CONST_BONUS_MULTIPLIER_TEXTURE;
extern const std::string CONST_BONUS_FLOOR_TEXTURE;
extern const std::string CONST_BALL_TEXTURE;
extern const std::string CONST_BALLGLOW_TEXTURE;
extern const std::string CONST_WALL_LEFT_TEXTURE;
extern const std::string CONST_WALL_RIGHT_TEXTURE;
extern const std::string CONST_WALL_UP_TEXTURE;
extern const std::string CONST_WALL_BONUS_TEXTURE;
extern const std::string CONST_REFLECTOR_TEXTURE;
extern const std::string CONST_BACK_BTN_TEXTURE;
extern const std::string CONST_SLIDE_UP_BTN_TEXTURE;
extern const std::string CONST_TAP_TO_CONTINUE_BTN_TEXTURE;
extern const std::string CONST_BACK_BTN_TEXTURE;
extern const std::string CONST_SLIDE_UP_BTN_TEXTURE;
extern const std::string CONST_TAP_TO_CONTINUE_BTN_TEXTURE;
extern const std::string CONST_LOADING_TEXTURE;
extern const std::string CONST_LOGO_SMALL_TEXTURE;
2017-11-14 17:04:04 +00:00
extern const std::string CONST_LOADING_BACKGROUND_BLACK;
2017-01-10 12:43:06 +00:00
extern const std::string CONST_CREDITS_TEXTURE;
const int CONST_GAMESTATE_LEVEL = 1;
const int CONST_GAMESTATE_MENU = 0;
const int CONST_GAMESTATE_FROM_MENU_TO_LEVEL = 2;
const int CONST_GAMESTATE_FROM_MENU_TO_CREDITS = 3;
const int CONST_GAMESTATE_CREDITS = 4;
const int CONST_GAMESTATE_FROM_CREDITS_TO_MENU = 5;
const int CONST_GAMESTATE_LOADING = 6;
const int CONST_GAMESTATE_PRELOADING = 7;
2017-11-14 17:04:04 +00:00
class TMyApplication : public TApplication
2017-01-10 12:43:06 +00:00
{
protected:
bool skipUpdateToUpdateScreen;
2018-03-26 11:42:25 +00:00
int levelScreenWidth;
int levelScreenHeight;
float levelScreenRatio = 1.6;
2018-03-26 11:42:25 +00:00
2018-05-17 07:56:46 +00:00
ParticleEffect lsparkler, rsparkler, tsparkler, bsparkler; // Different directed reflection
2018-04-03 09:47:08 +00:00
ParticleEffect lvlFirework; // Level finished effect
2017-01-10 12:43:06 +00:00
TGameMenu Menu;
2018-07-22 20:56:46 +00:00
std::shared_ptr<TGameLevel> GameLevel;
2017-01-10 12:43:06 +00:00
TGameCredits GameCredits;
TGameLoading GameLoading;
2017-11-14 17:04:04 +00:00
int GameState;
2017-01-10 12:43:06 +00:00
float StateTimer;
2017-11-14 17:04:04 +00:00
void TryLoadSavedGame();
void TrySaveGame();
bool Inited;
std::vector<std::pair<std::string, std::string> > TextureNamesToLoad;
void ApplySignalsToMenu();
void DisapplySignalsToMenu();
void ApplySignalsToGame();
void DisapplySignalsToGame();
void ApplySignalsToCredits();
void DisapplySignalsToCredits();
2017-01-10 12:43:06 +00:00
2018-07-22 20:56:46 +00:00
2018-04-02 08:46:31 +00:00
void EffectsInit();
2018-07-22 20:56:46 +00:00
// Mouse new methods
virtual void InnerOnMouseDown(TMouseState& mouseState);
virtual void InnerOnMouseMove(TMouseState& mouseState);
2018-07-22 20:56:46 +00:00
bool IsLevelOpened(int levelStar, int levelIndex);
2018-07-22 20:56:46 +00:00
2017-01-10 12:43:06 +00:00
public:
2017-11-14 17:04:04 +00:00
bool Loaded;
TMyApplication() : TApplication(), Loaded(false), Inited(false) { }
void LoadUserProgress();
void SaveUserProgress(int levelStar, int levelIndex);
2017-11-14 17:04:04 +00:00
2018-10-17 03:59:08 +00:00
void InnerChangeWidthHeight(int screenWidth, int screenHeight, float matrixWidth, float matrixHeight) override;
2018-10-17 03:59:08 +00:00
virtual void OnKeyPress(size_t key);
2017-11-14 17:04:04 +00:00
virtual void InnerInit();
virtual void RenderLevelSnapshots();
virtual void InnerReinitGLResources();
2017-11-14 17:04:04 +00:00
virtual void InnerDeinit();
2017-01-10 12:43:06 +00:00
virtual void InnerDraw();
2017-11-14 17:04:04 +00:00
virtual void InnerUpdate(size_t dt);
2018-07-22 20:56:46 +00:00
void GoFromMenuToGame(std::shared_ptr<TGameLevel> gameLevel);
2017-01-10 12:43:06 +00:00
void GoFromGameToMenu();
void GoFromMenuToCredits();
void GoFromCreditsToMenu();
void MarkSetGameLevelPause();
void MarkReleaseGameLevelPause();
2018-04-03 09:47:08 +00:00
// Effects -------
2018-04-02 08:46:31 +00:00
void EffectsUpdate(size_t dt);
void EffectsDraw();
2017-11-14 17:04:04 +00:00
2018-04-03 09:47:08 +00:00
void fireworkEffect();
void hitSpark(std::string direct, Vector2f Pos);
// Effects -------
2017-01-10 12:43:06 +00:00
void OpenNextLevel();
2017-11-14 17:04:04 +00:00
2017-01-10 12:43:06 +00:00
bool IsLoaded();
2017-11-14 17:04:04 +00:00
2017-01-10 12:43:06 +00:00
bool IsInited();
2017-11-14 17:04:04 +00:00
2017-01-10 12:43:06 +00:00
void LoadResources();
2017-11-14 17:04:04 +00:00
2018-05-21 11:19:56 +00:00
virtual void InnerOnTapDown(Vector2f p)
{
//-OnTapDownSignal(Vector2f(p.v[0], p.v[1]));
OnTapDownSignal(Vector2f(p(0), p(1)));
}
2017-11-14 17:04:04 +00:00
virtual void InnerOnTapUp(Vector2f p);
virtual void InnerOnTapUpAfterMove(Vector2f p);
virtual void InnerOnMove(Vector2f p, Vector2f shift);
virtual void OnFling(Vector2f v);
2018-03-26 11:42:25 +00:00
float GetGameLevelScreenWidth();
float GetGameLevelScreenHeight();
void SetGameLevelScreenScale();
2018-04-04 11:44:30 +00:00
2018-07-22 20:56:46 +00:00
void LoadGalaxyUi();
void SetupGalaxyUi(size_t levelStar);
2017-01-10 12:43:06 +00:00
};
2017-11-14 17:04:04 +00:00
extern TMyApplication* Application;
2017-01-10 12:43:06 +00:00
#endif