mcu_hi3321_watch/tjd/ui/app/game/TjdUiAppAirscraft.cpp
2025-05-26 20:15:20 +08:00

1183 lines
43 KiB
C++

#include "TjdUiAppAirscraft.h"
#include "TjdUiMultiLanguageExt.h"
#include "common/image_cache_manager.h"
#include "sys_config.h"
#include "dock/input_device.h"
#include "NativeAbility.h"
#include "sql_bt.h"
#include "hal_tick.h"
#include <stdio.h>
#define ENABLE_PRINT_INFO 1
#if ENABLE_PRINT_INFO
#define static_print_info(...) sys_ui_log_i(__VA_ARGS__) // 一般信息打印宏控制
#define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) // 警告信息打印一般常开
#define static_print_error(...) sys_ui_log_e(__VA_ARGS__) // 错误信息打印一般常开
#define static_print_debug(...) sys_ui_log_d(__VA_ARGS__) // 调试信息打印
#else
#define static_print_info(...)
#define static_print_warn(...)
#define static_print_error(...)
#define static_print_debug(...)
#endif
#define AIRSFCRAFT_ANIM_IMAGE_MAX_NUM 7
#define ENEMYPLANE_DIE_ANIM_IMAGE_MAX_NUM 8
#define BACKGROUND_MAX_NUM 2
#define GOLD_ANIM_MAX_NUM 8
#define ABS(x) ((x) < 0 ? -(x) : (x))
namespace TJD{
static GameAirsfcraftView *g_pv_AirsfcraftView = nullptr;
static GameAirsfcraftAnimotorCallback *g_pv_AirsfcraftAnimotorCallback = nullptr;
static int16_t HorizontalCenter(int16_t width) { return (OHOS::HORIZONTAL_RESOLUTION - width) / 2; }
static inline int16_t VerticalCenter(int16_t height, int16_t parentHeight) { return (parentHeight - height) / 2; }
static uint32_t history_score = 0;
OHOS::ImageAnimatorInfo g_pv_AirsfcraftInfo_[AIRSFCRAFT_ANIM_IMAGE_MAX_NUM] = {0};
OHOS::ImageAnimatorInfo g_pv_EnemyPlaneBoomInfo_[ENEMYPLANE_DIE_ANIM_IMAGE_MAX_NUM] = {0};
static void InitLabel(OHOS::UILabel &label, uint8_t size, int16_t y,const char *text)
{
label.SetFont(TJD_VECTOR_FONT_FILENAME, size);
label.SetText(text);
label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
label.SetPosition(HorizontalCenter(label.GetWidth()), y);
}
GameAirsfcraftView::GameAirsfcraftView()
{
g_pv_AirsfcraftView = this;
if(keyInputListener_ == nullptr){
keyInputListener_ = new AirsfcraftViewKeyInputListener();
}
OHOS::ImageCacheManager::GetInstance().LoadAllInMultiRes(IMAGE_BIN_PATH);
SetPosition(0, -466 , OHOS::VERTICAL_RESOLUTION,466 * 3);
SetStyle(STYLE_BACKGROUND_OPA, 0);
SetViewId("GameAirsfcraftView");
if(initGameView_ == nullptr){
initGameView_ = new OHOS::UIViewGroup();
}
initGameView_->SetPosition(0, 466, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
initGameView_->SetViewId("InitGameView");
initGameView_->SetVisible(false);
if(onClickListenser_ == nullptr){
onClickListenser_ = new GameAirsfcraftViewOnClickListenser();
}
InitGameView();
OHOS::RootView::GetInstance()->Add(this);
Add(initGameView_);
}
GameAirsfcraftView::~GameAirsfcraftView()
{
g_pv_AirsfcraftView = nullptr;
OHOS::ImageCacheManager::GetInstance().UnloadAllInMultiRes(IMAGE_BIN_PATH);
OHOS::RootView::GetInstance()->Remove(this);
RemoveAll();
if (initGameView_)
initGameView_->RemoveAll();
if (startGameView_)
startGameView_->RemoveAll();
if (startGameIngView_)
startGameIngView_->RemoveAll();
if (stopGameView_)
stopGameView_->RemoveAll();
if (startGameIngView_ != nullptr)
if(startGameIngView_->GetOnClickListener() != nullptr ){
delete startGameIngView_->GetOnClickListener();
startGameIngView_->GetOnClickListener() = nullptr;
}
if(initGameView_ != nullptr){
delete initGameView_;
initGameView_ = nullptr;
}
if(startGameView_ != nullptr){
delete startGameView_;
startGameView_ = nullptr;
}
if(startGameIngView_ != nullptr){
delete startGameIngView_;
startGameIngView_ = nullptr;
}
if(stopGameView_ != nullptr){
delete stopGameView_;
stopGameView_ = nullptr;
}
if(bgGameView != nullptr){
delete bgGameView;
bgGameView = nullptr;
}
if(bgGameView1 != nullptr){
delete bgGameView1;
bgGameView1 = nullptr;
}
if(airsfcraftIcon != nullptr){
delete airsfcraftIcon;
airsfcraftIcon = nullptr;
}
if(scoreLabel != nullptr){
delete scoreLabel;
scoreLabel = nullptr;
}
if(startGameView != nullptr){
delete startGameView;
startGameView = nullptr;
}
if(titleLabel != nullptr){
delete titleLabel;
titleLabel = nullptr;
}
if(scoreLabel1 != nullptr){
delete scoreLabel1;
scoreLabel1 = nullptr;
}
if(stopView_bg != nullptr){
delete stopView_bg;
stopView_bg = nullptr;
}
if(stopView_block != nullptr){
delete stopView_block;
stopView_block = nullptr;
}
if(stopView_icon != nullptr){
delete stopView_icon;
stopView_icon = nullptr;
}
if(stopView_start != nullptr){
delete stopView_start;
stopView_start = nullptr;
}
if(stopView_return != nullptr){
delete stopView_return;
stopView_return = nullptr;
}
if(animator != nullptr){
animator->Stop();
delete animator;
animator = nullptr;
}
if(animotorCallback != nullptr){
delete animotorCallback;
animotorCallback = nullptr;
}
for(int i = 0; i < BULLET_MAX_NUM; i++){
if(bullet[i] != nullptr){
delete bullet[i];
bullet[i] = nullptr;
}
}
for(int i = 0; i < ENEMYPLANE_MAX_NUM; i++){
if(enemyplane[i] != nullptr){
delete enemyplane[i];
enemyplane[i] = nullptr;
}
}
// for(int i = 0; i < RESOURCE_MAX_NUM; i++){
// if(resource[i] != nullptr){
// delete resource[i];
// resource[i] = nullptr;
// }
// }
// for(int i = 0; i < 2; i++){
// if(backGround[i] != nullptr){
// delete backGround[i];
// backGround[i] = nullptr;
// }
// }
if(bgStartingGame != nullptr){
delete bgStartingGame;
bgStartingGame = nullptr;
}
if(airsfcraft != nullptr){
delete airsfcraft;
airsfcraft = nullptr;
}
if(timerToStart_ != nullptr){
timerToStart_->Stop();
delete timerToStart_;
timerToStart_ = nullptr;
}
if(timeAnimator != nullptr){
timeAnimator->Stop();
delete timeAnimator;
timeAnimator = nullptr;
}
if(timerToFireBullet_ != nullptr){
timerToFireBullet_->Stop();
delete timerToFireBullet_;
timerToFireBullet_ = nullptr;
}
if(timerToShowEnemyplane != nullptr){
timerToShowEnemyplane->Stop();
delete timerToShowEnemyplane;
timerToShowEnemyplane = nullptr;
}
if(onClickListener_ != nullptr){
delete onClickListener_;
onClickListener_ = nullptr;
}
if(onClickListenser_ != nullptr){
delete onClickListenser_;
onClickListenser_ = nullptr;
}
if(keyInputListener_ != nullptr){
delete keyInputListener_;
keyInputListener_ = nullptr;
}
if(pause != nullptr){
delete pause;
pause = nullptr;
}
}
void GameAirsfcraftView::Show()
{
TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE);
TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(keyInputListener_, KeyModelType::APP_KEY_TYPE);
initGameView_->SetVisible(true);
SetVisible(true);
}
void GameAirsfcraftView::InitGameView()
{
if(bgGameView == nullptr){
bgGameView = new OHOS::UIImageView();
}
OHOS::ImageInfo *descRes = nullptr;
descRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_GAME_AIRSCRAFT_BJ, IMAGE_BIN_PATH);
if(descRes != nullptr){
bgGameView->SetSrc(descRes);
}
bgGameView->SetPosition(0, 0);
bgGameView->SetVisible(true);
if(airsfcraftIcon == nullptr){
airsfcraftIcon = new OHOS::UIImageView();
}
descRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_GAME_AIRSCRAFT_AIRCRAFT, IMAGE_BIN_PATH);
if(descRes != nullptr){
airsfcraftIcon->SetSrc(descRes);
}
airsfcraftIcon->SetPosition(114, 66);
airsfcraftIcon->SetVisible(true);
if(scoreLabel == nullptr){
scoreLabel = new OHOS::UILabel();
}
char scoreText[36] = {0};
history_score = sql_bt_get_game_score(GAME_AIRCRAFT);
sprintf(scoreText, "历史最高分: %d分\n", history_score);
InitLabel(*scoreLabel, 34, 284, scoreText);
scoreLabel->SetVisible(true);
if(startGameView == nullptr){
startGameView = new OHOS::UIButton();
}
descRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_GAME_AIRSCRAFT_CONFIRM, IMAGE_BIN_PATH);
if(descRes != nullptr){
startGameView->SetImageSrc(descRes,descRes);
}
// startGameView->SetOnClickListener(new GameAirsfcraftViewOnClickListenser());
startGameView->SetOnClickListener(onClickListenser_);
startGameView->SetViewId("StartGameView");
startGameView->SetPosition(180, 347, 106, 106);
startGameView->SetStyleForState(STYLE_BORDER_COLOR, 0xff000000, UIButton::PRESSED);
startGameView->SetTouchable(true);
startGameView->SetVisible(true);
initGameView_->Add(bgGameView);
initGameView_->Add(airsfcraftIcon);
initGameView_->Add(scoreLabel);
initGameView_->Add(startGameView);
// initGameView_->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
initGameView_->SetViewId("InitGameView");
initGameView_->SetVisible(true);
}
OHOS::ImageAnimatorInfo g_airscraft_waittimeInfo_[3] = {0};
void AirscraftTimerToStartCallback(void *arg)
{
if(GameAirsfcraftView::GetInstance()->GetTimeAnimator()->GetState() == OHOS::Animator::STOP){
GameAirsfcraftView::GetInstance()->GetTimerToStart()->Stop();
GameAirsfcraftView::GetInstance()->StartGameIng();
}
}
void GameAirsfcraftView::StartGame()
{
if(startGameView_ == nullptr){
startGameView_ = new OHOS::UIViewGroup();
}
startGameView_->SetPosition(0, 466, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
startGameView_->SetViewId("StartGameView");
startGameView_->SetVisible(false);
Add(startGameView_);
initGameView_->SetVisible(false);
startGameView_->SetVisible(true);
if(bgGameView1 == nullptr){
bgGameView1 = new OHOS::UIImageView();
}
OHOS::ImageInfo *descRes = nullptr;
descRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_GAME_AIRSCRAFT_BJ, IMAGE_BIN_PATH);
if(descRes != nullptr){
bgGameView1->SetSrc(descRes);
}
bgGameView1->SetPosition(0, 0);
bgGameView1->SetVisible(true);
// startGameView_->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
const int WaitAnimatorId[3] = {IMG_GAME_3, IMG_GAME_2, IMG_GAME_1};
auto &imgManager = OHOS::ImageCacheManager::GetInstance();
for (int i = 0; i < 3; i++) {
g_airscraft_waittimeInfo_[i].imageInfo = imgManager.LoadOneInMultiRes(WaitAnimatorId[i], IMAGE_COMMON_BIN_PATH);
g_airscraft_waittimeInfo_[i].pos = {166, 87};
g_airscraft_waittimeInfo_[i].width = 132;
g_airscraft_waittimeInfo_[i].height = 184;
g_airscraft_waittimeInfo_[i].imageType = OHOS::IMG_SRC_IMAGE_INFO;
}
// Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
/* 动画页面不允许滑动 */
startGameView_->SetIntercept(true);
startGameView_->SetTouchable(false);
if(timeAnimator == nullptr){
timeAnimator = new OHOS::UIImageAnimatorView();
}
timeAnimator->SetPosition(150, 113, 166, 164);
timeAnimator->SetImageAnimatorSrc(g_airscraft_waittimeInfo_, 3, 1000);
timeAnimator->SetTimeOfPause(1000);
timeAnimator->SetRepeat(false);
if(tipLabel == nullptr){
tipLabel = new OHOS::UILabel();
}
InitLabel(*tipLabel, 34, 304, "点击屏幕控制飞机移动\n");
tipLabel->SetVisible(true);
startGameView_->Add(bgGameView1);
startGameView_->Add(timeAnimator);
startGameView_->Add(tipLabel);
timeAnimator->Start();
if (timerToStart_ == nullptr) {
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
timerToStart_ = new OHOS::GraphicTimer(1000, AirscraftTimerToStartCallback, this, true);
}
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
timerToStart_->Start();
}
OHOS::ImageAnimatorInfo g_airscraft_goldInfo_[8] = {0};
void FireBulletCallback(void * arg){
// static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
GameAirsfcraftView * gameView = static_cast<GameAirsfcraftView*>(arg);
for(int i = 0; i < BULLET_MAX_NUM; i++){
if(gameView->GetBullet(i) != nullptr && !gameView->GetBullet(i)->GetBulletView().IsVisible()){
gameView->GetBullet(i)->GetBulletView().SetVisible(true);
return;
}
}
// gameView->GetTimerToFireBullet()->Stop();
}
void ShowEnenmyplaneCallback(void * arg){
// static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
GameAirsfcraftView * gameView = static_cast<GameAirsfcraftView*>(arg);
for(int i = 0; i < ENEMYPLANE_MAX_NUM; i++){
if(gameView->GetEnemyPlane(i) != nullptr && !gameView->GetEnemyPlane(i)->GetEnemyPlaneView().IsVisible()){
gameView->GetEnemyPlane(i)->GetEnemyPlaneView().SetVisible(true);
return;
}
}
// gameView->GetTimerToShowEnemyplane()->Stop();
}
void GameAirsfcraftView::StartGameIng()
{
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
srand(time(nullptr));
if(startGameIngView_ == nullptr){
startGameIngView_ = new OHOS::UIViewGroup();
}
startGameIngView_->SetPosition(0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION , OHOS::HORIZONTAL_RESOLUTION);
startGameIngView_->SetViewId("StartGameIngView");
startGameIngView_->SetVisible(false);
Add(startGameIngView_);
startGameView_->SetVisible(false);
if(pause == nullptr){
pause = new OHOS::UIButton();
}
ImageInfo * descRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_GAME_AIRSCRAFT_PAUSE, IMAGE_BIN_PATH);
if(descRes != nullptr){
pause->SetImageSrc(descRes,descRes);
}
// pause->SetOnClickListener(new GameAirsfcraftViewOnClickListenser());
pause->SetOnClickListener(onClickListenser_);
pause->SetViewId("PauseButton");
pause->SetPosition(151, 115, 164, 164);
pause->SetStyleForState(STYLE_BORDER_COLOR, 0xff000000, UIButton::PRESSED);
pause->SetTouchable(true);
pause->SetVisible(false);
if(bgStartingGame == nullptr){
bgStartingGame = new OHOS::UIImageView();
}
// OHOS::ImageInfo *descRes = nullptr;
descRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_GAME_AIRSCRAFT_BJ, IMAGE_BIN_PATH);
if(descRes != nullptr){
bgStartingGame->SetSrc(descRes);
}
bgStartingGame->SetPosition(0, 0);
bgStartingGame->SetVisible(true);
startGameIngView_->Add(bgStartingGame);
if(airsfcraft == nullptr){
airsfcraft = new Airsfcraft();
}
airsfcraft->InitAirsfcraft(153, 329, 161, 137, AIRSCRAFT_NORMAL);
airsfcraft->DrawAirsfcraft();
for(int i = 0; i < BULLET_MAX_NUM; i++){
if(bullet[i] == nullptr){
bullet[i] = static_cast<AirsfcraftBullet*>(new AirsfcraftBullet(230, 329, 6, 17));
}
bullet[i]->DrawBullet();
// bullet[i]->GetBulletView().SetVisible(false);
startGameIngView_->Add(&bullet[i]->GetBulletView());
}
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
for(int i = 0; i < ENEMYPLANE_MAX_NUM; i++){
// srand(time(nullptr));
// int score = rand() % 1000;
int resId = (i % 2 == 0 ? IMG_GAME_AIRSCRAFT_E_SC1 : IMG_GAME_AIRSCRAFT_E_SC2);
if(enemyplane[i] == nullptr){
enemyplane[i] = static_cast<EnemyPlane*>(new EnemyPlane(0,resId));
}
enemyplane[i]->DrawEnemyPlane();
// enemyplane[i]->GetEnemyPlaneView().SetVisible(false);
startGameIngView_->Add(&enemyplane[i]->GetEnemyPlaneView());
}
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
// for(int i = 0; i < GOLD_ANIM_MAX_NUM; i++){
// const int GoldAnimatorId[GOLD_ANIM_MAX_NUM] = { IMG_GAME_Airsfcraft_GOLD_0, IMG_GAME_Airsfcraft_GOLD_1, IMG_GAME_Airsfcraft_GOLD_2,
// IMG_GAME_Airsfcraft_GOLD_3, IMG_GAME_Airsfcraft_GOLD_4, IMG_GAME_Airsfcraft_GOLD_5, IMG_GAME_Airsfcraft_GOLD_6, IMG_GAME_Airsfcraft_GOLD_7};
// g_airscraft_goldInfo_[i].imageInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(GoldAnimatorId[i], IMAGE_BIN_PATH);
// g_airscraft_goldInfo_[i].pos = {0, 233};
// g_airscraft_goldInfo_[i].width = 45;
// g_airscraft_goldInfo_[i].height = 38;
// g_airscraft_goldInfo_[i].imageType = OHOS::IMG_SRC_IMAGE_INFO;
// }
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
// for(int i = 0; i < RESOURCE_MAX_NUM; i++){
// // srand(time(nullptr));
// // int randNum = rand() % 10;
// // int resId = (randNum <= 5 ? 0 : (randNum == 6 ? IMG_GAME_Airsfcraft_Airsfcraft_RIGHT : (randNum == 7 ? IMG_GAME_Airsfcraft_Airsfcraft_UP : (randNum == 8 ? IMG_GAME_Airsfcraft_Airsfcraft_UP_DOWN : IMG_GAME_Airsfcraft_Airsfcraft_DOWN))));
// static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
// if(resource[i] == nullptr){
// resource[i] = static_cast<Resource*>(new Resource(932 + i * 50,RESOURCE_GOLD,0));
// }
// resource[i]->DrawResource();
// if(resource[i]->GetResourceView() != nullptr){
// resource[i]->GetResourceView()->SetVisible(true);
// startGameIngView_->Add(resource[i]->GetResourceView());
// }else if(resource[i]->GetResourceAnimator() != nullptr){
// resource[i]->GetResourceAnimator()->SetVisible(true);
// startGameIngView_->Add(resource[i]->GetResourceAnimator());
// }
// }
startGameIngView_->SetIntercept(true);
startGameIngView_->SetTouchable(true);
startGameIngView_->SetDraggable(true);
startGameIngView_->SetOnDragListener(&ondragListener_);
// startGameIngView_->SetOnClickListener(onClickListenser_);
// startGameIngView_->SetOnLongPressListener(&longPressListenser_);
// startGameIngView_->SetOnClickListener(new AirsfcraftStartIngOnClickListenser());
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
// timerToAirsfcraft_->Start();
// timerToBackground_->Start();
if(animotorCallback == nullptr){
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
animotorCallback = new GameAirsfcraftAnimotorCallback(airsfcraft,bullet,enemyplane,startGameIngView_, AIRSCRAFT_NORMAL);
}
if(animator == nullptr){
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
animator = new OHOS::Animator(animotorCallback, this, 500, true);
}
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
airsfcraft->GetAnimator()->SetVisible(true);
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
startGameIngView_->Add(airsfcraft->GetAnimator());
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
animator->Start();
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
startGameIngView_->SetVisible(true);
startGameIngView_->Add(pause);
// Invalidate();
if(timerToFireBullet_ == nullptr){
timerToFireBullet_ = new OHOS::GraphicTimer(500, FireBulletCallback, this, true);
}
timerToFireBullet_->Start();
if(timerToShowEnemyplane == nullptr){
timerToShowEnemyplane = new OHOS::GraphicTimer(1000, ShowEnenmyplaneCallback, this, true);
}
timerToShowEnemyplane->Start();
}
void GameAirsfcraftView::PauseGame()
{
if (animator)
animator->Pause();
if (airsfcraft)
airsfcraft->GetAnimator()->Pause();
if (pause)
pause->SetVisible(true);
}
void GameAirsfcraftView::ResumeGame() {}
void GameAirsfcraftView::RestartGame()
{
airsfcraft->SetX(153);
airsfcraft->SetY(329);
airsfcraft->SetPosition();
airsfcraft->DrawAirsfcraft();
score = 0;
for(int i = 0; i < ENEMYPLANE_MAX_NUM; i++){
if(enemyplane[i] != nullptr){
srand(time(nullptr));
int randNum = rand() % (OHOS::VERTICAL_RESOLUTION - enemyplane[i]->GetWidth());
enemyplane[i]->SetX(randNum);
enemyplane[i]->SetY(randNum % 10);
enemyplane[i]->SetPosition();
}
}
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
// for(int i = 0; i < RESOURCE_MAX_NUM; i++){
// if(resource[i] != nullptr){
// srand(time(nullptr));
// int randNum = rand() % 50 + 30 * i;
// resource[i]->SetX(932 + randNum);
// resource[i]->SetPosition();
// }
// }
GameAirsfcraftAnimotorCallback::GetInstance()->Setevent(AIRSCRAFT_NORMAL);
GameAirsfcraftView::GetInstance()->GetAnimator()->Start();
// GameAirsfcraftView::GetInstance()->GetTimerToStart()->Start();
}
void GameAirsfcraftView::StopGame()
{
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
if(stopGameView_ == nullptr){
stopGameView_ = new OHOS::UIViewGroup();
}
// startGameIngView_->SetVisible(false);
// timerToFireBullet_->Stop();
// timerToShowEnemyplane->Stop();
stopGameView_->SetPosition(0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION, OHOS::HORIZONTAL_RESOLUTION);
stopGameView_->SetViewId("StopGameView");
stopGameView_->SetVisible(false);
Add(stopGameView_);
if(stopView_bg == nullptr){
stopView_bg = new OHOS::UIImageView();
}
OHOS::ImageInfo *descRes = nullptr;
descRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_GAME_AIRSCRAFT_BJ, IMAGE_BIN_PATH);
if(descRes != nullptr){
stopView_bg->SetSrc(descRes);
}
stopView_bg->SetPosition(0, 0);
stopView_bg->SetVisible(true);
if(titleLabel == nullptr){
titleLabel = new OHOS::UILabel();
}
InitLabel(*titleLabel, 46, 51, "GAME OVER\n");
titleLabel->SetVisible(true);
if(stopView_block == nullptr){
stopView_block = new OHOS::UIImageView();
}
descRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_GAME_AIRSCRAFT_GAME_OVER_BJ, IMAGE_BIN_PATH);
if(descRes != nullptr){
stopView_block->SetSrc(descRes);
}
stopView_block->SetPosition(81, 102);
stopView_block->SetVisible(true);
if(stopView_icon == nullptr){
stopView_icon = new OHOS::UIImageView();
}
descRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_GAME_AIRSCRAFT_AIRCRAFT_OVER_ICON, IMAGE_BIN_PATH);
if(descRes != nullptr){
stopView_icon->SetSrc(descRes);
}
stopView_icon->SetPosition(120, 143);
stopView_icon->SetVisible(true);
if(scoreLabel1 == nullptr){
scoreLabel1 = new OHOS::UILabel();
}
char scoreText[16] = {0};
sprintf(scoreText, "得分: %d分\n", score);
sql_bt_set_game_score(GAME_AIRCRAFT, &score);
InitLabel(*scoreLabel1, 28, 159, scoreText);
scoreLabel1->SetPosition(198,155);
scoreLabel1->SetStyle(STYLE_TEXT_COLOR, Color::Black().full);
scoreLabel1->SetVisible(true);
if(stopView_start == nullptr){
stopView_start = new OHOS::UIButton();
}
descRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_GAME_AIRSCRAFT_CONTINUE, IMAGE_BIN_PATH);
if(descRes != nullptr){
stopView_start->SetImageSrc(descRes,descRes);
}
stopView_start->SetOnClickListener(onClickListenser_);
// stopView_start->SetOnClickListener(new GameAirsfcraftViewOnClickListenser());
stopView_start->SetViewId("ContinueButton");
stopView_start->SetPosition(112, 216, 242, 76);
stopView_start->SetStyleForState(STYLE_BORDER_COLOR, 0xff000000, UIButton::PRESSED);
stopView_start->SetTouchable(true);
stopView_start->SetVisible(true);
if(stopView_return == nullptr){
stopView_return = new OHOS::UIButton();
}
descRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_GAME_AIRSCRAFT_RETURE, IMAGE_BIN_PATH);
if(descRes != nullptr){
stopView_return->SetImageSrc(descRes,descRes);
}
stopView_return->SetOnClickListener(onClickListenser_);
stopView_return->SetViewId("ReturnButton");
stopView_return->SetPosition(112, 296, 242, 76);
stopView_return->SetStyleForState(STYLE_BORDER_COLOR, 0xff000000, UIButton::PRESSED);
stopView_return->SetTouchable(true);
stopView_return->SetVisible(true);
stopGameView_->Add(stopView_bg);
stopGameView_->Add(titleLabel);
stopGameView_->Add(stopView_block);
stopGameView_->Add(stopView_icon);
stopGameView_->Add(scoreLabel1);
stopGameView_->Add(stopView_start);
stopGameView_->Add(stopView_return);
// initGameView_->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
stopGameView_->SetViewId("StopGameView");
stopGameView_->SetVisible(true);
}
GameAirsfcraftAnimotorCallback *GameAirsfcraftAnimotorCallback::GetInstance(){return g_pv_AirsfcraftAnimotorCallback;}
GameAirsfcraftView *GameAirsfcraftView::GetInstance() { return g_pv_AirsfcraftView; }
// AirsfcraftBackGround *GameAirsfcraftView::GetBackGround(uint8_t index)
// {
// if(index >= BACKGROUND_MAX_NUM) return nullptr;
// return backGround[index];
// }
#pragma region Airsfcraft
Airsfcraft::Airsfcraft() {}
Airsfcraft::~Airsfcraft()
{
if(animator != nullptr){
animator->Stop();
delete animator;
animator = nullptr;
}
}
void Airsfcraft::InitAirsfcraft(int x, int y, int width, int height, uint8_t statue)
{
this->x = x;
this->y = y;
this->width = width;
this->height = height;
this->statue = statue;
}
void Airsfcraft::MoveDownAirsfcraft()
{
if(statue == AIRSCRAFT_NORMAL){
y += 2;
if(y > OHOS::VERTICAL_RESOLUTION - height){
// y = OHOS::VERTICAL_RESOLUTION - height;
SetAirsfcraftStatue(AIRSCRAFT_DIE);
GameAirsfcraftAnimotorCallback::GetInstance()->Setevent(AIRSCRAFT_DIE);
}
SetPosition();
}
}
void Airsfcraft::MoveAirsfcraft(int16_t x_ , int16_t y_)
{
if(statue == AIRSCRAFT_NORMAL){
//使飞机坐标 x y 向 x_ y_ 方向移动
static_print_debug("x : %d , x_ : %d, y : %d , y_ : %d", x, x_, y, y_);
// x += (x_ > x) ? 5 : -5;
// y += (y_ > y) ? 5 : -5;
x = x_ - (width >> 1);
y = y_ - (height >> 1);
if( x < width >> 1 ){
x = width >> 1;
}
if(x > OHOS::VERTICAL_RESOLUTION - (width >> 1)){
x = OHOS::VERTICAL_RESOLUTION - (width >> 1);
}
if(y < height >> 1){
y = height >> 1;
}
if(y > OHOS::HORIZONTAL_RESOLUTION - (height >> 1)){
y = OHOS::HORIZONTAL_RESOLUTION - (height >> 1);
}
// if(x - x_ <= 0 || x_ - x < (width >> 1) || y - y_ < (height >> 1) || y_ - y < (height >> 1)){
// //飞机坐标与目标坐标距离小于飞机宽度高度的一半时,飞机停止移动
// static_print_debug("line is %d , x : %d , x_ : %d, y : %d , y_ : %d", __LINE__, x, x_, y, y_);
// x = x_ - (width >> 1);
// y = y_ - (height >> 1);
// }
// if(ABS(x - x_) <= 0 && ABS(y - y_) <= 0){
// //飞机坐标与目标坐标距离小于飞机宽度高度的一半时,触屏点位于飞机正中间
// x = x_ - (width >> 1);
// y = y_ - (height >> 1);
// static_print_debug("line is %d , x : %d , x_ : %d, y : %d , y_ : %d", __LINE__, x, x_, y, y_);
// }
// if(x_ > x){
// x++;
// }else{
// x--;
// }
// if(y_ > y){
// y++;
// }else{
// y--;
// }
SetX(x);
SetY(y);
SetPosition();
}
}
void Airsfcraft::DrawAirsfcraft()
{
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
const int AirsfcraftAnimatorId[AIRSFCRAFT_ANIM_IMAGE_MAX_NUM] = { IMG_GAME_AIRSCRAFT_SCRAFT0, IMG_GAME_AIRSCRAFT_SCRAFT1,
IMG_GAME_AIRSCRAFT_SCRAFT2, IMG_GAME_AIRSCRAFT_SCRAFT3, IMG_GAME_AIRSCRAFT_SCRAFT4,IMG_GAME_AIRSCRAFT_SCRAFT5,IMG_GAME_AIRSCRAFT_SCRAFT6};
// auto &imgManager = OHOS::ImageCacheManager::GetInstance();
for (int i = 0; i < AIRSFCRAFT_ANIM_IMAGE_MAX_NUM; i++) {
g_pv_AirsfcraftInfo_[i].imageInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(AirsfcraftAnimatorId[i], IMAGE_BIN_PATH);
g_pv_AirsfcraftInfo_[i].pos = {(signed short)this->x, (signed short)this->y};
g_pv_AirsfcraftInfo_[i].width = 161;
g_pv_AirsfcraftInfo_[i].height = 137;
g_pv_AirsfcraftInfo_[i].imageType = OHOS::IMG_SRC_IMAGE_INFO;
}
if(animator == nullptr){
animator = new OHOS::UIImageAnimatorView();
}
animator->SetPosition(g_pv_AirsfcraftInfo_->pos.x, g_pv_AirsfcraftInfo_->pos.y);
animator->Resize(g_pv_AirsfcraftInfo_->width, g_pv_AirsfcraftInfo_->height);
animator->SetImageAnimatorSrc(g_pv_AirsfcraftInfo_, AIRSFCRAFT_ANIM_IMAGE_MAX_NUM, 700);
animator->SetSizeFixed(true);
animator->Start();
}
void Airsfcraft::SetAirsfcraftStatue(uint8_t statue) {}
uint8_t Airsfcraft::GetAirsfcraftStatue() { return 0; }
#pragma endregion
AirsfcraftBullet::~AirsfcraftBullet() {}
void AirsfcraftBullet::DrawBullet()
{
// OHOS::ImageCacheManager::GetInstance().UnloadAllInMultiRes(IMAGE_BIN_PATH);
OHOS::ImageInfo * imageInfo = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_GAME_AIRSCRAFT_BULLET1, IMAGE_BIN_PATH);
if(imageInfo != nullptr){
bullet.SetSrc(imageInfo);
}
bullet.SetPosition(this->x, this->y, this->width, this->height);
bullet.SetVisible(false);
}
void AirsfcraftBullet::MoveBullet()
{
int y = this->y;
y-=5;
// printf("x = %d, x1 = %d\n", x, x1);
if (y <= 0)
{
x = GameAirsfcraftView::GetInstance()->GetAirsfcraft()->GetX() + (GameAirsfcraftView::GetInstance()->GetAirsfcraft()->GetWidth() >> 1);
y = GameAirsfcraftView::GetInstance()->GetAirsfcraft()->GetY() - height;
}
SetY(y);
SetPosition();
}
bool GameAirsfcraftViewOnClickListenser::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
{
if(view.GetViewId() == "StartGameView"){
GameAirsfcraftView::GetInstance()->StartGame();
}else if(view.GetViewId() == "ContinueButton"){
// GameAirsfcraftView::GetInstance()->GetAnimator()->Resume();
GameAirsfcraftView::GetInstance()->GetStopGameView()->SetVisible(false);
GameAirsfcraftView::GetInstance()->RestartGame();
}else if(view.GetViewId() == "ReturnButton"){
TjdUiAppGameView::GetInstance()->ReturnToMainPage();
}else if(view.GetViewId() == "PauseButton"){
GameAirsfcraftView::GetInstance()->GetAnimator()->Start();
GameAirsfcraftView::GetInstance()->GetAirsfcraft()->GetAnimator()->Start();
GameAirsfcraftView::GetInstance()->GetPauseBtn()->SetVisible(false);
}
return false;
}
GameAirsfcraftAnimotorCallback::GameAirsfcraftAnimotorCallback(Airsfcraft *Airsfcraft,AirsfcraftBullet ** bullet,EnemyPlane ** enemyplane,UIViewGroup *gameAirsfcraftView, uint8_t event):airsfcraft(Airsfcraft),
enemyplane(enemyplane),bullet(bullet),gameAirsfcraftView(gameAirsfcraftView), event(event)
{
g_pv_AirsfcraftAnimotorCallback = this;
}
GameAirsfcraftAnimotorCallback::~GameAirsfcraftAnimotorCallback()
{
g_pv_AirsfcraftAnimotorCallback = nullptr;
}
void GameAirsfcraftAnimotorCallback::Callback(UIView *view)
{
// static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
if(AIRSCRAFT_NORMAL == event){
// static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
// airsfcraft->MoveDownAirsfcraft();
// backGround1->MoveBackGround();
// backGround2->MoveBackGround();
for(int i = 0; i < BULLET_MAX_NUM; i++){
if(bullet[i] != nullptr && bullet[i]->GetBulletView().IsVisible()){
bullet[i]->MoveBullet();
}
// if(bullet[i] != nullptr && bullet[i+1] != nullptr && bullet[i]->GetBulletView().IsVisible()){
// if(ABS(bullet[i]->GetY() - bullet[i+1]->GetY()) <= 3){
// static_print_debug("下一颗子弹与上一颗子弹距离太近");
// // bullet[i+1]->SetY(GameAirsfcraftView::GetInstance()->GetAirsfcraft()->GetY() - GameAirsfcraftView::GetInstance()->GetAirsfcraft()->GetHeight());
// // bullet[i+1]->GetBulletView().SetVisible(false);
// }
// }
}
for(int i = 0; i < ENEMYPLANE_MAX_NUM; i++){
if(enemyplane[i] != nullptr && enemyplane[i]->GetEnemyPlaneView().IsVisible()){
enemyplane[i]->MoveEnemyPlane();
if(enemyplane[i]->GetY() >= OHOS::HORIZONTAL_RESOLUTION){
airsfcraft->SetAirsfcraftStatue(AIRSCRAFT_DIE);
Setevent(AIRSCRAFT_DIE);
}
}
}
int bullet_x , bullet_y, enemyplane_x, enemyplane_y, enemyplane_xd, enemyplane_xy = 0;
for(int i = 0; i < ENEMYPLANE_MAX_NUM; i++){
for(int j = 0; j < BULLET_MAX_NUM; j++){
enemyplane_x = enemyplane[i]->GetX() + (enemyplane[i]->GetWidth() >> 1);
enemyplane_y = enemyplane[i]->GetY() + (enemyplane[i]->GetHeight() >> 1);
bullet_x = bullet[j]->GetX() + (bullet[j]->GetWidth() >> 1);
bullet_y = bullet[j]->GetY() + (bullet[j]->GetHeight() >> 1);
enemyplane_xd = (bullet[j]->GetWidth() + enemyplane[i]->GetWidth()) >> 1;
enemyplane_xy = (bullet[j]->GetHeight() + enemyplane[i]->GetHeight()) >> 1;
uint32_t delta_x , delta_y = 0;
delta_x = ABS(enemyplane_x - bullet_x);
delta_y = ABS(enemyplane_y - bullet_y);
if(delta_x < enemyplane_xd && delta_y < enemyplane_xy){//撞到子弹
bullet[j]->GetBulletView().SetVisible(false);
bullet[j]->SetX(GameAirsfcraftView::GetInstance()->GetAirsfcraft()->GetX());
bullet[j]->SetY(GameAirsfcraftView::GetInstance()->GetAirsfcraft()->GetY() - GameAirsfcraftView::GetInstance()->GetAirsfcraft()->GetHeight());
enemyplane[i]->GetEnemyPlaneView().SetVisible(false);
enemyplane[i]->DrawEnemyPlaneBoomAnimator();
int rand_num = rand() % (OHOS::VERTICAL_RESOLUTION - enemyplane[i]->GetWidth());
enemyplane[i]->SetX(rand_num);
enemyplane[i]->SetY(0);
enemyplane[i]->SetPosition();
GameAirsfcraftView::GetInstance()->SetScore();
// enemyplane[i]->GetEnemyPlaneView().SetVisible(true);
}
// if(enemyplane[j] != nullptr && enemyplane[j]->GetEnemyPlaneView().IsVisible()){
// bullet_x = bullet[i]->GetBulletView().GetX();
// bullet_y = bullet[i]->GetBulletView().GetY();
// enemyplane_min_x = enemyplane[j]->GetX();
// enemyplane_min_y = enemyplane[j]->GetY();
// enemyplane_max_x = enemyplane_min_x + enemyplane[j]->GetWidth();
// enemyplane_max_y = enemyplane_min_y + enemyplane[j]->GetHeight();
// if(bullet_x >= enemyplane_min_x && bullet_x <= enemyplane_max_x && bullet_y >= enemyplane_min_y && bullet_y <= enemyplane_max_y){
// enemyplane[j]->GetEnemyPlaneView().SetVisible(false);
// enemyplane[j]->DrawEnemyPlaneBoomAnimator();
// bullet[i]->GetBulletView().SetVisible(false);
// GameAirsfcraftView::GetInstance()->SetScore();
// int rand_num = rand() % (OHOS::VERTICAL_RESOLUTION - enemyplane[j]->GetWidth());
// enemyplane[j]->SetX(rand_num);
// enemyplane[j]->SetY(0);
// enemyplane[j]->GetEnemyPlaneView().SetVisible(true);
// enemyplane[j]->SetPosition();
// }
// }
}
}
// int x1, x2, y1, y2, xd, yd = 0;
// short delta_x, delta_y = 0;
// x1 = airsfcraft->GetX() + (airsfcraft->GetWidth() >> 1);
// y1 = airsfcraft->GetY() + (airsfcraft->GetHeight() >> 1);
// for(int i = 0; i < ENEMYPLANE_MAX_NUM; i++){
// if(enemyplane[i] != nullptr && enemyplane[i]->GetEnemyPlaneView().IsVisible()){
// enemyplane[i]->MoveEnemyPlane();
// x2 = enemyplane[i]->GetX() + (enemyplane[i]->GetWidth() >> 1);
// y2 = enemyplane[i]->GetY() + (enemyplane[i]->GetHeight() >> 1);
// xd = ((airsfcraft->GetWidth() + enemyplane[i]->GetWidth()) >> 1) - 4;
// yd = ((airsfcraft->GetHeight() + enemyplane[i]->GetHeight()) >> 1) - 2;
// delta_x = x2 - x1;
// delta_y = y2 - y1;
// if(delta_x < xd && delta_y < yd){//撞到敌机
// airsfcraft->SetAirsfcraftStatue(AIRSCRAFT_DIE);
// Setevent(AIRSCRAFT_DIE);
// }
// }
// }
// for(int i = 0; i < RESOURCE_MAX_NUM; i++){
// resource[i]->MoveResource();
// x2 = resource[i]->GetX() + (resource[i]->GetWidth() >> 1);
// y2 = resource[i]->GetY() + (resource[i]->GetHeight() >> 1);
// xd = ((Airsfcraft->GetWidth() + resource[i]->GetWidth()) >> 1) - 4;
// yd = ((Airsfcraft->GetHeight() + resource[i]->GetHeight()) >> 1) - 2;
// delta_x = x2 - x1;
// delta_y = y2 - y1;
// if(delta_x < xd && delta_y < yd){//撞到资源
// resource[i]->ReleaseResource();
// GameAirsfcraftView::GetInstance()->SetScore();
// }
// }
}else if(AIRSCRAFT_DIE == event){
GameAirsfcraftView::GetInstance()->GetAnimator()->Pause();
// airsfcraft->ChangeAirsfcraftDieAnimator();
// while(airsfcraft->GetY() >= 0){
// airsfcraft->SetY(airsfcraft->GetY() + 20);
// airsfcraft->SetPosition();
// }
if(GameAirsfcraftView::GetInstance()->GetStopGameView() == nullptr){
GameAirsfcraftView::GetInstance()->StopGame();
}else{
GameAirsfcraftView::GetInstance()->GetStopGameView()->SetVisible(true);
GameAirsfcraftView::GetInstance()->GetStopGameView()->Invalidate();
}
}
// static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
gameAirsfcraftView->Invalidate();
}
bool AirsfcraftViewKeyInputListener::OnKeyAct(UIView &view, const KeyEvent &event)
{
if (!TjdUiCommonOnKeyListener::CheckIsExitEvent(event)) {
return true;
}
if (event.GetState() == OHOS::InputDevice::STATE_RELEASE && !GameAirsfcraftView::GetInstance()->GetPauseBtn()->IsVisible())
{
GameAirsfcraftView::GetInstance()->PauseGame();
} else if(GameAirsfcraftView::GetInstance()->GetPauseBtn()->IsVisible()){
TjdUiAppGameView::GetInstance()->ReturnToMainPage();
};
// if(GameAirsfcraftView::GetInstance()->GetTimeAnimator()->GetState() == OHOS::Animator::STOP)
return true;
}
// bool AirsfcraftOnLongPressListenser::OnLongPress(OHOS::UIView &view, const OHOS::LongPressEvent &event)
// {
// if(view.GetViewId() == "StartGameIngView"){
// int16_t x = event.GetCurrentPos().x;
// int16_t y = event.GetCurrentPos().y;
// GameAirsfcraftView::GetInstance()->GetAirsfcraft()->MoveAirsfcraft(x , y);
// }
// return false;
// }
bool AirsfcraftOnDragListener::OnDragStart(OHOS::UIView &view, const OHOS::DragEvent &event)
{
// if(view.GetViewId() == "StartGameIngView"){
// int16_t x = event.GetCurrentPos().x;
// int16_t y = event.GetCurrentPos().y;
// GameAirsfcraftView::GetInstance()->GetAirsfcraft()->MoveAirsfcraft(x , y);
// }
return false;
}
bool AirsfcraftOnDragListener::OnDragEnd(OHOS::UIView &view, const OHOS::DragEvent &event)
{
// if(view.GetViewId() == "StartGameIngView"){
// int16_t x = event.GetCurrentPos().x;
// int16_t y = event.GetCurrentPos().y;
// GameAirsfcraftView::GetInstance()->GetAirsfcraft()->MoveAirsfcraft(x , y);
// }
return false;
}
bool AirsfcraftOnDragListener::OnDrag(OHOS::UIView &view, const OHOS::DragEvent &event)
{
if(view.GetViewId() == "StartGameIngView"){
int16_t x = event.GetCurrentPos().x;
int16_t y = event.GetCurrentPos().y;
GameAirsfcraftView::GetInstance()->GetAirsfcraft()->MoveAirsfcraft(x , y);
}
return false;
}
EnemyPlane::EnemyPlane(int y , int resId): y(y), resId(resId)
{
if(resId == IMG_GAME_AIRSCRAFT_E_SC1){
this->width = 86;
int rand_num = rand() % (OHOS::VERTICAL_RESOLUTION - this->width);
this->x = rand_num;
this->height = 55;
}else if(resId == IMG_GAME_AIRSCRAFT_E_SC2){
this->width = 45;
int rand_num = rand() % (OHOS::VERTICAL_RESOLUTION - this->width);
this->x = rand_num;
this->height = 57;
}
};
void EnemyPlane::DrawEnemyPlane()
{
OHOS::ImageInfo * imageInfo = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(this->resId, IMAGE_BIN_PATH);
if(imageInfo != nullptr){
EnemyPlaneView.SetSrc(imageInfo);
}
EnemyPlaneView.SetPosition(this->x, this->y, this->width, this->height);
EnemyPlaneView.SetVisible(false);
}
void EnemyPlane::DrawEnemyPlaneBoomAnimator(){
const int AirsfcraftAnimatorId[ENEMYPLANE_DIE_ANIM_IMAGE_MAX_NUM] = { IMG_GAME_AIRSCRAFT_C_BOOM0, IMG_GAME_AIRSCRAFT_C_BOOM1,
IMG_GAME_AIRSCRAFT_C_BOOM2, IMG_GAME_AIRSCRAFT_C_BOOM3, IMG_GAME_AIRSCRAFT_C_BOOM4,IMG_GAME_AIRSCRAFT_C_BOOM5,IMG_GAME_AIRSCRAFT_C_BOOM6,
IMG_GAME_AIRSCRAFT_C_BOOM7};
// auto &imgManager = OHOS::ImageCacheManager::GetInstance();
for (int i = 0; i < ENEMYPLANE_DIE_ANIM_IMAGE_MAX_NUM; i++) {
g_pv_EnemyPlaneBoomInfo_[i].imageInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(AirsfcraftAnimatorId[i], IMAGE_BIN_PATH);
g_pv_EnemyPlaneBoomInfo_[i].pos = {(signed short)this->x, (signed short)this->y};
g_pv_EnemyPlaneBoomInfo_[i].width = 202;
g_pv_EnemyPlaneBoomInfo_[i].height = 107;
g_pv_EnemyPlaneBoomInfo_[i].imageType = OHOS::IMG_SRC_IMAGE_INFO;
}
animator.SetPosition(g_pv_EnemyPlaneBoomInfo_->pos.x, g_pv_EnemyPlaneBoomInfo_->pos.y);
animator.Resize(g_pv_EnemyPlaneBoomInfo_->width, g_pv_EnemyPlaneBoomInfo_->height);
animator.SetImageAnimatorSrc(g_pv_EnemyPlaneBoomInfo_, ENEMYPLANE_DIE_ANIM_IMAGE_MAX_NUM, 100);
animator.SetSizeFixed(true);
animator.SetRepeat(false);
animator.Start();
}
void EnemyPlane::MoveEnemyPlane()
{
int y = this->y;
y++;
// if (x + this->width <= 466)
// {
// srand(time(nullptr));
// int randNum = rand() % 300 + 30 * rand() % 3;
// x = 932 + randNum;
// srand(time(nullptr));
// randNum = rand() % 200 + 50;
// SetHeight(randNum);
// }
SetY(y);
SetPosition();
}
} // namespace TJD