Repository navigation
Expand file tree
/
Copy pathScuba.java
More file actions
174 lines (140 loc) · 4.95 KB
/
Copy pathScuba.java
File metadata and controls
174 lines (140 loc) · 4.95 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Scuba here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Scuba extends Scubas
{
private GreenfootImage [] imagens;
private GreenfootImage [] imagensInvertidas;
private int indice;
private int score = 0;
/**
* Act - do whatever the Scuba wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
anima();
move();
turnAtCena();
rasto();
removeAlgas();
removeCopo();
removeGarrafa();
removeLata();
removeOleo();
removePneu();
removeRede();
removeSaco();
removeTronco();
}
private GreenfootImage imageScuba;
public Scuba()
{
imagens = new GreenfootImage [5];
imagensInvertidas = new GreenfootImage[5];
imagens[0] = new GreenfootImage("scuba1.png");
imagens[1] = new GreenfootImage("scuba2.png");
imagens[2] = new GreenfootImage("scuba3.png");
imagens[3] = new GreenfootImage("scuba4.png");
imagens[4] = new GreenfootImage("scuba5.png");
imagensInvertidas[0] = new GreenfootImage("scuba1inv.png");
imagensInvertidas[1] = new GreenfootImage("scuba2inv.png");
imagensInvertidas[2] = new GreenfootImage("scuba3inv.png");
imagensInvertidas[3] = new GreenfootImage("scuba4inv.png");
imagensInvertidas[4] = new GreenfootImage("scuba5inv.png");
// imagens[0].scale(imagens[0].getWidth() - 100, imagens[0].getHeight() - 100);
// imagens[1].scale(imagens[1].getWidth() - 100, imagens[1].getHeight() - 100);
// imagens[2].scale(imagens[2].getWidth() - 100, imagens[2].getHeight() - 100);
// imagens[3].scale(imagens[3].getWidth() - 100, imagens[3].getHeight() - 100);
// imagens[4].scale(imagens[4].getWidth() - 100, imagens[4].getHeight() - 100);
setImage(imagens[0]);
imageScuba=getImage();
// int larguraActual=imageScuba.getWidth();
// int alturaActual=imageScuba.getHeight();
// imageScuba.scale(larguraActual/4,alturaActual/4);
}
private int tempo = 0;
private int i = 0;
private boolean esq = true;
private boolean dir;
public void anima(){
tempo++;
if(Greenfoot.isKeyDown("a")){
esq = true;
dir = false;
}
if(Greenfoot.isKeyDown("d")){
dir = true;
esq = false;
}
if(esq == true){
if(tempo % 10 == 0){
setImage(imagens[i]);
i++;
}
if(tempo >= 100 || i >= imagens.length){
i = 0;
tempo = 0;
}
for(int j = 0; j < imagens.length; j++)
imagens[j] = new GreenfootImage("scuba" + (j+1) + ".png");
}
if(dir == true){
if(tempo % 10 == 0){
setImage(imagens[i]);
i++;
}
if(tempo >= 100 || i >= imagens.length){
i = 0;
tempo = 0;
}
for(int j = 0; j < imagens.length; j++)
imagens[j] = new GreenfootImage("scuba" + (j+1) + "inv.png");
}
}
public void removeAlgas(){//remove as algas quando toca e perde pontos e vida do jogador em causa
if(isTouching(Algas.class)){
getWorldOfType(novo.class).somaPontos(-50);
getWorldOfType(novo.class).somaVidasUm(-1);
removeTouching(Algas.class);
}
}
public boolean not(boolean touching){//verifica se ha contacto
if(touching == true)
return false;
else
return true;
}
public void move(){//deslocação, excepto quando esta a tocar nos obstaculos
int y = getY();
int x = getX();
if(Greenfoot.isKeyDown("w"))y-=5;
if(Greenfoot.isKeyDown("s"))y+=5;
if(Greenfoot.isKeyDown("d") && not(isTouching(Cena.class))){x+=5;}
if(Greenfoot.isKeyDown("a") && not(isTouching(Cena.class))){x-=5;}
setLocation(x,y);
}
public void turnAtCena()//faz a inclinação ao chegar aos obstaculos
{
if (isTouching(Cena.class)){
setRotation(45);
}
else
setRotation(0);
}
private int sX,sY;
private final int DELTA=5;
private GreenfootImage imagem1, imagem2;
private int contador;
public void rasto(){//faz o rasto das bolhas
contador++;
if(contador==3){
getWorld().addObject(new Bolhas(),getX(),getY());
contador=0;
}
}
}