-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNarutoPlayer.java
113 lines (88 loc) · 2.37 KB
/
NarutoPlayer.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class ShipPlayer here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class NarutoPlayer extends Naruto
{ static GreenfootSound eating = new GreenfootSound("eat.mp3");
static GreenfootSound Hit = new GreenfootSound ("Kunai Hit.wav");
public NarutoPlayer(){
GreenfootImage MyImage =getImage();
}
/**
* Act - do whatever the ShipPlayer wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move();
eat();
hitShuriken();
hitBox();
}
public void move()
{
int y=getY();
int x=getX();
if(Greenfoot.isKeyDown("up"))
{ setLocation(x,y-1);
if(checkObstacle())
{ setLocation(x,y);
}
}
if(Greenfoot.isKeyDown("down"))
{
setLocation(x,y+1);
if(checkObstacle())
{ setLocation(x,y);
}
}
if(Greenfoot.isKeyDown("left"))
{ setLocation(x-1,y);
if(checkObstacle())
{ setLocation(x,y);
}
}
if(Greenfoot.isKeyDown("right"))
{setLocation(x+1,y);
if(checkObstacle())
{ setLocation(x,y);
}
}
}
public boolean checkObstacle()
{
if(isTouching(MazeBlock.class)||isTouching(Door.class))
{
return true;
}
else{
return false;
}
}
public void eat ()
{
if(isTouching(Food.class))
{
removeTouching(Food.class);
eating.play();
}
}
public void hitShuriken()
{
if(isTouching(ShurikenWeapon.class))
{
Greenfoot.setWorld(new GameOver());
}
}
public void hitBox()
{
if(isTouching(BoxTarget.class))
{
Play.music4Maze.stop();
Greenfoot.setWorld(new NextLevel());
}
}
}