-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCharacter.java
More file actions
95 lines (90 loc) · 2.76 KB
/
Character.java
File metadata and controls
95 lines (90 loc) · 2.76 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
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;
int newHomework = 0;
public Character(String myName){
name = myName;
setImage("images/Sans.png");
homework = 0;
}
/**
* 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();//diese beiden werden auf einen knopfdruck mehrfach ausgeführt
// 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")){
MyWorld.mb1.printOut("Copying Homework.....finished");
if(homework == 0){
newHomework = MyWorld.frnd1.giveHomework();
homework = homework + newHomework;
}
else if(homework == 1){
MyWorld.mb1.printOut("Du kannst nicht mehr machen als verlangt");
}
}
}
public void readMessage(){
MyWorld.mb1.printOut("This sign cant stop me because I cant read");
}
public void giveHomework(){
if(Greenfoot.isKeyDown("q")){
if(homework > 0){
homework = homework - 1;
MyWorld.mb1.printOut("level geschafft - lol");
}
else{
MyWorld.mb1.printOut("Wo sind deine Hausaufgaben?");
}
}
}
public void runAway(){
System.out.println("here we'll run away");
}
}