⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bomb.cpp

📁 《BATTLE OF SKY》
💻 CPP
字号:
#include "bomb.h"
#include <cassert>

Bomb::Bomb(SimpleWindow &W , const Position &p , const Bomb_Status &s , const Direction &f):GameWindow(W) ,
           CurrentDirection(f) , CurrentStatus(s) {
	BombPhoto.SetWindow(GetWindow()) ;
	BombPhoto.Load("bmp\\bomb.bmp") ;
    SetPosition(p) ;

    /* Set the distance of moving to the Enemy in the horizontal
	 * or vertical directions. The distance is based
     * on the size of the bitmap.
	 ***********************************/
    SetHorizMovement(GetBmp().GetWidth() * 8) ; 
	SetVertMovement(GetBmp().GetHeight() * 8 ) ;
}

//mutators
void Bomb::Draw() {
	GetBmp().Draw() ;
}

void Bomb::Erase() {
	GetBmp().Erase() ;
}

void Bomb::SetPosition(const Position &p) {
	CurrentPosition = p ;
    BombPhoto.SetPosition(p);
}

void Bomb::SetDirection(const Direction &d) {
	CurrentDirection = d ;
}

void Bomb::SetHorizMovement(float h) {
	HorizMovement = h ;
}

void Bomb::SetVertMovement(float v) {
	VertMovement = v ;
}

void Bomb::SetStatus(const Bomb_Status &s) {
	CurrentStatus = s ;
}

//inspectors
Position Bomb::GetPosition() const {
	return CurrentPosition ;
}

Direction Bomb::GetDirection() const {
	return CurrentDirection ;
}

float Bomb::GetHorizMovement() const {
	return HorizMovement ;
}

float Bomb::GetVertMovement() const {
	return VertMovement ;
}

BitMap& Bomb::GetBmp() {
	return BombPhoto ;
}

const BitMap&  Bomb::GetBmp() const {
	return BombPhoto;
}

SimpleWindow& Bomb::GetWindow() const {
	return GameWindow ;
}

Bomb_Status Bomb::GetStatus() const {
	return CurrentStatus ;
}


// determine if Enemy is at right edge of window
bool Bomb::AtRightEdge() const {
	return (GetBmp().GetPosition().GetXDistance() 
		+ GetBmp().GetWidth() 
		+ HorizMovement >= 15.5) ;
}

// determine if Enemy is at left edge of window
bool Bomb::AtLeftEdge() const {
    return (GetBmp().GetPosition().GetXDistance() - HorizMovement <= 0.6 ) ;
}

// determine if Enemy is at bottom edge of window
bool Bomb::AtBottomEdge() const {
	return (GetBmp().GetPosition().GetYDistance() 
		+ GetBmp().GetHeight() 
		+ VertMovement >= 15.5) ;
}

// determine if Enemy is at top edge of window
bool Bomb::AtTopEdge() const {
	return (GetBmp().GetPosition().GetYDistance() - VertMovement <= 0.6) ;
}

// compute new position for a Puff
Position Bomb::NewPosition() const {
    const Position OldPosition = GetPosition();
	if (GetDirection() == Left)
		return OldPosition
		 + Position(-GetHorizMovement(), 0);
	else if (GetDirection() == Right)
		return OldPosition
		 + Position(GetHorizMovement(), 0);
	else if (GetDirection() == Up)
		 return OldPosition
		 + Position(0, -GetVertMovement());
	else 
		return OldPosition
		 + Position(0, GetVertMovement());
}

void Bomb::Move() {
	Direction d = GetDirection() ;
    
	switch(d) {
	case Up:
		if(AtTopEdge()) {
            Erase() ;
			SetStatus(Ready) ;
			break ;
		}
		else {
            Erase();
            SetPosition(NewPosition());
	        Draw();
			break ;
		}
	case Right:
		if(AtRightEdge()) {
			SetStatus(Ready) ;
			Erase() ;
			break ;
		}
		else {
            Erase() ;
            SetPosition(NewPosition());
	        Draw();
			break ;
		}
	case Down:
		if(AtBottomEdge()) {
			SetStatus(Ready) ;
			Erase() ;
			break ;
		}
		else { 
			Erase() ;
		    SetPosition(NewPosition());
	        Draw();
			break ;
		}
	case Left:
        if(AtLeftEdge()) {
			SetStatus(Ready) ;
			Erase() ;
			break ;
		}
		else { 
			Erase() ;
		    SetPosition(NewPosition());
	        Draw();
			break ;
		}
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -