Click here to Skip to main content
15,888,454 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralMessage Removed Pin
20-Mar-11 1:56
goldenrose920-Mar-11 1:56 
GeneralRe: can anyone convert this MFC code to WIN32 code please help Pin
Hans Dietrich20-Mar-11 2:43
mentorHans Dietrich20-Mar-11 2:43 
JokeMessage Removed Pin
20-Mar-11 2:52
goldenrose920-Mar-11 2:52 
GeneralRe: can anyone convert this MFC code to WIN32 code please help PinPopular
Hans Dietrich20-Mar-11 3:14
mentorHans Dietrich20-Mar-11 3:14 
GeneralMessage Removed Pin
20-Mar-11 6:02
goldenrose920-Mar-11 6:02 
GeneralRe: can anyone convert this MFC code to WIN32 code please help PinPopular
Richard MacCutchan20-Mar-11 7:16
mveRichard MacCutchan20-Mar-11 7:16 
GeneralRe: can anyone convert this MFC code to WIN32 code please help Pin
tagopi21-Mar-11 0:29
tagopi21-Mar-11 0:29 
QuestionInstances of an object [modified] Pin
Cyclone_S19-Mar-11 14:01
Cyclone_S19-Mar-11 14:01 
Hi,

I'm currently making a simple game. Pressing the down arrow places a box on the form. Pressing up shoots missiles(blue boxes) and creates multiple instances of m1 which is part of the missle class.

What I want to do is change the color of each missle as it collides with the red box. So far only the last missile changes color. The other instances of the missle class get ignored.

#include "stdafx.h"
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;

public ref class object
{
	public:
			PictureBox^ Box3;
			
			object( Form ^ form ) // Class Constructor.
			{
				Box3 = gcnew PictureBox();
				Box3->Left = 150;
				Box3->Top = 50;
				Box3->Width = 100;
				Box3->Height = 100;
				Box3->BackColor = System::Drawing::Color::Red;
				form->Controls->Add(Box3);
			}
};

public ref class missile
{
	public:
			PictureBox^ Box1;
			Timer^ Timer1;

			missile( Form ^ form ) // Class Constructor.
			{
				Timer1 = gcnew Timer;
				Timer1->Interval = 1;
				Timer1->Start();
				Box1 = gcnew PictureBox();
				Box1->Left = 150;
				Box1->Top = 240;
				Box1->Width = 10;
				Box1->Height = 10;
				Box1->BackColor = System::Drawing::Color::Blue;
				form->Controls->Add(Box1);
				Timer1->Tick += gcnew System::EventHandler(this, &missile::timer1_Tick);
			}

		System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e)
		{
			Box1->Top -= 1;
		}
};


public ref class Form1 : public Form 
{
	public:
			PictureBox^ Box2;
			missile^ m1;
			object^ o1;
			Timer^ Timer3;
			bool x;

			Form1() // Class constructor.
			{	
				x=false;
				Timer3 = gcnew Timer();
				Timer3->Interval = 1;
				Timer3->Start();
				Box2 = gcnew PictureBox();
				Box2->BackColor = Color::Blue;
				Box2->Top = 240;
				Box2->Left = (this->Width / 2) - 40;
				Box2->Width = 40;
				Box2->Height = 10;
				this->Controls->Add(Box2);
				this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::Form_KeyDown);
				Timer3->Tick += gcnew System::EventHandler(this, &Form1::timer3_Tick);
			}

			System::Void Form_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
			{	
				if(e->KeyCode == Keys::Up){x=true;m1 = gcnew missile(this);m1->Box1->Left = Box2->Left + (Box2->Width / 2) - 10;}
				if(e->KeyCode == Keys::Left){Box2->Left -= 4;}
				if(e->KeyCode == Keys::Right){Box2->Left += 4;}
				if(e->KeyCode == Keys::Down) {o1 = gcnew object(this); }
			}

			System::Void timer3_Tick(System::Object^  sender, System::EventArgs^  e)
			{
				if(x==true)
				{
					if(m1->Box1->Top == o1->Box3->Bottom){m1->Box1->BackColor = Color::Green;}
				}
			}

			bool isColliding(PictureBox^ box1, PictureBox^ box3)
			{
				Rectangle r1 = m1->Box1->Bounds;
				Rectangle r2 = o1->Box3->Bounds;
				return r1.IntersectsWith(r2); //return true if they collide
			}
			
};


[STAThread]
int main()
{	
    Application::Run(gcnew Form1());
}






I also am trying to figure out how to remove the instances from memory after a set amount of time as too many instances slows the program.

Thanks for the help.

modified on Saturday, March 19, 2011 9:48 PM

AnswerRe: Instances of an object Pin
Luc Pattyn19-Mar-11 14:49
sitebuilderLuc Pattyn19-Mar-11 14:49 
GeneralRe: Instances of an object Pin
Cyclone_S19-Mar-11 15:58
Cyclone_S19-Mar-11 15:58 
AnswerRe: Instances of an object Pin
Luc Pattyn19-Mar-11 17:20
sitebuilderLuc Pattyn19-Mar-11 17:20 
GeneralRe: Instances of an object Pin
Cyclone_S21-Mar-11 15:36
Cyclone_S21-Mar-11 15:36 
Questionhow to remove the extra border of a button after enabling xp visual style Pin
goldenrose918-Mar-11 17:38
goldenrose918-Mar-11 17:38 
AnswerRe: how to remove the extra border of a button after enabling xp visual style Pin
Hans Dietrich19-Mar-11 2:32
mentorHans Dietrich19-Mar-11 2:32 
QuestionRe: how to remove the extra border of a button after enabling xp visual style Pin
goldenrose919-Mar-11 8:02
goldenrose919-Mar-11 8:02 
QuestionAccess violation reading location 0x00378004. Pin
so0_lanhlung218-Mar-11 17:06
so0_lanhlung218-Mar-11 17:06 
QuestionRe: Access violation reading location 0x00378004. Pin
CPallini18-Mar-11 23:37
mveCPallini18-Mar-11 23:37 
AnswerRe: Access violation reading location 0x00378004. Pin
so0_lanhlung219-Mar-11 3:31
so0_lanhlung219-Mar-11 3:31 
QuestionRe: Access violation reading location 0x00378004. Pin
Code-o-mat18-Mar-11 23:59
Code-o-mat18-Mar-11 23:59 
AnswerRe: Access violation reading location 0x00378004. Pin
so0_lanhlung219-Mar-11 3:23
so0_lanhlung219-Mar-11 3:23 
GeneralRe: Access violation reading location 0x00378004. Pin
Richard MacCutchan19-Mar-11 3:59
mveRichard MacCutchan19-Mar-11 3:59 
GeneralRe: Access violation reading location 0x00378004. Pin
Code-o-mat19-Mar-11 4:01
Code-o-mat19-Mar-11 4:01 
GeneralRe: Access violation reading location 0x00378004. Pin
so0_lanhlung219-Mar-11 6:22
so0_lanhlung219-Mar-11 6:22 
QuestionRe: Access violation reading location 0x00378004. Pin
CPallini19-Mar-11 4:41
mveCPallini19-Mar-11 4:41 
QuestionMy computer is possessed Pin
Kaaib18-Mar-11 11:30
Kaaib18-Mar-11 11:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.