GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Gather Gather
Jasper Geurtz edited this page
In this tutorial we will learn to draw information to the screen and to give orders to ingame units. In the Setup we already saw how to draw public void onFrame() { game.drawTextScreen(100, 100, "Hello World!"); } This is, as the name suggests, executed every frame. The public void onStart() { game = bwClient.getGame(); } Which gives you access to all information available to you in the game. To test this out let's change the code in onFrame to print out your name and current minerals. public void onFrame() { Player self = game.self(); game.drawTextScreen(20, 20, self.getName() + " has " + self.minerals() + " minerals"); }
The first thing you do in StarCraft is ofcourse gathering more minerals. Let's order our workers to gather the mineral patch closest to them! When a unit completes (even at the start of the game!), they trigger an public void onUnitComplete(Unit unit) { if (unit.getType().isWorker()) { Unit closestMineral = null; int closestDistance = Integer.MAX_VALUE; for (Unit mineral : game.getMinerals()) { int distance = unit.getDistance(mineral); if (distance < closestDistance) { closestMineral = mineral; closestDistance = distance; } } // Gather the closest mineral unit.gather(closestMineral); } }
Ofcourse this is not an optimal spread of workers over the available minerals patches, even randomly assigning would probably be better, but that is left as an exercise to the reader ;) In the next tutorial we will Train some workers, to improve the gather production! Clone this wiki locally |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |