Another day of Tower Defense

Published April 10, 2010
Advertisement
So yet another day of work on this school project, and it's starting to shape into an actual game finally!

I refocused my efforts a bit on trying to get the most basic parts of tower defense together first, so I put on hold the GUI work for tower upgrades and focused on more important tasks.

Today I have implemented a score system, waypoints, defendable object that must be protected and the mobs ability to attack this object when they reach it along the path.

For each mob you kill, you'll gain score, but for each tower you build or upgrade, you will spend you score. So to gain the highest possible score, you must do with as few builds and upgrades as you can afford.

The waypoint system is just a very simple node path registration system. I'll exchange this for A* later, but I thought it was better focus to get in this very simplified version of mobs moving over the grid first, so that I can really focus on getting the game to a playable level before I do the nice/cool-to-have parts!



I've found that I need to implement a FSM for how I deal with gun/attack logic. Right now I have every type of weapon set up in it's own component, which is fine, but the logic within is kind of messy. I'd clean it up a lot by using FSM instead.

Here's my railgun sourcecode.
Railgun::Railgun(Entity *entity, const EntityEngine::T_String &name): Component(entity, name), go((GameEngine::Object *)entity){	railgunFire = new Scene::General::RailgunFire(go->getGameSystem()->getSceneManager(), go);	go->add(railgunFire);	firerate_property = go->AddProperty<float>("FireRate", 0.9f);	firepower_property = go->AddProperty<float>("FirePower", 0.4f);	fireaccuracy_property = go->AddProperty<float>("FireAccuracy", 0.4f);	overheat_property = go->AddProperty<float>("OverheatTime", 5.0f);	cooldown_property = go->AddProperty<float>("CooldownTime", 1.9f);	offset_property = go->AddProperty("GunPositionOffset", siut::simd::Vec3f(0.0f,0.0f,0.0f));	slotOffsetChanged = offset_property.ValueChanged().connect(this, &Railgun::OnOffsetChanged);	damage = new GameEngine::Damage(GameEngine::DAMAGE_BULLET, 6.0f);	fireCounter = 0.0f;	overheatCounter = 0.0f;	cooldownCounter  = 0.0f;	rand.randomize();}Railgun::~Railgun(){}void Railgun::Update(double dt){	//If the gun is overheated, calculate the cooldown	if(overheatCounter > overheat_property.Get())	{		//While overheated, the gun has no target!		railgunFire->setTarget(NULL);		cooldownCounter += 0.1f;		if(cooldownCounter < cooldown_property.Get())			return;		else		{			overheatCounter = 0.0f;			cooldownCounter = 0.0f;		}	}	GameEngine::Object *target = go->getTarget(0);	railgunFire->setTarget(target);	//If there is no target, the gun should cool down a little bit	if(target == NULL)	{		overheatCounter -= 0.1f;		if(overheatCounter < 0.0f)			overheatCounter = 0.0f;		return;	}	//Make sure we don't fire more often than our firerate permits	fireCounter += 0.1f;	if(firerate_property.Get() > 1.0f)		firerate_property = 1.0f; //Clamp firerate at 1.0f, which is a constant rate fire	if(fireCounter < 1.0f - firerate_property.Get())	{		railgunFire->setTarget(NULL); //Don't draw a fire-line to target, if we're not shooting		return;	}	//For every time we fire, the gun gets a little bit hotter	overheatCounter += 0.1f;	//Calculate a damage value based on a small random modifier and the fire power of the gun	damage->setValue(((rand.rand() * 10.0f) + 4.0f) * firepower_property.Get()); // mod between 4.0 and 14.0 multiplied with firepower	if(fireaccuracy_property.Get() > 1.0f)		fireaccuracy_property = 1.0f; //Clamp fire accuracy at 1.0f, can't have more accuracy than 100%	if(rand.rand() <= fireaccuracy_property.Get())		target->executeEvent(EventEngine::Event(EventEngine::EVENT_TAKE_DAMAGE, damage, go), &go->getPlayer());	else		target->executeEvent(EventEngine::Event(EventEngine::EVENT_MISS_TARGET, damage, go), &go->getPlayer());}void Railgun::OnOffsetChanged(const siut::simd::Vec3f &oldValue, const siut::simd::Vec3f &newValue){	railgunFire->setOffsetPos(newValue);}


The beauty of it is that the properties makes it very easy to put the property settings in a data-file, or allow tweaking of them at realtime through a console or GUI element. But yeah, it's a bit messy until I get the FSM in there to clean it up.

Next on my list now is to add Win and Lose conditions, which really isn't much work seeing how I've got the damage working on the object you need to defend. After that I thought I'd set up a simple state manager for handling multiple levels. That will pull out quite a bit of code from the GameSystem manager, as right now I treat the game logic as a single level :P That will do good for the location of code and readability.

It's starting to look like a game! Yey!
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement