<commit_before>#include "Globals.h"
#include "Application.h"
#include "ModuleRender.h"
#include "ModuleSceneIntro.h"
#include "ModuleSceneGameOver.h"
#include "ModuleInput.h"
#include "ModuleTextures.h"
#include "ModuleAudio.h"
#include "ModulePlayer.h"
#include "ModuleFonts.h"

#include "ModulePhysics.h"
#include"Animation.h"

ModuleSceneIntro::ModuleSceneIntro(Application* app, bool start_enabled) : Module(app, start_enabled)
{
	//circle = box = rick = NULL;
	
	ray_on = false;
	sensed = false;
}

ModuleSceneIntro::~ModuleSceneIntro()
{}

// Load assets
bool ModuleSceneIntro::Start()
{
	
	
		LOG("Loading Intro assets");
		
		
		App->renderer->camera.x = App->renderer->camera.y = 0;
		//Pinball ground that ball can't go outside
		if(App->player->player_ball != nullptr)
		App->player->player_ball->body->SetTransform({ PIXEL_TO_METERS(PLAYER_POS_X),PIXEL_TO_METERS(PLAYER_POS_Y) }, 0);
		

		idle_pusher.PushBack({ 48,0, 19, 103 });
		anim_pusher.PushBack({ 48,0, 19, 103 });
		anim_pusher.PushBack({ 24,0, 19, 103 });
		anim_pusher.PushBack({ 0,0, 19, 103 });
		anim_pusher.speed = 0.7f;
		anim_pusher.loop = false;

		current_animpusher = &idle_pusher;
		//--------------------Textures
		spritesheet = App->textures->Load("Assets/textures/spritesheet.png");

		map_tex = App->textures->Load("Assets/textures/background.png");

		L_BlueLight = App->textures->Load("Assets/textures/left_blueshine.png");

		R_BlueLight = App->textures->Load("Assets/textures/right_blueshine.png");

		L_GreenLight = App->textures->Load("Assets/textures/left_greenshine.png");

		R_GreenLight = App->textures->Load("Assets/textures/right_greenshine.png");

		L_RedLight = App->textures->Load("Assets/textures/left_redshine.png");

		R_RedLight = App->textures->Load("Assets/textures/right_redshine.png");

		M_RedLight = App->textures->Load("Assets/textures/central_redshine.png");
		//--------------------
		
		//--------------------FX & Music

		App->audio->PlayMusic("Assets/audio/music/intro.ogg");

		earn_points_fx = App->audio->LoadFx("Assets/audio/fx/points.wav");

		pusher_hit_fx = App->audio->LoadFx("Assets/audio/fx/pusher_hit.wav");

		flipper_hit_fx = App->audio->LoadFx("Assets/audio/fx/flipper_hit.wav");

		bonus_fx = App->audio->LoadFx("Assets/audio/fx/bonus.wav");

		bounce_fx = App->audio->LoadFx("Assets/audio/fx/bouncer.wav");

		loose_ball_fx = App->audio->LoadFx("Assets/audio/fx/loose_ball.wav");

		loose_fx = App->audio->LoadFx("Assets/audio/fx/loose.wav");
		
		if (!background_created) {
			AddBouncers();
			PinballGround();
			setScores();
			background_created  = true;
		}
		//-------------------------
		//-------------------------Fonts for score
		font_score = App->fonts->Load("Assets/fonts/score_points_font.png", "01234.56789 ", 2);

		App->player->score = 0;
	
	return true;
}

bool ModuleSceneIntro::CleanUp()
{
	LOG("Unloading Intro scene");
	App->textures->Unload(spritesheet);
	App->textures->Unload(map_tex);
	App->textures->Unload(L_BlueLight);
	App->textures->Unload(R_BlueLight);
	App->textures->Unload(L_GreenLight);
	App->textures->Unload(R_GreenLight);
	App->textures->Unload(L_RedLight);
	App->textures->Unload(R_RedLight);
	App->textures->Unload(M_RedLight);
	
	// sets all light sensors to false
	bll = blr = brl = brr = rll = rlr = rrl = rrr = rml = rmr = rmm = gll = glr = grl = grr = rlnl = llnl = false;

	//audio
	bonus_fx = bounce_fx = earn_points_fx = loose_ball_fx = loose_fx = flipper_hit_fx = intro_music = pusher_hit_fx = NULL;

	App->fonts->Unload(font_score);
	return true;
}

