Mario.hpp
上传用户:zhj2929
上传日期:2022-07-23
资源大小:28772k
文件大小:11k
- #ifndef _MARIO_HPP_
- #define _MARIO_HPP_
- class JumpingBlock;
- #include "Weasel.hpp"
- #include "Snowman.hpp"
- #include "Turtle.hpp"
- #include "monster.hpp"
- #include "../../JGE/HGE/include/hgesprite.h"
- #include "../../JGE/HGE/include/hgeparticle.h"
- extern HGE *hge;
- class Mario: public MoveableObject
- {
- private:
- JSprite* mRun;
- JSprite* mIdle;
- JSprite* mJump;
- JSprite* mDuck;
- hgeSprite* spt;
- HTEXTURE mTex;
- hgeParticleSystem * mPar;
- bool attack;
- float mTall;
- float mBulletStartX,mBulletStartY;
- float mBulletX,mBulletY;
- float keepdirection;
-
- bool hurt[10];
- public:
- Mario(GameStatePlay* app);
- virtual ~Mario();
- float experience;
- virtual void Update(float dt);
- virtual void Render();
- virtual void HitBottom(int left, int right, int row);
- virtual void StandingOnNothing(int col, int row);
-
- virtual void HitTop(int colLeft, int colRight, int row);
- virtual void HitRight(int colLeft, int colRight, int row);
- virtual void EatFruit(int colLeft, int colRight, int row);
- virtual void Bullet(float x, float y,float direction);
- virtual void Hit();
- void AnswerRight();
- void AnswerWrong();
- int getExperience();
- };
- Mario::Mario(GameStatePlay* app): MoveableObject(app)
- {
- mMap = mApp->GetTileMap();
- mIdle = new JSprite(mTexture, 0, 0, 100, 88);
- mIdle->SetHotSpot(0.0f, 93.0f);
- mJump = new JSprite(mTexture, 300, 0, 100, 90);
- mJump->SetHotSpot(0.0f, 95.0f);
- mDuck = new JSprite(mTexture, 400, 0, 100, 90);
- mDuck->SetHotSpot(0.0f, 95.0f);
- mRun = new JSprite(mTexture, 0, 0, 100, 88);
- mRun->SetHotSpot(0.0f, 93.0f);
- mRun->AddFrame(100,0,100,95);
- mRun->AddFrame(200,0,100,95);
- mRun->StartAnimation();
- mCurrAnimation = mIdle;
- mCurrAnimation->SetFlip(true);
- mX = 32.0f;
- mY = VIRTUAL_HEIGHT - 32.0f - 1.0f;
- mTall = 64.0f;
- mYRenderOffset = 3.0f;
- mHScale = 0.70f;
- mVScale = 0.70f;
- mLeftAdjustment = 23;
- mRightAdjustment = 47;
- mHitLeftAdjustment = 12;
- mHitRightAdjustment = 58;
- mFallLeftAdjustment = -20;
- mFallRightAdjustment = -10;
- experience=0;
- mRealHeight = 60;
- experience = 0.0f;
- for(int i = 0 ;i < 10 ; i++)
- hurt[i] = false;
- //粒子的渲染图形
- mTex=hge->Texture_Load("particle/particles.png");
- //如果加载失败,则弹出提示窗口
- if(!mTex)
- {
- MessageBox(NULL, "Can't load particles.png", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
- }
- //设置粒子的渲染图形
- spt=new hgeSprite(mTex, 32, 32, 32, 32);
- spt->SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE);
- spt->SetHotSpot(16,16);
- //初始化粒子系统,并点燃粒子系统
- mPar=new hgeParticleSystem("trail.psi",spt);
- mPar->Fire();
- mBulletX=0;
- mBulletY=0;
- keepdirection=1;
- attack = false;
- }
- Mario::~Mario()
- {
- delete mRun;
- delete mIdle;
- delete mDuck;
- delete mJump;
- delete mPar;
- }
- void Mario::Bullet(float x, float y,float direction)
- {
-
- mBulletStartX=x-mapPositionX+25;
- mBulletStartY=y-mapPositionY-25;
- if(keepdirection==0)
- keepdirection=direction;
- if(mBulletY==0)
- {
- mBulletY=mBulletStartY;
- }
- if(mBulletX==0)
- {
- mBulletX=mBulletStartX;
- }
- attack = true;
- float dt = mEngine->GetDelta();
- mPar->info.nEmission=(int)(10*10+10*10)*2;
- mPar->Transpose(mBulletX,mBulletY);
- if(keepdirection>0)
- mBulletX=mBulletX+2;
- else
- mBulletX=mBulletX-2;
-
- mPar->Update(dt);
- if(((mBulletX-32)>512)||mBulletX<-32)
- {
- mBulletX=0;
- mBulletY=0;
- mBullet=false;
- keepdirection=0;
- }
- for(int i =0 ;i<2 ;i++)
- {
- Weasel* weasel = mApp->GetWeasel(i);
- Snowman* snowman = mApp->GetSnowman(i);
-
- Turtle* turtle = mApp->GetTurtle(i);
- Monster* monster = mApp->GetMonster();
-
- int bx=int(mBulletX)+int(mapPositionX)-25;
- int by=int(mBulletY)+int(mapPositionY)+25;
- int wx=int(weasel->GetX());
- int wy=int(weasel->GetY());
- int sx=int(snowman->GetX());
- int sy=int(snowman->GetY());
- int tx=int(turtle->GetX());
- int ty=int(turtle->GetY());
- int mx=int(monster->GetX());
- int my=int(monster->GetY());
- if(abs(wx-bx)<5&&abs(wy-by)<10)
- {
- weasel->die();
- mBullet=false;
- attack=false;
- }
- if(abs(sx-bx)<5&&abs(sy-by)<10)
- {
- snowman->die();
- mBullet=false;
- attack=false;
- }
- if(abs(tx-bx)<5&&abs(ty-by)<10)
- {
-
- turtle->die();
- mBullet=false;
- attack=false;
- }
- if(abs(mx-bx)<5&&abs(my-by)<10)
- {
-
- monster->die();
- mBullet=false;
- attack=false;
- }
- }
- }
- void Mario::HitTop(int left, int right, int row)
- {
-
- float dt = mEngine->GetDelta();
- int colLeft = (left>>TILE_SHIFT)<<TILE_SHIFT;
- int colRight = (right>>TILE_SHIFT)<<TILE_SHIFT;
-
- JumpingBlock* block = mApp->GetJumpingBlock();
- if (left < colLeft+24)
- {
- if(mApp->GetTileMap()->GetTileInfo(colLeft>>TILE_SHIFT, row)==BLOCK_QUES)
- {
- block->Update(dt);
- }
- block->Animate(colLeft>>TILE_SHIFT, row);
- }
- else
- {
- if(mApp->GetTileMap()->GetTileInfo(colRight>>TILE_SHIFT, row)==BLOCK_QUES)
- {
- block->Update(dt);
- }
- block->Animate(colRight>>TILE_SHIFT, row);
- }
- }
- void Mario::HitRight(int colLeft, int colRight, int row)
- {
- if(mApp->GetTileMap()->GetTileInfo(colRight>>TILE_SHIFT, row)==CHANGE_SEASON||mApp->GetTileMap()->GetTileInfo(colLeft>>TILE_SHIFT,row)==CHANGE_SEASON)
- {
- mApp->Season++;
- mApp->experience0=experience;
- }
- }
- void Mario::EatFruit(int left, int right, int row)
- {
-
-
- float dt = mEngine->GetDelta();
- int colLeft = (left>>TILE_SHIFT)<<TILE_SHIFT;
- int colRight = (right>>TILE_SHIFT)<<TILE_SHIFT;
-
- JumpingBlock* block = mApp->GetJumpingBlock();
-
-
- if (left < colLeft+24)
- {
- if(mApp->GetTileMap()->GetTileInfo(colLeft>>TILE_SHIFT, row)==BLOCK_APPLE)
- {
-
- block->Update(dt);
- mApp->apple++;
- mApp->PlaySfx(2);
- }
-
- else if(mApp->GetTileMap()->GetTileInfo(colLeft>>TILE_SHIFT, row)==BLOCK_BANANA)
- {
-
- block->Update(dt);
- mApp->banana++;
- mApp->PlaySfx(2);
- }
- block->Animate(colLeft>>TILE_SHIFT, row);
- }
- else
- {
- if(mApp->GetTileMap()->GetTileInfo(colRight>>TILE_SHIFT, row)==BLOCK_APPLE)
- {
- block->Update(dt);
- mApp->apple++;
- mApp->PlaySfx(2);
- }
- else if(mApp->GetTileMap()->GetTileInfo(colRight>>TILE_SHIFT, row)==BLOCK_BANANA)
- {
-
- block->Update(dt);
- mApp->banana++;
- mApp->PlaySfx(2);
- }
- block->Animate(colRight>>TILE_SHIFT, row);
- }
-
- }
- void Mario::AnswerRight()
- {
- experience+=4;
- }
- void Mario::AnswerWrong()
- {
- experience-=2;
- }
- void Mario::Hit()
- {
- bool check = false;
-
- for(int i =0 ;i<2 ;i++)
- {
- Weasel* weasel = mApp->GetWeasel(i);
- Snowman* snowman = mApp->GetSnowman(i);
-
- Turtle* turtle = mApp->GetTurtle(i);
- Monster* monster = mApp->GetMonster();
- if(mX<(weasel->GetX()+3)&&mX>(weasel->GetX()-3)&&mY>(weasel->GetY()-54)&&mY<(weasel->GetY()))
- {
- weasel->die();
- }
- else if(mX<(snowman->GetX()+3)&&mX>(snowman->GetX()-3)&&mY>(snowman->GetY()-174)&&mY<(snowman->GetY()))
- {
- snowman->die();
- }
-
- if(!hurt[i])
- {
-
- if(mX<(weasel->GetX()+47)&&mX>(weasel->GetX())&&mY<(weasel->GetY()+34)&&mY>(weasel->GetY()-1))
- {
- if(weasel->aLive())
- {
- hurt[i] = true;
- check = true ;
- }
- }
-
-
- if(mX>(weasel->GetX())&&mX<(weasel->GetX()+47)&&mY<(weasel->GetY()+34)&&mY>(weasel->GetY()-1))
- {
- if(weasel->aLive())
- {
- hurt[i] = true;
- check = true ;
- }
- }
- if((mX>(snowman->GetX())&&mX<(snowman->GetX()+47)&&mY<(snowman->GetY()+134)&&mY>(snowman->GetY()-155)))
- {
- if(snowman->aLive())
- {
- hurt[i] = true;
- check = true ;
- }
- }
- if(mX>(snowman->GetX())&&mX<(snowman->GetX()+47)&&mY<(snowman->GetY()+34)&&mY>(snowman->GetY()-155))
- {
- if(snowman->aLive())
- {
- hurt[i] = true;
- check = true ;
- }
- }
-
-
- if((mX>(turtle->GetX())&&mX<(turtle->GetX()+47)&&mY<(turtle->GetY()+34)&&mY>(turtle->GetY()-1)))
- {
- if(turtle->aLive())
- {
- hurt[i] = true;
- check = true ;
- }
- }
- if(mX>(turtle->GetX())&&mX<(turtle->GetX()+47)&&mY<(turtle->GetY()+34)&&mY>(turtle->GetY()-1))
- {
- if(turtle->aLive())
- {
- hurt[i] = true;
- check = true ;
- }
- }
- }
-
- }
- if(check)
- experience-=0.001f;
- for(int i =0 ;i<10 ;i++)
- hurt[i] = false;
-
-
- }
- void Mario::HitBottom(int left, int right, int row)
- {
- float dt = mEngine->GetDelta();
- int colLeft = (left>>TILE_SHIFT)<<TILE_SHIFT;
- int colRight = (right>>TILE_SHIFT)<<TILE_SHIFT;
- if(mApp->GetTileMap()->GetTileInfo(colRight>>TILE_SHIFT, row)==BLOCK_TUNNEL)
- {
- mApp->GetTileMap()->SetTileInfo(colRight>>TILE_SHIFT, row,0);
- mApp->GetTileMap()->SetTileInfo(colLeft>>TILE_SHIFT, row,0);
- mYVelocity = 0.0f;
- mJumping = true;
- }
- if(mApp->GetTileMap()->GetTileInfo(colRight>>TILE_SHIFT, row)==CHANGE_SEASON||mApp->GetTileMap()->GetTileInfo(colLeft>>TILE_SHIFT,row)==CHANGE_SEASON)
- {
- mApp->Season++;
- mApp->experience0=experience;
- }
-
- JumpingBlock* block = mApp->GetJumpingBlock();
-
- if (left < colLeft+24)
- {
- if(mApp->GetTileMap()->GetTileInfo(colLeft>>TILE_SHIFT, row)==BLOCK_BANANA)
- {
- block->Update(dt);
- }
- block->Animate(colLeft>>TILE_SHIFT, row);
- }
- else
- {
- if(mApp->GetTileMap()->GetTileInfo(colRight>>TILE_SHIFT, row)==BLOCK_BANANA)
- {
- block->Update(dt);
- }
- block->Animate(colRight>>TILE_SHIFT, row);
- }
- }
- void Mario::StandingOnNothing(int col, int row)
- {
- mCurrAnimation = mJump;
- MoveableObject::StandingOnNothing(col, row);
-
- }
- void Mario::Update(float dt)
- {
- if (mEngine->GetAnalogX() < 64)
- {
- mXVelocity = -DEFAULT_WALK_SPEED;
-
- if (!mJumping)
- mCurrAnimation = mRun;
- mCurrAnimation->SetFlip(false);
- mIdle->SetFlip(false);
- }
- else if (mEngine->GetAnalogX() > 192)
- {
- mXVelocity = DEFAULT_WALK_SPEED;
-
- if (!mJumping)
- mCurrAnimation = mRun;
- mCurrAnimation->SetFlip(true);
- mIdle->SetFlip(true);
- }
- else
- {
- mXVelocity = 0.0f;
-
- if (!mJumping)
- mCurrAnimation = mIdle;
- }
- //int col , row;
- if (!mJumping)
- {
- #ifdef WIN32
- if (mEngine->GetAnalogY() < 64 || mEngine->GetButtonClick(PSP_CTRL_CIRCLE))
- #else
- if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE))
- #endif
- {
- mCurrAnimation = mJump;
- mJumping = true;
- mYVelocity = BIGM_INITIAL_JUMP_VEL;
- mApp->PlaySfx(SFX_JUMP2);
- }
- else if (mEngine->GetAnalogY() > 192)
- {
- mCurrAnimation = mDuck;
- mDucking = true ;
- mXVelocity = 0.0f;
- }
- }
- #ifdef WIN32
- if (mEngine->GetButtonClick(PSP_CTRL_DOWN))
- #endif
- {
- if(mApp->apple>0||mApp->banana>0)
- {
- mBullet=true;
- if(mApp->apple>0)
- {
- mApp->apple--;
- }
- else
- {
- mApp->banana--;
- }
- }
- }
-
- MoveableObject::Update(dt);
- for(int i = 0 ; i<10 ; i++)
- if(!hurt[i])
- Hit();
- if (mY > VIRTUAL_HEIGHT)
- {
- mY = -64.0f;
- mYVelocity = 0.0f;
- }
- mMap->SetTarget(mX - 210.0f, mY - 136.0f);
- }
- int Mario::getExperience()
- {
- return int(experience);
- }
- void Mario::Render()
- {
- // hge->Gfx_BeginScene();
- // hge->Gfx_Clear(0);
- if(attack)
- {
- mPar->Render();
- // mPar->Transpose(mBulletStartX,mBulletStartY);
- // mBulletStartX=mBulletStartX+2;
- // if(mBulletStartX<mapPositionX||mBulletStartX>mapPositionX+512)
- // attack=false;
- }
- // attack=false;
- // hge->Gfx_EndScene();
- MoveableObject::Render();
-
- }
- #endif