double-hit-balls/game/gamecode.h

206 lines
4.5 KiB
C
Raw Permalink Normal View History

2017-01-10 12:43:06 +00:00
#ifndef GAMECODE_H_INCLUDED
#define GAMECODE_H_INCLUDED
#include "include/Engine.h"
#include "game_area_interface.h"
#include <list>
using namespace SE;
const int CONST_BRICKSTATE_VISIBLE = 3;
const int CONST_BRICKSTATE_DISAPPEAR = 2;
const int CONST_BRICKSTATE_INVISIBLE = 1;
const int CONST_BRICKSTATE_APPEAR = 0;
const float CONST_BRICK_DISAPPEAR_TIME = 200.f;
const float CONST_BRICK_APPEAR_TIME = 200.f;
const int CONST_BRICKMATRIX_WIDTH = 12;
const int CONST_BRICKMATRIX_HEIGHT = 13;
const float CONST_BRICK_WIDTH = 37.5f;
const float CONST_BRICK_HEIGHT = 0.5f*CONST_BRICK_WIDTH;
const float CONST_BRICK_SHIFT_X = 15.f;
const float CONST_BRICK_SHIFT_Y = -16.f;
const float CONST_BONUS_APPEAR_TIME = 400.f;
const float CONST_BONUS_FALL_SPEED = 100.f;
const float CONST_BONUS_GOTHROUGH_TIME = 8000.f;
const float CONST_BONUS_CATCH_DISTANCE_X = 65.f;
const float CONST_BONUS_CATCH_DISTANCE_Y = 20.f;
const float CONST_BONUS_FLOOR_TIME = 8000.f;
const float CONST_BONUS_FLOOR_APPEAR_SPEED = 50.f;
const int CONST_BONUS_TYPE_MULTIPLIER = 0;
const int CONST_BONUS_TYPE_GOTHROUGH = 1;
const int CONST_BONUS_TYPE_FLOOR = 2;
class TBrick
{
protected:
int InitialLocked;
int Locked; //0, 1 or 2
int State;
float StateTimer;
2017-11-14 17:04:04 +00:00
Vector4f Color;
2017-01-10 12:43:06 +00:00
public:
TBrick();
2017-11-14 17:04:04 +00:00
void SetVisible(Vector4f color, int locked);
2017-01-10 12:43:06 +00:00
void SetInvisible();
void TryDrawAppear(int ipos, int jpos);
2017-11-14 17:04:04 +00:00
void Update(size_t dt);
Vector2f GetPosFrom(int ipos, int jpos);
Vector4f GetColor();
void Appear(Vector4f color, int locked);
2017-01-10 12:43:06 +00:00
void Appear();
void Hit();
void Disappear();
int GetLocked();
bool CanReact();
};
class TBonusFalling
{
protected:
float Lifetime;
2017-11-14 17:04:04 +00:00
Vector2f Pos;
2017-01-10 12:43:06 +00:00
std::string TexName;
int BonusType; //0 - multiplier, 1 - Go-through, 2 - floor
public:
2017-11-14 17:04:04 +00:00
TBonusFalling(Vector2f pos);
Vector2f GetPos();
2017-01-10 12:43:06 +00:00
int GetType();
void Draw();
2017-11-14 17:04:04 +00:00
void Update(size_t dt);
2017-01-10 12:43:06 +00:00
};
struct TBall
{
2017-11-14 17:04:04 +00:00
Vector2f Pos;
Vector2f Velocity;
Vector4f Color;
std::list<Vector2f> TalePos;
2017-01-10 12:43:06 +00:00
2017-11-14 17:04:04 +00:00
Vector2f BallInBlock;
Vector2f PrevBallInBlock;
2017-01-10 12:43:06 +00:00
2017-11-14 17:04:04 +00:00
TBall(Vector2f pos, Vector2f velocity, Vector4f color);
Vector2f GetPos();
Vector2f GetVelocityVector();
2017-01-10 12:43:06 +00:00
void Go();
void ReflectToLeft();
void ReflectToRight();
void ReflectToUp();
void ReflectToDown();
2017-11-14 17:04:04 +00:00
void TryReflectOnReflector(Vector2f refPos);
2017-01-10 12:43:06 +00:00
2017-11-14 17:04:04 +00:00
void Update(size_t dt);
2017-01-10 12:43:06 +00:00
};
2017-11-14 17:04:04 +00:00
typedef std::pair<Vector4f, std::string> PairColorTexture;
2017-01-10 12:43:06 +00:00
struct TBlockInstansingList
{
//color-texture ---> and list of triangles for this color
std::list<std::pair<PairColorTexture, TTriangleList>> ColorBlockList;
};
struct TBallInstancingList
{
std::map<int, TTriangleList> BallAndGlowList;
};
class TGameLevel : public TGameAreaAncestor
{
protected:
std::string BkgTexture;
std::string LevelScreenTexture;
std::string LevelFileName;
2017-11-14 17:04:04 +00:00
Vector2f ReflectorPos;
2017-01-10 12:43:06 +00:00
int LevelState;
bool PrevLevelStateIsStandby;
float StateTimer;
TBrick BlockMatrix[CONST_BRICKMATRIX_WIDTH][CONST_BRICKMATRIX_HEIGHT];
TBlockInstansingList BlockInstansingList;
2017-11-14 17:04:04 +00:00
bool TapInBackBtnArea(const Vector2f& pos);
2017-01-10 12:43:06 +00:00
void ReloadBlockInstansingList();
void SetFinished();
void SetFinishFreeze();
void DrawBuffer();
void DrawPauseButtons();
void DrawBallInstancingList();
bool RenderBufferReady;
float OutScale;
float OutScaleVelocity;
void TryGoToMenu();
std::list<TBonusFalling> BonusFallingList;
std::list<TBall> BallList;
TBallInstancingList BallInstancingList;
2017-11-14 17:04:04 +00:00
Vector4f BallColor;
2017-01-10 12:43:06 +00:00
void ReloadBallInstancingList();
void RefreshBallInstancingList();
2017-11-14 17:04:04 +00:00
void UpdateBallList(size_t dt);
void MultiplyBalls(Vector2f pos, Vector2f velocity);
2017-01-10 12:43:06 +00:00
2017-11-14 17:04:04 +00:00
Vector2f GetBlock(const Vector2f& pos);
2017-01-10 12:43:06 +00:00
void InitLevel();
float BonusGothroughTimer;
float BonusFloorTimer;
float BonusFloorPosY;
2017-11-14 17:04:04 +00:00
Vector4f ParseColor(const std::string& s);
2017-01-10 12:43:06 +00:00
void ReloadLevel();
public:
TGameLevel();
~TGameLevel();
void FillWithFile(const std::string& filename);
void SetStandBy();
void SetLoading(const std::string& bkg, const std::string& levelscreen);
bool IsLoaded();
virtual void Draw();
void SetPause();
bool IsPaused();
void ReleasePause();
2017-11-14 17:04:04 +00:00
virtual void Update(size_t dt);
virtual void OnTapDown(Vector2f pos);
virtual void OnTapUp(Vector2f pos);
virtual void OnFling(Vector2f slideSpeed);
virtual void OnScroll(Vector2f shift);
2017-01-10 12:43:06 +00:00
};
#endif