-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreenRotation.java
executable file
·130 lines (121 loc) · 4.2 KB
/
ScreenRotation.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* Updates the board screen and handels the random screen rotation
*
* @author (Pavithran Pathmarajah)
* @version (2014 Jun 06)
*/
import java.util.*;
public class ScreenRotation extends Thread
{
static boolean runLoop=false;
static boolean runUpdate=false;
int mode;//current oreintation mode
long timerDelay;//chagne every x seconds
boolean orientations[];//avialbe orientions
long timeForNextLoop=0;//timerforrotation
long timeForScreenDraw=0;//screenupdate timer
double curRotation;//rotation amount radians
Random rand;//random orientiaon
int curR;//used for random
double tmp;//used for random
//requirments to make thread
public ScreenRotation(int mode,long rDelay, boolean oriendtaions[])
{
super("GRAPHICS");
this.mode=mode;
timerDelay=rDelay;
orientations=oriendtaions;
rand=new Random();
curR=0;
}
//returns orietnaion radian value for given orientaion number 1 2 3 or 4
public double Orientation(int i)
{
if (orientations[i]) //if aid orientaion is enabled
{
//return that radian value
switch (i)
{
case 0:
return 0;
case 1:
return Math.PI/2;
case 2:
return Math.PI;
case 3:
return Math.PI+Math.PI/2;
}
}
//if not then check the next orientaion
if((i+1)<4)
{
return Orientation (i+1); //recursion
}
//if no more go back to the first oriantion
if(i==3)
{
return Orientation (0); //recurision
}
return 0; //dfault #worstcase scenario
}
public void run ()
{
//while game is running
while(runLoop)
{
//while update is requested
while(runUpdate)
{
//if it's time to rotate screen
if (timeForNextLoop < System.currentTimeMillis ())
{
Board.bufferG.rotate(Math.PI*2-curRotation, 300,300); //set screen back to normal
if(mode==0) //one orientaion mode
{
curRotation=Orientation(0); //set orinetiaon
}
if(mode==1) //random orientiaon mode
{
curRotation=Orientation(rand.nextInt(4));
}
if(mode==2)//clockwise mode
{
//continue form last mode and keep going until you get to the next mode ensuring not to repeat the same one
do
{
curR++;
if(curR>3)
curR=0;
tmp=Orientation(curR);
}while(curRotation==tmp);
curRotation=tmp;
}
if(mode==3) //same as above expecpt counter cllockwise
{
do
{
curR--;
if(curR<0)
curR=3;
tmp=Orientation(curR);
}while(curRotation==tmp);
curRotation=tmp;
}
Board.bufferG.rotate(curRotation, 300,300);//draw board now rotated
timeForNextLoop=System.currentTimeMillis ()+timerDelay; //time until next orinetiaon change
}
//if it's time to update the screen
if(timeForScreenDraw< System.currentTimeMillis ())
{
//update block bomb colour
gameColour.updateColor();
//set next update time
timeForScreenDraw= System.currentTimeMillis() +15;
Board.drawAll();
Main.runWindow.getGraphics ().drawImage (Board.buffered, 0, 0, Main.panel);
}
}
}
Main.runWindow.repaint();//repaint the new panel,just incase this class overrides the panels first paint
}
}