#pragma comment(lib, "irrKlang.lib")
#include <windows.h>
namespace SuperMetroidCraft {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Media;
using namespace IrrKlang;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Timer^ GunTimer;
protected:
protected:
private: System::ComponentModel::IContainer^ components;
private: System::Windows::Forms::PictureBox^ Player;
private: System::Windows::Forms::Timer^ PlayerMoveTimer;
private: System::Windows::Forms::PictureBox^ Ground;
private: System::Windows::Forms::Timer^ MasterTimer;
private: System::Windows::Forms::Label^ DirLabel;
private: System::Windows::Forms::PictureBox^ Grenade;
private: System::Windows::Forms::Timer^ GrenadeExplosionTimer;
private: System::Windows::Forms::Label^ AmmoBox;
private: System::Windows::Forms::Label^ HPLabel;
private: System::Windows::Forms::Label^ ScoreLabel;
private: System::Windows::Forms::Label^ ComboLabel;
protected:
private:
/// <summary>
/// Required designer variable.
static int BulletCtr=0, UpwardMomentum=-11, GrenadeUpwardsMomentum=-15, GrenadeExpCtr=0, AnimCtr=0;
static int ReloadCtr=0, Ammo=100, RndHolder, MetroidCtr=0, MetLaserCtr=0;
static int MetLaserMoveCtr=0, HP=5, Score=0, PlayerDeathCtr=0, Combo=0;
static array<int>^ BulletHeight=gcnew array<int>(100);
static array<int>^ ShellLateral=gcnew array<int>(100);
static array<int>^ ShellMomentum=gcnew array<int>(100);
static array<int>^ MetMoveCtr=gcnew array<int>{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static array<int>^ MetMoveX=gcnew array<int>(20);
static array<int>^ MetMoveY=gcnew array<int>(20);
static array<int>^ MetKillCtr=gcnew array<int>(20);
Random^ Rnd;
static bool OnGround=true, IsJumping=false, GrenadeCook=false, GrenadeThrow=false, GrenadeOnGround=false;
static bool GrenadeLeft=false, Left=false, Move=false, Reload=false, DoubleJump=false;
static bool IsReloading=false, GrenadeExplode=false, IsDead=false, PlayCombo=false, BulletRoll=false;
static bool HasFlushedGunshot=false, HasFlushedMetLaser=false, HasFlushedMetKill=false;
static array<bool>^ BulletLeft=gcnew array<bool>(100);
static array<bool>^ MetDead=gcnew array<bool>(100);
char dir;
static String^ path="C:\\Users\\Owner.Ben-PC\\Documents\\Visual Studio 2010\\Projects\\SuperMetroidCraft\\Resources\\";
static array<System::Windows::Forms::PictureBox^>^ Bullet=gcnew array<System::Windows::Forms::PictureBox^>(100);
static array<System::Windows::Forms::PictureBox^>^ Shell=gcnew array<System::Windows::Forms::PictureBox^>(100);
static array<System::Windows::Forms::PictureBox^>^ MetLaser=gcnew array<System::Windows::Forms::PictureBox^>(100);
static array<System::Windows::Forms::PictureBox^>^ Metroid=gcnew array<System::Windows::Forms::PictureBox^>(20);
static ISoundEngine^ Main=gcnew ISoundEngine();
static ISoundEngine^ Gunshot=gcnew ISoundEngine();
static ISoundEngine^ ReloadSound=gcnew ISoundEngine();
static ISoundEngine^ MetLaserSound=gcnew ISoundEngine();
static ISoundEngine^ MetKillSound=gcnew ISoundEngine();
static ISoundEngine^ GrenadeSound=gcnew ISoundEngine();
static ISoundEngine^ DeathSound=gcnew ISoundEngine();
static ISoundEngine^ ComboSound=gcnew ISoundEngine();
static ISoundEngine^ ComboBreakerSound=gcnew ISoundEngine();
/// </summary>
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
this->GunTimer = (gcnew System::Windows::Forms::Timer(this->components));
this->Player = (gcnew System::Windows::Forms::PictureBox());
this->PlayerMoveTimer = (gcnew System::Windows::Forms::Timer(this->components));
this->Ground = (gcnew System::Windows::Forms::PictureBox());
this->MasterTimer = (gcnew System::Windows::Forms::Timer(this->components));
this->DirLabel = (gcnew System::Windows::Forms::Label());
this->Grenade = (gcnew System::Windows::Forms::PictureBox());
this->GrenadeExplosionTimer = (gcnew System::Windows::Forms::Timer(this->components));
this->AmmoBox = (gcnew System::Windows::Forms::Label());
this->HPLabel = (gcnew System::Windows::Forms::Label());
this->ScoreLabel = (gcnew System::Windows::Forms::Label());
this->ComboLabel = (gcnew System::Windows::Forms::Label());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->Player))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->Ground))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->Grenade))->BeginInit();
this->SuspendLayout();
//
// GunTimer
//
this->GunTimer->Tick += gcnew System::EventHandler(this, &Form1::GunTimer_Tick);
//
// Player
//
this->Player->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"Player.Image")));
this->Player->Location = System::Drawing::Point(0, 500);
this->Player->Name = L"Player";
this->Player->Size = System::Drawing::Size(24, 31);
this->Player->TabIndex = 0;
this->Player->TabStop = false;
//
// PlayerMoveTimer
//
this->PlayerMoveTimer->Interval = 10;
this->PlayerMoveTimer->Tick += gcnew System::EventHandler(this, &Form1::PlayerMoveTimer_Tick);
//
// Ground
//
this->Ground->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"Ground.Image")));
this->Ground->Location = System::Drawing::Point(0, 531);
this->Ground->Name = L"Ground";
this->Ground->Size = System::Drawing::Size(1233, 133);
this->Ground->TabIndex = 1;
this->Ground->TabStop = false;
//
// MasterTimer
//
this->MasterTimer->Enabled = true;
this->MasterTimer->Interval = 10;
this->MasterTimer->Tick += gcnew System::EventHandler(this, &Form1::MasterTimer_Tick);
//
// DirLabel
//
this->DirLabel->AutoSize = true;
this->DirLabel->Location = System::Drawing::Point(13, 13);
this->DirLabel->Name = L"DirLabel";
this->DirLabel->Size = System::Drawing::Size(26, 13);
this->DirLabel->TabIndex = 2;
this->DirLabel->Text = L"Dir=";
//
// Grenade
//
this->Grenade->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"Grenade.BackgroundImage")));
this->Grenade->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"Grenade.Image")));
this->Grenade->Location = System::Drawing::Point(12, 29);
this->Grenade->Name = L"Grenade";
this->Grenade->Size = System::Drawing::Size(7, 10);
this->Grenade->TabIndex = 3;
this->Grenade->TabStop = false;
//
// GrenadeExplosionTimer
//
this->GrenadeExplosionTimer->Interval = 250;
this->GrenadeExplosionTimer->Tick += gcnew System::EventHandler(this, &Form1::GrenadeExplosionTimer_Tick);
//
// AmmoBox
//
this->AmmoBox->AutoSize = true;
this->AmmoBox->Location = System::Drawing::Point(679, 9);
this->AmmoBox->Name = L"AmmoBox";
this->AmmoBox->Size = System::Drawing::Size(83, 13);
this->AmmoBox->TabIndex = 4;
this->AmmoBox->Text = L"Ammo: 100/100";
//
// HPLabel
//
this->HPLabel->AutoSize = true;
this->HPLabel->Location = System::Drawing::Point(628, 9);
this->HPLabel->Name = L"HPLabel";
this->HPLabel->Size = System::Drawing::Size(45, 13);
this->HPLabel->TabIndex = 5;
this->HPLabel->Text = L"HP: 5/5";
//
// ScoreLabel
//
this->ScoreLabel->AutoSize = true;
this->ScoreLabel->Location = System::Drawing::Point(768, 9);
this->ScoreLabel->Name = L"ScoreLabel";
this->ScoreLabel->Size = System::Drawing::Size(47, 13);
this->ScoreLabel->TabIndex = 6;
this->ScoreLabel->Text = L"Score: 0";
//
// ComboLabel
//
this->ComboLabel->AutoSize = true;
this->ComboLabel->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 40, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->ComboLabel->Location = System::Drawing::Point(514, 210);
this->ComboLabel->Name = L"ComboLabel";
this->ComboLabel->Size = System::Drawing::Size(0, 63);
this->ComboLabel->TabIndex = 7;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::SystemColors::ButtonHighlight;
this->ClientSize = System::Drawing::Size(1234, 664);
this->Controls->Add(this->ComboLabel);
this->Controls->Add(this->ScoreLabel);
this->Controls->Add(this->HPLabel);
this->Controls->Add(this->AmmoBox);
this->Controls->Add(this->Grenade);
this->Controls->Add(this->DirLabel);
this->Controls->Add(this->Ground);
this->Controls->Add(this->Player);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::Form1_KeyDown);
this->KeyUp += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::Form1_KeyUp);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->Player))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->Ground))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->Grenade))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
Rnd=gcnew Random();
Main->Play2D(path+"MainTrack.wav",true);
}
private: System::Void Form1_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
if(IsDead==false)
{
//Gun
if(GunTimer->Enabled==false&&e->KeyCode==Keys::E)
{
GunTimer->Enabled=true;
HasFlushedGunshot=false;
}
//Reload
if(IsReloading==false&&e->KeyCode==Keys::R)
{
Reload=true;
}
//Grenade
if(e->KeyCode==Keys::G)
{
if(GrenadeThrow==false&&GrenadeExplosionTimer->Enabled==false)
{
this->Grenade->Location=System::Drawing::Point(this->Player->Location.X+10, this->Player->Location.Y+10);
GrenadeCook=true;
}
}
//Player motion
if(e->KeyCode==Keys::Right)
{
Left=false;
}
if(e->KeyCode==Keys::Left)
{
Left=true;
}
if(e->KeyCode==Keys::Up)
{
dir='u';
IsJumping=true;
if(OnGround==false&&DoubleJump==false)
{
DoubleJump=true;
UpwardMomentum+=10;
}
if(PlayerMoveTimer->Enabled==false)
{
PlayerMoveTimer->Enabled=true;
}
for(int i=1; i<6; i++)
{
if(this->Player->ImageLocation==(path+"PlayerRunRight"+i+".jpg"))
{
Left=false;
break;
}
}
for(int i=1; i<6; i++)
{
if(this->Player->ImageLocation==(path+"PlayerRunLeft"+i+".jpg"))
{
Left=true;
break;
}
}
}
}
}
private: System::Void Form1_KeyUp(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
//Gun
if(GunTimer->Enabled==true&&e->KeyCode==Keys::E)
{
GunTimer->Enabled=false;
}
//Grenade
if(e->KeyCode==Keys::G&&IsDead==false)
{
if(GrenadeThrow==false&&GrenadeExplosionTimer->Enabled==false)
{
this->Grenade->Location=System::Drawing::Point(this->Player->Location.X+10, this->Player->Location.Y+10);
GrenadeUpwardsMomentum=10;
GrenadeThrow=true;
GrenadeCook=false;
if(Left==true)
{
GrenadeLeft=true;
}
else
{
GrenadeLeft=false;
}
}
}
if(IsDead==false)
{
//Player movement
if(PlayerMoveTimer->Enabled==true&&e->KeyCode==Keys::Right&&OnGround==true)
{
if(Left==false)
{
Move=false;
PlayerMoveTimer->Enabled=false;
}
this->Player->ImageLocation=(path+"PlayerStandRight.jpg");
}
else if(PlayerMoveTimer->Enabled==true&&e->KeyCode==Keys::Right&&OnGround==false)
{
if(Left==false)
{
Move=false;
}
this->Player->ImageLocation=(path+"PlayerStandRight.jpg");
}
if(PlayerMoveTimer->Enabled==true&&e->KeyCode==Keys::Left&&OnGround==true)
{
if(Left==true)
{
Move=false;
PlayerMoveTimer->Enabled=false;
}
this->Player->ImageLocation=(path+"PlayerStandLeft.jpg");
}
else if(PlayerMoveTimer->Enabled==true&&e->KeyCode==Keys::Left&&OnGround==false)
{
if(Left==true)
{
Move=false;
}
this->Player->ImageLocation=(path+"PlayerStandLeft.jpg");
}
}
}
private: System::Void GunTimer_Tick(System::Object^ sender, System::EventArgs^ e)
{
if(BulletCtr<Bullet->Length&&Reload==false)
{
Gunshot->Play2D(path+"Gunshot.wav",false);
HasFlushedGunshot=false;
if(BulletRoll==false)
{
this->Bullet[BulletCtr] = gcnew System::Windows::Forms::PictureBox();
this->Bullet[BulletCtr]->BackColor = System::Drawing::SystemColors::Window;
this->Bullet[BulletCtr]->Name = L"Bullet";
this->Bullet[BulletCtr]->Size = System::Drawing::Size(11,3);
this->Bullet[BulletCtr]->TabIndex = 2;
this->Bullet[BulletCtr]->Location = System::Drawing::Point(this->Player->Location.X, this->Player->Location.Y+9);
this->Controls->Add(Bullet[BulletCtr]);
this->Shell[BulletCtr] = gcnew System::Windows::Forms::PictureBox();
this->Shell[BulletCtr]->BackColor = System::Drawing::SystemColors::Window;
this->Shell[BulletCtr]->Name = L"Shell";
this->Shell[BulletCtr]->Size = System::Drawing::Size(12,3);
this->Shell[BulletCtr]->TabIndex = 2;
this->Shell[BulletCtr]->Location = System::Drawing::Point(this->Player->Location.X, this->Player->Location.Y+9);
this->Controls->Add(Shell[BulletCtr]);
}
else
{
this->Bullet[BulletCtr]->Left-=(Bullet[BulletCtr]->Location.X)-(Player->Location.X);
this->Bullet[BulletCtr]->Top-=((Bullet[BulletCtr]->Location.Y)-(Player->Location.Y))-9;
this->Shell[BulletCtr]->Left-=(Shell[BulletCtr]->Location.X)-(Player->Location.X);
this->Shell[BulletCtr]->Top-=((Shell[BulletCtr]->Location.Y)-(Player->Location.Y))-9;
}
ShellMomentum[BulletCtr]=10;
if(Rnd->Next()%2==0)
{
ShellLateral[BulletCtr]=Rnd->Next()%5;
}
else
{
ShellLateral[BulletCtr]=-Rnd->Next()%5;
}
if(Left==true)
{
BulletLeft[BulletCtr]=true;
this->Bullet[BulletCtr]->ImageLocation = path+"BulletLeft.gif";
this->Shell[BulletCtr]->ImageLocation = path+"ShellLeft.jpg";
}
else if (Left==false)
{
BulletLeft[BulletCtr]=false;
this->Bullet[BulletCtr]->ImageLocation = path+"BulletRight.gif";
this->Shell[BulletCtr]->ImageLocation = path+"ShellRight.jpg";
}
Ammo--;
this->AmmoBox->Text="Ammo: "+Ammo+"/100";
BulletCtr++;
if(BulletCtr==Bullet->Length)
{
BulletRoll=true;
}
}
else
{
if(IsReloading==false)
{
IsReloading=true;
ReloadSound->Play2D(path+"Reload.wav",false);
}
Reload=true;
}
}
private: System::Void PlayerMoveTimer_Tick(System::Object^ sender, System::EventArgs^ e)
{
//Cooking grenade
if(GrenadeCook==true)
{
this->Grenade->Location=System::Drawing::Point(this->Player->Location.X+10, this->Player->Location.Y+10);
}
//Player movement
if(IsDead==false)
{
//Run animation
if(AnimCtr==0)
{
AnimCtr+=PlayerMoveTimer->Interval;
if(Left==false)
{
this->Player->ImageLocation=(path+"PlayerRunRight1.jpg");
}
else if(Left==true)
{
this->Player->ImageLocation=(path+"PlayerRunLeft1.jpg");
}
}
else if(AnimCtr<=5*PlayerMoveTimer->Interval)
{
AnimCtr+=PlayerMoveTimer->Interval;
if(Left==false)
{
this->Player->ImageLocation=(path+"PlayerRunRight2.jpg");
}
else if(Left==true)
{
this->Player->ImageLocation=(path+"PlayerRunLeft2.jpg");
}
}
else if(AnimCtr<=10*PlayerMoveTimer->Interval)
{
AnimCtr+=PlayerMoveTimer->Interval;
if(Left==false)
{
this->Player->ImageLocation=(path+"PlayerRunRight3.jpg");
}
else if(Left==true)
{
this->Player->ImageLocation=(path+"PlayerRunLeft3.jpg");
}
}
else if(AnimCtr<=15*PlayerMoveTimer->Interval)
{
AnimCtr+=PlayerMoveTimer->Interval;
if(Left==false)
{
this->Player->ImageLocation=(path+"PlayerRunRight4.jpg");
}
else if(Left==true)
{
this->Player->ImageLocation=(path+"PlayerRunLeft4.jpg");
}
}
else if(AnimCtr<=20*PlayerMoveTimer->Interval)
{
AnimCtr+=PlayerMoveTimer->Interval;
if(Left==false)
{
this->Player->ImageLocation=(path+"PlayerRunRight5.jpg");
}
else if(Left==true)
{
this->Player->ImageLocation=(path+"PlayerRunLeft5.jpg");
}
}
else if(AnimCtr<=25*PlayerMoveTimer->Interval)
{
AnimCtr=0;
if(Left==false)
{
this->Player->ImageLocation=(path+"PlayerRunRight6.jpg");
}
else if(Left==true)
{
this->Player->ImageLocation=(path+"PlayerRunLeft6.jpg");
}
}
//Move player
if(Move==true)
{
if(Left==false&&this->Player->Location.X<1220)
{
this->Player->Left+=5;
}
else if(Left==true&&this->Player->Location.X>=0)
{
this->Player->Left-=5;
}
}
//Jumping
if(IsJumping==true)
{
CheckDirection();
Player->BringToFront();
if(OnGround==true)
{
UpwardMomentum=15;
this->Player->Top-=UpwardMomentum;
UpwardMomentum--;
OnGround=false;
}
else if(OnGround==false&&UpwardMomentum>=0)
{
this->Player->Top-=UpwardMomentum;
UpwardMomentum--;
}
else if(OnGround==false&&UpwardMomentum<0)
{
if(this->Player->Location.Y>=this->Ground->Location.Y-31)
{
UpwardMomentum=0;
this->Player->Top=this->Ground->Location.Y-31;
OnGround=true;
IsJumping=false;
DoubleJump=false;
}
else
{
this->Player->Top-=UpwardMomentum;
UpwardMomentum--;
}
}
}
}
}
private: System::Void MasterTimer_Tick(System::Object^ sender, System::EventArgs^ e)
{
//Updade labels
this->DirLabel->Text="BulletRoll="+BulletRoll;
this->ScoreLabel->Text="Score: "+Score;
if(Combo<10)
{
this->ComboLabel->Text="";
}
//Check for arrow key state
if(GetAsyncKeyState(VK_LEFT)==0&&GetAsyncKeyState(VK_RIGHT)==0)
{
Move=false;
}
else
{
Move=true;
}
//Spawn Metroid
if(Rnd->Next()%50==49)
{
if(MetroidCtr<Metroid->Length)
{
MetDead[MetroidCtr]=false;
this->Metroid[MetroidCtr] = gcnew System::Windows::Forms::PictureBox();
this->Metroid[MetroidCtr]->BackColor = System::Drawing::SystemColors::Window;
this->Metroid[MetroidCtr]->ImageLocation = path+"Metroid.gif";
this->Metroid[MetroidCtr]->Location = System::Drawing::Point((Rnd->Next()%250)+900, (Rnd->Next()%250)+150);
this->Metroid[MetroidCtr]->Name = L"Metroid";
this->Metroid[MetroidCtr]->Size = System::Drawing::Size(32, 29);
this->Metroid[MetroidCtr]->TabIndex = 2;
this->Controls->Add(Metroid[MetroidCtr]);
MetroidCtr++;
}
else
{
for(int i=0; i<MetroidCtr; i++)
{
if(MetDead[i]==true)
{
MetDead[i]=false;
this->Metroid[i]->Location = System::Drawing::Point((Rnd->Next()%250)+900, (Rnd->Next()%250)+150);
this->Metroid[i]->ImageLocation = path+"Metroid.gif";
this->Metroid[i]->Size = System::Drawing::Size(32, 29);
break;
}
}
for(int i=0; i<MetroidCtr; i++)
{
if(MetDead[i]==true)
{
MetDead[i]=false;
this->Metroid[i]->Location = System::Drawing::Point((Rnd->Next()%250)+900, (Rnd->Next()%250)+150);
this->Metroid[i]->ImageLocation = path+"Metroid.gif";
this->Metroid[i]->Size = System::Drawing::Size(32, 29);
break;
}
}
}
}
//Move Metroids and make them shoot
for(int i=0; i<MetroidCtr; i++)
{
if(MetDead[i]==false)
{
if(MetMoveCtr[i]==0)
{
MetMoveCtr[i]++;
if(Rnd->Next()%2==0)
{
MetMoveX[i]=Rnd->Next()%5;
MetMoveY[i]=Rnd->Next()%5;
}
else
{
MetMoveX[i]=-Rnd->Next()%5;
MetMoveY[i]=-Rnd->Next()%5;
}
}
else if(MetMoveCtr[i]<100)
{
MetMoveCtr[i]++;
if(this->Metroid[i]->Location.X>850&&this->Metroid[i]->Location.X<1215)
{
this->Metroid[i]->Left+=MetMoveX[i];
}
else if(this->Metroid[i]->Location.X<850)
{
this->Metroid[i]->Location=System::Drawing::Point(1210,this->Metroid[i]->Location.Y);
}
else
{
this->Metroid[i]->Location=System::Drawing::Point(860,this->Metroid[i]->Location.Y);
}
if(this->Metroid[i]->Location.Y>35&&this->Metroid[i]->Location.Y<500)
{
this->Metroid[i]->Top+=MetMoveY[i];
}
else if(this->Metroid[i]->Location.Y<35)
{
this->Metroid[i]->Location=System::Drawing::Point(this->Metroid[i]->Location.X,480);
}
else
{
this->Metroid[i]->Location=System::Drawing::Point(this->Metroid[i]->Location.X,50);
}
}
else
{
MetMoveCtr[i]=0;
}
}
if(Rnd->Next()%100==99&&MetDead[i]!=true)//Make Metroids shoot
{
MetLaserSound->Play2D(path+"MetLaserSound.wav");
HasFlushedMetLaser=false;
if(MetLaserCtr<MetLaser->Length)
{
this->MetLaser[MetLaserCtr] = gcnew System::Windows::Forms::PictureBox();
this->MetLaser[MetLaserCtr]->BackColor = System::Drawing::SystemColors::Window;
this->MetLaser[MetLaserCtr]->ImageLocation = path+"MetLaser.gif";
this->MetLaser[MetLaserCtr]->Location = System::Drawing::Point(this->Metroid[i]->Location.X, this->Metroid[i]->Location.Y);
this->MetLaser[MetLaserCtr]->Name = L"Laser";
this->MetLaser[MetLaserCtr]->Size = System::Drawing::Size(13, 3);
this->MetLaser[MetLaserCtr]->TabIndex = 2;
this->Controls->Add(MetLaser[MetLaserCtr]);
MetLaserCtr++;
}
else if(MetLaserMoveCtr<MetLaser->Length)
{
this->MetLaser[MetLaserMoveCtr]->Left-=(this->MetLaser[MetLaserMoveCtr]->Location.X)-(this->Metroid[i]->Location.X);
this->MetLaser[MetLaserMoveCtr]->Top-=(this->MetLaser[MetLaserMoveCtr]->Location.Y)-(this->Metroid[i]->Location.Y);
this->MetLaser[MetLaserMoveCtr]->ImageLocation = path+"MetLaser.gif";
MetLaserMoveCtr++;
}
else
{
MetLaserMoveCtr=0;
}
}
}
//Make Metroid lasers move and check for Metroid laser collision with player
for(int i=0; i<MetLaserCtr; i++)
{
if(this->MetLaser[i]->Location.X>-15)
{
this->MetLaser[i]->Left-=5;
this->MetLaser[i]->BringToFront();
}
else
{
this->MetLaser[i]->ImageLocation=nullptr;
}
if(this->MetLaser[i]->Location.X-24<=this->Player->Location.X&&this->MetLaser[i]->Location.X+5>this->Player->Location.X)
{
if(this->MetLaser[i]->Location.Y+3>=this->Player->Location.Y&&this->MetLaser[i]->Location.Y<this->Player->Location.Y+34)
{
if(HP>0)
{
HP--;
HPLabel->Text="HP: "+HP+"/5";
this->MetLaser[i]->Location=System::Drawing::Point(1000, 1000);
}
if(HP==0&&IsDead==false)
{
IsDead=true;
Score=0;
this->Player->Size=System::Drawing::Size(125,100);
this->Player->Location=System::Drawing::Point(this->Player->Location.X,this->Player->Location.Y-100);
this->Player->BackColor=Color::White;
this->Player->ImageLocation=path+"Bloodsplat.gif";
DeathSound->Play2D(path+"DeathSound.wav",false);
}
if(Combo>=10)
{
ComboBreakerSound->Play2D(path+"ComboBreaker.wav");
}
Combo=0;
}
}
}
//Player death code
if(IsDead==true)
{
if(PlayerDeathCtr<80)
{
PlayerDeathCtr++;
}
else
{
IsDead=false;
this->PlayerMoveTimer->Enabled=false;
PlayerDeathCtr=0;
HP=5;
HPLabel->Text="HP: "+HP+"/5";
Player->Size=System::Drawing::Size(24,34);
Player->ImageLocation=(path+"PlayerStandRight.jpg");
Player->Location=System::Drawing::Point(0,500);
}
}
//Jumping
if(UpwardMomentum>-11)
{
PlayerMoveTimer->Enabled=true;
}
//Force stand
if(Move==false&&Left==true&&IsDead==false)
{
this->Player->ImageLocation=(path+"PlayerStandLeft.jpg");
}
else if(Move==false&&Left==false&&IsDead==false)
{
this->Player->ImageLocation=(path+"PlayerStandRight.jpg");
}
//Make bullets and shells move
for(int i=0; i<BulletCtr; i++)
{
if(this->Bullet[i]->Location.X<1250&&this->Bullet[i]->Location.X>-15)
{
this->Bullet[i]->BringToFront();
if(BulletLeft[i]==true)
{
this->Bullet[i]->Left-=15;
}
else
{
this->Bullet[i]->Left+=15;
}
}
else
{
this->Bullet[i]->ImageLocation=nullptr;
}
if(Shell[i]->Location.Y<550)
{
this->Shell[i]->Top-=ShellMomentum[i];
this->Shell[i]->Left-=ShellLateral[i];
ShellMomentum[i]--;
}
}
//Check for bullet collision with Metroid
for(int a=0; a<BulletCtr; a++)
{
if(this->Bullet[a]->Location.X<1250&&this->Bullet[a]->Location.X>-15)
{
for(int b=0; b<MetroidCtr; b++)
{
if(this->Bullet[a]->Location.X+13>=this->Metroid[b]->Location.X&&this->Bullet[a]->Location.X+13<this->Metroid[b]->Location.X+32)
{
if(this->Bullet[a]->Location.Y+3>=this->Metroid[b]->Location.Y&&this->Bullet[a]->Location.Y+3<this->Metroid[b]->Location.Y+29)
{
if(MetDead[b]==false)
{
MetDead[b]=true;
this->Bullet[a]->Location = System::Drawing::Point(1000, 1000);
this->Metroid[b]->Size = System::Drawing::Size(50,50);
this->Metroid[b]->ImageLocation=(path+"GrenadeExplosion.gif");
MetKillSound->Play2D(path+"MetKillSound.wav");
HasFlushedMetKill=false;
Score++;
Combo++;
PlayCombo=false;
CheckCombo();
}
}
}
}
}
}
//Check for grenade collision with Metroid
if(Grenade->Location!=System::Drawing::Point(12, 29))
{
for(int b=0; b<MetroidCtr; b++)
{
if(this->Grenade->ImageLocation==(path+"GrenadeSprite.png"))//When not exploding.
{
if(this->Grenade->Location.X+this->Grenade->Width>=this->Metroid[b]->Location.X&&this->Grenade->Location.X+this->Grenade->Width<this->Metroid[b]->Location.X+32)
{
if(this->Grenade->Location.Y+this->Grenade->Height>=this->Metroid[b]->Location.Y&&this->Grenade->Location.Y+this->Grenade->Height<this->Metroid[b]->Location.Y+29)
{
if(this->Grenade->ImageLocation==(path+"GrenadeSprite.png"))
{
GrenadeExplode=true;
GrenadeThrow=false;
this->Grenade->BackgroundImage=nullptr;
this->Grenade->Size=System::Drawing::Size(50, 50);
this->Grenade->ImageLocation=(path+"GrenadeExplosion.gif");
this->GrenadeExplosionTimer->Enabled=true;
GrenadeSound->Play2D(path+"GrenadeSound.wav",false);
for(int c=0; c<MetroidCtr; c++)
{
if(this->Grenade->Location.X+50>=this->Metroid[c]->Location.X&&this->Grenade->Location.X-50<this->Metroid[c]->Location.X+32)
{
if(this->Grenade->Location.Y+50>=this->Metroid[c]->Location.Y&&this->Grenade->Location.Y-50<this->Metroid[c]->Location.Y+29)
{
if(MetDead[c]==false)
{
MetDead[c]=true;
this->Metroid[c]->Size = System::Drawing::Size(50,50);
this->Metroid[c]->ImageLocation=(path+"GrenadeExplosion.gif");
MetKillSound->Play2D(path+"MetKillSound.wav");
HasFlushedMetKill=false;
Score++;
Combo++;
PlayCombo=false;
CheckCombo();
}
}
}
}
}
if(MetDead[b]==false)
{
MetDead[b]=true;
this->Metroid[b]->Size = System::Drawing::Size(50,50);
this->Metroid[b]->ImageLocation=(path+"GrenadeExplosion.gif");
MetKillSound->Play2D(path+"MetKillSound.wav");
HasFlushedMetKill=false;
}
}
}
}
}
}
//Metroid exploding code
for(int i=0; i<MetroidCtr; i++)
{
if(MetDead[i]==true)
{
if(MetKillCtr[i]<25)
{
MetKillCtr[i]++;
}
else
{
MetKillCtr[i]=0;
this->Metroid[i]->Location = System::Drawing::Point(1000, 1000);
}
}
}
//Reloading
if(IsReloading==false&&Reload==true)
{
IsReloading=true;
ReloadSound->Play2D(path+"Reload.wav",false);
}
if(Reload==true)
{
ReloadCtr++;
}
if(ReloadCtr==75)
{
Ammo=100;
this->AmmoBox->Text="Ammo: "+Ammo+"/100";
Reload=false;
IsReloading=false;
BulletCtr=0;
ReloadCtr=0;
}
//Made grenade move
if(GrenadeThrow==true&&GrenadeExplode==false)
{
if(GrenadeUpwardsMomentum>=0)
{
if(GrenadeLeft==true)
{
this->Grenade->Left-=15;
}
else
{
this->Grenade->Left+=15;
}
this->Grenade->Top-=GrenadeUpwardsMomentum;
GrenadeUpwardsMomentum--;
}
else if(GrenadeUpwardsMomentum<0)
{
if(this->Grenade->Location.Y>=this->Ground->Location.Y-10&&this->GrenadeExplosionTimer->Enabled==false)
{
this->Grenade->BackgroundImage=nullptr;
this->Grenade->Size=System::Drawing::Size(50, 50);
this->Grenade->Location=System::Drawing::Point(this->Grenade->Location.X,this->Ground->Location.Y-50);
this->Grenade->ImageLocation=path+"GrenadeExplosion.gif";
this->GrenadeExplosionTimer->Enabled=true;
GrenadeSound->Play2D(path+"GrenadeSound.wav",false);
GrenadeThrow=false;
GrenadeUpwardsMomentum=-15;
for(int c=0; c<MetroidCtr; c++)
{
if(this->Grenade->Location.X+50>=this->Metroid[c]->Location.X&&this->Grenade->Location.X-50<this->Metroid[c]->Location.X+32)
{
if(this->Grenade->Location.Y+50>=this->Metroid[c]->Location.Y&&this->Grenade->Location.Y-50<this->Metroid[c]->Location.Y+29)
{
if(MetDead[c]==false)
{
MetDead[c]=true;
this->Metroid[c]->Size = System::Drawing::Size(50,50);
this->Metroid[c]->ImageLocation=(path+"GrenadeExplosion.gif");
MetKillSound->Play2D(path+"MetKillSound.wav");
HasFlushedMetKill=false;
Score++;
Combo++;
PlayCombo=false;
CheckCombo();
}
}
}
}
}
else
{
if(GrenadeLeft==true)
{
this->Grenade->Left-=15;
}
else
{
this->Grenade->Left+=15;
}
this->Grenade->Top-=GrenadeUpwardsMomentum;
GrenadeUpwardsMomentum--;
}
}
}
//Flush objects from memory and rebuild them
if(GunTimer->Enabled==true&&HasFlushedGunshot==false)
{
delete Gunshot;
Gunshot=gcnew ISoundEngine();
HasFlushedGunshot=true;
}
if(MetLaserSound->IsCurrentlyPlaying(path+"MetLaserSound.wav")==false&&HasFlushedMetLaser==false)
{
delete MetLaserSound;
MetLaserSound=gcnew ISoundEngine();
HasFlushedMetLaser=true;
}
if(MetKillSound->IsCurrentlyPlaying(path+"MetKillSound.wav")==false&&HasFlushedMetKill==false)
{
delete MetKillSound;
MetKillSound=gcnew ISoundEngine();
HasFlushedMetKill=true;
}
this->Ground->BringToFront();
}
private: System::Void GrenadeExplosionTimer_Tick(System::Object^ sender, System::EventArgs^ e)
{
if(GrenadeExpCtr<1250)
{
GrenadeExpCtr+=250;
}
else if(GrenadeExpCtr==1250)
{
this->Grenade->Size=System::Drawing::Size(7,10);
this->Grenade->Location=System::Drawing::Point(12, 29);
this->Grenade->ImageLocation=path+"GrenadeSprite.png";
GrenadeExpCtr=0;
GrenadeExplosionTimer->Enabled=false;
GrenadeExplode=false;
}
}
void CheckDirection()
{
for(int i=1; i<6; i++)
{
if(this->Player->ImageLocation==(path+"PlayerRunRight"+i+".jpg"))
{
Left=false;
break;
}
}
for(int i=1; i<6; i++)
{
if(this->Player->ImageLocation==(path+"PlayerRunLeft"+i+".jpg"))
{
Left=true;
break;
}
}
if(this->Player->ImageLocation==(path+"PlayerStandLeft.jpg"))
{
Left=true;
}
if(this->Player->ImageLocation==(path+"PlayerStandRight.jpg"))
{
Left=false;
}
}
void CheckCombo()
{
//Check for combo
if(Combo>=10)
{
this->ComboLabel->Text="x"+Combo;
}
else
{
this->ComboLabel->Text="";
}
if(Combo==20&&PlayCombo==false)
{
ComboSound->Play2D(path+"TwoCombo.wav", false);
PlayCombo=true;
}
else if(Combo==30&&PlayCombo==false)
{
ComboSound->Play2D(path+"ThreeCombo.wav", false);
PlayCombo=true;
}
else if(Combo==40&&PlayCombo==false)
{
ComboSound->Play2D(path+"FourCombo.wav", false);
PlayCombo=true;
}
else if(Combo==50&&PlayCombo==false)
{
ComboSound->Play2D(path+"FiveCombo.wav", false);
PlayCombo=true;
}
else if(Combo==60&&PlayCombo==false)
{
ComboSound->Play2D(path+"SixCombo.wav", false);
PlayCombo=true;
}
else if(Combo==70&&PlayCombo==false)
{
ComboSound->Play2D(path+"SevenCombo.wav", false);
PlayCombo=true;
}
else if(Combo==80&&PlayCombo==false)
{
ComboSound->Play2D(path+"EightCombo.wav", false);
PlayCombo=true;
}
else if(Combo==90&&PlayCombo==false)
{
ComboSound->Play2D(path+"NineCombo.wav", false);
PlayCombo=true;
}
}
};
}