forked from TechHead27/EW
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrow.java
More file actions
50 lines (46 loc) · 1.39 KB
/
Arrow.java
File metadata and controls
50 lines (46 loc) · 1.39 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
import greenfoot.*;
/**
* Write a description of class Arrow here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Arrow extends Actor
{
private final int[][] options;
private int selection;
private static final int DELAY = 12;
public Arrow(int[][] menu)
{
GreenfootImage cross = new GreenfootImage("images/buttons/Cross.png");
cross.scale(67, 64);
setImage(cross);
options = menu;
selection = 0;
setLocation(options[selection][0], options[selection][1]);
}
/**
* Act - do whatever the Arrow wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
if (Greenfoot.isKeyDown("down") || Greenfoot.isKeyDown("right"))
{
selection = (selection + 1) % options.length;
setLocation(options[selection][0], options[selection][1]);
Greenfoot.delay(DELAY);
}
if (Greenfoot.isKeyDown("up") || Greenfoot.isKeyDown("left"))
{
selection = selection==0?options.length - 1:selection - 1;
setLocation(options[selection][0], options[selection][1]);
Greenfoot.delay(DELAY);
}
}
public int getSelection()
{
return selection;
}
}