Two Stupid Things

  • With a few minor changes, like, not being able to shoot. and a few other bits, each building in my game is modeled class wise exactly after the original Tower building. Based on the MinimalTD example.

    The towers in my game can be attacked and hit by the enemy so they need to be destroyed. When it is destroyed, some things happen, an emitter goes off, and it is removed from it's group.

    R.PS.towerGroup.remove(this, true);

    In the other building, called Gate, it does this too.

    R.PS.gateGroup.remove(this, true);

    When a tower is hit, it gets and casts a tower.

    private function hitTower(enemy:Enemy, thing:Tower):Void
    	var hitTower:Tower = cast(thing);		

    Some other things are done. And when it has no health, it is blown up like so.

    if ( <= 0) 
    		//Each group ALSO needs to be removed from baseGroup.

    Notice how the class removal and the state removal is different. Now if I lose that tower, if I want to build another in the same place, easy, I am allowed to do so. Now let's copy this EXACT system for another building.

    First, the class object is the "same" as the tower only it has a different picture, health, and can't shoot. It can still get destroyed. So we do the same thing.

    R.PS.gateGroup.remove(this, true);

    Now let's give it it's own get hit function and cast it properly.

    private function hitGate(enemy:Enemy, thing:Gate):Void
    	var hitGate:Gate = cast(thing);		

    And destroy it properly.

    if ( <= 0) 
    		//Each group ALSO needs to be removed from basegroup.

    Now. When I lose a gate, I SHOULD be able to place one where that other one was exactly right? Nope. Nor am I allowed to put anything else there either.

    What the heck is going on here?!

  • Why do you cast tower? They're the same type. And you should rename the parameter instead:

    private function hitTower(enemy:Enemy, hitTower:Tower):Void

    Same with Gates.

    Also when health reaches 0 or below, kill() will be called automatically so you should override kill().

  • Well, I'm using cast because that's how I saw it done in an older version somewhere. But I'm overriding kill which is where I'm putting the:

    R.PS.towerGroup.remove(this, true);  //Same for gate

    I don't want to post the whole thing but:

    The first function works like this:

    If I build a tower, and that tower is destroyed by enemies, remove the tower. Now because it's a tower, I can place a second tower in the same spot of the tower that I lost.

    The second function is for an experimental class called GateB. If I build a gateB, and that gateB is destroyed by enemies, it should be removed. The code is the same as the one for the tower. However, I can't build a new gateB in the same spot I lost a gateB.


    What would you do here to achieve the same thing?

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.