#ifndef TJD_UI_APP_BIRD_FLY_H #define TJD_UI_APP_BIRD_FLY_H #include "TjdUiAppGameView.h" #include "TjdUiImageIds.h" #include "ui_view_group.h" #include "ui_image_animator.h" #include "components/ui_label.h" #include "components/ui_image_view.h" #include "components/ui_button.h" #define IMAGE_BIN_PATH TJD_IMAGE_PATH "img_game_birdfly.bin" #define IMAGE_COMMON_BIN_PATH TJD_IMAGE_PATH "img_game.bin" #define IMAGE_PAUSE_BIN_PATH TJD_IMAGE_PATH "img_stopwatch.bin" #define BARRIER_MAX_NUM 3 #define RESOURCE_MAX_NUM 5 namespace TJD { enum { BIRDFLY_NORMAL, BIRDFLY_DIE, BIRDFLY_PAUSE, BIRDFLY_RESUME, BIRDFLY_BIRD_FLYING_ON, // 向上飞 BIRDFLY_BIRD_GLIDING, // 滑翔模式 BIRDFLY_BIRD_QUICK_RIGHT_FLY, // 快速右飞 BIRDFLY_BIRD_DIE_FALLDOWN, // 小鸟被撞死 BIRDFLY_QUIT_DLG, BIRDFLY_GAMEOVER_DLG, BIRDFLY_MAX, }; enum { RESOURCE_GOLD, RESOURCE_BIRD_RIGHT, RESOURCE_BARRIER_UP, RESOURCE_BARRIER_DOWN, RESOURCE_BARRIER_UPDOWN, RESOURCE_MAX, }; class Bird { public: Bird(); ~Bird(); void InitBird(int x, int y, int width, int height, uint8_t statue); void MoveDownBird(void); void MoveUpBird(void); void DrawBird(void); void ChangeBirdDieAnimator(void); void ChangeBirdFlyingAnimator(void); void SetBirdStatue(uint8_t statue); void SetPosition(){animator->SetPosition(x, y, width, height);} void SetX(int x){this->x = x;} void SetY(int y){this->y = y;} void SetWidth(int width){this->width = width;} void SetHeight(int height){this->height = height;} int GetX(void){return animator->GetX();} int GetY(void){return animator->GetY();}; int GetWidth(void){return animator->GetWidth();}; int GetHeight(void){return animator->GetHeight();}; uint8_t GetBirdStatue(); OHOS::UIImageAnimatorView * GetAnimator(){return animator;}; private: int x; int y; int width; int height; uint8_t statue; OHOS::UIImageAnimatorView *animator{nullptr}; }; class BackGround { public: BackGround(int x, int y, int width, int height):x(x), y(y), width(width), height(height){}; ~BackGround(); void DrawBackGround(); void MoveBackGround(); void SetX(int x){this->x = x;} void SetPosition(){backGround->SetPosition(x, y, width, height);} OHOS::UIImageView * GetBackGroundView(){return backGround;} private: int x; int y; int width; int height; uint8_t statue; OHOS::UIImageView *backGround{nullptr}; }; class Barrier { public: Barrier(int x , int resId): x(x), resId(resId) { if(resId == IMG_GAME_BIRDFLY_PILLAR_BOTTOM){ this->y = 466 - 138; this->width = 71; this->height = 138; }else if(resId == IMG_GAME_BIRDFLY_PILLAR_TOP){ this->y = 0; this->width = 71; this->height = 180; } }; ~Barrier(); void DrawBarrier(); void MoveBarrier(); void SetPosition(){barrierView->SetPosition(x, y, width, height);} uint8_t GetStatue(){return statue;}; void SetX(int x){this->x = x;}; void SetY(int y){this->y = y;}; void SetWidth(int width){this->width = width;}; void SetHeight(int height){this->height = height;}; int GetX(void){return barrierView->GetX();} int GetY(void){return barrierView->GetY();} int GetWidth(void){return barrierView->GetWidth();} int GetHeight(void){return barrierView->GetHeight();} OHOS::UIImageView * GetBarrierView(){return barrierView;} private: int x; int y; int width; int height; int resId; uint8_t statue; OHOS::UIImageView *barrierView{nullptr}; }; class Resource { public: Resource(int x, uint8_t resourceType,int resId); ~Resource(); void ReleaseResource(); void DrawResource(); void MoveResource(); void SetX(int x){this->x = x;} void SetPosition(); int GetX(void); int GetY(void); int GetWidth(void); int GetHeight(void); OHOS::UIImageView * GetResourceView(){return resourceView;} OHOS::UIImageAnimatorView * GetResourceAnimator(){return resourceAnimator;} private: // std::map resourceMap; uint8_t resourceType; int x; int y; int width; int height; int resId; OHOS::UIImageView *resourceView{nullptr}; OHOS::UIImageAnimatorView *resourceAnimator{nullptr}; }; class GameBirdFlyViewOnClickListenser : public OHOS::UIView::OnClickListener { public: GameBirdFlyViewOnClickListenser(){}; virtual ~GameBirdFlyViewOnClickListenser(){}; virtual bool OnClick(OHOS::UIView& view, const OHOS::ClickEvent& event); }; class GameStartIngOnClickListenser : public OHOS::UIView::OnClickListener { public: GameStartIngOnClickListenser(){}; virtual ~GameStartIngOnClickListenser(){}; virtual bool OnClick(OHOS::UIView& view, const OHOS::ClickEvent& event); }; class BirdFlyViewKeyInputListener : public RootView::OnKeyActListener { public: explicit BirdFlyViewKeyInputListener() {} virtual ~BirdFlyViewKeyInputListener() {} bool OnKeyAct(UIView& view, const KeyEvent& event) override; }; // class GameBirdFlyView; class GameBirdFlyAnimotorCallback : public OHOS::AnimatorCallback { public: GameBirdFlyAnimotorCallback(Bird *bird, BackGround *backGround1, BackGround *backGround2, Barrier **barrier, Resource **resource,UIViewGroup * gameBirdFlyView, uint8_t event); virtual ~GameBirdFlyAnimotorCallback(); void Callback(UIView* view) override; void Setevent(uint8_t event){this->event = event;}; static GameBirdFlyAnimotorCallback * GetInstance(); private: Bird *bird{nullptr}; BackGround *backGround1{nullptr}; BackGround *backGround2{nullptr}; Barrier **barrier{nullptr}; Resource **resource{nullptr}; UIViewGroup * gameBirdFlyView{nullptr}; uint8_t event; }; class GameBirdFlyView : public GameItemViewBase { public: GameBirdFlyView(); ~GameBirdFlyView(); void Show() override; void InitGameView(); void StartGame(); void StartGameIng(); void PauseGame(); void ResumeGame(); void RestartGame(); void StopGame(); bool CheckBirdRamBarriers(); bool CheckBirdRamResource(); void SetScore(void){this->score++;printf("score:%d\n", score);} void SetBirdStatue(uint8_t statue){bird->SetBirdStatue(statue);}; static GameBirdFlyView * GetInstance(); OHOS::UIImageAnimatorView * GetTimeAnimator(){return timeAnimator;}; OHOS::UIViewGroup * & GetStartGameView(){return startGameView_;}; OHOS::UIViewGroup * & GetStartGameIngView(){return startGameIngView_;}; OHOS::UIViewGroup * & GetStopGameView(){return stopGameView_;}; BackGround * GetBackGround(uint8_t index); Bird * GetBird(){return bird;}; OHOS::GraphicTimer *GetTimerToStart(){return timerToStart_;}; OHOS::Animator *GetAnimator(){return animator;}; OHOS::UIButton *GetPauseBtn(){return pause;}; // bool OnKeyAct(OHOS::UIView& view, const OHOS::KeyEvent& event) override; private: // OHOS::UIViewGroup *mainConner_{nullptr}; OHOS::UIViewGroup *initGameView_{nullptr}; OHOS::UIViewGroup *startGameView_{nullptr}; OHOS::UIViewGroup *startGameIngView_{nullptr}; OHOS::UIViewGroup *stopGameView_{nullptr}; OHOS::UILabel *scoreLabel{nullptr}; OHOS::UILabel *tipLabel{nullptr}; OHOS::UIImageView *birdIcon{nullptr}; OHOS::UIImageView *bgGameView{nullptr}; OHOS::UIImageView *bgGameView1{nullptr}; OHOS::UIButton *startGameView{nullptr}; OHOS::UILabel *titleLabel{nullptr}; OHOS::UILabel *scoreLabel1{nullptr}; OHOS::UIImageView *stopView_bg{nullptr}; OHOS::UIImageView *stopView_block{nullptr}; OHOS::UIImageView *stopView_icon{nullptr}; OHOS::UIButton *stopView_start{nullptr}; OHOS::UIButton *stopView_return{nullptr}; OHOS::UIButton *pause{nullptr}; OHOS::UIImageAnimatorView *timeAnimator{nullptr}; OHOS::GraphicTimer *timerToStart_{nullptr}; GameBirdFlyViewOnClickListenser * onClickListenser_{nullptr}; BirdFlyViewKeyInputListener * keyInputListener_{nullptr}; // OHOS::GraphicTimer *timerToBird_{nullptr}; // OHOS::GraphicTimer *timerToBackground_{nullptr}; Bird *bird{nullptr}; BackGround * backGround[2]{nullptr}; Barrier * barrier[BARRIER_MAX_NUM]{nullptr}; Resource * resource[RESOURCE_MAX_NUM]{nullptr}; GameBirdFlyAnimotorCallback * animotorCallback{nullptr}; Animator * animator{nullptr}; uint32_t score{0}; }; } #endif /* TJD_UI_APP_BIRD_FLY_H */