monster.hpp
上传用户:zhj2929
上传日期:2022-07-23
资源大小:28772k
文件大小:8k
- #ifndef _MONSTER_HPP
- #define _MONSTER_HPP
- #include "../../JGE/HGE/include/hgesprite.h"
- #include "../../JGE/HGE/include/hgeparticle.h"
- #include "Mario.hpp"
- extern HGE *hge;
- extern float mario_x;
- extern float mario_y;
- extern float mapPositionX;
- extern float mapPositionY;
- class Monster: public MoveableObject
- {
- private:
-
- JSprite* mRun;
- JSprite* mDie;
- JSprite* mIdle;
- TileMap* mMap;
-
- u8 mTileInfo;
- hgeSprite* spt;
- HTEXTURE tex;
- hgeParticleSystem * par1;
- hgeParticleSystem * par2;
- hgeParticleSystem * par3;
- hgeParticleSystem * par4;
- hgeParticleSystem * par5;
- hgeParticleSystem * par6;
- hgeParticleSystem * par7;
- hgeParticleSystem * par8;
- hgeParticleSystem * par9;
- hgeParticleSystem * par10;
- hgeParticleSystem * par11;
- hgeParticleSystem * par12;
- bool attack;
- int dead;
-
- public:
- Monster(GameStatePlay* app);
- virtual ~Monster();
- virtual void Update(float dt);
- virtual void HitLeft();
- virtual void HitRight();
-
- virtual void Render();
- void Spawn(int col, int row);
- void die();
- int aLive();
- int gameEnd;
- };
- void Monster::die()
- {
- mCurrAnimation = mDie;
- dead = 1 ;
- attack = 0 ;
- }
- int Monster::aLive()
- {
- if(dead==0)
- return 1;
- else
- return 0;
- }
- Monster::Monster(GameStatePlay* app): MoveableObject(app)
- {
- gameEnd = false ;
- mMap = mApp->GetTileMap();
- mRun = new JSprite(mTexture, 131,329,110,160);
- mRun->SetHotSpot(0.0f, 160.0f);
- mRun->AddFrame(260,334,120,160);
- mRun->AddFrame(383,339,120,160);
- mRun->SetDuration(400.0f);
- mRun->StartAnimation();
- mIdle = new JSprite(mTexture, 131,329,110,160);
- mIdle->SetHotSpot(0.0f, 160.0f);
- mIdle->StartAnimation();
- mDie = new JSprite(mTexture, 131,329,110,160);
- mDie->SetHotSpot(0.0f, 160.0f);
- mDie->AddFrame(212,489,131,148);
- mDie->AddFrame(353,492,145,152);
- mDie->SetDuration(300.0f);
- mDie->StartAnimation();
-
- mCurrAnimation = mIdle;
- mYRenderOffset = 6.0f;
- mXVelocity = -DEFAULT_WALK_SPEED/2;
- mFlipped = false;
- mHScale = 0.80f;
- mVScale = 0.80f;
- mLeftAdjustment = 23;
- mRightAdjustment = 47;
- mHitLeftAdjustment = 2;
- mHitRightAdjustment = 46;
- mFallLeftAdjustment = -20;
- mFallRightAdjustment = -10;
- mRealHeight = 60;
- dead = 0 ;
- //粒子的渲染图形
- tex=hge->Texture_Load("particle/particles.png");
- //如果加载失败,则弹出提示窗口
- if(!tex)
- {
- MessageBox(NULL, "Can't load particles.png", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
- }
- //设置粒子的渲染图形
- spt=new hgeSprite(tex, 32, 32, 32, 32);
- spt->SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE);
- spt->SetHotSpot(16,16);
- //初始化粒子系统,并点燃粒子系统
- par1=new hgeParticleSystem("trail.psi",spt);
- par1->Fire();
- par2=new hgeParticleSystem("trail.psi",spt);
- par2->Fire();
- par3=new hgeParticleSystem("trail.psi",spt);
- par3->Fire();
- par4=new hgeParticleSystem("trail.psi",spt);
- par4->Fire();
- par5=new hgeParticleSystem("trail.psi",spt);
- par5->Fire();
- par6=new hgeParticleSystem("trail.psi",spt);
- par6->Fire();
- par7=new hgeParticleSystem("trail.psi",spt);
- par7->Fire();
- par8=new hgeParticleSystem("trail.psi",spt);
- par8->Fire();
- par9=new hgeParticleSystem("trail.psi",spt);
- par9->Fire();
- par10=new hgeParticleSystem("trail.psi",spt);
- par10->Fire();
- par11=new hgeParticleSystem("trail.psi",spt);
- par11->Fire();
- par12=new hgeParticleSystem("trail.psi",spt);
- par12->Fire();
- attack = false;
- }
- Monster::~Monster()
- {
-
- delete mRun;
- delete mIdle;
- delete mDie;
- delete par1;
- delete par2;
- delete par3;
- delete par4;
- delete par5;
- delete par6;
- delete par7;
- delete par8;
- delete par9;
- delete par10;
- delete par11;
- delete par12;
- delete spt;
- hge->Texture_Free(tex);
- }
- void Monster::Update(float dt)
- { float distance=0.0f;
- distance+=mario_x;
-
- // mCurrAnimation = mDie;
- if(dead)
- dead++;
- if(dead<1050&&dead)
- mCurrAnimation->Update(dt);
- if(dead>=1050)
-
- { mActive = false ;
- gameEnd = 1;
- }
- if(dead==0)
- {
- mCurrAnimation = mRun;
- mCurrAnimation->Update(dt);
- if(mCurrAnimation->GetAnimationFrame()==2)
- {
- float marioPositionX,marioPositionY;
- float bossPositionX,bossPositionY;
- bossPositionX = this->GetX() - mapPositionX;
- bossPositionY = this->GetY() - mapPositionY;
- if(mario_y<=480)
- {
- //mCurrAnimation = mRun;
- marioPositionX = mario_x - mapPositionX;
- marioPositionY = mario_y - mapPositionY;
- if(bossPositionX-marioPositionX<=250)
- {
- attack = true;
- par1->info.nEmission=(int)(10*10+10*10)*2;
-
- par1->MoveTo(bossPositionX-10,bossPositionY - 75);
- par1->MoveTo(bossPositionX-150,bossPositionY + 100);
- par2->info.nEmission=(int)(10*10+10*10)*2;
- par2->MoveTo(bossPositionX-10,bossPositionY - 75);
- par2->MoveTo(bossPositionX-200,bossPositionY + 70);
- par3->info.nEmission=(int)(10*10+10*10)*2;
- par3->MoveTo(bossPositionX-10,bossPositionY - 75);
- par3->MoveTo(bossPositionX-240,bossPositionY + 40);
- par4->info.nEmission=(int)(10*10+10*10)*2;
- par4->MoveTo(bossPositionX-10,bossPositionY - 75);
- par4->MoveTo(bossPositionX-270,bossPositionY + 10);
- par5->info.nEmission=(int)(10*10+10*10)*2;
- par5->MoveTo(bossPositionX-10,bossPositionY - 75);
- par5->MoveTo(bossPositionX-290,bossPositionY - 20);
- par6->info.nEmission=(int)(10*10+10*10)*2;
- par6->MoveTo(bossPositionX-10,bossPositionY - 75);
- par6->MoveTo(bossPositionX-300,bossPositionY - 50);
- par7->info.nEmission=(int)(10*10+10*10)*2;
-
- par7->MoveTo(bossPositionX-10,bossPositionY - 75);
- par7->MoveTo(bossPositionX-300,bossPositionY - 100);
- par8->info.nEmission=(int)(10*10+10*10)*2;
- par8->MoveTo(bossPositionX-10,bossPositionY - 75);
- par8->MoveTo(bossPositionX-290,bossPositionY - 130);
- par9->info.nEmission=(int)(10*10+10*10)*2;
- par9->MoveTo(bossPositionX-10,bossPositionY - 75);
- par9->MoveTo(bossPositionX-270,bossPositionY - 160);
- par10->info.nEmission=(int)(10*10+10*10)*2;
- par10->MoveTo(bossPositionX-10,bossPositionY - 75);
- par10->MoveTo(bossPositionX-240,bossPositionY - 190);
- par11->info.nEmission=(int)(10*10+10*10)*2;
- par11->MoveTo(bossPositionX-10,bossPositionY - 75);
- par11->MoveTo(bossPositionX-200,bossPositionY - 210);
- par12->info.nEmission=(int)(10*10+10*10)*2;
- par12->MoveTo(bossPositionX-10,bossPositionY - 75);
- par12->MoveTo(bossPositionX-150,bossPositionY - 240);
- par1->Update(dt);
- par2->Update(dt);
- par3->Update(dt);
- par4->Update(dt);
- par5->Update(dt);
- par6->Update(dt);
- par7->Update(dt);
- par8->Update(dt);
- par9->Update(dt);
- par10->Update(dt);
- par11->Update(dt);
- par12->Update(dt);
- if((marioPositionX-bossPositionX)*(marioPositionX-bossPositionX)+ (marioPositionY-bossPositionY)*(marioPositionY-bossPositionY)<250*250)
- {
- gameEnd = 2;
- }
- }
- else
- {
- attack = false;
- }
- }
- else
- {
- marioPositionX = mario_x;
- marioPositionY = mario_y;
- }
- }
- else
- {
- attack = false;
- }
- }
- }
- void Monster::Spawn(int col, int row)
- {
- mX = (float)(col<<TILE_SHIFT);
- mY = (float)((row+1)<<TILE_SHIFT) - 1.0f;
- SetActive(true);
- }
- void Monster::HitLeft()
- {
- mXVelocity = DEFAULT_WALK_SPEED/2;
- mCurrAnimation->SetFlip(true);
- }
- void Monster::HitRight()
- {
- mXVelocity = -DEFAULT_WALK_SPEED/2;
- mCurrAnimation->SetFlip(false);
- }
- void Monster::Render()
- {
- if(mY<=470)
- {
- float x, y;
- mCurrAnimation->SetScale(mHScale, mVScale);
- mMap->GetPosition(&x, &y);
- mCurrAnimation->SetPosition(mX-x, mY-y+mYRenderOffset);
- mCurrAnimation->Render();
- if(attack)
- {
- par1->Render();
- par2->Render();
- par3->Render();
- par4->Render();
- par5->Render();
- par6->Render();
- par7->Render();
- par8->Render();
- par9->Render();
- par10->Render();
- par11->Render();
- par12->Render();
- }
- }
- }
- #endif