// Update with other functions to keep this clean
update_status ModuleSceneIntro::Update()
{
		if (map_tex != NULL)
		{
			App->renderer->Blit(map_tex, 0, 0, NULL, 1.0f);
		}
		App->renderer->Blit(spritesheet, 448, 414, &current_animpusher->GetCurrentFrame());

		UpdateSensors();
		PlayerLives();
		
		sprintf_s(score_text, 10, "%7d", App->player->score);
		App->fonts->BlitText(140, 465, font_score, score_text, 3.0f);
		
	
	return UPDATE_CONTINUE;


}

void ModuleSceneIntro::PlayerLives()
{
	//This is for the lives shown in the right space
	for (int i = 0; i < App->player->lives - 1; i++)
	{
		App->renderer->Blit(App->player->ball_tex, 446 - 11* i, 570 - 15 * i, NULL, 1.0f);
	}

	if ((App->player->position.y < 300) && (App->player->position.y > 100))
	{
		dead = false;	
	}
	if ((App->player->position.y >= 800) &&(!dead))
	{
		dead = true;
		
		App->player->lives-=1;
		if (App->player->lives != 0) 
		{
			App->player->player_ball->body->SetTransform({ PIXEL_TO_METERS(PLAYER_POS_X),PIXEL_TO_METERS(PLAYER_POS_Y) }, 0);
			App->audio->PlayFx(loose_ball_fx);
		}
		if (App->player->lives == 0)
		{
			
			App->audio->PlayFx(loose_fx);
			SceneChange();
		}
	}
}

