-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSunCounter.java
80 lines (70 loc) · 2.55 KB
/
SunCounter.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
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class SunCounter here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class SunCounter extends Actor
{
public static final int x = 120;
public static final int y = 50;
public int sun = 50;
public static final int textY = 45;
public long currentFrame = System.nanoTime();
public long lastFrame = System.nanoTime();
public long deltaTime;
/**
* Act - do whatever the SunCounter wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
MyWorld MyWorld;
public void act()
{
currentFrame = System.nanoTime();
deltaTime = (currentFrame - lastFrame) / 1000000;
if (deltaTime >= 10000L) {
MyWorld.addObject(new FallingSun(), Random.Int(SeedBank.x1, SeedBank.x2), 0);
lastFrame = System.nanoTime();
}
// Add your action code here.
}
public void addedToWorld(World world) {
MyWorld = (MyWorld)getWorld();
currentFrame = System.nanoTime();
lastFrame = System.nanoTime();
updateText();
}
public void updateText() {
String number = ""+sun;
char[] text = number.toCharArray();
getImage().clear();
setImage("suncounter.png");
for (int i = 0; i < text.length; i++) {
if (text.length > 5) {
sun = 99999;
System.out.println("hacker");
} else if (text.length > 4) {
getImage().drawImage(new GreenfootImage("text"+text[i]+".png"), 20+i*12,textY);
} else if (text.length > 3) {
getImage().drawImage(new GreenfootImage("text"+text[i]+".png"), 26+i*12,textY);
}else if (text.length > 2) {
getImage().drawImage(new GreenfootImage("text"+text[i]+".png"), 33+i*12,textY);
}else if (text.length > 1) {
getImage().drawImage(new GreenfootImage("text"+text[i]+".png"), 38+i*12,textY);
}else if (text.length == 1) {
getImage().drawImage(new GreenfootImage("text"+text[i]+".png"), 44,textY);
} else {
//Nothing
}
}
}
public void addSun(int sun) {
this.sun += sun;
updateText();
}
public void removeSun(int sun) {
this.sun -= sun;
updateText();
}
}