Exemplo n.º 1
0
//************************************************************************
void CNutDropScene::OnMouseMove (HWND hWnd, int x, int y, UINT keyFlags)
//************************************************************************
{
	static BOOL fInuse = FALSE;

	if (fInuse)
		return;
	fInuse = TRUE;

	// Reduce mouse sensitivity
	if (abs (m_ptLastMouseXY.x - x) < 5)
	{
		fInuse = FALSE;
		return;
	}

	if (!m_lpPlayerSprite)
	{
		fInuse = FALSE;
		return;
	}

	int iWidth, iTmp;
	m_lpPlayerSprite->GetMaxSize (&iWidth, &iTmp);

	// See if the player changed directions
	if (x < m_ptLastMouseXY.x)
		ChangeDirection (WALKLEFT);
	else
		ChangeDirection (WALKRIGHT);

	m_lpPlayerSprite->SetCellsPerSec (10);
	if (x < m_nScreenLeftEdge)
		m_lpPlayerSprite->Move (m_nScreenLeftEdge, m_nScreenBottom);
	else
	if ((x + iWidth) > m_nScreenRightEdge)
		m_lpPlayerSprite->Move (m_nScreenRightEdge - iWidth, m_nScreenBottom);
	else
	{
		iTmp = x;
		if ((x + iWidth) > m_nScreenRightEdge)
			iTmp = m_nScreenRightEdge - iWidth;
		m_lpPlayerSprite->Move (iTmp, m_nScreenBottom);
	}

	m_ptLastMouseXY.x = x;
	m_ptLastMouseXY.y = y;
	fInuse = FALSE;
}
Exemplo n.º 2
0
	void CPlayerView::Notify(int eventType)
	{
		if (eventType == ALLEGRO_GET_EVENT_TYPE('D', 'I', 'R', 'C'))
			ChangeDirection(m_player->GetDirection());
		else if(eventType == ALLEGRO_GET_EVENT_TYPE('S', 'P', 'D', 'C'))
			OnSpeedChange();
	}
Exemplo n.º 3
0
void Enermy_Tom::Update()
{
	Enermy::Update();
	if(Life<=0) return;

	switch( Direction )
	{
	case DIR_LEFT:
		x--;
		if( x<0 )
		{
			x=0;
			Direction = DIR_FORWARD;
		}
		break;
	case DIR_RIGHT:
		x++;
		if( x + w > GameWorld::Width )
		{
			x = GameWorld::Width - w;
			Direction = DIR_FORWARD;
		}
		break;
	}

	if( rand() < 300 )
		ChangeDirection();
}
Exemplo n.º 4
0
	void CPlayerView::SetPlayer(CPlayer* player)
	{
		if (m_player)
			m_player->SubscribeFromAll(this);

		m_player = player;

		if (m_player)
		{
			ChangeDirection(m_player->GetDirection());
			m_player->SubscribeTo("LevelUp", this);
			m_player->SubscribeTo("DirectionChanged", this);
		}
	}
