Missile Command
Missile Command
Hi all,
Well I have started a little project called Missile Command. It is a very old game I used to play on the Amiga.
Basically at the moment I got the mouse to move my crosshair, and when the fire button is pressed a line is drawn from the firing position to the crosshair. The line at the moment represents the angle at which the missile will fire, and when I get the missile code to work I will remove the line. Also I got the crosshair to disappear when I move the mouse out of the window. It will crash if you start to fire out of the window at the moment, but I will worry about that later.
I do have a feature request though. Because I have made my own crosshair, I would like the mouse arrow to disappear while in the game window. Is this possible?
I am starting to make a missile class. The class will hold the location of the missile, and control the movement of the missile. I am sure that once I have deigned the missile I can use some of the code from the Drawline function to work out the trajectory it should fire towards the target.
I am using a class rather than a struct as I want the class to do more than just hold a location.
Also I can run many instances of the same class for more missiles.
Anyway I have attached the code for you to play with, and I will now be working on firing the missile next.
Asimov
Well I have started a little project called Missile Command. It is a very old game I used to play on the Amiga.
Basically at the moment I got the mouse to move my crosshair, and when the fire button is pressed a line is drawn from the firing position to the crosshair. The line at the moment represents the angle at which the missile will fire, and when I get the missile code to work I will remove the line. Also I got the crosshair to disappear when I move the mouse out of the window. It will crash if you start to fire out of the window at the moment, but I will worry about that later.
I do have a feature request though. Because I have made my own crosshair, I would like the mouse arrow to disappear while in the game window. Is this possible?
I am starting to make a missile class. The class will hold the location of the missile, and control the movement of the missile. I am sure that once I have deigned the missile I can use some of the code from the Drawline function to work out the trajectory it should fire towards the target.
I am using a class rather than a struct as I want the class to do more than just hold a location.
Also I can run many instances of the same class for more missiles.
Anyway I have attached the code for you to play with, and I will now be working on firing the missile next.
Asimov
- Attachments
-
- Missile Command.zip
- (1.09 MiB) Downloaded 520 times
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
Re: Missile Command
To get the mouse disappear, add "ShowCursor(false);" at windows.cpp after the form creation code.
If you need help with the rockets I can share some code I made for my missile launcher in my own project. But its fairly easy so I doubt you are going to have much problems with it...
If you need help with the rockets I can share some code I made for my missile launcher in my own project. But its fairly easy so I doubt you are going to have much problems with it...
ʕ •ᴥ•ʔ
Re: Missile Command
Hi Lux,
Hey your code works and now I can kill my cursor woohoo.
As for the missile I am stuck on something, but not going to tell you until I have totally run out of ideas LOL. I don't like admitting defeat until I have tried for a few days LOL.
I think I learn more by trying than being handed the answers.
Asimov
Hey your code works and now I can kill my cursor woohoo.
As for the missile I am stuck on something, but not going to tell you until I have totally run out of ideas LOL. I don't like admitting defeat until I have tried for a few days LOL.
I think I learn more by trying than being handed the answers.
Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
Re: Missile Command
for more info about builtin functions visit msdn.microsoft.com
Chili++ for President
Re: Missile Command
Hi all,
Well I am stuck. Seeing as I am making a missile class I want all the functions of the missile to be in that class. I even want to draw the missile in that class.
The problem is scope. If I am in the main Game class I can just do Game::My function, but I can't do that in my missile class. Basically gfx cannot be seen in my class.
I will paste my missile header file and my cpp file. I not going to show all the lines of the cpp because it isn't necessary so I will truncate it.
I believe this is a newby error LOL.
PS I also tried #include "Game.h" in my header at one point too, but that didn't work.
Missile.h
Missile.cpp (truncated)
Asimov
Well I am stuck. Seeing as I am making a missile class I want all the functions of the missile to be in that class. I even want to draw the missile in that class.
The problem is scope. If I am in the main Game class I can just do Game::My function, but I can't do that in my missile class. Basically gfx cannot be seen in my class.
I will paste my missile header file and my cpp file. I not going to show all the lines of the cpp because it isn't necessary so I will truncate it.
I believe this is a newby error LOL.
PS I also tried #include "Game.h" in my header at one point too, but that didn't work.
Missile.h
Code: Select all
#pragma once
class Missile
{
public:
Missile();
int Missile::MissileX();
int Missile::MissileY();
void Missile::DrawMissile();
private:
int x;
int y;
};
Code: Select all
#include "Missile.h"
Missile::Missile()
:x(400 ),
y( 580 )
{
}
int Missile::MissileX()
{
return x;
}
int Missile::MissileY()
{
return y;
}
void Missile::DrawMissile()
{
gfx.PutPixel(0 + x, 0 + y, 29, 5, 1);
gfx.PutPixel(1 + x, 0 + y, 31, 6, 2);
gfx.PutPixel(2 + x, 0 + y, 36, 8, 4);
gfx.PutPixel(3 + x, 0 + y, 39, 8, 3);
gfx.PutPixel(4 + x, 0 + y, 46, 9, 3);
gfx.PutPixel(5 + x, 0 + y, 53, 10, 3);
gfx.PutPixel(6 + x, 0 + y, 60, 11, 4);
gfx.PutPixel(7 + x, 0 + y, 69, 12, 3);
gfx.PutPixel(8 + x, 0 + y, 77, 13, 3);
<snip>
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
Re: Missile Command
I'm not sure how its done, but you have to declare D3DGraphics class as gfx before you can use it.
ʕ •ᴥ•ʔ
Re: Missile Command
Easiest way would be to pass the gfx object as a parameter to the Draw() function. It should be passed by address (i.e. by pointer or reference). I cover pointers in lesson 16 or 17 I think.
Chili
Re: Missile Command
Hi Chilli,
I have re-edited this post as I come to that conclusion also.
Just gotta work out how to pass the gfx object. I watched the pointer tutorial.
I tried this
void Missile::DrawMissile(void Missile::DrawMissile(D3DGraphics* gfx));
and I don't think it is right somehow, cos I got the red squigglies LOL.
Asimov
I have re-edited this post as I come to that conclusion also.
Just gotta work out how to pass the gfx object. I watched the pointer tutorial.
I tried this
void Missile::DrawMissile(void Missile::DrawMissile(D3DGraphics* gfx));
and I don't think it is right somehow, cos I got the red squigglies LOL.
Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
Re: Missile Command
First of all, it should be:
void Missile::DrawMissile(D3DGraphics* gfx)
{
<function body>
}
Why on Earth would you want to do this:
void Missile::DrawMissile(void Missile::DrawMissile(D3DGraphics* gfx));
Also, did you remember to include "d3dgraphics.h"?
void Missile::DrawMissile(D3DGraphics* gfx)
{
<function body>
}
Why on Earth would you want to do this:
void Missile::DrawMissile(void Missile::DrawMissile(D3DGraphics* gfx));
Also, did you remember to include "d3dgraphics.h"?
Chili
Re: Missile Command
Hi Chilli,
Yes the void inside the void was a bit silly, but that was down to badly pasting rather than badly programming LOL. Had a hard day at work, and can hardly keep my eyes open, but I have been trying to make this work heh heh.
Ok I will paste my header and cpp file. I still have the red squigglies.
I tried putting &gfx as well.
I think the problem is that I did watch the pointer tutorial, but that dealt with integers. If you asked me to pass an integer as a pointer I wouldn't have a problem, but I am a bit fuzzy on doing this.
Also I am guessing I would call my function like this
Missile.DrawMissile(D3DGraphics.h* gfx);
missile.cpp
Asimov
Yes the void inside the void was a bit silly, but that was down to badly pasting rather than badly programming LOL. Had a hard day at work, and can hardly keep my eyes open, but I have been trying to make this work heh heh.
Ok I will paste my header and cpp file. I still have the red squigglies.
I tried putting &gfx as well.
I think the problem is that I did watch the pointer tutorial, but that dealt with integers. If you asked me to pass an integer as a pointer I wouldn't have a problem, but I am a bit fuzzy on doing this.
Also I am guessing I would call my function like this
Missile.DrawMissile(D3DGraphics.h* gfx);
Code: Select all
#pragma once
#include "D3DGraphics.h"
class Missile
{
public:
Missile();
int Missile::MissileX();
int Missile::MissileY();
void Missile::DrawMissile(D3DGraphics* gfx);
private:
int x;
int y;
};
Code: Select all
#include "Missile.h"
Missile::Missile()
:x(400 ),
y( 580 )
{
}
int Missile::MissileX()
{
return x;
}
int Missile::MissileY()
{
return y;
}
void Missile::DrawMissile(D3DGraphics* gfx)
{
gfx.PutPixel(0 + x, 0 + y, 29, 5, 1);
gfx.PutPixel(1 + x, 0 + y, 31, 6, 2);
gfx.PutPixel(2 + x, 0 + y, 36, 8, 4);
gfx.PutPixel(3 + x, 0 + y, 39, 8, 3);
gfx.PutPixel(4 + x, 0 + y, 46, 9, 3);
gfx.PutPixel(5 + x, 0 + y, 53, 10, 3);
<snip>
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk