-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaddle2.java
More file actions
57 lines (53 loc) · 1.48 KB
/
Paddle2.java
File metadata and controls
57 lines (53 loc) · 1.48 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
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Paddle2 here.
*
* @author Abdulkader Alomar
* @version 1
*/
public class Paddle2 extends Actor
{
private int width;
private int height;
private int dx;
public Paddle2(int width, int height)
{
this.width = width;
this.height = height;
dx = 1;
createImage();
// Paddle constructer *//
}
public void act()
{
respawn();
setLocation(getX() + dx, getY());
}
private void respawn()
{
//Check to see if we are touching the outer boundaries of the world:
// IF we are touching the right boundary OR we are touching the left boundary:
if(isAtEdge())
{
int rnd = Greenfoot.getRandomNumber(2);
int y = Greenfoot.getRandomNumber(280)+55;
if(rnd == 0){
setLocation(10,y);
dx = 1;
} else if(rnd == 1) {
setLocation(getWorld().getWidth() - 10, y);
dx = -1;
}
width = Greenfoot.getRandomNumber(41)+40;
height = Greenfoot.getRandomNumber(11)+10;
createImage();
}
}
private void createImage()
{ // creating the image for the paddle //
GreenfootImage image1 = new GreenfootImage(width, height);
image1.setColor(Color.WHITE);
image1.fill();
setImage(image1);
}
}