Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / RTS Unit Attack Help

Author
Message
AdunToridas
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location: Cyberspace
Posted: 21st Jan 2011 23:33
I am trying to make a basic system for making buildings for my RTS. I want it so that whenever you select a worker, you can select a option where the worker can build things like buildings and defence towers. I can't figure out how to do that though. Can someone direct me to a tutorial or give me some source code or something?

my life for aiur
Kiaurutis
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location: Lithuania
Posted: 22nd Jan 2011 16:07
i don't know if that helps, but i have been making RTS on C++ using DarkGDK library, so commands should be similar to DBPro (dbGetTerrainGroundHeight(C++ dark gdk library)= get terrain ground height (inDBPro)) and maybe u find some useful functions.
In code snippet there is full code (which used to work on C++ 2008 express edition, but now i have 2010 so it doesn't work anymore, drop some errors)
(sorry if code is not in code snippet, i try to make this for first time and there are no tutorials for making posts)



I used sprites for buttons:
1)loaded some sprites as buttons and maked "ActiveButton" variable which can contain number of button i have.
2)if mouse pointer is on the sprite(sprite x,y is 1 coordinate and (x+-width of sprite), (y+-height of sprite) is another), i change sprite picture so button looks like pressed
3)if mouse is clicked, i check if pointer is in fields where are buttons or whether there is 3d graphics: maked variables where are button fields boundaries (egzample: if (mouse y is less than 200 pixels)then run function which checks over which button (sprite)mouse is):


as i remember this function used to show 1 of few buttons pushed- was kind a building mode to show menu of chosable objects to make eg. if pushed 1st button u can chose to build vehicles, if another- ships and etc.

4) now u can insert your functions to place buildings, use special attacks on enemies, repair friendly units or whatever program should do when buttons are pushed

i added .exe file to download and see what this code can do including textures and objects

and sorry if it is not clear enough what code do- when programed it, didnt knew someone else will read it so didn't add too much of comments and some words are in lithuanian language...

PS there is a good tutorial to make menus and buttons http://forum.thegamecreators.com/?m=forum_view&t=106004&b=10&p=0

Attachments

Login to view attachments
kamac
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location: Poland
Posted: 22nd Jan 2011 16:21
First of: is this a 3d or 2d game? And even with that, i suppose we can do nothing about helping you, while we have no idea about how your code looks. It may have many different vars, etc.

Cheers!

~Kamac
Kiaurutis
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location: Lithuania
Posted: 23rd Jan 2011 14:40
It is no difference for 2D or 3D. In 2D all the program is made from sprites, in 3D u insert sprites to be visible in front of your 3D objects. Made function to show sprites appear as buttons, and make some actions, if mouse clicked in specific location of screen, will work in any case. U just need to load different images and check different coordinates.
Good luck on your project, if don't understand smth in my code don't be shy and ask
I am building some RTS game myself atm, but i am just making a start in DBPro, so am stuck in selecting objects and getting coordinates of map point clicked. Found some good code sources for selecting objects OR getting coordinates of point in map, but have problems to do both at a time.
Agent
20
Years of Service
User Offline
Joined: 7th Sep 2004
Location: Sydney, Australia
Posted: 25th Jan 2011 02:46
Hey guys.

I have completed two different RTS games in DBPro in the past. I'm happy to help with specific questions if you have some.

I assume you can detect when the player has clicked on a worker. Use a flag called BuildMenuVisible or something similar. When you click on a worker, set the flag. When you click on somethinng else, clear the flag.

When you draw your hud (radar screen, money count, etc), if the flag is set, you should also draw the menu for selecting a structure to build. This will make the build menu appear when a worker is selected, and disappear when something else is selected.

Now, whenever the mouse is clicked, check to see if the flag is set. If it is, check the mouse coordinates to see if we've clicked on one of the build menu options. If we have, set another variable like BuildingSelected to represent which structure has been selected.

Back to your HUD code again, and if BuildingSelected contains a value, then draw a ghost image at the mouse, of the building that's been selected.

And back to your mouseclick code again: when the mouse is clicked, in addition to checking if BuildMenuVisible is set to check if we've clicked on a building icon, we will also check to see if BuildingSelected has a value. If it does, we've just placed the building identified by BuildingSelected, at the coordinates of the mouse.

This is a pretty basic overview, but that's how I do my worker/construction logic in my RTS games.

Login to post a reply

Server time is: 2024-11-24 07:43:49
Your offset time is: 2024-11-24 07:43:49