Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by stahlmanDesign

What is the best way to make ladders? I have done it before in Objective-C but it was kind of convoluted and probably not the best way. I had a lot of variables like isOnLadder, isClimbing, isJumpingOffLadder (so he CAN jump off and doesn't immediately stick to it again on the next update() because isClimbing is true)

Is it best to use global states or moods instead, like isSwimming, isClimbing, isFlying, and then limit possible movements based on the state/mood?

What is the best way to have an entity walk by a ladder and not stick to it unless you press up, but not fall off of it by pressing to the side, yet still be able to jump off?

1 decade ago by Hareesun

I'd always go the most detailed option, it may be kinda code messy, but if there's a loader then it doesnt matter.

Rather than having the ladder as an entity, you could assign a collision tile to allow you climb.

Write out as many possible scenarios for the ladder as sentences and then scale it back into a bunch of IF statements. Works for me. :)

Also, this plugin may help - http://impactjs.com/forums/code/symbols-plugin

1 decade ago by MikeL

I'm more partial to the state machine sort of approach. So if I have an entity that may have multiple different behaviors, then I keep track of the current behavior with state, and have a separate update function for each state. Sounds like a lot of work, but it keeps things way more organized and easy to change. Here is an example from my updated YOSS game.

update: function(){
    switch(this.state){
      case ig.Entity.PATH_ON:
        this.pathUpdate();
        break;
      case ig.Entity.GRID_TRACKING:
        this.gridTrackingUpdate();
        break;
      case ig.Entity.GRID_SNAP:
        this.gridSnapUpdate();
        break;
      case ig.Entity.GRID_GROUP:
        this.gridGroupUpdate();
        break;
      case ig.Entity.FLIGHT_PATTERN:
        this.flightPatternUpdate();
        break;
      default:
        break;
  }
  //Put code common to any behavior here.
}

This is the update for the entities that swirl around when they enter the screen, then attach themselves to the main group, and then periodically swoop down to cause havoc. Each situation is handled very differently, therefore the separate updates. Because you have different updates, then you can alter the way each update handles input. Changes in state are handled within each individual update accordingly. Then, if the state is changed, it will show up in the next general update.

I will add that if you decide to create the ladder as an entity then the .check( other ) function is super useful for seeing if two entities are overlapping. For instance, the ladder entities can do a check and if other is the player, then it could cause the player to change state to OVER_LADDER or some such thing. Then the player entity will go to it's special "sub-update" during the next general update.

1 decade ago by stahlmanDesign

Very helpful response. I've been wanted to implement your symbols plugin http://impactjs.com/forums/code/symbols-plugin

but I hadn't thought about separate update methods.
Page 1 of 1
« first « previous next › last »