//We use this for adding the bouncers on a different function of update
void ModuleSceneIntro::AddBouncers()
{
	//Top left blue	
	bouncers.add(App->physics->CreateCircle(100, 55, 18, 0.8f, b2_staticBody));
	bouncers.add(App->physics->CreateCircle(135, 45, 18, 0.8f, b2_staticBody));

	//Top right blue	
	bouncers.add(App->physics->CreateCircle(333, 48, 18, 0.8f, b2_staticBody));<commit_msg>Fixed error that ball has initial velocity<commit_after>#include "Globals.h"
#include "Application.h"
#include "ModuleRender.h"
#include "ModuleSceneIntro.h"
#include "ModuleSceneGameOver.h"
#include "ModuleInput.h"
#include "ModuleTextures.h"
#include "ModuleAudio.h"
#include "ModulePlayer.h"
#include "ModuleFonts.h"

#include "ModulePhysics.h"
#include"Animation.h"

ModuleSceneIntro::ModuleSceneIntro(Application* app, bool start_enabled) : Module(app, start_enabled)
{
	//circle = box = rick = NULL;
	
	ray_on = false;
	sensed = false;
}

ModuleSceneIntro::~ModuleSceneIntro()
{}

// Load assets
bool ModuleSceneIntro::Start()
{
	
	
		LOG("Loading Intro assets");
		
		
		App->renderer->camera.x = App->renderer->camera.y = 0;
		//Pinball ground that ball can't go outside
		if (App->player->player_ball != nullptr)
		{
			App->player->player_ball->body->SetTransform({ PIXEL_TO_METERS(PLAYER_POS_X),PIXEL_TO_METERS(PLAYER_POS_Y) }, 0);
			App->player->player_ball->body->SetLinearVelocity({ 0,0 });
		}

		idle_pusher.PushBack({ 48,0, 19, 103 });
		anim_pusher.PushBack({ 48,0, 19, 103 });
		anim_pusher.PushBack({ 24,0, 19, 103 });
		anim_pusher.PushBack({ 0,0, 19, 103 });
		anim_pusher.speed = 0.7f;
		anim_pusher.loop = false;

		current_animpusher = &idle_pusher;
		//--------------------Textures
		spritesheet = App->textures->Load("Assets/textures/spritesheet.png");

		map_tex = App->textures->Load("Assets/textures/background.png");

		L_BlueLight = App->textures->Load("Assets/textures/left_blueshine.png");

		R_BlueLight = App->textures->Load("Assets/textures/right_blueshine.png");

		L_GreenLight = App->textures->Load("Assets/textures/left_greenshine.png");

		R_GreenLight = App->textures->Load("Assets/textures/right_greenshine.png");

		L_RedLight = App->textures->Load("Assets/textures/left_redshine.png");

		R_RedLight = App->textures->Load("Assets/textures/right_redshine.png");

		M_RedLight = App->textures->Load("Assets/textures/central_redshine.png");
		//--------------------
		
		//--------------------FX & Music

		App->audio->PlayMusic("Assets/audio/music/intro.ogg");

		earn_points_fx = App->audio->LoadFx("Assets/audio/fx/points.wav");

		pusher_hit_fx = App->audio->LoadFx("Assets/audio/fx/pusher_hit.wav");

		flipper_hit_fx = App->audio->LoadFx("Assets/audio/fx/flipper_hit.wav");

		bonus_fx = App->audio->LoadFx("Assets/audio/fx/bonus.wav");

		bounce_fx = App->audio->LoadFx("Assets/audio/fx/bouncer.wav");

		loose_ball_fx = App->audio->LoadFx("Assets/audio/fx/loose_ball.wav");

		loose_fx = App->audio->LoadFx("Assets/audio/fx/loose.wav");
		
		if (!background_created) {
			AddBouncers();
			PinballGround();
			setScores();
			background_created  = true;
		}
		//-------------------------
		//-------------------------Fonts for score
		font_score = App->fonts->Load("Assets/fonts/score_points_font.png", "01234.56789 ", 2);

		App->player->score = 0;
	
	return true;
}

bool ModuleSceneIntro::CleanUp()
{
	LOG("Unloading Intro scene");
	App->textures->Unload(spritesheet);
	App->textures->Unload(map_tex);
	App->textures->Unload(L_BlueLight);
	App->textures->Unload(R_BlueLight);
	App->textures->Unload(L_GreenLight);
	App->textures->Unload(R_GreenLight);
	App->textures->Unload(L_RedLight);
	App->textures->Unload(R_RedLight);
	App->textures->Unload(M_RedLight);
	
	// sets all light sensors to false
	bll = blr = brl = brr = rll = rlr = rrl = rrr = rml = rmr = rmm = gll = glr = grl = grr = rlnl = llnl = false;

	//audio
	bonus_fx = bounce_fx = earn_points_fx = loose_ball_fx = loose_fx = flipper_hit_fx = intro_music = pusher_hit_fx = NULL;

	App->fonts->Unload(font_score);
	return true;
}

// Update with other functions to keep this clean
update_status ModuleSceneIntro::Update()
{
		if (map_tex != NULL)
		{
			App->renderer->Blit(map_tex, 0, 0, NULL, 1.0f);
		}
		App->renderer->Blit(spritesheet, 448, 414, &current_animpusher->GetCurrentFrame());

		UpdateSensors();
		PlayerLives();
		
		sprintf_s(score_text, 10, "%7d", App->player->score);
		App->fonts->BlitText(140, 465, font_score, score_text, 3.0f);
		
	
	return UPDATE_CONTINUE;


}

void ModuleSceneIntro::PlayerLives()
{
	//This is for the lives shown in the right space
	for (int i = 0; i < App->player->lives - 1; i++)
	{
		App->renderer->Blit(App->player->ball_tex, 446 - 11* i, 570 - 15 * i, NULL, 1.0f);
	}

	if ((App->player->position.y < 300) && (App->player->position.y > 100))
	{
		dead = false;	
	}
	if ((App->player->position.y >= 800) &&(!dead))
	{
		dead = true;
		
		App->player->lives-=1;
		if (App->player->lives != 0) 
		{
			App->player->player_ball->body->SetTransform({ PIXEL_TO_METERS(PLAYER_POS_X),PIXEL_TO_METERS(PLAYER_POS_Y) }, 0);
			App->player->player_ball->body->SetLinearVelocity({ 0, 0 });
			App->audio->PlayFx(loose_ball_fx);
		}
		if (App->player->lives == 0)
		{			
			App->audio->PlayFx(loose_fx);
			SceneChange();
		}
	}
}

//We use this for adding the bouncers on a different function of update
void ModuleSceneIntro::AddBouncers()
{
	//Top left blue	
	bouncers.add(App->physics->CreateCircle(100, 55, 18, 0.8f, b2_staticBody));
	bouncers.add(App->physics->CreateCircle(135, 45, 18, 0.8f, b2_staticBody));

	//Top right blue	
	bouncers.add(App->physics->CreateCircle(333, 48, 18, 0.8f, b2_staticBody));
{'fraction_non_alphanumeric': 0.18895966029723993, 'fraction_numerical': 0.02451264234703725, 'mean_word_length': 3.9774255523535063, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 233, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2106020', 'n_tokens_mistral': 4437, 'n_tokens_neox': 3969, 'n_words': 637}