Skip to content

Commit a5f5f7b

Browse files
committed
Engine Import
Imported the previous version of this engine from eclipse
1 parent 8ac0ced commit a5f5f7b

21 files changed

Lines changed: 2316 additions & 0 deletions

Audio.java

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package Engine;
2+
import java.io.File;
3+
import javax.sound.sampled.AudioInputStream;
4+
import javax.sound.sampled.AudioSystem;
5+
import javax.sound.sampled.Clip;
6+
import javax.sound.sampled.LineEvent;
7+
import javax.sound.sampled.LineEvent.Type;
8+
import javax.sound.sampled.LineListener;
9+
public class Audio
10+
{
11+
private Clip audioFile;
12+
public String Path;
13+
public boolean error = false;
14+
public double ClipLength = 0;
15+
public double ClipStart = 0;
16+
public boolean play = false;
17+
public boolean Loop = false;
18+
public Audio(String fileName, double cS, double cL)
19+
{
20+
Path = fileName;
21+
ClipStart = cS * 1000000;
22+
ClipLength = cL * 1000000;
23+
Refresh();
24+
}
25+
public void Play()
26+
{
27+
new Thread(new Runnable()
28+
{
29+
public void run()
30+
{
31+
try
32+
{
33+
play = true;
34+
audioFile.start();
35+
audioFile.addLineListener(new LineListener()
36+
{
37+
public void update(LineEvent event)
38+
{
39+
if (event.getType() != Type.STOP)
40+
{
41+
return;
42+
}
43+
//play = false;
44+
}
45+
});
46+
while ((audioFile.getMicrosecondLength() != audioFile.getMicrosecondPosition()) && (play))
47+
{
48+
if ((ClipLength > 0) && (GetPosition() > ClipLength))
49+
{
50+
audioFile.stop();
51+
play = false;
52+
}
53+
}
54+
play = false;
55+
Refresh();
56+
}
57+
catch (Exception e)
58+
{
59+
60+
}
61+
}
62+
}).start();
63+
}
64+
public void Stop()
65+
{
66+
audioFile.stop();
67+
play = false;
68+
}
69+
public boolean IsPlaying()
70+
{
71+
return audioFile.isRunning();
72+
}
73+
public void Refresh()
74+
{
75+
new Thread(new Runnable()
76+
{
77+
public void run()
78+
{
79+
try
80+
{
81+
AudioInputStream ais = AudioSystem.getAudioInputStream(new File(Path));
82+
audioFile = AudioSystem.getClip();
83+
audioFile.open(ais);
84+
audioFile.setMicrosecondPosition((long)ClipStart);
85+
if (Loop == true)
86+
{
87+
Play();
88+
}
89+
}
90+
catch (Exception e)
91+
{
92+
e.printStackTrace();
93+
error = true;
94+
}
95+
}
96+
}).start();
97+
}
98+
public double GetPosition()
99+
{
100+
return audioFile.getMicrosecondPosition();
101+
}
102+
}

Button.java

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package Engine;
2+
import java.awt.Font;
3+
import java.awt.event.MouseEvent;
4+
import Spark.EventHandler;
5+
public class Button
6+
{
7+
public Point Location = new Point(0, 0);
8+
public Size Size = new Size(130, 25);
9+
public String Text = "button";
10+
public Font TextFont = new Font("Segoe UI", Font.PLAIN, 11);
11+
public Color[] BackColor = {Color.Black, Color.Red, Color.Green};
12+
public Color[] ForeColor = {Color.White, Color.Green, Color.Red};
13+
public EventHandler OnClick = new EventHandler();
14+
public boolean Enabled = true;
15+
private int state = 0;
16+
private Rectangle rect;
17+
private boolean down = false;
18+
Window wnd;
19+
public Button(Window wnd, String text)
20+
{
21+
wnd.OnMouseMove.Add(this, "Check");
22+
wnd.OnMouseDown.Add(this, "Check");
23+
wnd.OnMouseUp.Add(this, "Check");
24+
wnd.OnShow.Add(this, "Initialize");
25+
Text = text;
26+
this.wnd = wnd;
27+
}
28+
public Button(Window wnd, String text, Point location, Size size)
29+
{
30+
wnd.OnMouseMove.Add(this, "Check");
31+
wnd.OnMouseDown.Add(this, "Check");
32+
wnd.OnMouseUp.Add(this, "Check");
33+
wnd.OnShow.Add(this, "Initialize");
34+
Text = text;
35+
Location = location;
36+
Size = size;
37+
this.wnd = wnd;
38+
}
39+
public void SetBackColor(Color normal, Color hover, Color press)
40+
{
41+
BackColor = new Color[]{normal, hover, press};
42+
}
43+
public void SetForeColor(Color normal, Color hover, Color press)
44+
{
45+
ForeColor = new Color[]{normal, hover, press};
46+
}
47+
public void Initialize()
48+
{
49+
rect = new Rectangle(BackColor[state], Location, Size);
50+
}
51+
public void Check(Point MouseLocation, int Button)
52+
{
53+
if (Enabled == true)
54+
{
55+
rect = new Rectangle(BackColor[state], Location, Size);
56+
if (rect.Intersects(MouseLocation))
57+
{
58+
if (wnd.Mouse[MouseEvent.BUTTON1])
59+
{
60+
state = 2;
61+
down = true;
62+
}
63+
else
64+
{
65+
state = 1;
66+
if (down == true)
67+
{
68+
OnClick.InvokeAll(MouseLocation, Button);
69+
down = false;
70+
}
71+
}
72+
}
73+
else
74+
{
75+
down = false;
76+
state = 0;
77+
}
78+
}
79+
}
80+
public void Render(GraphicsUnit Graphics)
81+
{
82+
Size center = Graphics.GetTextSize(Text, TextFont);
83+
Point text = new Point((Location.X + (Size.Width) / 2) - (center.Width / 2), (Location.Y + (Size.Height) / 2) - (center.Height / 2));
84+
Graphics.FillRectangle(BackColor[state], Location, Size);
85+
Graphics.DrawString(Text, ForeColor[state], text, TextFont);
86+
}
87+
}

