-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevel2.java#backup
More file actions
89 lines (85 loc) · 2.49 KB
/
Level2.java#backup
File metadata and controls
89 lines (85 loc) · 2.49 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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
* Write a description of class Level2 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Level2 extends World
{
/**
* Constructor for objects of class Level2.
*
*/
private int xOffset = 0;
private final static int SWIDTH = 1600;
private final static int SHEIGHT = 700;
private final static int WWIDTH = 9500;
private GreenfootImage bimg;
public Level2()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(SWIDTH, SHEIGHT, 1, false);
bimg = new GreenfootImage("2level_high.png");
shiftWorld(0);
prepare();
}
public void shiftWorld(int dx)
{
if ((xOffset + dx) <= 0 && (xOffset + dx) >= SWIDTH - WWIDTH)
{
xOffset = xOffset + dx;
shiftWorldBackground(dx);
shiftWorldActors(dx);
}
}
private void shiftWorldBackground(int dx)
{
GreenfootImage bkgd = new GreenfootImage(SWIDTH, SHEIGHT);
bkgd.drawImage(bimg, xOffset, 0);
setBackground(bkgd);
}
private void shiftWorldActors(int dx)
{
List<ScrollingActor> saList;
saList = getObjects(ScrollingActor.class);
for( ScrollingActor a : saList)
{
a.setAbsoluteLocation(dx);
}
}
Mobby mobby = IntroScreen.mobby;
PowerBar powerBar = new PowerBar();
HealthBar healthBar = new HealthBar();
private void prepare()
{
addObject(mobby, 525, getHeight() / 2);
addObject(powerBar, getWidth() / 2, 200);
addObject(healthBar, getWidth() / 2, 100);
}
boolean canReturn = false;
public double power;
public void act()
{
meatballPower();
healthBar.setLocation(mobby.getX(), mobby.getY() - 175);
powerBar.setLocation(mobby.getX(), mobby.getY() - 150);
if (xOffset < 0) canReturn = true;
if (xOffset >= 0 && canReturn) {
Level1 level1 = IntroScreen.level1;
Greenfoot.setWorld(level1);
}
}
public static boolean resetPower;
public void meatballPower()
{
if (Greenfoot.isKeyDown("f")) {
power++;
resetPower = false;
}
else {
if (resetPower) power = 0;
}
}
}