Stop Spawners and actors?

Games4lifeGames4life Member, PRO Posts: 279

Is there a way to stop the spawner from spawning and the actors to stop moving when one of the actors collide with another actor? Also is there a way so that once an animation is completed that it changes the scene? Any help is appreciated!

(G4L)

Comments

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @Games4life, the answer is yes to all of your questions, but as there are countless ways that you could have implemented your game logic, there are similarly countless possible answers to your question.

    Generally speaking, if you need to implement things like stopping and starting movement and spawning, it is good practice to work with game states.

    Make a game level attribute GameState and define different values for different states, e.g.:

    1 = setup
    2 = running
    3 = paused
    4 = game over

    You can now wrap your code section in rules which trigger according to the GameState.

    At the beginning of the game, start with GameState=1

    Then have rules like so to control individual behaviors

    Rule: if GameState=1
             Set lives to full
             Set score to 0
             Set GameState to 2
    End rule
    
    Rule:if  GameState=2 (enemies will only spawn if GameState is 2)
             Spawn enemies
    End Rule
    
    Rule: if GameState=2
             Allow movement of hero
             Rule: If hero collides, set GameState to 3
    End Rule
    
    Rule: if GameState=3
             Stop hero movement 
             (this totally depends on how your movement is controlled, 
             by MOVE, Accelerate, by gravity, by setting the velocity. 
             More info needed)
    End Rule 
    

    This gives you a lot of control over your code.

    .
    Change scene at end of animation

    If you use the animate behavior, then you will probably have a sequence of images inside it, lets assume they are called ANIM001, ANIM002, ..., ANIM009.

    Don't have "Loop" or "Restore actor image" on.

    You can now have a rule:

    Rule: If self.image = "ANIM009" then
             Change scene 
    End Rule
    
Sign In or Register to comment.