200 likes | 217 Views
Master Java basics using NetBeans IDE combined with XML for practical game development. Courses and tutorials provided. Dive into API, game behaviors, and dungeon exploration with this hands-on guide.
E N D
CS3523 Pacticals Guide
Tools you need • Java • IDE (preferably NetBeans) • XML (a tiny bit) • We may use some other software too.
Java • Knowledge of the Java programming language is essential for this course. • If you don’t have such knowledge then you had better be prepared to acquire it rapidly, on your own. • Tutorials http://docs.oracle.com/javase/tutorial/ • Documentation http://docs.oracle.com/javase/6/docs/
IDE • Use of an IDE like NetBeans or Eclipse is strongly recommended for manipulating the many files used for particular programs. • I favour NetBeans • http://netbeans.org/
The Dungeon • Practicals use a “dungeon” game of a typical kind to help you learn how to dostuff. • Game is played on a PC • One human player • NPCs are mostly hostile monsters • Player explores dungeon, finds treasure, fights monsters.
The Key • Hero is the green circle. • Other creatures are the red circles. • Strength/health potions in blue and green bottles • Gold (in various quantities), keys (associated with particular doors). • Tiles: rooms, doors, flame traps, pits, non-game space (black), Finish (green). • Doors: open (white), closed (grey) • [Run demo.]
The Dungeon World • World model • Tiles: Floor, Door, Flametrap, Pit, Finish • dungeon.model.structure • Treasure: Gold, Potion, Key • dungeon.model.items.treasure • Mobs: Orc, Ogre, Hero • dungeon.model.items.mobs
Dungeon • The dungeon program can get info about tiles, treasure, mob via methods of the gameobject. • Can load/save game to XML file from GUI (or from API)
Dungeon XML file <Game Name="simple"> - <Map> <Tiles> <Vector> <Floor Height="50" Width="50" X="0.0" Y="0.0" /> <Floor Height="10" Width="10" X="-20" Y="0.0" /> </Vector> </Tiles> </Map> - <Creatures> <Vector> - <Orc CurrentEnergy="10" CurrentHealth="10" Gold="20" X="25" Y="25" Behaviour="dungeon.ai.DefaultBehaviour"> - <Attacks> - <Vector> <Smash /> </Vector> </Attacks> - <Inventory> <Vector /> </Inventory> </Orc> </Vector> </Creatures> - <Treasure>- <Vector> <Gold Worth="10" X="23" Y="17" /> <Gold Worth="20" X="5" Y="37" /> <Gold Worth="30" X="42" Y="11" /> <Gold Worth="40" X="45" Y="29" /> <Potion Type="0" X="3" Y="5" /> </Vector></Treasure> </Game>
Creatures (NPC) • Have parameters • Location, Size, Strength, Health, … • Goal: location NPC is moving towards • Behaviour: class which defines how NPC acts (ie, the AI behind NPC)
Behaviour class • Implements Behaviour interface • Specifies there must be onTick method • Called every tick of game clock • Updates NPC’s position, status, goals, etc according to AI logic • DefaultBehaviour class
3 steps to Defining new behaviour • Create new class that implements Behaviour • Can copy-and-edit DefaultBehaviour • Specify behaviour • Example: delete goal stuff in DefaultBehaviour • Change XML file to specify new behaviour used by NPC. • Start dungeon, load XML file, run
API • You must familiarise yourself with this as soon as possible. • [Walk through API]. • Go and read the Dungeon XML Primer (on the course Information page). • Play with the game (on the Info page). • Come to the practical on Thursday.
How it works 1: Main • Application enters at main in App class in dungeon.App. • Initial random dungeon fGame built by DungeonBuilder.createDungeon. • Window created as object fMainForm of classDungeonForm. • Event-handling for user interaction and game state updates: fTimerTick and fKeyDispatcher.
How it works 2: Game State • Game state (world) held in an object fgame of Game class. • New initial game state can be loaded from XML from here (implements Persistent class). • XML file gives the data for the initial game state.
How it works 3: Updating • fGame has a method tick() that advances the game by one round. Each round has the following stages: • Each map tile is informed about the new round. • Each treasure item informed about new round. • For each creature in turn, and then for the hero: • The tile they stand upon is informed of this fact. • The creature is prompted to act. • Dead creatures are removed from the game.
How it works 4 • Action listener fTimerTick hears ticks from fGame.tick and updates game via fMainForm.updateGame(). • fMainForm.updateGame() refreshes the User Interface (UI) after the game tick. • fKeyDispatcher in App intercepts presses by user on arrow-keys, so that hero can be moved. This changes game state via fGame.getHero().getMovement() .
How it works 5: Mobs & Behaviour • A mob is a mobile item (orc, creature, hero) which implements the class Mob. • Each mob has various fields which set its properties (strength, energy, treasure list, goals, …, and fBehaviour). • The class Behaviour and its various implementations are used to define the (intelligent) behaviours of mobs.
The brain, not the engine • We are focussed on the AI aspects here. • You won’t have to mess-around with most of the game engine. • You will mostly need to modify Behaviour classes, and a few others.