Tutorial
Following are some random code snippets that are meant to illustrate how to make use of the API.
Global
The only thing more global than getting a game going is to have a loader to load your images from a specified path. Upon creating the game you pass it a function to restart it. At the time of writing (v0.2) die Game engine is not able to restart itself, so the passed function gets called.
#instantiate the pyglet image loader
loader = Loader( path = "../../pyTower/art")
# make a new game with no restart function and the loader
game = Game.pyTowerGame(None, loader)
Game
Adjustment on the Game engine can either be done in the constructor of the Game or in your script before you set the game running.
#give your game an ID to mark it
game.ID = 2
#set the exits of your maze
game.add_exit((19,10), (0,10))
game.add_exit((10,0), (10,19))
#here you can build a predefined maze
game.maze.update_adjacents() #let the maze nodes find their neighbors
game.maze.dijkstra_flood() #let the routing initialize
# this is how you register a build type
# register_build_type( Type, Name, instantiation_func, sprite)
game.register_build_type(Brick, "Brick",
lambda game: Brick(game, loader.image("wall.png")), Brick(game, loader.image("wall.png")))
# this is how you state that "dtdPellet" can be built on top of a "Brick"
game.register_build_compatibility(Brick, dtdPellet)
# fire it of
game.go()
Wave
The dtd_creep_stats Class is a template class holding values and methods needed to equip Waves of Creeps with sensable attributes. In the base version it makes creeps that are more or less aligned on the creep waves of Desktop Tower Defense.
# make 60 waves from a predefined attribute container you can adjust or specialize. The only method you call externally is the make_wave method. The other methods help building the shape of the waves. Please look at the docstrings for information on them.
stats = dtd_creep_stats(game)
for i in range(1,61):
game.add_wave(stats.make_wave(i))
Brick
Currently there are 3 Brick classes. In general, a Brick is a Tower that is so simple it doesn't do anything. Each Brick can be used just like a Tower, except it won't do anything. We have the "normal" Brick, an unsellableBrick and an invisibleUnsellableBrick. The names are pretty self explanatory. The invisibleUnsellableBrick is the choice to make when you want to model a predifined road. Just use the Game functions to pave anything except your path with this Brick type and nothing will block the view of your background image. If you combine this with build incompatibilities you can limit the build spaces for the player as well.
# the creation of the path from the fetd example
# first the entrance and exit
game.add_exit((13,19), (8,19))
# brick is a function, that when called with no argument returnes a new brick
brickClass = invisibleUnsellableBrick
brick = lambda: brickClass(game, None)
game.make_maze_background("green_ground.png")
# Start the path with the entrance and the exit
exceptions = [(13,19),(8,19)]
# add all the rest
exceptions.extend([(8,18),(8,17),(8,16),(8,15),(7,15),(6,15),(5,15),(4,15),
(3,15),(2,15),(1,15),(1,14),(1,13),(1,12),(1,11),(1,10),(2,10),(3,10),(4,10),
(5,10),(6,10),(7,10),(8,10),(9,10),(10,10),(10,11),(10,12),(10,13),(11,13),
(12,13),(13,13),(14,13),(14,12),(14,11),(14,10),(14,9),(14,8),(14,7),(14,6),
(13,6),(12,6),(11,6),(10,6),(10,7),(10,8),(9,8),(8,8),(7,8),(6,8),(5,8),
(4,8),(3,8),(2,8),(1,8),(1,7),(1,6),(1,5),(1,4),(1,3),(1,2),(1,1),(2,1),
(3,1),(4,1),(5,1),(6,1),(7,1),(8,1),(9,1),(10,1),(11,1),(12,1),(13,1),(14,1),
(15,1),(16,1),(17,1),(18,1),(18,2),(18,3),(18,4),(18,5),(18,6),(18,7),(18,8),
(18,9),(18,10),(18,11),(18,12),(18,13),(18,14),(18,15),(18,16),(17,16),(16,16),
(15,16),(14,16),(13,16),(13,17),(13,18)])
# pave anything except our path with the brick
game.pave_rect_except(((0,0),(19,19)), exceptions, brick)
Bullet
Normally, the Bullets are handled by the Towers so you won't need to worry about them. However, some behavior has been assigned to the bullet, so we have different types:
- SeekingBullet: A SeekingBullet has two builtin extras. It accellerates towards its target and if its target dies it retargets within a definable range
- SlowingBullet: A Bullet that will slow its target upon hit
- SplashBullet: A Bullet that will not only damage its target, but all targets within a certain range for a percentage dependant on their distance
- AirBullet: An AirBullet features a flying animation and is directed. As default it is a rocket with smoke comming from its rear end.
- Normal Creep. The most basic one
- Headed Creep. A creep that has a head and is always walking where its nose points.
- Immune Creep. A creep that will ignore slowing and the like.
- Fyling Creep. A creep that will _not_ ask for direction, but just move the shortest way to the exit.
- Animation Creep. A creep that supports an animation like behavior. It can be given triples of image, duration and next. The creep will show image for duration of time and then switch to next. With a circular reference, we have an animation. An excerpt from the fetd flying creep:
creep.define_rendering(So the creep flaps its wings for 0.2 seconds with a 1 second glide in between.
{
# show the open wing image for a second, switch to image 1
0: [rabbyt.Sprite(game.loader.image("fetd_fly_open.png")),1,1],
# show the closed wing image for 0.2 seconds and swtich back to 0
1: [rabbyt.Sprite(game.loader.image("fetd_fly_close.png")),0.2,0]
}
)
- MultipleImageTower: This tower has an image for each upgrade level. The images are input as one and the tower then slices the input to an array of #max_level slots.
- SingleImageTower: This tower has one main image that does not change with upgrades. there are however additional images that are attached to the rendering on each level up.
- AirTower: A Tower that targets only flying creeps
- BashTower: A Tower that doesn't shot bullets but damages an area around him.
- BoostTower: A Tower that doesn't do damage at all but enhances the attributes of its surrounding towers.
- MultiplBulletTower: A Tower that does not target a single Creep, but is capable of shooting multiple bullets at once
- PoisonTower: A Tower that shoots Bullets which inflict damage over time
- SeekingTower: A Tower that shoots seeking, retargeting rockets
- SlowTower: A Tower that will slow the target
- SplashTower: A Tower which bullets will hit all creeps within a range of the target.
Creep
Creeps have builtin pathfinding (they ask the maze node where to go next) and handle almost all creep activity (slowing, unslowing, leaking, dieing) internally. All creeps of the dtd and fetd examples (with the exception of the darkcreep) are just renamed derivates of these standard types. The following types are available per default:
gameclock
The clock has only two methods that are of interest: pause and unpause. Their meaning is pretty self explanatory and they don't take any arguments.
maze
The maze is the heart of the board. It is devided into a matrix. Each cell is occupied by a node. the maze knows the widht and height of a cell and is thus able to give information about window coordinates as well. The maze has methods for giving the node for a window position and vice versa. The maze is also the starting point for triggering the routing updates. Apart from that the maze holds some accumulative helper functions for the contained nodes.
node
One node occupies one cell in the matrix that represents the game board. Every node holds a list of his adjacent nodes. He can be blocking or non-blocking. Blocking is not a boolean but an integer, as one node can be blocked by multiple things. Each node contains a routing table with an entry for each exit on the maze. the value of the entry is the adjacent node and the cost till the exit. the cost is the count of nodes that have to be visited before the exit is reached. A node also holds a list of all creeps currently walking towards it, so that if he becomes blocking, all creeps can be told to go back to where they came from to obtain a different target.
Tower
The basic Tower class takes care of all basic behavior like rotating, shooting, targeting, reloading, upgrading, boosting, selling, processing kills and leaks and (de)activation. The specializations overwrite or extend these behaviors as needed. The following specialized Towers are available:
04.11.2008. 23:47
Comments
xGY6VT lvpygskamnay, [url=http://zazrungjyydp.com/]zazrungjyydp[/url], [link=http://lgfgtonvburl.com/]lgfgtonvburl[/link], http://psaedfwswnhb.com/
hKI927 ruqoifiqqksp, [url=http://lxnvksjawnqa.com/]lxnvksjawnqa[/url], [link=http://qqgiecfvlwdp.com/]qqgiecfvlwdp[/link], http://kxnvvccurbgn.com/
MQdaqw dolqsolvucpz, [url=http://scasdlnmttcc.com/]scasdlnmttcc[/url], [link=http://hcjeweghhbkk.com/]hcjeweghhbkk[/link], http://gobvuqvcmeao.com/
BSPvLx chdwgthelmji, [url=http://sfslpknprcvw.com/]sfslpknprcvw[/url], [link=http://fcsgvpsttzya.com/]fcsgvpsttzya[/link], http://qqeuqcubzmmx.com/
TsDXOy cbwdhozawnbt, [url=http://rwelnzpxlbhm.com/]rwelnzpxlbhm[/url], [link=http://hkhjwynpaagx.com/]hkhjwynpaagx[/link], http://bukahzgwcjlz.com/
TEStWf ibzjfcvqpzbm, [url=http://ohbpsmzejmtr.com/]ohbpsmzejmtr[/url], [link=http://ujcewgntgorr.com/]ujcewgntgorr[/link], http://gvupmyhqhcav.com/
Amazing blog post, this is very similar to a site that I have.
Please check it out sometime and feel free to leave me a comenet on it and tell me what you think. Im always looking for feedback.
This is a superb post {%H1%}.
But I was wondering how do I suscribe to the RSS feed?
Outstanding site, where did you come up with the info in this piece of writing? Im glad I found it though, ill be checking back soon to see what other articles you have.
I stumbled onto your blog and read a few post. I like your style of writing.
KDhxxW dfkzichrfrfh, [url=http://cqelfabcrqib.com/]cqelfabcrqib[/url], [link=http://zckhylcuzefb.com/]zckhylcuzefb[/link], http://gciwqffdwnwf.com/
HIe9S1 kxtuufpwcjfw, [url=http://wxpkkxngdwih.com/]wxpkkxngdwih[/url], [link=http://nigxsilmnqyv.com/]nigxsilmnqyv[/link], http://izstcwrngpwh.com/
3Gt6a2 yuftsfloqtfs, [url=http://ccpzmgpuyqlc.com/]ccpzmgpuyqlc[/url], [link=http://okvcwkwwwzcx.com/]okvcwkwwwzcx[/link], http://cwnciywzhhcq.com/
SeeKTK asojcakjkyzm, [url=http://nmolhewhbbvv.com/]nmolhewhbbvv[/url], [link=http://rclolerjmkan.com/]rclolerjmkan[/link], http://kspenhlxqfet.com/

Write a comment
* = required field