-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreen.java
More file actions
67 lines (56 loc) · 1.53 KB
/
Screen.java
File metadata and controls
67 lines (56 loc) · 1.53 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
/**
* This Class handles all the interactive menues and Gui for my game,
* It detects where the mouse is and conveys this to my other classes,
* It displayes the backgrounds and buttons
* @author elan
*
*/
public class Screen
{
protected Button[] buttons;
public static Point mouse;
protected String filename;
public Screen(String filename)
{
this.filename = filename;
mouse = new Point(StdDraw.mouseX(), StdDraw.mouseY());
}
public void setBackGround()
{
StdDraw.picture(States.WINDOW_CENTRE, States.WINDOW_CENTRE, filename, States.WINDOW_RESOLUTION, States.WINDOW_RESOLUTION);
}
public void render()
{
setBackGround();
if(buttons != null)
for (int i = 0; i < buttons.length; i++)
buttons[i].render();
}
public void checkMouseActivity()
{
//if mouse x or y changes then check mouse for buttons
if(mouse.getX() != StdDraw.mouseX() || mouse.getY() != StdDraw.mouseY())
{
if(buttons != null)
for (int i = 0; i < buttons.length; i++)
buttons[i].checkMouse();
mouse = new Point(StdDraw.mouseX(), StdDraw.mouseY());
if(this instanceof PlayScreen && !States.controlsKeyboard)
{
Controller.player.setAngle();
}
}
if(!StdDraw.mousePressed())
States.mouseClicked = false;
if(StdDraw.mousePressed())
{
if(!States.mouseClicked)
if(buttons != null)
for (int i = 0; i < buttons.length; i++)
buttons[i].isClicked();
if(this instanceof PlayScreen && !States.controlsKeyboard)
Controller.player.shoot();
States.mouseClicked = true;
}
}
}