This site requires JavaScript, please enable it in your browser!
Greenfoot back
ppali
ppali wrote ...

2024/4/30

mario mode

ppali ppali

2024/4/30

#
I want when touching a superstar (RaakSuperStar) that my walk and jump animations switch to some mario animations. However when i code this it only happens for when actually touching the star and not the full 15 seconds that the "super modues" should last. (im doing this for school). also onsterfelijktimer is the time "Joker" is immune to damage. Help is appreciated
1
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import greenfoot.*;
public class Joker extends Actor {
    public int snelheid = 5;
    private int vSpeed = 0;
    private int acceleration = 1;
    private int state = 1;
    int sprinten = 1;
    int tellerAnimatie = 10;
    private Healthbar healthBar;
    private SimpleTimer onsterfelijkTimer = new SimpleTimer();
    private GreenfootSound sterSound = new GreenfootSound("Super Mario Bros - Star.mp3");
    private int raakCooldown = 0;
    private final int RAAK_COOLDOWN_TIJD = 80;
    public Joker(Healthbar healthBar) {
        this.healthBar = healthBar;
    }
     
    public void act() {
        checkKeys();
        fall();
        StatusJoker();
        raakCooldown();
        raakThwomp();
        raakSuperStar();    
    }
     
    private void StatusJoker() {
        if (state == 2 && onsterfelijkTimer.millisElapsed() > 15000) {
            state = 1;
            // Zet een timer voor 15 seconden wanneer joker een SuperStar aanraakt
            // Als Joker geen ster aanraakt wordt hij in zijn standaard stand gezet (state 1) zodat hij wel damage kan pakken
        }
    }
     
    private void raakCooldown() {
        if (raakCooldown > 0) {
        raakCooldown--;
        }
    }
     
    public void raakSuperStar() {
        if (isTouching(SuperStar.class)) {
        state = 2;
        onsterfelijkTimer.mark(); // als joker een ster aanraakt speelt er een soundeffect af en wordt de timer van 15 seconden aangeroepen
        sterSound.play();
        }
    }  
 
 
    public void raakThwomp() {
    if (state == 1 && raakCooldown == 0 && (isTouching(Thwomp.class) || isTouching(SuperThwomp.class))) {
        int damage = 4;
        if (isTouching(SuperThwomp.class)) {
            damage = 7;
        }
        if (isTouching(Terence.class)) {
            damage = 25;
        }
        if (healthBar != null) {
            healthBar.loseHealth(damage);
            raakCooldown = RAAK_COOLDOWN_TIJD;
             
            Greenfoot.playSound("Joker Persona 5 Royal Sound Effects HD.mp3");
             
            Actor thwomp = getOneIntersectingObject(Thwomp.class);
            Actor superThwomp = getOneIntersectingObject(SuperThwomp.class);
            Actor Terence = getOneIntersectingObject(Terence.class);
            if (thwomp != null) {
                getWorld().removeObject(thwomp);
            }
            if (superThwomp != null) {
                getWorld().removeObject(superThwomp);
            }
            if (Terence != null) {
                getWorld().removeObject(Terence);
            }
        }
    }
    }
 
    public void checkKeys() {
        // Deze methode checkt welke toetsen worden ingedrukt en welke actie dan moet gebeuren
        if (Greenfoot.isKeyDown("d")) {
        /**
        * Zorgt ervoor dat Joker naar rechts kan bewegen wanneer D wordt ingedrukt en een animatie speelt.
        */
             if (sprinten<=10)
        {
            if(tellerAnimatie == 10) {       
        setImage("jokerright" + sprinten + ".png");
        sprinten++;
        tellerAnimatie = 1;
         
        }
         
        }  
        else
        {
            sprinten=1;
        }
        tellerAnimatie++;
            setLocation(getX() + snelheid, getY());
        }
         
        if (Greenfoot.isKeyDown("a")) {
        /**
         * Zorgt ervoor dat Joker naar Links kan bewegen wanneer A wordt ingedrukt en een animatie speelt.
         */
             if (sprinten<=10)
        {
            if(tellerAnimatie == 10) {       
        setImage("jokerleft" + sprinten + ".png");
        sprinten++;
        tellerAnimatie = 1;
        }
         
        }  
        else
        {
            sprinten=1;
        }
        tellerAnimatie++;
            setLocation(getX() - snelheid, getY());
        }
          
        if (Greenfoot.isKeyDown("w")&& (onGrond() == true))
        /**
         * roept methode aan dat Joker kan springen wanneer hij op de grond staat
         */
        {
            jump();
        }
    }
         
    public void jump() {
    /**
    * methode om joker te laten springen dmv Vertical Speed en als joker op de world Hell of Japan is kan hij minder hoog springen
    * Ook wordt ervoor gezorgd wnr hij jumped er een png wordt laten zien
    */
    if (getWorld().getClass() == Hell.class || getWorld().getClass() == Japan.class) {
        vSpeed = -20;
    } else {
        vSpeed = -25;
    }
    fall();
    setImage("jokerjump6.png");
    }  
 
    public boolean onGrond()
    /**
    * Zorgt ervoor dat Joker niet door de Grond valt
    */
    {
        Actor under = getOneObjectAtOffset ( 0, getImage().getHeight() /2, Grond.class);
          return under != null;
    }
     
    public void fall()
    /**
    * Wanneer joker springt zorgt deze code ervoor dat hij naar beneden valt  
    */
    {
          vSpeed = vSpeed + acceleration;
          setLocation(getX(), getY() + vSpeed);
    }
}
You need to login to post a reply.