-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntroWorld.java
More file actions
55 lines (48 loc) · 1.77 KB
/
IntroWorld.java
File metadata and controls
55 lines (48 loc) · 1.77 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
import greenfoot.*;
/**
* Write a description of class IntroWorld here.
*
* @author Patrik Valentiny (PM), Jakov Klaric, Abdulkader Alomar, Ignas Klimas
* @version 1.2
*/
public class IntroWorld extends World
{
private static final int WORLD_WIDTH = 500;
private static final int WORLD_HEIGHT = 700;
private int timer = 0;
private GreenfootImage background = getBackground();
private boolean up = true;
/**
* Constructor for objects of class IntroWorld.
*/
public IntroWorld()
{
super(WORLD_WIDTH, WORLD_HEIGHT, 1);
Greenfoot.start();
}
public void act()
{
background.clear();
String key = Greenfoot.getKey();
if (key != null && key.equals("enter"))
{
Greenfoot.setWorld(new PingWorld(true));
}
if (timer == 255){
up = false;
} else if (timer == 0){
up = true;
}
if (up){
timer++;
} else{
timer--;
}
background.setColor(new Color(255 - timer, 255 - timer, 255 - timer));
background.fill();
background.drawImage(new GreenfootImage("PONG", 80, new Color(timer, timer, timer), null), 150, 200);
background.drawImage(new GreenfootImage("Play for the lives of wombats", 20, new Color(timer, timer, timer), null), 140, 300);
background.drawImage(new GreenfootImage("Hit <enter> to start game", 30, new Color(timer, timer, timer), null), 120, WORLD_HEIGHT / 2);
background.drawImage(new GreenfootImage("Controls: \n- LEFT and RIGHT arrow keys control the paddle`s direction\n- UP and DOWN arrow keys control the paddle`s speed", 15, new Color(timer, timer, timer), null), 80, WORLD_HEIGHT / 2 + 100);
}
}