This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

Super_Hippo
Super_Hippo presents ...

2017/3/9

Age of Empires Demo

A game like Age of Empires.

Things which work:
- Menu. If no color was picked (=white), a random one will be used
- Town Center and Barracks. Going to the next age does not require to build any buildings (mostly because there aren't enough yet)
- Cutting trees. (Other resources (except animals) are also implemented, but not randomly created yet)
- Map size based on number of players. Town Center placed randomly across the world. A forest near to each Town Center
- You start with a town center and three villagers. Click (left mouse button) on a villager to select it. Then you can click (right mouse button) to move the unit. Left clicking on the shown buildings on the bottom let the unit build that building if enough resources are available (which is likely the case because you pretty much have infinite). Choose the position of the building and click the left mouse button to confirm.
- When selecting a building (clicking on it), you can build units and research things (read the tooltips for help) depending on the building. (Only the town center and barracks are functional yet.)

Things which do not work / should not happen:
- Units moving over each other (could fix that by handling them the same as building, but see next point)
- Finding the shortest route works, but is far too slow. Each building has four actors around them (a bit off of the corners). Then some sort of Djikstra algorithm is used to calculate the shortest route. This works to move around buildings without problems, but with the forest, the calculation takes ages... If anyone has a better idea, please let me know. Without this being fixed, there is no real reason to continue working on this project.
- The other three buildings do not have any effect yet. Mostly because I did not create the images and write the tooltips yet and the possible population is not calculated anywhere either (so you can build as many units as you want without having houses). The population part wouldn't be that hard to fix though.
- No AI yet. (There is no reason to write complicated AI code if moving for one single unit isn't working without lag...) You can not attack anyone either. The menu selection of the difficulty and the teams obviously do not have any effect because of that
- Random placement of created units is somewhat broken
- Probably more things I am not aware of or that I forgot to mention


It was still fun to code it even though the pathfinding is really screwing that up...
Have fun!

2362 views / 704 in the last 7 days

Tags: mouse game demo strategy scrolling

Your browser does not support the canvas tag.
Nosson1459Nosson1459

2017/3/9

I can scroll up but not down - annoying. All I know how to do in this scenario is scrolling with the mouse and pressing on Town Centers and villagers. What else is there to do and how do I do it? You talk about shortest routes around obstacles but you don't say how to make anything move or what to make move. You also mentioned that the map is bigger for more teams but all I see in the map is the Town Center no other teams to make bigger maps.
Nosson1459Nosson1459

2017/3/9

I figured out how to scroll down. For all the other scrolling the edge of the map is the edge of the screen but for scrolling down I have to go to the bottom of the frame which is way off the map. There's lag for scrolling too (I said "too" but I don't know how to direct people to walk).
Super_HippoSuper_Hippo

2017/3/9

It is wanted that for scrolling down, you have to put the mouse to the very bottom so the mouse can click on the buttons on the bottom part which appear if you select something. To select something, simply click (left mouse button) on it (for example a villager). Then a click with the right mouse button chooses the target for the villager (a tree, a building which is not finished yet or simply a free space to move (for every kind of unit). Clicking on a building results in having the unit move into the building (bug)). After selecting a villager, you can also choose a building to build. You can also select more than one unit by drawing a rectangle around them (press and drag the mouse). I will add it to the description how to select and move. Thank you for pointing that out.
Super_HippoSuper_Hippo

2017/3/9

Added two points to the "Things which work" section. Hope this helps!
Nosson1459Nosson1459

2017/3/10

Now I see what you mean by lag but I still like the fact that you found a way (path). Why don't you increase the simulation speed and then put a delay on everything else if you have to OR put the path finding code in a javax.swing.Timer by doing: <code>private javax.swing.Timer timer = new javax.swing.Timer(0, new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { timerActionPerformed(e); } });</code> Then create a timerActionPerformed method: <code>private void timerActionPerformed(java.awt.event.ActionEvent e) { // path finding code }</code> And then you use timer.start() or timer.stop() to start or pause the timer execution. I'm not saying that you don't know how to do this but danpost was wondering where I got this code from so I'm just posting it in case you have any questions on how to do it. If you're wondering WHAT this does is that it basically calls the actionPerformed method automatically every certain amount of time. This amount of time is specified in milliseconds as the first parameter in the Timer constructor (so here it's 0 so it will be executing quite often).
Super_HippoSuper_Hippo

2017/3/10

Increasing the simulation speed won't change anything about the lag. The calculation of one act cycle is always at maximal speed. When it is not at speed = 100, it has a defined delay between the beginnings of the act cycles though. So if I increase the speed, the operations can't be executed faster. I am in fact not understanding what this code is doing. What I am doing is that whenever a new target for a unit is chosen (like moving a unit or unit automatically walks back to nearest town center / storage pit after collecting 10 wood from a tree), it calculates the route once. Then it will walk this route without calculating (unless the route gets blocked by a new building). If it would help, I could post the code used for the route calculation in a new discussion. If I get this right, I can't use this Timer class because the code is not executed once in a while but always when a unit gets a new target.
Nosson1459Nosson1459

2017/3/10

"If I get this right, I can't use this Timer class because the code is not executed once in a while but always when a unit gets a new target." That's not the reason because you can start and stop the timer execution at will. The reason it will or won't help is because it doesn't have anything to do with act cycles (so if all your code is in one act cycle it probably won't help to move it to your own artificial act cycle which is at speed 100%).
Super_HippoSuper_Hippo

2017/3/10

I think the problem is that the calculated route is not something which can be pre-calculated because the target is unknown before it was chosen and the unit should instantly move after the target was chosen. And since this doesn't even work with one unit, what would happen if there are a lot more trying to move around? I guess either Java is not efficient, my code is not optimal or my computer is too slow.

Want to leave a comment? You must first log in.

Who likes this?

No votes yet.