Exemplo n.º 5
0
// This is our "main loop"
void RunApp(HDC hdc)
{
    int wallIndex;

    // If we've collided with a wall
    if(CheckCollision(wallIndex))
    {
        ChangeDirection(wallIndex); // Change the ball's direction
    }
    else
        ball.moveBall(); // Otherwise just move in the same direction we've been going

    ball.drawBall(hdc); // Draw the ball
}
Exemplo n.º 6
0
void Player::Update(D3DXVECTOR3 look, const float dt,bool oldSchoolView,LPCSTR dir )
{
	if(!mHit)
	{
		Move(dt);

		if(!oldSchoolView)
			ChangeDirection(look);
		else
			OldSchoolControl(dir);
	}

	Animation(dt);
	
}
Exemplo n.º 7
0
	void Player::Update(float deltaTime)
	{
		if (std::sqrt(std::pow(this->Location.X - (this->GridLocation.X * 64 + 32), 2.0) + std::pow(this->Location.Y - (this->GridLocation.Y * 64 + 32), 2.0)) < 2)
		{
			this->Location.X = this->GridLocation.X * 64 + 32;
			this->Location.Y = this->GridLocation.Y * 64 + 32;
			if (this->WalkingQueue.size() > 0)
			{
				this->GridLocation = this->WalkingQueue.front();
				this->WalkingQueue.pop();
			}
		}

		float xOffs = 0, yOffs = 0;
		if (this->Location.X != (float)(this->GridLocation.X * 64 + 32))
		{
			xOffs = (float)(this->GridLocation.X * 64 + 32) - this->Location.X;
			this->Location.X += xOffs / std::abs(xOffs) * 1.5f;
			if (std::abs(xOffs) < 1.0f) xOffs = 0.0f;
		}
		if (this->Location.Y != (float)(this->GridLocation.Y * 64 + 32))
		{
			yOffs = (float)(this->GridLocation.Y * 64 + 32) - this->Location.Y;
			this->Location.Y += yOffs / std::abs(yOffs) * 1.5f;
			if (std::abs(yOffs) < 1.0f) yOffs = 0.0f;
		}
		if (xOffs + yOffs == 0)
		{
			this->CurrentAnimation->Stop();
			this->CurrentAnimation->Reset();
		}
		else if (xOffs != 0) ChangeDirection(xOffs > 0 ? RIGHT : LEFT);
		else ChangeDirection(yOffs > 0 ? DOWN : UP);

		CurrentAnimation->Update(deltaTime);
	}
Exemplo n.º 8
0
	void CPlayerView::OnSpeedChange(void)
	{
		//const bool isIdle = m_player->GetXSpeed() != 0 && m_player->GetYSpeed() != 0;
		//if (isIdle)
		//{
		//	ChangeDirection(m_player->GetDirection());
		//}
		//else
		//{

		//}

		//if (m_player->GetSpeed() == b2Vec2(0,0))
		//{
		//	std::string anim;
		//	const std::string curAnim = m_anims.GetCurrentAnimName();
		//}
		ChangeDirection(m_player->GetDirection());
	}