Camera.java

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package Engine;
2+
import java.awt.MouseInfo;
3+
import java.awt.Robot;
4+
import java.awt.Toolkit;
5+
public class Camera
6+
{
7+
public Vertex Location = new Vertex();
8+
public Vertex Rotation = new Vertex();
9+
private Point MousePreviousPosition;
10+
private Robot rob;
11+
public boolean FreeFloating = true;
12+
public Camera()
13+
{
14+
try
15+
{
16+
rob = new Robot();
17+
}
18+
catch (Exception e)
19+
{
20+
e.printStackTrace();
21+
}
22+
}
23+
public Camera(Vertex _location, Vertex _rotation)
24+
{
25+
try
26+
{
27+
rob = new Robot();
28+
}
29+
catch (Exception e)
30+
{
31+
e.printStackTrace();
32+
}
33+
Location = new Vertex(_location);
34+
Rotation = new Vertex(_rotation);
35+
}
36+
public void Look(double MouseSpeed, Point WindowLocation, Size WindowSize)
37+
{
38+
Size Monitor = new Size((int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(), (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight());
39+
if (MousePreviousPosition != null)
40+
{
41+
Point moved = GetMousePosition().subtract(MousePreviousPosition);
42+
Rotation.Z -= moved.X * MouseSpeed;
43+
Rotation.X -= moved.Y * MouseSpeed;
44+
if (Rotation.Z >= 360)
45+
{
46+
Rotation.Z -= 360;
47+
}
48+
if (Rotation.Z <= -360)
49+
{
50+
Rotation.Z += 360;
51+
}
52+
if (Rotation.X >= 360)
53+
{
54+
Rotation.X -= 360;
55+
}
56+
if (Rotation.X <= -360)
57+
{
58+
Rotation.X += 360;
59+
}
60+
}
61+
int offset = 2;
62+
if ((GetMousePosition().X <= WindowLocation.X + offset) || (GetMousePosition().X <= 0))
63+
{
64+
SetMousePosition(new Point(WindowLocation.X + WindowSize.Width, GetMousePosition().Y));
65+
}
66+
else if ((GetMousePosition().X >= WindowLocation.X + WindowSize.Width - offset) || GetMousePosition().X >= Monitor.Width)
67+
{
68+
SetMousePosition(new Point(WindowLocation.X + 1, GetMousePosition().Y));
69+
}
70+
else if ((GetMousePosition().Y <= WindowLocation.Y + offset) || (GetMousePosition().Y <= 0))
71+
{
72+
SetMousePosition(new Point(GetMousePosition().X, WindowLocation.Y + WindowSize.Height));
73+
}
74+
else if ((GetMousePosition().Y >= WindowLocation.Y + WindowSize.Height - offset) || GetMousePosition().Y >= Monitor.Height - 1)
75+
{
76+
SetMousePosition(new Point(GetMousePosition().X, WindowLocation.Y + 1));
77+
}
78+
MousePreviousPosition = GetMousePosition();
79+
}
80+
private void SetMousePosition(Point location)
81+
{
82+
rob.mouseMove((int)location.X, (int)location.Y);
83+
}
84+
private Point GetMousePosition()
85+
{
86+
return new Point(MouseInfo.getPointerInfo().getLocation().x, MouseInfo.getPointerInfo().getLocation().y);
87+
}
88+
public void SetMousePreviousPosition(Point MouseLocation)
89+
{
90+
MousePreviousPosition = new Point(MouseLocation);
91+
}
92+
public void Forward(double factor)
93+
{
94+
double radian = Rotation.Z * Math.PI / 180;
95+
double x = Math.sin(radian) * factor;
96+
double z = Math.cos(radian) * factor;
97+
Location.X -= x;
98+
Location.Z += z;
99+
radian = Rotation.X * Math.PI / 180;
100+
if (FreeFloating == true)
101+
{
102+
double y = Math.sin(radian) * factor;
103+
Location.Y += y;
104+
}
105+
}
106+
public void Right(double factor)
107+
{
108+
double radian = (Rotation.Z - 90) * Math.PI / 180;
109+
double x = Math.sin(radian) * factor;
110+
double z = Math.cos(radian) * factor;
111+
Location.X -= x;
112+
Location.Z += z;
113+
radian = (Rotation.X - 90) * Math.PI / 180;
114+
}
115+
public Vertex GetForwardPoint(double factor)
116+
{
117+
Vertex _return = new Vertex();
118+
double radian = Rotation.Z * Math.PI / 180;
119+
double x = Math.sin(radian) * factor;
120+
double z = Math.cos(radian) * factor;
121+
_return.X = Location.X - x;
122+
_return.Z = Location.Z + z;
123+
radian = Rotation.X * Math.PI / 180;
124+
double y = Math.sin(radian) * factor;
125+
_return.Y = Location.Y + y;
126+
return _return;
127+
}
128+
}

0 commit comments

Comments
 (0)