Ejemplo n.º 1
0
/*
 * do_move:
 *	Execute a move
 */
static bool
do_move(int dy, int dx)
{
	static COORD newpos;

	newpos.y = My_pos.y + dy;
	newpos.x = My_pos.x + dx;
	if (newpos.y <= 0 || newpos.y >= Y_FIELDSIZE ||
	    newpos.x <= 0 || newpos.x >= X_FIELDSIZE ||
	    Field[newpos.y][newpos.x] > 0 || eaten(&newpos)) {
		if (Running) {
			Running = false;
			leaveok(stdscr, false);
			move(My_pos.y, My_pos.x);
			refresh();
		}
		else {
			putchar(CTRL('G'));
			reset_count();
		}
		return false;
	}
	else if (dy == 0 && dx == 0)
		return true;
	mvaddch(My_pos.y, My_pos.x, ' ');
	My_pos = newpos;
	mvaddch(My_pos.y, My_pos.x, PLAYER);
	if (!jumping())
		refresh();
	return true;
}
Ejemplo n.º 2
0
/*
 * play_level:
 *	Let the player play the current level
 */
void
play_level(void)
{
	COORD	*cp;

	move(My_pos.y, My_pos.x);
	addch(PLAYER);
	refresh();
	for (cp = Robots; cp < &Robots[MAXROBOTS]; cp++) {
		if (cp->y < 0)
			continue;
		move(cp->y, cp->x);
		addch(ROBOT);
	}
	refresh();
#ifdef DEBUG
	standout();
	move(Min.y, Min.x);
	addch(inch());
	move(Max.y, Max.x);
	addch(inch());
	standend();
#endif /* DEBUG */
	flushinp();
	while (!Dead && Num_robots > 0) {
		move(My_pos.y, My_pos.x);
		if (!jumping())
			refresh();
		get_move();
		if (Field[My_pos.y][My_pos.x] != 0)
			Dead = TRUE;
		if (!Dead)
			move_robots();
		if (Was_bonus) {
			move(Y_PROMPT, X_PROMPT);
			clrtoeol();
			move(Y_PROMPT + 1, X_PROMPT);
			clrtoeol();
			Was_bonus = FALSE;
		}
	}

	/*
	 * if the player didn't die, add on the possible bonuses
	 */

	if (!Dead) {
		Was_bonus = FALSE;

		if (Level == Start_level && Start_level > 1) {
			move(Y_PROMPT, X_PROMPT);
			printw("Advance bonus: %d", S_BONUS);
			refresh();
			add_score(S_BONUS);
			Was_bonus = TRUE;
		}

		if (Wait_bonus != 0) {
			if (!Was_bonus)
				move(Y_PROMPT, X_PROMPT);
			else
				move(Y_PROMPT + 1, X_PROMPT);
			printw("Wait bonus: %d", Wait_bonus);
			refresh();
			add_score(Wait_bonus);
			Was_bonus = TRUE;
		}
	}
}
Ejemplo n.º 3
0
void SoftFox::run()
{
	//Set all default boolean
	running = true;
	jump = false;
	hasJumped = false;
	playerCollision = false;

	resetPlayer(); 	//Sets the players position

	//Thomas Easterbrook Coding Task two start
	hunterX = tileSize * level->getVillianX() + tileSize/2;
	hunterY = tileSize * level->getVillianY() + tileSize/2;
	//Thomas Easterbrook Coding Task two end

	//Dean Harland Coding Task Two Start
	//Set mushroom start posistion to the tile using level
	mushroomX = tileSize * level->getMushroomX() + tileSize / 2;
	mushroomY = tileSize * level->getMushroomY() + tileSize / 2;
	//Dean Harland Coding Task Two End

	while (running)
	{
		//Set an event
		SDL_Event ev;
		if (SDL_PollEvent(&ev))
		{
			switch (ev.type)
			{
				//Create a case for quitting the window and set running to false to deconstruct the window
				//Break or system breaks
				case SDL_QUIT:
					running = false;
					break;

				default:
					break;
			}
		}

		SDL_RenderCopy(renderer, backgroundImage, nullptr, NULL); //Render the background first

		drawLevel(); //Draw the level using the method drawTile shown below
		playerKeyBoardCommands();

		//Thomas Easterbrook Coding Task two start
		hunterSprite->render(renderer, hunterX, hunterY + spriteAdjustmentHunterSize, tileSize, tileSize);
		//Thomas Easterbrook Coding Task two end

		//Drawing mushroom sprite
		mushroomSprite->render(renderer, mushroomX, mushroomY + spriteAdjustmentMushroomSize, SPRITE_SIZE, SPRITE_SIZE);

		///Drawing player sprite (texture class)
		playerSprite->render(renderer, playerX, playerY, SPRITE_SIZE, playerSpriteHeight);

		//Drawing player sprite (texture class)
		controls->render(renderer, WINDOW_WIDTH - spriteControlXAdjustment, spriteControlYAdjustment, tileSize * 1.5, tileSize);

		////Sam Wills coding task two start
		jumping();
		hasFoxTouchedPlatform();
		sideCollision();
		isFoxInWindow();
		//Sam Wills coding task two end

		//Thomas Easterbrook Coding Task two start
		hunterMovement();
		hasFoxTouchedHunter();
		//Thomas Easterbrook Coding Task two end

		//Dean Harland Coding Task Two Start
		endGameMushroom();	
		//Dean Harland Coding Task Two Start

		SDL_RenderPresent(renderer);				
	}
}