-
Notifications
You must be signed in to change notification settings - Fork 0
/
Captain.java
86 lines (77 loc) · 2.05 KB
/
Captain.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Capitan here.
*
* @author
* @version (a version number or a date)
*/
public class Captain extends Enemy
{
private int stepsX;
private int stepsY;
/**
* Builder Captain class. StepsY stepsX and the variables used for the movement of the enemy are initialized.
*
*/
public Captain()
{
stepsX = 100;
stepsY = 1;
shotEnemy = new GreenfootSound("disparoEnemigo.wav");
attackType = new ShotEnemy();
}
/**
* Act - do whatever the Captain wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if(!stepByPlayer())
{
super.act();
bounce();
}
else
{
Scenario e = (Scenario)getWorld();
Shaktimaan i = e.getShaktimaan();
i.reduceHealth(i.getSalud()/2);
e.reduceEnemies();
getWorld().removeObject(this);
}
}
/**
* Move to Captain zigzag
*/
public void mover()
{
if(stepsX > 0)
{
setLocation(this.getX()-velMov, this.getY()+stepsY);
stepsX--;
}
else if(stepsX <= 0 && stepsX > -70 && getX()+getImage().getWidth()/2 < getWorld().getWidth())
{
setLocation(this.getX()+velMov, this.getY()+stepsY);
stepsX--;
}
else if(stepsX <= -70)
stepsX = 100;
}
/**
* Touching an edge either upper or lower direction is reversed.
*/
public void bounce()
{
if(getY() <= getImage().getHeight()/2)
stepsY = 1;
else if(getY() > getWorld().getHeight()-getImage().getHeight()/2)
stepsY = -1;
else if(getX() >= getWorld().getWidth())
stepsX = 100;
}
public void attack()
{
super.attack();
}
}