-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNiñaFight.java
86 lines (81 loc) · 1.99 KB
/
NiñaFight.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 niña here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class NiñaFight extends Actor
{
int speed = 5;
SimpleTimer shoot= new SimpleTimer();
int SHOT_INTERVAL = 300;
public NiñaFight()
{
GreenfootImage myImage = getImage();
int myNewHeight = (int)myImage.getHeight()/4;
int myNewWidth = (int)myImage.getWidth()/4;
myImage.scale(myNewWidth,myNewHeight);
}
/**
* Act - do whatever the niña wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
slideAround();
}
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);
}
}
if(Greenfoot.isKeyDown("space")&& shoot.millisElapsed()>SHOT_INTERVAL)
{
getWorld().addObject(new Justificante(),x,y);
shoot.mark();
}
}
public boolean hitWalls()
{
if(isTouching(Wall.class))
{
return true;
}
else
{
return false;
}
}
}