コード例 #1
0
void ModeMenu::Draw(SDL_Surface* screenSurface)
{
	if(mWall.get())
	{
		Vector2f offset((Widget::GetScreenSize().x - mWall->GetBounds().x) / 2, 0);

		vector<Brick::SharedPointer> bricks = mWall->GetBricks();
		for(vector<Brick::SharedPointer>::iterator brick = bricks.begin(); brick != bricks.end(); ++brick)
		{
			Animation* sprite;
			switch((*brick)->GetBrickType())
			{
			default:
			case BrickType::BlueBrick:
				sprite = StandardTextures::blue_brick_animation[0];
				break;
			case BrickType::RedBrick:
				sprite = StandardTextures::red_brick_animation[(*brick)->GetLives() - 1];
				break;
			case BrickType::YellowBrick:
				sprite = StandardTextures::yellow_brick_animation[(*brick)->GetLives() - 1];
				break;
			}

			Vector2i inverted_y = (*brick)->GetPosition() + mWall->GetPosition() + offset + Vector2f(Brick::BRICK_WIDTH / 2, 0);
			inverted_y.y = 480 - inverted_y.y;
			sprite->GetCurrentFrame()->Draw(inverted_y);
		}
	}
}
コード例 #2
0
int ScriptedAnimation::GetCurrentFrame()
{
	Animation *anim = anims[P_HOLD*MAX_ORIENT];
	if (anim) {
		return anim->GetCurrentFrame();
	}
	return 0;
}
コード例 #3
0
ファイル: ModulePlayer.cpp プロジェクト: adrixdx/ms-pacman
// Update: draw background
update_status ModulePlayer::Update()
{
	Animation* current_animation = &idle;
	Animation* units = &n_0;
	Animation* dozens = &n_0;
	Animation* hundreds = &n_0;
	Animation* thousands = &n_0;
	Animation* t_thousands = &n_0;
	bool colision = false;
	float speed = 2;
	
	int position_x = position.x;
	int position_y = position.y;
	//static int dir = 1;
	static int s_dir = 1;
	int tilepos_x = ((position_x + 16) / 16) * 16;
	int tilepos_y = ((position_y + 16) / 16) * 16;
	
	uint n_units;
	uint n_dozens;
	uint n_hundreds; 
	uint n_thousands;
	uint n_10thousands;

	n_units = points % 10;
	n_dozens = (points / 10) % 10;
	n_hundreds = (points / 100) % 10;
	n_thousands = (points / 1000) % 10;
	n_10thousands = (points / 10000) % 10;
	
	switch (n_dozens){
	case 0: dozens = &n_0; break;
	case 1:dozens = &n_1; break;
	case 2:dozens = &n_2; break;
	case 3:dozens = &n_3; break;
	case 4:dozens = &n_4; break;
	case 5:dozens = &n_5; break;
	case 6:dozens = &n_6; break;
	case 7:dozens = &n_7; break;
	case 8:dozens = &n_8; break;
	case 9:dozens = &n_9; break;
	}

	switch (n_hundreds){
	case 0:hundreds = &n_0; break;
	case 1:hundreds = &n_1; break;
	case 2:hundreds = &n_2; break;
	case 3:hundreds = &n_3; break;
	case 4:hundreds = &n_4; break;
	case 5:hundreds = &n_5; break;
	case 6:hundreds = &n_6; break;
	case 7:hundreds = &n_7; break;
	case 8:hundreds = &n_8; break;
	case 9:hundreds = &n_9; break;
	}

	switch (n_thousands){
	case 0: thousands = &n_0; break;
	case 1:thousands = &n_1; break;
	case 2:thousands = &n_2; break;
	case 3:thousands = &n_3; break;
	case 4:thousands = &n_4; break;
	case 5:thousands = &n_5; break;
	case 6:thousands = &n_6; break;
	case 7:thousands = &n_7; break;
	case 8:thousands = &n_8; break;
	case 9:thousands = &n_9; break;
	}
	switch (n_10thousands){
	case 0: t_thousands = &n_0; break;
	case 1:t_thousands = &n_1; break;
	case 2:t_thousands = &n_2; break;
	case 3:t_thousands = &n_3; break;
	case 4:t_thousands = &n_4; break;
	case 5:t_thousands = &n_5; break;
	case 6:t_thousands = &n_6; break;
	case 7:t_thousands = &n_7; break;
	case 8:t_thousands = &n_8; break;
	case 9:t_thousands = &n_9; break;
	}



	if (App->input->keyboard[SDL_SCANCODE_RIGHT] == 1)
	{
		s_dir= 0;
		
	}
	if (dir == 0){
		current_animation = &right;

	}


	if (App->input->keyboard[SDL_SCANCODE_LEFT] == 1)
	{
		s_dir= 1;
	
	}
	if (dir == 1){
		current_animation = &left;
		
	}

	if (App->input->keyboard[SDL_SCANCODE_UP] == 1)
	{
		s_dir = 2;
	
		

	}
	if (dir == 2){
		current_animation = &up;
	}

	if (App->input->keyboard[SDL_SCANCODE_DOWN] == 1)
	{
		s_dir = 3;
	}	

	if (dir == 3){
		current_animation = &down;
		
	}

	if (dir == 0 && s_dir == 1){
		dir = s_dir;
	}
	if (dir == 1 && s_dir == 0){
		dir = s_dir;
	}
	if (dir == 2 && s_dir == 3){
		dir = s_dir;
	}
	if (dir == 3 && s_dir == 2){
		dir = s_dir;
	}

	if (s_map[tilepos_y / 16][(tilepos_x / 16)] == -1 || s_map[tilepos_y / 16][(tilepos_x / 16)] == -2){
		if (s_dir == 0 && s_map[tilepos_y / 16][(tilepos_x / 16) + 1] != 2){
			dir = s_dir;

		}
		if (s_dir == 1 && s_map[tilepos_y / 16][(tilepos_x / 16) - 1] != 2){
			dir = s_dir;

		}
		if (s_dir == 2 && s_map[(tilepos_y / 16) - 1][(tilepos_x / 16)] != 2){
			dir = s_dir;

		}
		if (s_dir == 3 && s_map[(tilepos_y / 16) + 1][(tilepos_x / 16)] != 2){
			dir = s_dir;

		}

	}
	if (god == true){
		if (dir == 0){
			current_animation = &g_right;
			
		}
		if (dir == 1){
			current_animation = &g_left;
			
		}
		if (dir == 2){
			current_animation = &g_up;
			
		}
		if (dir == 3){
			current_animation = &g_down;
		
		}
	}



	// Collider--------------

	

	col->SetPos(tilepos_x, tilepos_y);

	
	if (dir == 0 && s_map[tilepos_y / 16][(tilepos_x / 16)] < 2){

		position_x = position_x + speed;
		position.x = position_x;
		position.y = (position_y / 16) * 16 + 8;
	}
	if (dir == 1 && s_map[tilepos_y / 16][(tilepos_x / 16)] < 2){

		position_x = position_x - speed;
		position.x = position_x;
		position.y = (position_y / 16) * 16 + 8;

	}
	if (dir == 2 && s_map[tilepos_y / 16][(tilepos_x / 16)] < 2){

		position_y = position_y - speed;
		position.y = position_y;
		position.x = (position_x / 16) * 16 + 8;
	}
	if (dir == 3 && s_map[tilepos_y / 16][(tilepos_x / 16)] < 2){

		position_y = position_y + speed;
		position.y = position_y;
		position.x = (position_x / 16) * 16 + 8;
	}


	if (dir == 0 && s_map[tilepos_y / 16][(tilepos_x / 16) + 1] >= 2){

		position_x = position_x - speed;
		position.x = (position_x / 16) * 16 +8;
		position.y = (position_y / 16) * 16 + 8;
		
		
	}


	if (dir == 1 && s_map[tilepos_y / 16][(tilepos_x / 16) - 1] >= 2){

		position_x = position_x + speed;
		position.x = (position_x / 16) * 16 + 8;
		position.y = (position_y / 16) * 16 + 8;
	}
			
	
	if (dir == 2 && s_map[(tilepos_y / 16) - 1][(tilepos_x / 16)] >= 2){

			position_y = position_y + speed;
			position.y = (position_y / 16) * 16 + 8;
			position.x = (position_x / 16) * 16 + 8;
			
			
		}

	if (dir == 3 && s_map[(tilepos_y / 16) + 1][(tilepos_x / 16)] >= 2){
		position_y = position_y - speed;
		position.y = (position_y / 16) * 16 + 8;
		position.x = (position_x / 16) * 16 + 8;
				
				}
	if (s_map[(tilepos_y / 16)][(tilepos_x / 16)] == -3)
	{
		position.x = 0;
	}
	if (s_map[(tilepos_y / 16)][(tilepos_x / 16)] == -4)
	{
		position.x = 410;
	}

	
	
		if (destroyed == false)
			App->render->Blit(graphics, position.x, position.y, &(current_animation->GetCurrentFrame()));
		App->render->Blit(graphics, 128+16, 16, &(units->GetCurrentFrame()));
		App->render->Blit(graphics, 128, 16, &(dozens->GetCurrentFrame()));
		App->render->Blit(graphics, 96+16, 16, &(hundreds->GetCurrentFrame()));
		App->render->Blit(graphics, 96, 16, &(thousands->GetCurrentFrame()));
		App->render->Blit(graphics, 96-16, 16, &(t_thousands->GetCurrentFrame()));



		// Draw everything --------------------------------------
		SDL_Rect r = current_animation->GetCurrentFrame();

		if (destroyed == true){
			points = 0;
		}

		if (SDL_GetTicks() - time > 4000){
			power = false;
		}



		

		return UPDATE_CONTINUE;
	}