Exemplo n.º 9
0
Npc::Npc(bool leftSide)
	: GameObject()
	, mpHealthBar(nullptr)
	, mMaxHealth(100)
	, mLeftSide(leftSide)
	, mpTarget(nullptr)
	, mHard(false)
	, mElapsedTime(0)
	, mTime(0)
	, mPrevTime(0)
{
	mHealth = mMaxHealth;
	mVelocity.x = 1.0f;
	mDirection = rand() % 2;
	if (mDirection == 1) ChangeDirection();
	mSpeed = 5.0f;
	
	Position().y = 700;
	if (mLeftSide)
		Position().x = 200;
	else
		Position().x = 1080;
}
Exemplo n.º 10
0
void Npc::SetState()
{
	switch(State())
	{
	case AnimState::Idle:
		{
			mVelocity.x = 1.0f;
			Flip(false);
			mDirection = rand() % 2;
			if (mDirection == 1) ChangeDirection();
			SetAnimState(AnimState::Walk);
			break;
		}
	case AnimState::Walk:
		{
			if (OutOfScreen()) { ChangeDirection(); }
			break;
		}
	case AnimState::Punch:
		{
			Velocity() = Vector2();
			if (AnimDone())
			{
				SetActiveCollider(true);
				SetAnimState(AnimState::Idle);
			}
			break;
		}
	case AnimState::Kick:
		{
			Velocity() = Vector2();
			if (AnimDone())
			{
				SetActiveCollider(true);
				SetAnimState(AnimState::Idle);
			}
			break;
		}
	case AnimState::Block:
		{
			Velocity() = Vector2();
			if (AnimDone())
			{
				Animate() = false;
				mElapsedTime += (mTime - mPrevTime) / 1000.0f;
				if (mElapsedTime > 2.0f)
				{
					Animate() = true;
					SetAnimState(AnimState::Idle);
					mElapsedTime = 0;
				}
			}
			break;
		}
	case AnimState::Special:
		{
			Velocity() = Vector2();
			if (AnimDone())
			{
				SetActiveCollider(true);
				SetAnimState(AnimState::Idle);
			}
			break;
		}
	case AnimState::Hurt:
		{
			Velocity() = Vector2();
			SetActiveCollider(false);
			if (AnimDone())
			{
				SetActiveCollider(true);
				SetAnimState(AnimState::Idle);
			}
			break;
		}
	case AnimState::Death:
		{
			Velocity() = Vector2();
			SetActiveCollider(false);
			if (AnimDone())
			{
				Animate() = false;
			}
			break;
		}
	}
}
Exemplo n.º 11
0
//下按下
void CSnakeGame::OnDownBtnPressed()
{
	ChangeDirection(DIR_DOWN);
}
Exemplo n.º 12
0
//************************************************************************
void CNutDropScene::OnKey (HWND hWnd, UINT vk, BOOL fDown, int cRepeat, UINT flags)
//************************************************************************
{
	if (vk != VK_LEFT && vk != VK_RIGHT)
	{
		CGBScene::OnKey (hWnd, vk, fDown, cRepeat, flags);
		return;
	}		

	static BOOL fInuse = FALSE;
	if (!m_lpPlayerSprite)
		return;

	// In case of fast key repeat
	if (fInuse)
		return;
	fInuse = TRUE;

	if (m_SoundPlaying == IntroPlaying || m_SoundPlaying == SuccessPlaying)
	{
	 	m_pSound->StopChannel (NORMAL_CHANNEL);
		m_SoundPlaying = NotPlaying;
		StartGame();
	}

	RECT rLoc;
	int iWidth, iTmp;
	// Get current player location and size info.
	m_lpPlayerSprite->Location (&rLoc);
	m_lpPlayerSprite->GetMaxSize (&iWidth, &iTmp);

	switch (vk)
	{
		// Move the player left
		case VK_LEFT:
			ChangeDirection (WALKLEFT);
			if (rLoc.left - m_nKeyboardDistance < m_nScreenLeftEdge)
			{
				rLoc.left = m_nScreenLeftEdge;
				rLoc.right = rLoc.left + iWidth;
			}
			else
			{
				rLoc.left -= m_nKeyboardDistance;
				rLoc.right -= m_nKeyboardDistance;
			}
			break;

		// Move the player right
		case VK_RIGHT:
			ChangeDirection (WALKRIGHT);
			if ((rLoc.left + iWidth + m_nKeyboardDistance) > m_nScreenRightEdge)
			{
				rLoc.left = m_nScreenRightEdge - iWidth;
				rLoc.right = rLoc.left + iWidth;
			}
			else
			{
				rLoc.left += m_nKeyboardDistance;
				rLoc.right += m_nKeyboardDistance;
			}
			break;
	}

	m_lpPlayerSprite->Move (rLoc.left, m_nScreenBottom);
	m_lpPlayerSprite->CycleCells();
	m_lpPlayerSprite->Draw();
	fInuse = FALSE;
}
Exemplo n.º 13
0
//右按下
void CSnakeGame::OnRightBtnPressed()
{
	ChangeDirection(DIR_RIGHT);
}
Exemplo n.º 14
0
//左按下
void CSnakeGame::OnLeftBtnPressed()
{
	ChangeDirection(DIR_LEFT);
}
Exemplo n.º 15
0
void Character::Move(Character* playerMove, Cell * Room[20][20])
{
	int tempType = Room[*m_playerRow][*m_playerColumn]->GetType();
	switch(playerMove->GetDirection())
	{
	case 1:	//Up
		if(Room[*m_playerRow-1][*m_playerColumn]->isEmpty())
		{
			Room[*m_playerRow][*m_playerColumn]->Reset();
			Room[*m_playerRow-1][*m_playerColumn]->SetType(tempType);
			Room[*m_playerRow-1][*m_playerColumn]->SetEmpty();
			Room[*m_playerRow-1][*m_playerColumn]->SetVisibility(true);
			Room[*m_playerRow-1][*m_playerColumn]->SetObject(playerMove);
			SetPosition(*m_playerRow-1,*m_playerColumn);
		}
		else
		{
			ChangeDirection(2);
			cout <<"You ran into "<<Room[*m_playerRow-1][*m_playerColumn]->GetDescription()<<endl;
			Room[*m_playerRow-1][*m_playerColumn]->SetVisibility(true);
			Room[*m_playerRow-1][*m_playerColumn]->SetDiscovered(true);
		}
		break;
	case 2:	//Down
		if(Room[*m_playerRow+1][*m_playerColumn]->isEmpty())
		{
			Room[*m_playerRow][*m_playerColumn]->Reset();
			Room[*m_playerRow+1][*m_playerColumn]->SetType(tempType);
			Room[*m_playerRow+1][*m_playerColumn]->SetEmpty();
			Room[*m_playerRow+1][*m_playerColumn]->SetVisibility(true);
			Room[*m_playerRow+1][*m_playerColumn]->SetObject(playerMove);	//Sets it so the Cell's Object is pointing to the character
			SetPosition(*m_playerRow+1, *m_playerColumn);
		}
		else
		{
			ChangeDirection(1);
			cout <<"You ran into "<<Room[*m_playerRow+1][*m_playerColumn]->GetDescription()<<endl;
			Room[*m_playerRow+1][*m_playerColumn]->SetVisibility(true);
			Room[*m_playerRow+1][*m_playerColumn]->SetDiscovered(true);
		}
		break;
		case 3:	//Left
		if(Room[*m_playerRow][*m_playerColumn-1]->isEmpty())
		{
			Room[*m_playerRow][*m_playerColumn]->Reset();
			Room[*m_playerRow][*m_playerColumn-1]->SetType(tempType);
			Room[*m_playerRow][*m_playerColumn-1]->SetEmpty();
			Room[*m_playerRow][*m_playerColumn-1]->SetVisibility(true);
			Room[*m_playerRow][*m_playerColumn-1]->SetObject(playerMove);	//Sets it so the Cell is pointing to the character
			SetPosition(*m_playerRow,*m_playerColumn-1);
		}
		else
		{
			ChangeDirection(4);
			cout <<"You ran into "<<Room[*m_playerRow][*m_playerColumn-1]->GetDescription()<<endl;
			Room[*m_playerRow][*m_playerColumn-1]->SetVisibility(true);
			Room[*m_playerRow][*m_playerColumn-1]->SetDiscovered(true);
		}
		break;
	case 4:	//Right
		if(Room[*m_playerRow][*m_playerColumn+1]->isEmpty())
		{
			Room[*m_playerRow][*m_playerColumn]->Reset();
			Room[*m_playerRow][*m_playerColumn+1]->SetType(tempType);
			Room[*m_playerRow][*m_playerColumn+1]->SetEmpty();
			Room[*m_playerRow][*m_playerColumn+1]->SetVisibility(true);
			Room[*m_playerRow][*m_playerColumn+1]->SetObject(playerMove);	//Sets it so the Cell is pointing to the character
			SetPosition(*m_playerRow,*m_playerColumn+1);
		}
		else
		{
			ChangeDirection(3);
			cout <<"You ran into "<<Room[*m_playerRow][*m_playerColumn+1]->GetDescription()<<endl;
			Room[*m_playerRow][*m_playerColumn+1]->SetVisibility(true);
			Room[*m_playerRow][*m_playerColumn+1]->SetDiscovered(true);
		}
		break;
	}
}
Exemplo n.º 16
0
bool CEnemy::OnCollision(CEntity* entity)
{
	ChangeDirection();
	return true;
}
Exemplo n.º 17
0
//上按下
void CSnakeGame::OnUpBtnPressed()
{
	ChangeDirection(DIR_UP);
}