Help with Tower Defense game

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
codinitup
Posts: 112
Joined: June 27th, 2012, 7:43 am

Help with Tower Defense game

Post by codinitup » July 17th, 2012, 4:06 am

Hey Chili and others, I've been having some trouble with the mouse input. For example:

Code: Select all

if (mouse.IsInWindow() && mouse.LeftIsPressed()
{
      DrawGunnerTurret(mouse.GetMouseX(),mouse.GetMouseY());
}
But it doesn't place it down, it just draws it and moves it. I know the reason is because it is only being draw when the mouse is pressed and it isn't draw when the mouse isn't pressed. I tried something similar to when Chili checked to see if a key was pressed in Lesson 12 (Tic Tac Toe), but it didn't work. Does anybody have any ideas?
MOOOOOO

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

Re: Help with Tower Defense game

Post by chili » July 17th, 2012, 4:37 am

You need to create a variable (or an array of variables) that remembers where you clicked, and then you can draw your turret(s) based on that (array of) variable(s).
Chili

User avatar
codinitup
Posts: 112
Joined: June 27th, 2012, 7:43 am

Re: Help with Tower Defense game

Post by codinitup » July 17th, 2012, 5:08 am

So like this:

Code: Select all

DrawGunnerTurret(gx,gy);
gx = mouse.GetMouseX();
gy = mouse.GetMouseY();
MOOOOOO

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

Re: Help with Tower Defense game

Post by chili » July 17th, 2012, 5:31 am

No... more like you should draw the gunner turret in your compose frame every frame if it has been set, and you should set the gunner turret only if the mouse button is pressed.
Chili

User avatar
codinitup
Posts: 112
Joined: June 27th, 2012, 7:43 am

Re: Help with Tower Defense game

Post by codinitup » July 17th, 2012, 7:26 am

Chili, once again you were right!

P.S. Because your such a great tutor, and make great tutorials, I'm currently sharing your video's and website on my website :)
MOOOOOO

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

Re: Help with Tower Defense game

Post by chili » July 17th, 2012, 8:02 am

Good luck with your game bro. ;)
Chili

Post Reply