Beispiel #1
0
int main(int argc, char *argv[])
{
	Init();

	Character *snake = new Snake("snake2.bmp", 20, 20);
	Character *dot = new Dot("dot.bmp", 20, 20);

	bool quit = false;

	while (!quit)
	{
		while (SDL_PollEvent(&event) != 0)
		{
			if (event.type == SDL_QUIT) {
				quit = true;
			}
		}
		SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);		// select colour for drawing
		SDL_RenderClear(renderer);									// clear entire screen to our selected colour

		snake->m_Move();  // (*snake).Move();
		dot->Render();
		OutOfScreen(*snake);
		collisionDetection(*snake, *dot);

		if (collisionDetection(*snake, *dot)) {						// checks IF TRUE
			dot->NewDot();
			dot->Render();
		}
		

		SDL_RenderPresent(renderer);								/* everything before this was drawn behind the scenes this actually
																	puts the colour on screen for us */
		SDL_Delay(70);												// gives us time to see the screen
	}

	Close();

	return 0;
}
Beispiel #2
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;
		}
	}
}