-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCharacter.java
100 lines (95 loc) · 2.9 KB
/
Character.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Character here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Character extends Actor
{
String name;
messageBoard mb1;
int lr = 0;
int llr = 0;
int homework = 0;
int newHomework = 0;
boolean givenHW = false;
public Character(String myName){
name = myName;
setImage("images/Sans.png");
}
/**
* Act - do whatever the Character wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
//readMessage();
//MyWorld.mb1.printOut("Hello, World");
walk();
talkWith();
giveHomework();
// Add your action code here.
}
public void walk(){
llr = lr;
if(Greenfoot.isKeyDown("d") | Greenfoot.isKeyDown("right")&& getX() < 1130){
setRotation(0);
move(5);
lr = 1;
}
if(Greenfoot.isKeyDown("a") | Greenfoot.isKeyDown("left") && getX() > 70){
setRotation(0);
move(-5);
lr = 0;
}
if(Greenfoot.isKeyDown("s") | Greenfoot.isKeyDown("down") && getY() < 705){
setRotation(0);
setLocation(getX(), getY()+5);
}
if(Greenfoot.isKeyDown("w") | Greenfoot.isKeyDown("up") && getY() > 255){
setRotation(0);
setLocation(getX(), getY()-5);
}
if(lr == 0 && llr != 0){
getImage().mirrorHorizontally();
}
else if(lr ==1 && llr != 1){
getImage().mirrorHorizontally();
}
}
public void talkWith(){
if(Greenfoot.isKeyDown("h")){
newHomework = MyWorld.frnd1.giveHomework();
if(newHomework >=1){
MyWorld.mb1.printOut("Copying Homework.....finished");
}
homework = homework + newHomework;
}
}
public void readMessage(){
MyWorld.mb1.printOut("This sign cant stop me because I cant read");
}
public void giveHomework(){
if(Greenfoot.isKeyDown("g") && givenHW==false){
if(homework > 0){
homework = homework - 1;
MyWorld.mb1.printOut("level geschafft - lol");
if(homework == 0){
givenHW=true;
}
}
else{
MyWorld.mb1.printOut("Wo sind deine Hausaufgaben?");
}
}
}
public void runAway(){
System.out.println("here we'll run away");
}
public void setLocation(int x, int y){
if (getWorld().getObjectsAt(x, y, table.class).isEmpty() && getWorld().getObjectsAt(x, y, chair.class).isEmpty()){
super.setLocation(x, y);
}
}
}