-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackground.java
executable file
·155 lines (125 loc) · 4.37 KB
/
Background.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Background here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Background extends World
{
/**
* Constructor for objects of class Background.
*
*/
public static long startTime = System.currentTimeMillis();
public static long endTime = System.currentTimeMillis();
public static int millsPassed = 0;
public static double timeDelta = 0.0;
public Platform platform[] = new Platform[6];
int platformNum = -1;
//Default to practice
public int setting = 0;
public Background()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(640, 480, 1,false);
setPaintOrder(PlayerActor.class,LeftWingActor.class,RightWingActor.class,InfoLayer.class,Platform.class);
setActOrder(PlayerActor.class,LeftWingActor.class,RightWingActor.class);
prepare();
setting = 0;
PlayerActor.setting = setting;
}
public Background(boolean doPrepare)
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(640, 480, 1,false);
if(doPrepare)
{
setPaintOrder(PlayerActor.class,LeftWingActor.class,RightWingActor.class,InfoLayer.class,Platform.class);
prepare();
}
setActOrder(PlayerActor.class,LeftWingActor.class,RightWingActor.class);
setting = 0;
PlayerActor.setting = setting;
}
public Background(int setting)
{
this();
this.setting = setting;
PlayerActor.setting = setting;
System.out.println("Difficulty Setting set to " + setting);
}
public void activateNewPlatform()
{
int newNum = platformNum;
while(newNum == platformNum)
{
newNum = Greenfoot.getRandomNumber(6);
}
platformNum = newNum;
platform[platformNum].activate();
}
/**
* Prepare the world for the start of the program. That is: create the initial
* objects and add them to the world.
*/
private void prepare()
{
/*
PlayerActor playeractor = new PlayerActor();
addObject(playeractor, 277, 220);
RightWingActor rightwingactor = new RightWingActor();
addObject(rightwingactor, 289, 223);
LeftWingActor leftwingactor = new LeftWingActor();
addObject(leftwingactor, 271, 219);
leftwingactor.setLocation(272, 215);
rightwingactor.setLocation(282, 215);
*/
platform[0] = new Platform();
addObject(platform[0], 140, 269);
platform[1] = new Platform();
addObject(platform[1], 467, 238);
platform[2] = new Platform();
addObject(platform[2], 336, 379);
platform[3] = new Platform();
addObject(platform[3], 156, 405);
platform[4] = new Platform();
addObject(platform[4], 521, 354);
platform[5] = new Platform();
addObject(platform[5], 289, 205);
platformNum = Greenfoot.getRandomNumber(5);
platform[platformNum].activate();
Cloud cloud = new Cloud();
addObject(cloud, 125, 101);
Cloud cloud2 = new Cloud();
addObject(cloud2, 521, 194);
Cloud cloud3 = new Cloud();
addObject(cloud3, 205, 275);
PlayerActor playeractor = new PlayerActor();
addObject(playeractor, 295, 185);
Ground ground = new Ground();
addObject(ground, 320, 489);
startTime = System.currentTimeMillis();
endTime = System.currentTimeMillis();
InfoLayer infolayer = new InfoLayer();
addObject(infolayer, 320, 240);
}
public void act()
{
//pull this into the player class
startTime = endTime;
endTime = System.currentTimeMillis();
millsPassed = (int)(endTime - startTime);
timeDelta = (double)millsPassed/1000.0;
}
public void started()
{
System.out.println("Started");
startTime = System.currentTimeMillis();
endTime = System.currentTimeMillis();
}
public void stopped()
{
System.out.println("Stopped");
}
}