-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatBox.java
More file actions
98 lines (86 loc) · 2.37 KB
/
ChatBox.java
File metadata and controls
98 lines (86 loc) · 2.37 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
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import java.awt.Font;
/**
* the chat box, or more commonly, the warning box that shows up <br>
* when you do something illegal in the game
*
* @author James Lu
* @version 0.01
*/
public class ChatBox extends Actor
{
private Map map;
private GreenfootImage bg;
private Font font;
private Color color;
private Color warningColor;
private Color startColor;
private String message;
private int trans;
private boolean show;
public ChatBox(){
map = (Map) getWorld();
bg = new GreenfootImage (1000, 75);
font = new Font ("Verdana", 1, 35);
warningColor = new Color (255, 50, 0);
startColor = new Color (0 , 0 , 0);
color = warningColor;
message = "";
trans = 500;
show = false;
refresh();
}
protected void addedToWorld (World world){
if (map == null){
map = (Map) world;
map.removeObject (this);
}
}
public void act(){
if (map.getObjects (ChatBox.class) != null){
if (show){
if (bg.getTransparency() > 0){
trans -= 5;
}
else{
show = false;
trans = 0;
map.removeObject (this);
}
if (trans <= 255){
bg.setTransparency (trans);
refresh();}
}
//bg.fill();
//this.setImage (bg);
}
}
/**
* sets the message to whatever passes to it
* id is which type of message is passed through
* 1 is warning, red
* 2 is wave starting, in black
*/
public void setMessage(String m, int id){
map.addObject (this, 512, 500);
if (id == 1){
color = warningColor;
} else if(id == 2){
color = startColor;
}
message = m;
trans = 500;
show = true;
bg.setTransparency (255);
refresh();
}
private void refresh(){
bg.clear();
bg.setFont (font);
bg.setColor (color);
int tempX = 500 - message.length() * 10;
bg.drawString (message, tempX, 50);
this.setImage (bg);
}
}