There is a lot of complex things that go into making an rts game; its not so much about how to program it as it is understanding exactly what you want to happen; Age of Mythology is setup basically like Age of Empires but it's also much different. There are 10 million things to consider when making an rts.
Before you read thru this nightmare of a post, keep in mind three things;
1. Rome wasn't built in a day. It takes time to learn all these things;
2. We are here to help. You can always ask more questions, and if no one can answer them, work on it for a couple weeks and ask again; we're all learning new things every day! Maybe you'll figure it out and end up telling US!
3. If this seems complex, just take a look at the ending credits for a game like AOE or AOM. Look at how many people it took to make those games!
Now, for the enemy building his own buildings: he's gonna do it basically the same way you're gonna do it.
The only things you have to decide for him are: when to build a building, that is, which order does it build them in?
Obviously a granary comes first; and then other economic buildings, then a barracks and temple; then an armory; right?
and secondly, how many ppl will he devote to building?
You do this with ActorCount;
First i would make a variable that tells the cpu what the current building needed is;
and a case switch based off that; you'll use actor count to tell the enemy which buildings he already has;
- Code: Select all
switch (buildingtype){
case 0://make granary
break;
case 1://make wood shed
break;
case 2://make gold mine
break;
case 3: //make barracks
break;
}
So the enemy has a timer like this;
- Code: Select all
if (ActorCount("granary")> 1){buildingtype+=1;}
the building type will never make it to 1 until he's got at least one granary.
Does that make sense?
You can then use ActorCount to tell him how many ppl to devote to the building;
For instance, you could tell him to devote 1/4 of his workforce to building. Just count the number of peasants and divide by four. Instructing the individual peasants can be a lot harder; you can use cloneindex to tell it which peasants to send.
I'll tell you more on that after i do some testing.
Attacking the enemy based on a right click...well once again, that won't be too much different than telling the enemy to attack you; Some variable is checked (like attackpoints) and a decision is made to attack; however you don't want too much code in the individual units;
Basically you'll use the same code for each of them; their different animations will make them look like they are doing different things; so all infantry/cavalry will be one type of unit, with one type of script;
all archers/catapults will be another type of unit, with a different type of script.
And there will be a single enemy actor, the 'brain' which does all the actorcounts, comparisons, timers that decide what the enemy should be doing. All the individual units need to do is move to enemies, and attack them.
This being said, the difficulty lies not in making a unit do something; but making him do as LITTLE as possible!
So i could tell you A way to do it but its not the best way, and all i'll be doing is starting you down the wrong path.
Since i've never made an RTS myself, I am exploring methods as i tell you these things.
But here are the basic variables a unit needs to attack;
A target and
a movement to the target;
A simple collision takes care of the attack itself.
YOu can use 'moveto' but you could also use angle/directional velocity;
- Code: Select all
angle = direction(x, y, targetx, targety);
directional velocity=whatever this unit's speed is;
you can then designate an animation change based of which direction the unit is facing;
- Code: Select all
animationnumber=angle/90;
This would give him 4 possible animations (360/90=4); animationnumber is a variable i made up; for complex animations, you'd have a case switch to tell him which animation corresponds with which animationnumber.
since his angle will always be toward the target, this takes care of animation when walking; Of course there will be an animation change when he collides with the enemy...his attack animation. And of course this is only for infantry...archers will change animation upon being with a certain DISTANCE of a target rather than colliding with them.....More on this later.
animpos designates which frame of the animation is currently being shown; in order to use it, you first have to stop the current animation;
Building>createactor>
- Code: Select all
ChangeAnimationDirection("Event Actor", STOPPED);
animpos=0;//that's the basic animation frame before workers have done anything to it;
Then create a timer for that building (lets say 5 sec, repeat);
ON timer 5 sec:
- Code: Select all
animpos=pts/250;//now for every 250pts added to the structure the animpos will increase by one
We do this on a timer to save cpu; 'draw actor' events check every frame (30-60 times per second!) which is a waste of cpu for a building that only changes animation 4 times in 30 seconds or a minute (depends on how many workers are on it).
Here is a ged file that shows the basics of the array; If you look in script>global code you will see the line of code that created the array ('choose' on the lower left hand side of the global script editor).
Now the blocks were part of another experiment, but the important thing is to drag pacman around; you will see his 'cell' number change; that shows the screen is divided into a grid and fed into the array; You can put pacman over the moving block and notice that they will then be in the same array cell!
You can look inside pacman's script to see how i told pacman to tell the array which cell he was in.
Then the simple thing to do on the map screen is to have pacman, on his creation, create a dot on the map; and the dot will translate pacman's value into the map value; It may seem complex, But it will make more sense once you feel comfortable with arrays. A side note on arrays.....every time you create anything its stored in an array. Arrays are used everyday in every single program you've ever used!