Missile Command

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Missile Command

Post by LuX » June 3rd, 2012, 8:10 am

Haha, I would still recommend to use a different formula for the rockets. It's gonna make editing stuff on em a bit more easier in my opinion. For example later to draw the rockets at the correct tilt using a calculation based on actual angles is gonna be much better.

But I'm not gonna spoil it for you...
ʕ •ᴥ•ʔ

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Missile Command

Post by Asimov » June 3rd, 2012, 12:37 pm

Hi Chilli,

My mind has been exploding trying to work this out. I even played about in photoshop trying to work it out. I worked out that the lengh of x and the hieght y would give c, which is the distance that my missile would travel.

Then after working that out I realise that you have already done this with dx and dy.

int dx = TargetX - x;
int dy = TargetY - y;

dx is the length of x and dy is the length of y.

I watched your DrawLine tutorial, but I admit I didn't understand everything.
Anyway I tried this in the end.

Velocity=5+m;
y=y-Velocity;

I must watch your tutorial again to find out what m is LOL, my mind shuts off with too much maths LOL.

Strangely enough it kinda worked to a point, on the right hand side, but not on the left hand side. I probably have to reverse things for that.

What didn't work however was on the side it was working if I took my angle down too low it would suddenly crash. Also it would get to the point where y was never reaching TargetY and I was getting stuck in an infinite loop. My mind is exploding LOL.

By the way on the same subject I have found the following code sends output to the debug window
char buf[2048];
sprintf(buf,"The value of variable num is %d \n",missilecount);
OutputDebugStringA(buf);

But unfortunately I can't see this debug window when I am running the program. In codeblocks I was able to have the console window open while debugging and I could output to there. Is this possible in Visual c++.

I know you can use breakpoints, but I find these are useless when you are checking mouse input because it gets to the breakpoint before you press the keys LOL.

@Lux: I will look at your formula later if that is ok. It probably is a better formula, but I am trying to learn. It's not that I am totally rubbish at maths, I can work out problems, but geometry gets me flummuxed LOL.

Asimov
Attachments
pythag.jpg
(113.79 KiB) Downloaded 107 times
Last edited by Asimov on June 3rd, 2012, 12:51 pm, edited 1 time in total.
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Missile Command

Post by LuX » June 3rd, 2012, 12:47 pm

mmhm...

I tried to get the debug window working as well, but couldn't so I made this little beauty here
here : -)
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Missile Command

Post by chili » June 3rd, 2012, 1:07 pm

Asimov wrote:By the way on the same subject I have found the following code sends output to the debug windowchar buf[2048];sprintf(buf,"The value of variable num is %d \n",missilecount);OutputDebugStringA(buf);
OutputDebugStringA works like a charm Asimov. Are you sure you were looking in the right window. You have to run the program in debug mode under debug configuration. Look in the very bottom right window under the 'ouput' tab. ;)

P.S. Your math above is dead wrong Asimov. :lol:
Length* Height != C
Absolutely not! :?
Chili

ghilllie
Posts: 72
Joined: May 2nd, 2012, 3:25 am

Re: Missile Command

Post by ghilllie » June 3rd, 2012, 1:16 pm

chili wrote:
Asimov wrote:By the way on the same subject I have found the following code sends output to the debug windowchar buf[2048];sprintf(buf,"The value of variable num is %d \n",missilecount);OutputDebugStringA(buf);
OutputDebugStringA works like a charm Asimov. Are you sure you were looking in the right window. You have to run the program in debug mode under debug configuration. Look in the very bottom right window under the 'ouput' tab. ;)

P.S. Your math above is dead wrong Asimov. :lol:
Length* Height != C
Absolutely not! :?
Yep because
c = sqrt(x*x + y*y) - That's a hypotenuse.
where x = the value of the x distance and y is the value of y distance from the base point
Chili++ for President :)

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Missile Command

Post by Asimov » June 3rd, 2012, 3:51 pm

Hi all,

I wish my maths wasn't so bad, but I am having a hard time of this.

I found the equation that gillie put all over the web.

|v| = Sqrt(x2 + y2)

But I am having trouble using it.

My origin is x,y and my target is TargetX,TartgetY

dy and dx work out the length of x and y, and so I tried
Velocity=sqrt ((float)dx + dy);

That didn't work, and crashed quite well.

Then I tried
Velocity=sqrt ((float)TargetX + TargetY) ;

Which didn't crash, but didn't quite do what I want.

I haven't a problem with programming, but I am useless at maths. It was my very worse subject at school, but I am trying to learn.
That is why I drew it in photoshop to visualise the problem, but I am stuck.

It's not just understanding the equation it is the ability to translate the equation into programming terms.

I am annoyed with myself that I have failed.

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

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Missile Command

Post by LuX » June 3rd, 2012, 4:43 pm

Can't.... Resist....

Just use this formula:

newX = (originalX + DistanceOfNewLocation_Aka_Velocity * cos(AngleInRadians))
newY = (originalY + DistanceOfNewLocation_Aka_Velocity * sin(AngleInRadians))

In short:
x = (x + r * cos(a));
y = (y + r * sin(a));

To get "a", the angle to shoot towards, calculate the angle between the shooting place and your mouse, I'll leave that for you to figure out.

Not saying you can't use the calculations you made at the top, but this is a lot shorter and nicer to use : -)
ʕ •ᴥ•ʔ

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Missile Command

Post by Asimov » June 3rd, 2012, 6:28 pm

Hi Lux,

Thank you for your formula, but I have no idea how to implement it.

I am however still stuck on the velocity formula so I had a break and went onto explosions.
Now these circles will hopefully be filled circles when I work out how to do it, but at the moment they are just circles which look cool getting bigger.

I presume to do a filled circle I would have to store all the circles in an array to hold the circle there as it gets bigger, but it is getting there.

PS been looking all over the forum for the code to do the clipping. Haven't found it yet LOL.

Asimov
Attachments
mcExplosions.jpg
(13.33 KiB) Downloaded 101 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

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Missile Command

Post by LuX » June 3rd, 2012, 7:01 pm

Filled circles? There's a "DrawDisc" function in d3dgraphics. Just increase the radius to make it bigger.

As for clipped pixels, It really shouldn't be that hard to do without seeing the code...
You can find it in many of the newer frameworks. Look f.ex. inside lesson 19 in download materials, and look at its pixels in d3d.
ʕ •ᴥ•ʔ

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Missile Command

Post by Asimov » June 3rd, 2012, 9:45 pm

Hi Lux,

Thanks for that suggestion. Well I got my missiles to explode ok. For some reason my code for waiting for the mouse to be released before firing isn't working, amongst other problems. So I have had successes and failures, I just hope I can get through them.

I think for this version I need to fix the size of the window to stop it getting larger, because if it is made larger I would have to use higher resolution graphics, so for now it is best to fix it.

I think next I will make a smaller missile, because it is too big for the screen, and offset it so that it is in the centre, but here is my work so far.

Will have to watch the rest of the font tutorial so that I can make the score. On the other hand I could just scan the numbers 0 to 9 into the lux program.

Asimov
Attachments
Whitelight.jpg
Whitelight.jpg (7.13 KiB) Viewed 3793 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

Post Reply