crystal-of-rhylil/jni/match3/match3field.h

283 lines
6.8 KiB
C
Raw Normal View History

2013-01-19 22:25:53 +00:00
#ifndef MATCH3FIELD_H_INCLUDED
#define MATCH3FIELD_H_INCLUDED
#include "include/Engine.h"
2018-02-01 14:39:31 +00:00
#include <Eigen/src/Core/Matrix.h>
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
const size_t CONST_MAX_FIELD_WIDTH = 11;
const size_t CONST_MAX_FIELD_HEIGHT = 11;
2013-01-19 22:25:53 +00:00
const float CONST_MATCH3_CELL_WIDTH = 42.f;
const float CONST_MATCH3_CELL_HEIGHT = 42.f;
const float CONST_CHIP_LOWEST_SPEED = -0.5f;
const float CONST_CHIP_ACCELERATION = -0.0014f;
/*
const float CONST_MATCH3_CELL_WIDTH = 32.f;
const float CONST_MATCH3_CELL_HEIGHT = 32.f;
const float CONST_CHIP_LOWEST_SPEED = -0.3f;
const float CONST_CHIP_ACCELERATION = -0.001f;
*/
2018-02-01 14:39:31 +00:00
const size_t CONST_MATCH_TIME = 150;
2013-01-19 22:25:53 +00:00
const float CONST_CHIP_POSITION_EPSILON = 1.f;
const float CONST_CHIP_VELOCITY_EPSILON = 0.3f;
const float CONST_CHIP_K = 0.4f;
2018-02-01 14:39:31 +00:00
const size_t CONST_CHIP_TYPE_COUNT = 4;
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
struct TChipTemplateParams : public SE::TSerializeInterface
2013-01-19 22:25:53 +00:00
{
2018-02-01 14:39:31 +00:00
SE::THalibutExternalAnimObject SelectedTemplateAnimObject;
SE::THalibutExternalAnimObject FinishingTemplateAnimObject;
SE::TRenderParams SelectedRenderParams;
SE::TRenderParams FinishingRenderParams;
2013-01-19 22:25:53 +00:00
virtual void Serialize(boost::property_tree::ptree& propertyTree);
};
2018-02-01 14:39:31 +00:00
struct TMatch3FieldParams : public SE::TSerializeInterface
2013-01-19 22:25:53 +00:00
{
2018-02-01 14:39:31 +00:00
size_t FieldWidth;
size_t FieldHeight;
2013-01-19 22:25:53 +00:00
float CellWidth;
float CellHeight;
float ChipLowestSpeed;
float ChipAcceleration;
float ChipPositionEpsilon;
float ChipVelocityEpsilon;
float ChipK;
2018-02-01 14:39:31 +00:00
size_t ChipMatchTime;
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
size_t ChipTypeCount;
2013-01-19 22:25:53 +00:00
std::vector<TChipTemplateParams> ChipTemplateParamsArr;
TMatch3FieldParams()
: FieldWidth(CONST_MAX_FIELD_WIDTH)
, FieldHeight(CONST_MAX_FIELD_HEIGHT)
, CellWidth(CONST_MATCH3_CELL_WIDTH)
, CellHeight(CONST_MATCH3_CELL_HEIGHT)
, ChipLowestSpeed(CONST_CHIP_LOWEST_SPEED)
, ChipAcceleration(CONST_CHIP_ACCELERATION)
, ChipPositionEpsilon(CONST_CHIP_POSITION_EPSILON)
, ChipVelocityEpsilon(CONST_CHIP_VELOCITY_EPSILON)
, ChipK(CONST_CHIP_K)
, ChipMatchTime(CONST_MATCH_TIME)
, ChipTypeCount(CONST_CHIP_TYPE_COUNT)
{
}
virtual void Serialize(boost::property_tree::ptree& propertyTree);
};
struct TChip
{
int ChipType; // -1 means empty field
std::string AnimName; //Generated automatically
2018-02-01 14:39:31 +00:00
SE::TRenderPairList::iterator RenderPair;
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
size_t VertexListShift;
2013-01-19 22:25:53 +00:00
float Velocity;
enum TChipState
{
CS_STANDBY,
CS_SWAPPING,
CS_FALLING,
CS_LOCKED,
CS_FINISHING,
CS_X,
} ChipState;
2018-02-01 14:39:31 +00:00
TChip(int chipType, SE::TRenderPairList::iterator renderPair, size_t vertexListShift, TChipState chipState = CS_FALLING);
2013-01-19 22:25:53 +00:00
~TChip();
2018-02-01 14:39:31 +00:00
Eigen::Vector2f GetLeftBottomPos();
void SetLeftBottomPos(Eigen::Vector2f newPos);
void MoveLeftBottomPos(Eigen::Vector2f shift);
2013-01-19 22:25:53 +00:00
static int StaticAnimationIndex;
};
2018-02-01 14:39:31 +00:00
2013-01-19 22:25:53 +00:00
struct TChipSwappingPair
{
float T;
2018-02-01 14:39:31 +00:00
Eigen::Vector2i Chip1;
Eigen::Vector2i Chip2;
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
Eigen::Vector2f Chip1RealPosFrom;
Eigen::Vector2f Chip2RealPosFrom;
2013-01-19 22:25:53 +00:00
bool IsReturning;
2018-02-01 14:39:31 +00:00
TChipSwappingPair(Eigen::Vector2i chip1, Eigen::Vector2i chip2, Eigen::Vector2f chip1PosFrom, Eigen::Vector2f chip2PosFrom)
2013-01-19 22:25:53 +00:00
: Chip1(chip1)
, Chip2(chip2)
, T(0)
, Chip1RealPosFrom(chip1PosFrom)
, Chip2RealPosFrom(chip2PosFrom)
, IsReturning(false)
{
}
};
struct TChipDeletingData
{
float T;
2018-02-01 14:39:31 +00:00
Eigen::Vector2i Chip;
Eigen::Vector2f Pos;
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
TChipDeletingData(Eigen::Vector2i chip, Eigen::Vector2f pos)
2013-01-19 22:25:53 +00:00
: T(0.f)
, Chip(chip)
, Pos(pos)
{
}
};
2018-02-01 14:39:31 +00:00
2013-01-19 22:25:53 +00:00
class TMatch3Logic
{
protected:
2018-02-01 14:39:31 +00:00
size_t ChipTypeCount;
2013-01-19 22:25:53 +00:00
std::vector<std::vector<TChip> > ChipMatrix;
std::vector<TChipSwappingPair> ChipSwappingPairVector;
std::vector<TChipDeletingData> ChipDeletingVector;
2018-02-01 14:39:31 +00:00
std::vector<SE::TRenderPairList::iterator> RenderPairIteratorVector;
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
Eigen::Vector2i selectedChip;
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
Eigen::Vector2f LeftBottomPosField;
2013-01-19 22:25:53 +00:00
TMatch3FieldParams Match3FieldParams;
2018-02-01 14:39:31 +00:00
void FillRandomChipMatrix(std::vector<SE::TRenderPairList::iterator> renderPairIteratorVector, Eigen::Vector2f leftBottomPos);
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
Eigen::Vector2f GetExpectedLeftBottomPos(size_t x, size_t y);
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
void StartAnimateChip(size_t x, size_t y);
void StopAnimateChip(size_t x, size_t y);
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
bool ChipIsLocked(Eigen::Vector2i chip);
bool ChipIsFinishing(Eigen::Vector2i chip);
bool ChipIsStable(Eigen::Vector2i chip);
bool ChipCanBeSelected(Eigen::Vector2i chip);
bool ChipsCanBeSwapped(Eigen::Vector2i p1, Eigen::Vector2i p2);
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
bool ChipCanBeMatchedUp(Eigen::Vector2i chip);
bool ChipCanBeMatchedDown(Eigen::Vector2i chip);
bool ChipCanBeMatchedLeft(Eigen::Vector2i chip);
bool ChipCanBeMatchedRight(Eigen::Vector2i chip);
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
void UnmatchChips(std::vector<Eigen::Vector2i> chipList);
void UpdateChipPosition(size_t dt);
2013-01-19 22:25:53 +00:00
void RemoveBubbles();
2018-02-01 14:39:31 +00:00
void ReplaceAnimation(Eigen::Vector2i p);
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
void MoveVertexListShiftBack(SE::TRenderPairList::iterator renderPairItr, size_t moveFrom);
2018-02-02 15:00:17 +00:00
void MoveVertexListShiftBackWithoutAnimation(SE::TRenderPairList::iterator renderPairItr, size_t moveFrom);
2018-02-01 14:39:31 +00:00
void MoveVertexCoordDown(SE::TRenderPairList::iterator renderPairItr, size_t moveFrom, float value);
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
void AddChipToUp(size_t colNum, int chipType, Eigen::Vector2f spawnPos, TChip::TChipState chipState = TChip::CS_FALLING);
2018-02-02 15:00:17 +00:00
void InnerAddChipToUp(size_t colNum, int chipType, Eigen::Vector2f spawnPos, TChip::TChipState chipState = TChip::CS_FALLING);
2018-02-01 14:39:31 +00:00
void InsertEmptyChip(size_t colNum, size_t rowNum, int chipType);
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
void UpdateChipSwapping(size_t dt);
2013-01-19 22:25:53 +00:00
void TryMatchAllChips();
2018-02-01 14:39:31 +00:00
void DestroyChip(Eigen::Vector2i p);
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
void ChangeChipType(Eigen::Vector2i p);
2013-01-19 22:25:53 +00:00
public:
TMatch3Logic();
virtual ~TMatch3Logic();
2018-02-01 14:39:31 +00:00
void SelectChip(Eigen::Vector2i pos);
2013-01-19 22:25:53 +00:00
void UnselectChip();
2018-02-01 14:39:31 +00:00
Eigen::Vector2i GetSelectedChip();
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
std::vector<Eigen::Vector2i> GetAvailableMatchingChips();
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
void SwapChips(Eigen::Vector2i p1, Eigen::Vector2i p2, bool isReturning = false);
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
void ResetChipPos(Eigen::Vector2i p);
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
void UpdateLogic(size_t dt);
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
void HitFieldWithPattern(Eigen::Vector2i pos, std::vector<std::vector<char> > pattern, std::vector<std::vector<char> > jumpingPattern);
2013-01-19 22:25:53 +00:00
};
2018-02-01 14:39:31 +00:00
2013-01-19 22:25:53 +00:00
class TMatch3Controller;
2018-02-02 15:00:17 +00:00
class TMatch3Field : protected TMatch3Logic
2013-01-19 22:25:53 +00:00
{
protected:
void FillBasicChipMatrixAndTriangleList();
//TMatch3Controller& Match3Controller;
2018-02-01 14:39:31 +00:00
Eigen::Vector2f LastTappedPos;
Eigen::Vector2f LastMovePos;
2013-01-19 22:25:53 +00:00
2018-02-01 14:39:31 +00:00
Eigen::Vector2i PosToChip(Eigen::Vector2f pos);
2018-02-02 08:07:21 +00:00
2013-01-19 22:25:53 +00:00
public:
2018-02-02 15:00:17 +00:00
//should be in protected
Eigen::Vector2f LeftBottomPos;
SE::TRenderPairList TriangleListVector;
2013-01-19 22:25:53 +00:00
TMatch3Field();
TMatch3Field(const TMatch3Field& m);
TMatch3Field& operator=(const TMatch3Field& m);
TMatch3Field(TMatch3Controller& match3Controller);
~TMatch3Field();
2018-02-01 14:39:31 +00:00
virtual void Update(size_t dt);
virtual void OnTapDown(Eigen::Vector2f pos);
virtual void OnTapUp(Eigen::Vector2f pos);
virtual void OnMove(Eigen::Vector2f shift);
virtual bool CheckClick(Eigen::Vector2f mousePos);
2013-01-19 22:25:53 +00:00
void HighlightMatch3();
};
#endif