-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAllObjects.java
More file actions
executable file
·74 lines (64 loc) · 2.2 KB
/
Copy pathAllObjects.java
File metadata and controls
executable file
·74 lines (64 loc) · 2.2 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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class AllObjects here.
*
* @author (João Paulo S. Abreu (joaoabreu@ufba.br), Mateus C. Moura
* (mateuschaves@ufba.br), Rafael P. Casaes Sampaio
* (rafael.casaes@ufba.br),
* Uanderson S. Celestino (uandersoncelestino@ufba.br), Lílian T. de
* Sousa (lilian.sousa@ufba.br), Jefferson Aimon de B. Silva
* (jefferson.raimon@ufba.br))
* @version (a version number or a date)
*/
//classe com os metodos que serão herdadas por outras classes
public class AllObjects extends Actor {
int horScale;
int vertScale;
int velDown = 1;
private int up = 7;
/**
* Act - do whatever the AllObjects wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
@Override
public void act() {
// Add your action code here.
}
//metodo para dimensionar imagens
public void scaleImage(int x, int y) {
horScale = x;
vertScale = y;
getImage().scale(getImage().getWidth() / horScale, getImage().getHeight() / vertScale);
}
public void fall() {
// metodo para fazer o objeto cair do ceu
setLocation(getX(), getY() + velDown);
}
// método para movimentar o objeto(direita, esquerda, para cima)
public void movers() {
if (Greenfoot.isKeyDown("right")) {
move(+1);
setImage(new GreenfootImage("pDireita.png"));
}
if (Greenfoot.isKeyDown("left")) {
move(-1);
setImage(new GreenfootImage("pEsquerda.png"));
}
if (Greenfoot.isKeyDown("up")) {
moveUp();
}
}
// movimenta para cima(Y)
public void moveUp() {
setLocation(getX(), getY() - up);
}
public void moveEnemies() {
// método usado para movimentar o objeto horizontalmente(X), sendo da direita
// para esquerda(-1)
setLocation(getX() - velDown, getY());
// condicional para remover objeto na posição <=15px
if (getX() <= 15) {
((Florest) getWorld()).removeObject(this);
}
}
}