コード例 #1
0
ファイル: game_state.cpp プロジェクト: jduranmaster/spritely
// SetupStage_Level1
// Set up the stage (sprites and backgrounds) for level 1.
void GameState::SetupStage_Level1() {
	// Set the default sprite video mode.
	SetSpriteVideoMode();

	// Setup the foreground sprites.
	// The sprite data is not active until we copy it from our data
	// tables (in sprites.cpp) into the real Palette and Graphics memory.
	// So, let's copy the default spriteset there now.
	ClearSprites();
	LoadSpriteset(0);

	// Setup the background tiles and map.
	// Just like sprites, the data is not active until we copy it from
	// our data tables (in background_maps.cpp) into real memory.
	ClearBackgrounds();
	LoadBgTileset(0);
	LoadBgMap(0);

	// Initialize the objects for the first level.
	InitObject(kObj_Player, kSprites_Player);
	InitObject(kObj_New, kSprites_New);

	// Set the initial location of each object.
	_xPlayer = 0;
	_yPlayer = 0;
	MoveObjectTo(kObj_Player, _xPlayer, _yPlayer);
	MoveObjectTo(kObj_New, 50, 50);

	// TODO: Add more initialization for level 1 here.
}
コード例 #2
0
ファイル: game_state.cpp プロジェクト: jduranmaster/spritely
// Update_Level1
// Handle buttons and update game state for level 1.
void GameState::Update_Level1() {
	// The arrow keys are used to move the current object.
	// We use CheckKeyHeld() because we want the action to repeat as long
	// as the player is holding down the button.
	int dx = 0;
	int dy = 0;
	if (CheckKeyHeld(KEY_LEFT))
		dx = -1;
	if (CheckKeyHeld(KEY_RIGHT))
		dx = 1;
	if (CheckKeyHeld(KEY_UP))
		dy = -1;
	if (CheckKeyHeld(KEY_DOWN))
		dy = 1;

	// Handle the player pressing the 'A' button.
	// We use CheckKeyPress() because we *don't* want the action to repeat
	// unless the player presses the 'A' button multiple times.
	if (CheckKeyPress(KEY_A) && !_has_projectile) {
		// ToDo: Add code to respond to 'A' button press here.
		_xBall = _xPlayer + 12;
		_yBall = _yPlayer + 5;
		MoveObjectTo(kObj_Ball, _xBall, _yBall);

		_has_projectile = true;
		ShowObject(kObj_Ball, true);
	}

	if (_has_projectile) {
		_xBall += 0;
		_yBall += 1;
		MoveObjectTo(kObj_Ball, _xBall, _yBall);

		// Get the width/height of the projectile.
		int width, height;
		GetObjectSize(kObj_Ball, &width, &height);

		// Turn off the projectile when it leaves the screen.
		if (_xBall < -width
				|| _xBall > SCREEN_WIDTH
				|| _yBall < -height
				|| _yBall > SCREEN_HEIGHT) {
			ShowObject(kObj_Ball, false);
			_has_projectile = false;
		}
	}

	// If we need to move the player.
	if (dx != 0 || dy != 0) {
		// Record the player's new location.
		_xPlayer += dx;
		_yPlayer += dy;

		// Move the player to the new location.
		MoveObjectTo(kObj_Player, _xPlayer, _yPlayer);
	}

	// TODO: Add additional game state updates for level 1 here.
}
コード例 #3
0
ファイル: Field.cpp プロジェクト: evolvazpr/evolva
bool Field::MoveObject(std::shared_ptr<Unit> object, const long x_steps, const long y_steps, const bool trim) {
	const bool x_trim = (x_steps < 0 && static_cast<size_t>(-x_steps) > object->GetX());
	const bool y_trim = (y_steps < 0 && static_cast<size_t>(-y_steps) > object->GetY());
	if (trim) {
		return MoveObjectTo(object, x_trim ? 0 : object->GetX() + x_steps, y_trim ? 0 : object->GetY() + y_steps, true);
	}
	else {
		return MoveObjectTo(object, object->GetX() + x_steps, object->GetY() + y_steps, trim);
	}
}
コード例 #4
0
ファイル: game_state.cpp プロジェクト: jduranmaster/spritely
// Update_Level1
// Handle buttons and update game state for level 1.
void GameState::Update_Level1() {
	// The arrow keys are used to move the current object.
	// We use CheckKeyHeld() because we want the action to repeat as long
	// as the player is holding down the button.
	int dx = 0;
	int dy = 0;
	if (CheckKeyHeld(KEY_LEFT))
		dx = -1;
	if (CheckKeyHeld(KEY_RIGHT))
		dx = 1;
	if (CheckKeyHeld(KEY_UP))
		dy = -1;
	if (CheckKeyHeld(KEY_DOWN))
		dy = 1;

	// Handle the player pressing the 'A' button.
	// We use CheckKeyPress() because we *don't* want the action to repeat
	// unless the player presses the 'A' button multiple times.
	if (CheckKeyPress(KEY_A)) {
		// ToDo: Add code to respond to 'A' button press here.
	}

	// If we need to move the player.
	if (dx != 0 || dy != 0) {
		// Record the player's new location.
		_xPlayer += dx;
		_yPlayer += dy;

		// Move the player to the new location.
		MoveObjectTo(kObj_Player, _xPlayer, _yPlayer);
	}

	// TODO: Add additional game state updates for level 1 here.
}
コード例 #5
0
ファイル: game_state.cpp プロジェクト: jduranmaster/spritely
// Update_Level1
// Handle buttons and update game state for level 1.
void GameState::Update_Level1() {
	// The arrow keys are used to move the current object.
	// We use CheckKeyHeld() because we want the action to repeat as long
	// as the player is holding down the button.
	int dx = 0;
	int dy = 0;
	if (CheckKeyHeld(KEY_LEFT))
		dx = -1;
	if (CheckKeyHeld(KEY_RIGHT))
		dx = 1;
	if (CheckKeyHeld(KEY_UP))
		dy = -1;
	if (CheckKeyHeld(KEY_DOWN))
		dy = 1;

	// Handle the player pressing the 'A' button.
	// We use CheckKeyPress() because we *don't* want the action to repeat
	// unless the player presses the 'A' button multiple times.
	if (CheckKeyPress(KEY_A)) {
		// ToDo: Add code to respond to 'A' button press here.
	}

	// If we need to move the player.
	if (dx != 0 || dy != 0) {
		// Calculate the player's new location.
		int x = _xPlayer + dx;
		int y = _yPlayer + dy;

		// Get the width/height of the player.
		int width, height;
		GetObjectSize(kObj_Player, &width, &height);

		// Don't let the player go outside the screen boundaries.
		if (x < 0 || x > SCREEN_WIDTH - width)
			dx = 0;
		if (y < 0 || y > SCREEN_HEIGHT - height)
			dy = 0;

		// Record the player's new location.
		_xPlayer += dx;
		_yPlayer += dy;

		// Move the player to the new location.
		MoveObjectTo(kObj_Player, _xPlayer, _yPlayer);
	}

	// TODO: Add additional game state updates for level 1 here.
}