コード例 #4
0
ファイル: ModuleBlinky.cpp プロジェクト: adrixdx/ms-pacman
// Update: draw background
update_status ModuleBlinky::Update()
{
	Animation* current_animation = &idle;
	Animation* horitzontal = &a_hor;
	Animation* vertical = &a_vert;
	float position_x = position.x;
	float position_y = position.y;
	int i_position_x = position.x;
	int i_position_y = position.y;

	int tilepos_x = ((i_position_x + 16) / 16) * 16;
	int tilepos_y = ((i_position_y + 16) / 16) * 16;

	
	int d_up = 1000;
	int d_down = 1000;
	int d_right = 1000;
	int d_left = 1000;
	
	

	
	float speed = 1.5;

	if (SDL_GetTicks() - time <= 700){
		
			direction = 2;
		
			//if (SDL_GetTicks() - time >= 2000) direction = 1;
	}
	else if (SDL_GetTicks() - time <= 810){
		direction = 1;
	}
	else {
		if (turn == true){

			if (App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16)] == -1 || App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16)] == -2){
				if (App->player->s_map[(tilepos_y / 16) - 1][(tilepos_x / 16)] != 2){
					d_up = SDL_sqrt(((tilepos_x)-App->player->position.x)*(tilepos_x - App->player->position.x) + ((tilepos_y - 16) - App->player->position.y)*((tilepos_y - 16) - App->player->position.y));
				}

				if (App->player->s_map[(tilepos_y / 16) + 1][(tilepos_x / 16)] != 2){
					d_down = SDL_sqrt(((tilepos_x)-App->player->position.x)*(tilepos_x - App->player->position.x) + ((tilepos_y + 16) - App->player->position.y)*((tilepos_y + 16) - App->player->position.y));
				}

				if (App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16) - 1] != 2){
					d_left = SDL_sqrt(((tilepos_x - 16) - App->player->position.x)*((tilepos_x - 16) - App->player->position.x) + ((tilepos_y)-App->player->position.y)*((tilepos_y)-App->player->position.y));
				}

				if (App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16) + 1] != 2){
					d_right = SDL_sqrt(((tilepos_x + 16) - App->player->position.x)*((tilepos_x + 16) - App->player->position.x) + ((tilepos_y)-App->player->position.y)*((tilepos_y)-App->player->position.y));
				}

				if (direction == 0){
					d_left = 1000;
				}
				if (direction == 1){
					d_right = 1000;
				}
				if (direction == 2){
					d_down = 1000;
				}
				if (direction == 3){
					d_up = 1000;
				}


				if (d_up <= d_down && d_up <= d_right && d_up <= d_left){
					direction = 2; turn = false;
				}
				else if (d_right <= d_down && d_right <= d_left && d_right <= d_up){
					direction = 0; turn = false;
				}
				else if (d_down <= d_up && d_down <= d_right && d_down <= d_left){
					direction = 3; turn = false;
				}

				else if (d_left <= d_up && d_left <= d_right && d_left <= d_down){
					direction = 1; turn = false;
				}

			}
			if (App->player->power == true){

				d_up = 0;
				d_down = 0;
				d_right = 0;
				d_left = 0;

				if (App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16)] == -1 || App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16)] == -2){
					if (App->player->s_map[(tilepos_y / 16) - 1][(tilepos_x / 16)] != 2){
						d_up = SDL_sqrt(((tilepos_x)-App->player->position.x)*(tilepos_x - App->player->position.x) + ((tilepos_y - 16) - App->player->position.y)*((tilepos_y - 16) - App->player->position.y));
					}

					if (App->player->s_map[(tilepos_y / 16) + 1][(tilepos_x / 16)] != 2){
						d_down = SDL_sqrt(((tilepos_x)-App->player->position.x)*(tilepos_x - App->player->position.x) + ((tilepos_y + 16) - App->player->position.y)*((tilepos_y + 16) - App->player->position.y));
					}

					if (App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16) - 1] != 2){
						d_left = SDL_sqrt(((tilepos_x - 16) - App->player->position.x)*((tilepos_x - 16) - App->player->position.x) + ((tilepos_y)-App->player->position.y)*((tilepos_y)-App->player->position.y));
					}

					if (App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16) + 1] != 2){
						d_right = SDL_sqrt(((tilepos_x + 16) - App->player->position.x)*((tilepos_x + 16) - App->player->position.x) + ((tilepos_y)-App->player->position.y)*((tilepos_y)-App->player->position.y));
					}

				

					if (d_up >= d_down && d_up >= d_right && d_up >= d_left){
						direction = 2; turn = false;
					}
					else if (d_down >= d_up && d_down >= d_right && d_down >= d_left){
						direction = 3; turn = false;
					}
					else if (d_right >= d_down && d_right >= d_left && d_right >= d_up){
						direction = 0; turn = false;
					}
					else if (d_left >= d_up && d_left >= d_right && d_left >= d_down){
						direction = 1; turn = false;
					}

				}

			}

		}
	}

		if (App->player->power == true ||App->player->god ==true){
			if (SDL_GetTicks() - App->player->time > 2000 && SDL_GetTicks() - App->player->time < 4000){
				current_animation = &scared2;
			}
			else
				current_animation = &scared;
		}
		else{

			if (direction == 0){
				current_animation = &right;
				//position.x += speed;

			}

			if (direction == 1){
				current_animation = &left;
				//position.x -= speed;
			}


			if (direction == 2){
				current_animation = &up;
				//position.y -= speed;
			}

			if (direction == 3){
				current_animation = &down;
				//position.y += speed;
			}

		}

	

	


	if (direction == 0 && App->player->s_map[tilepos_y / 16][(tilepos_x / 16)] != 2){

		position_x = position_x + speed;
		position.x = position_x;
		position.y = (i_position_y / 16) * 16 + 8;
	}
	if (direction == 1 && App->player->s_map[tilepos_y / 16][(tilepos_x / 16)] != 2){

		position_x = position_x - speed;
		position.x = position_x;
		position.y = (i_position_y / 16) * 16 + 8;

	}
	if (direction == 2 && App->player->s_map[tilepos_y / 16][(tilepos_x / 16)] != 2){

		position_y = position_y - speed;
		position.y = position_y;
		position.x = (i_position_x / 16) * 16 + 8;
	}
	if (direction == 3 && App->player->s_map[tilepos_y / 16][(tilepos_x / 16)] != 2){

		position_y = position_y + speed;
		position.y = position_y;
		position.x = (i_position_x / 16) * 16 + 8;
	}


	if (direction == 0 && App->player->s_map[tilepos_y / 16][(tilepos_x / 16) + 1] == 2){

		position_x = position_x - speed;
		position.x = (i_position_x / 16) * 16 + 8;

	}


	if (direction == 1 && App->player->s_map[tilepos_y / 16][(tilepos_x / 16) - 1] == 2){

		position_x = position_x + speed;
		position.x = (i_position_x / 16) * 16 + 8;
	}


	if (direction == 2 && App->player->s_map[(tilepos_y / 16) - 1][(tilepos_x / 16)] == 2){

		position_y = position_y + speed;
		position.y = (i_position_y / 16) * 16 + 8;


	}

	if (direction == 3 && App->player->s_map[(tilepos_y / 16) + 1][(tilepos_x / 16)] == 2){
		position_y = position_y - speed;
		position.y = (i_position_y / 16) * 16 + 8;

	}



	float t_positionx = position.x;
	float t_positiony = position.y;
	float t_position_x = t_positionx;
	float t_position_y = t_positiony;
	int p_position_x = App->player->position.x;
	int p_position_y = App->player->position.y;
	int player_position_x = (( p_position_x+ 16) / 16) * 16;
	int player_position_y = ((p_position_y + 16) / 16) * 16;
	bool t_turn = true;
	// Collider--------------

	col->SetPos(tilepos_x, tilepos_y);
	int i = 0, n = 0;
	int temp_dir = direction;
	bool ret = false;
	int cont = 0;
	if (debug ==true){
	while (ret != true){
		d_up = 1000;
		d_down = 1000;
		d_left = 1000;
		d_right = 1000;
		//t_position_x + i != App->player->position.x  && t_position_y + n != App->player->position.y
		float t_position_x = t_positionx;
		float t_position_y = t_positiony;
		int t_i_position_x = t_positionx;
		int t_i_position_y = t_positiony;
		int t_tilepos_y = ((t_i_position_y + 16) / 16) * 16;
		int t_tilepos_x = ((t_i_position_x + 16) / 16) * 16;

		
		if (t_turn == true){

			if (App->player->s_map[(t_tilepos_y / 16)][(t_tilepos_x / 16)] == -1 || App->player->s_map[(t_tilepos_y / 16)][(t_tilepos_x / 16)] == -2){
				if (App->player->s_map[(t_tilepos_y / 16) - 1][(t_tilepos_x / 16)] != 2){
					d_up = SDL_sqrt(((t_tilepos_x)-App->player->position.x)*(t_tilepos_x - App->player->position.x) + ((t_tilepos_y - 16) - App->player->position.y)*((t_tilepos_y - 16) - App->player->position.y));
				}

				if (App->player->s_map[(t_tilepos_y / 16) + 1][(t_tilepos_x / 16)] != 2){
					d_down = SDL_sqrt(((t_tilepos_x)-App->player->position.x)*(t_tilepos_x - App->player->position.x) + ((t_tilepos_y + 16) - App->player->position.y)*((t_tilepos_y + 16) - App->player->position.y));
				}

				if (App->player->s_map[(t_tilepos_y / 16)][(t_tilepos_x / 16) - 1] != 2){
					d_left = SDL_sqrt(((t_tilepos_x - 16) - App->player->position.x)*((t_tilepos_x - 16) - App->player->position.x) + ((t_tilepos_y)-App->player->position.y)*((t_tilepos_y)-App->player->position.y));
				}

				if (App->player->s_map[(t_tilepos_y / 16)][(t_tilepos_x / 16) + 1] != 2){
					d_right = SDL_sqrt(((t_tilepos_x + 16) - App->player->position.x)*((t_tilepos_x + 16) - App->player->position.x) + ((t_tilepos_y)-App->player->position.y)*((t_tilepos_y)-App->player->position.y));
				}

				if (temp_dir == 0){
					d_left = 1000;
				}
				if (temp_dir == 1){
					d_right = 1000;
				}
				if (temp_dir == 2){
					d_down = 1000;
				}
				if (temp_dir == 3){
					d_up = 1000;
				}


				if (d_up <= d_down && d_up <= d_right && d_up <= d_left){
					temp_dir = 2; t_turn = false;
				}
				else if (d_right <= d_down && d_right <= d_left && d_right <= d_up){
					temp_dir = 0; t_turn = false;
				}
				else if (d_down <= d_up && d_down <= d_right && d_down <= d_left){
					temp_dir = 3; t_turn = false;
				}

				else if (d_left <= d_up && d_left <= d_right && d_left <= d_down){
					temp_dir = 1; t_turn = false;
				}

			}


		}
		if (temp_dir == 0 && App->player->s_map[t_tilepos_y / 16][(t_tilepos_x / 16)] != 2){

			t_position_x = t_position_x + speed;
			t_positionx = t_position_x;
			t_positiony = (t_i_position_y / 16) * 16 + 8;
		}
		if (temp_dir == 1 && App->player->s_map[t_tilepos_y / 16][(t_tilepos_x / 16)] != 2){

			t_position_x = t_position_x - speed;
			t_positionx = t_position_x;
			t_positiony = (t_i_position_y / 16) * 16 + 8;

		}
		if (temp_dir == 2 && App->player->s_map[t_tilepos_y / 16][(t_tilepos_x / 16)] != 2){

			t_position_y = t_position_y - speed;
			t_positiony = t_position_y;
			t_positionx = (t_i_position_x / 16) * 16 + 8;
		}
		if (temp_dir == 3 && App->player->s_map[t_tilepos_y / 16][(t_tilepos_x / 16)] != 2){

			t_position_y = t_position_y + speed;
			t_positiony = t_position_y;
			t_positionx = (t_i_position_x / 16) * 16 + 8;
		}


		if (temp_dir == 0 && App->player->s_map[t_tilepos_y / 16][(t_tilepos_x / 16) + 1] == 2){

			t_position_x = t_position_x - speed;
			t_positionx = (t_i_position_x / 16) * 16 + 8;

		}


		if (temp_dir == 0 || temp_dir == 1){
			App->render->Blit(graphics, t_tilepos_x, t_tilepos_y, &(horitzontal->GetCurrentFrame()));
		}
		else App->render->Blit(graphics, t_tilepos_x, t_tilepos_y, &(vertical->GetCurrentFrame()));

		if (temp_dir == 0){
			t_tilepos_x += 16;
		}
		if (temp_dir == 1){
			t_tilepos_x -= 16;
		}
		if (temp_dir == 2){
			t_tilepos_y -= 16;
		}
		if (temp_dir == 3){
			t_tilepos_y += 16;
		}
		if (App->player->s_map[(t_tilepos_y / 16)][(t_tilepos_x / 16)] != -1 && App->player->s_map[(t_tilepos_y / 16)][(t_tilepos_x / 16)] != -2)
		{

			t_turn = true;
		}
		if ((t_tilepos_y == player_position_y && t_tilepos_x == player_position_x) || cont >= 100){
			ret = true;
			t_turn = true;
			temp_dir = direction;
		}
		cont++;
	}
	}
	
	if (destroyed == false)
		App->render->Blit(graphics, position.x, position.y, &(current_animation->GetCurrentFrame()));
	if (App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16)] == -3)
	{
		position.x = 0;
	}
	if (App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16)] == -4)
	{
		position.x = 410;
	}

	// Draw everything --------------------------------------
	SDL_Rect r = current_animation->GetCurrentFrame();

	//App->render->Blit(graphics, position.x, position.y - r.h, &r);
	/*int tilepos_x_temp = ((i_position_x + 16) / 16) * 16;
	int tilepos_y_temp = ((i_position_y + 16) / 16) * 16;

	if (tilepos_x_temp != tilepos_x || tilepos_y_temp != tilepos_y){
		turn = true;
	}*/
	if (App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16)] != -1 && App->player->s_map[(tilepos_y / 16)][(tilepos_x / 16)] != -2)
	{
		turn = true;
	}

	return UPDATE_CONTINUE;
}