279 lines
9.1 KiB
C++
279 lines
9.1 KiB
C++
#ifndef TJD_UI_APP_AIRSCAFT_H
|
|
#define TJD_UI_APP_AIRSCAFT_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_airscraft.bin"
|
|
#define IMAGE_COMMON_BIN_PATH TJD_IMAGE_PATH "img_game.bin"
|
|
|
|
#define ENEMYPLANE_MAX_NUM 4
|
|
#define RESOURCE_MAX_NUM 5
|
|
#define BULLET_MAX_NUM 8
|
|
|
|
namespace TJD {
|
|
|
|
enum
|
|
{
|
|
AIRSCRAFT_NORMAL,
|
|
AIRSCRAFT_DIE,
|
|
AIRSCRAFT_PAUSE,
|
|
AIRSCRAFT_RESUME,
|
|
AIRSCRAFT_BIRD_FLYING_ON, // 向上飞
|
|
AIRSCRAFT_BIRD_GLIDING, // 滑翔模式
|
|
AIRSCRAFT_BIRD_QUICK_RIGHT_FLY, // 快速右飞
|
|
AIRSCRAFT_BIRD_DIE_FALLDOWN, // 小鸟被撞死
|
|
AIRSCRAFT_QUIT_DLG,
|
|
AIRSCRAFT_GAMEOVER_DLG,
|
|
AIRSCRAFT_MAX,
|
|
};
|
|
|
|
enum
|
|
{
|
|
AIRSCRAFT_GOLD,
|
|
AIRSCRAFT_BIRD_RIGHT,
|
|
AIRSCRAFT_BARRIER_UP,
|
|
AIRSCRAFT_BARRIER_DOWN,
|
|
AIRSCRAFT_BARRIER_UPDOWN,
|
|
AIRSCRAFT_RES_MAX,
|
|
};
|
|
|
|
class Airsfcraft
|
|
{
|
|
public:
|
|
Airsfcraft();
|
|
~Airsfcraft();
|
|
void InitAirsfcraft(int x, int y, int width, int height, uint8_t statue);
|
|
void MoveDownAirsfcraft(void);
|
|
void MoveAirsfcraft(int16_t x , int16_t y);
|
|
void DrawAirsfcraft(void);
|
|
void ChangeAirsfcraftDieAnimator(void);
|
|
void ChangeAirsfcraftFlyingAnimator(void);
|
|
void SetAirsfcraftStatue(uint8_t statue);
|
|
void SetPosition(){animator->SetPosition(x - width / 2, y - height / 2, 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 GetAirsfcraftStatue();
|
|
OHOS::UIImageAnimatorView * GetAnimator(){return animator;};
|
|
private:
|
|
int x;
|
|
int y;
|
|
int width;
|
|
int height;
|
|
uint8_t statue;
|
|
OHOS::UIImageAnimatorView *animator{nullptr};
|
|
|
|
};
|
|
|
|
class AirsfcraftBullet
|
|
{
|
|
public:
|
|
AirsfcraftBullet(int x, int y, int width, int height):x(x), y(y), width(width), height(height){};
|
|
~AirsfcraftBullet();
|
|
void DrawBullet();
|
|
void MoveBullet();
|
|
void SetX(int x){this->x = x;}
|
|
void SetY(int y){this->y = y;}
|
|
int GetX(void){return this->x;}
|
|
int GetY(void){return this->y;}
|
|
int GetWidth(void){return this->width;}
|
|
int GetHeight(void){return this->height;}
|
|
void SetPosition(){bullet.SetPosition(x, y, width, height);}
|
|
OHOS::UIImageView &GetBulletView(){return bullet;}
|
|
|
|
private:
|
|
int x;
|
|
int y;
|
|
int width;
|
|
int height;
|
|
uint8_t statue;
|
|
OHOS::UIImageView bullet;
|
|
|
|
};
|
|
|
|
class EnemyPlane
|
|
{
|
|
public:
|
|
EnemyPlane(int y , int resId);
|
|
~EnemyPlane(){};
|
|
void DrawEnemyPlane();
|
|
void MoveEnemyPlane();
|
|
void DrawEnemyPlaneBoomAnimator();
|
|
void SetPosition(){EnemyPlaneView.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 EnemyPlaneView.GetX();}
|
|
int GetY(void){return EnemyPlaneView.GetY();}
|
|
int GetWidth(void){return EnemyPlaneView.GetWidth();}
|
|
int GetHeight(void){return EnemyPlaneView.GetHeight();}
|
|
OHOS::UIImageView &GetEnemyPlaneView(){return EnemyPlaneView;}
|
|
OHOS::UIImageAnimatorView &GetAnimator(){return animator;};
|
|
|
|
private:
|
|
int x;
|
|
int y;
|
|
int width;
|
|
int height;
|
|
int resId;
|
|
uint8_t statue;
|
|
OHOS::UIImageView EnemyPlaneView;
|
|
OHOS::UIImageAnimatorView animator;
|
|
};
|
|
|
|
class GameAirsfcraftViewOnClickListenser : public OHOS::UIView::OnClickListener
|
|
{
|
|
public:
|
|
GameAirsfcraftViewOnClickListenser(){};
|
|
virtual ~GameAirsfcraftViewOnClickListenser(){};
|
|
virtual bool OnClick(OHOS::UIView& view, const OHOS::ClickEvent& event);
|
|
|
|
};
|
|
|
|
class AirsfcraftStartIngOnClickListenser : public OHOS::UIView::OnClickListener
|
|
|
|
{
|
|
public:
|
|
AirsfcraftStartIngOnClickListenser(){};
|
|
virtual ~AirsfcraftStartIngOnClickListenser(){};
|
|
virtual bool OnClick(OHOS::UIView& view, const OHOS::ClickEvent& event);
|
|
|
|
};
|
|
|
|
// class AirsfcraftOnLongPressListenser : public OHOS::UIView::OnLongPressListener
|
|
// {
|
|
// public:
|
|
// AirsfcraftOnLongPressListenser(){};
|
|
// virtual ~AirsfcraftOnLongPressListenser(){};
|
|
// virtual bool OnLongPress(OHOS::UIView& view, const OHOS::LongPressEvent& event);
|
|
// };
|
|
|
|
class AirsfcraftOnDragListener : public OHOS::UIView::OnDragListener
|
|
{
|
|
public:
|
|
AirsfcraftOnDragListener(){};
|
|
virtual ~AirsfcraftOnDragListener(){};
|
|
virtual bool OnDragStart(OHOS::UIView &view, const OHOS::DragEvent &event);
|
|
virtual bool OnDrag(OHOS::UIView &view, const OHOS::DragEvent &event);
|
|
virtual bool OnDragEnd(OHOS::UIView &view, const OHOS::DragEvent &event);
|
|
};
|
|
|
|
class AirsfcraftViewKeyInputListener : public RootView::OnKeyActListener {
|
|
public:
|
|
explicit AirsfcraftViewKeyInputListener() {}
|
|
virtual ~AirsfcraftViewKeyInputListener() {}
|
|
bool OnKeyAct(UIView& view, const KeyEvent& event) override;
|
|
};
|
|
|
|
// class GameAirsfcraftView;
|
|
class GameAirsfcraftAnimotorCallback : public OHOS::AnimatorCallback
|
|
{
|
|
public:
|
|
GameAirsfcraftAnimotorCallback(Airsfcraft *airsfcraft,AirsfcraftBullet ** bullet, EnemyPlane ** enemyplane,UIViewGroup * gameAirsfcraftView, uint8_t event);
|
|
virtual ~GameAirsfcraftAnimotorCallback();
|
|
void Callback(UIView* view) override;
|
|
void Setevent(uint8_t event){this->event = event;};
|
|
static GameAirsfcraftAnimotorCallback * GetInstance();
|
|
private:
|
|
Airsfcraft *airsfcraft{nullptr};
|
|
// AirsfcraftBackGround *backGround1{nullptr};
|
|
// AirsfcraftBackGround *backGround2{nullptr};
|
|
AirsfcraftBullet ** bullet{nullptr};
|
|
EnemyPlane ** enemyplane{nullptr};
|
|
UIViewGroup * gameAirsfcraftView{nullptr};
|
|
uint8_t event;
|
|
uint32_t startTime_;
|
|
|
|
};
|
|
|
|
class GameAirsfcraftView : public GameItemViewBase
|
|
{
|
|
public:
|
|
GameAirsfcraftView();
|
|
~GameAirsfcraftView();
|
|
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 SetAirsfcraftStatue(uint8_t statue){airsfcraft->SetAirsfcraftStatue(statue);};
|
|
static GameAirsfcraftView * GetInstance();
|
|
OHOS::UIImageAnimatorView * GetTimeAnimator(){return timeAnimator;};
|
|
OHOS::UIViewGroup * & GetStartGameView(){return startGameView_;};
|
|
OHOS::UIViewGroup * & GetStartGameIngView(){return startGameIngView_;};
|
|
OHOS::UIViewGroup * & GetStopGameView(){return stopGameView_;};
|
|
// AirsfcraftBackGround * GetBackGround(uint8_t index);
|
|
Airsfcraft * GetAirsfcraft(){return airsfcraft;};
|
|
OHOS::GraphicTimer *GetTimerToStart(){return timerToStart_;};
|
|
OHOS::GraphicTimer *GetTimerToFireBullet(){return timerToFireBullet_;};
|
|
OHOS::GraphicTimer *GetTimerToShowEnemyplane(){return timerToShowEnemyplane;};
|
|
OHOS::Animator *GetAnimator(){return animator;};
|
|
OHOS::UIButton *GetPauseBtn(){return pause;};
|
|
AirsfcraftBullet * GetBullet(int index){return bullet[index];};
|
|
EnemyPlane * GetEnemyPlane(int index){return enemyplane[index];};
|
|
// 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 *airsfcraftIcon{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};
|
|
OHOS::GraphicTimer *timerToFireBullet_{nullptr};
|
|
OHOS::GraphicTimer *timerToShowEnemyplane{nullptr};
|
|
GameAirsfcraftViewOnClickListenser * onClickListenser_{nullptr};
|
|
AirsfcraftViewKeyInputListener * keyInputListener_{nullptr};
|
|
AirsfcraftOnDragListener ondragListener_;
|
|
// AirsfcraftOnLongPressListenser longPressListenser_;
|
|
Airsfcraft *airsfcraft{nullptr};
|
|
OHOS::UIImageView *bgStartingGame{nullptr};
|
|
AirsfcraftBullet * bullet[BULLET_MAX_NUM]{nullptr};
|
|
EnemyPlane * enemyplane[ENEMYPLANE_MAX_NUM]{nullptr};
|
|
GameAirsfcraftAnimotorCallback * animotorCallback{nullptr};
|
|
Animator * animator{nullptr};
|
|
uint32_t score{0};
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif /* TJD_UI_APP_BIRD_FLY_H */ |