-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrowPaddle.java
More file actions
29 lines (26 loc) · 1.05 KB
/
Copy pathGrowPaddle.java
File metadata and controls
29 lines (26 loc) · 1.05 KB
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* This class represents the GrowPaddle power-up.
* It makes the opponent's paddle grow in size when applied.
*
@authors (Rupert & Raymond Van Niekerk)
* @student Numbers (222894237 & 221154469)
* @version (1)
*/
public class GrowPaddle extends PowerUp {
public void applyEffect(Ball ball, PingPongWorld world) {
// Apply the effect of growing the opponent's paddle
Paddle opponent;
if (ball.getHorizontalSpeed() > 0) {
opponent = world.getPaddle1();
} else {
opponent = world.getPaddle2();
}
int originalHeight = opponent.getImage().getHeight();
opponent.getImage().scale(opponent.getImage().getWidth(), originalHeight * 2);
// Add a timed effect to revert the paddle back to original size after 6 seconds
world.addObject(new TimedEffect(6000, () -> {}, () -> {
opponent.getImage().scale(opponent.getImage().getWidth(), originalHeight);
}), 0, 0);
}
}