JumpDecider.emam 934 Bytes
Newer Older
Bernhard Rumpe's avatar
BR-sy    
Bernhard Rumpe committed
1
/* (c) https://github.com/MontiCore/monticore */
Jean-Marc Ronck's avatar
Jean-Marc Ronck committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package de.rwth.supermario.haller.actuator;

component JumpDecider {
    ports
        in Z jumpAdvice,
        in Z marioResting,

        out Z marioJump;

    implementation Math{
        //Once Mario lands, he needs to stop "jumping" for once, since the
        //simulator only jumps once if the jump key is pressed.
        static Z marioAlreadyRestedOnce = 0;
        
        if(marioResting == 0) //We are in the air
            if(jumpAdvice==1) //Update the "we already rested"-flag
                marioAlreadyRestedOnce = 0;
            else
                marioAlreadyRestedOnce = 1;
            end
            marioJump = jumpAdvice;
        else
            if(marioAlreadyRestedOnce == 1)
                marioJump = jumpAdvice;
            else
                marioAlreadyRestedOnce = 1;
                marioJump = 0;
            end
        end
        
    }
Bernhard Rumpe's avatar
BR-sy    
Bernhard Rumpe committed
33
}