-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCabezaNiña.java
148 lines (139 loc) · 3.06 KB
/
CabezaNiña.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class CabezaNiña here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class CabezaNiña extends Actor
{
int speed=2;
public CabezaNiña(){
}
/**
* Act - do whatever the CabezaNiña wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
slideAround();
collectPills();
//minSpeed();
traslador();
traslador2();
traslador3();
}
/* void minSpeed()
{
if(speed>=4){
speed = 4;
}
}*/
public void moveAround(){
if(Greenfoot.isKeyDown("d"))
{
setRotation(0);
move(4);
}
if(Greenfoot.isKeyDown("a"))
{
setRotation(180);
move(4);
}
if(Greenfoot.isKeyDown("w"))
{
setRotation(270);
move(4);
}
if(Greenfoot.isKeyDown("s"))
{
setRotation(90);
move(4);
}
}
public void slideAround()
{
int x= getX();
int y= getY();
if(Greenfoot.isKeyDown("right"))
{
setLocation(x+speed, y);
if(hitWalls())
{
setLocation(x-1, y);
}
}
if(Greenfoot.isKeyDown("left"))
{
setLocation(x-speed, y);
if(hitWalls())
{
setLocation(x+1, y);
}
}
if(Greenfoot.isKeyDown("up"))
{
setLocation(x, y-speed);
if(hitWalls())
{
setLocation(x, y+1);
}
}
if(Greenfoot.isKeyDown("down"))
{
setLocation(x, y+speed);
if(hitWalls())
{
setLocation(x, y-1);
}
}
}
public boolean hitWalls()
{
if(isTouching(Wall.class))
{
return true;
}
else
{
return false;
}
}
public void collectPills()
{
if(isTouching(Pildora.class)){
//speed++;
removeTouching(Pildora.class);
Maze.score.add(10);
contador++;
}
}
int contador=0;
public void traslador()
{
if(contador==3){
if(isTouching(BasesDatos.class)){
Greenfoot.setWorld(new SalonClases());
contador=0;
}
}
}
public void traslador2()
{
if(contador==6){
if(isTouching(Algoritmos.class)){
Greenfoot.setWorld(new SalonClases2());
contador=0;
}
}
}
public void traslador3()
{
if(contador==9){
if(isTouching(POO.class)){
Greenfoot.setWorld(new SalonClases3());
contador=0;
}
}
}
}