-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialognick.java
41 lines (38 loc) · 1.76 KB
/
dialognick.java
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
public class dialognick extends Actor
{
static GreenfootImage dialog0 = new GreenfootImage("images/dialog-nick0.png");
static GreenfootImage dialog1 = new GreenfootImage("images/dialog-nick1.png");
static GreenfootImage dialog2 = new GreenfootImage("images/dialog-nick2.png");
static GreenfootImage dialog3 = new GreenfootImage("images/dialog-nick3.png");
static GreenfootImage dialog4 = new GreenfootImage("images/dialog-nick4.png");
static GreenfootImage dialog5 = new GreenfootImage("images/dialog-nick5.png");
private static boolean shouldclose=false;
// list of all dialog images above
public static List<GreenfootImage> imgs = List.of(dialog0, dialog1, dialog2, dialog3, dialog4, dialog5);
// singleton instance of dialog
private static final dialognick dialog = new dialognick();
// set transparent
public dialognick() {getImage().setTransparency(0);}
// function for other objects to access singleton
public static dialognick get() {return dialog;}
public static int getimg() { return imgs.indexOf(dialog.getImage()); }
public static void setimg(int i) { dialog.setImage(imgs.get(i)); }
// make opaque and switch image
public static void show(int num) {
dialog.setImage(imgs.get(num));
dialog.getImage().setTransparency(255);
shouldclose = num==1;
}
public void act() {
// hide dialog on enter key
if (Greenfoot.isKeyDown("enter") && shouldclose) {
getImage().setTransparency(0);
sleepFor(5);
} else if (Greenfoot.isKeyDown("enter") && !shouldclose) {
show(getimg()+1);
sleepFor(5);
}
}
}