-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMain.java
More file actions
181 lines (150 loc) · 5.35 KB
/
Copy pathMain.java
File metadata and controls
181 lines (150 loc) · 5.35 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package Testing;
import javagameengine.backend.Scene;
import javagameengine.backend.UpdateThread;
import javagameengine.backend.input.Input;
import javagameengine.components.Component;
import javagameengine.components.colliders.SquareCollider;
import javagameengine.components.GameObject;
import javagameengine.JavaGameEngine;
import javagameengine.msc.Vector2;
import javagameengine.ui.Button;
import javagameengine.ui.HorizontalLayout;
import javagameengine.ui.Panel;
import javagameengine.ui.Text;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Main extends JavaGameEngine{
public static int level = 0;
public static void main(String[] args){
Main m = new Main();
Level1 l = new Level1();
setSelectedScene(l);
JFrame frame = new JFrame();
frame.setSize(1020,640);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
m.start(frame);
//Debug.showWhere = true;
}
@Override
public void update() {
super.update();
if(!UpdateThread.running){
setSelectedScene(new Start());
UpdateThread.running = true;
}
}
static class Start extends Scene{
public Start(){
Main.level = 0;
JButton b = new JButton("Level1");
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
Main.setSelectedScene(new Level1());
System.out.println(1);
}
});
add(b);
b.setBounds(200,200,100,50);
JButton b1 = new JButton("Level2");
b1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
Main.setSelectedScene(new Level2());
System.out.println(2);
}
});
add(b1);
b1.setBounds(400,200,100,50);
JButton b2 = new JButton("Level3");
b2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
Main.setSelectedScene(new Level4());
System.out.println(3);
}
});
add(b2);
b2.setBounds(600,200,100,50);
}
@Override
public void update() {
super.update();
setFocusable(false);
}
}
static class Level1 extends Scene{
public Level1(){
id=0;
Main.level = 1;
Panel mainPanel = new Panel();
mainPanel.setFixed(true);
mainPanel.setPosition(new Vector2(140,60));
mainPanel.setLayer(100);
mainPanel.setLayout(new HorizontalLayout());
mainPanel.setFixed(true);
mainPanel.addChild(new Text("Hej alli vad gör du nu tri hi"));
mainPanel.addChild(new Button());
// add(mainPanel);
/* Player s = new Player(new Vector2(-100,-110));
components.add(s);
components.add(new Goal(new Vector2(100,-100)));
components.add(new Ground(new Vector2(0,0)));*/
GameObject g = new GameObject(){
@Override
public void draw(Graphics g) {
super.draw(g);
g.fillOval((int) Input.getMouseWorldPosition().getX(), (int) Input.getMouseWorldPosition().getY(),10,10);
}
};
g.addChild(new GameObject());
add(g);
}
}
static class Level2 extends Scene{
public Level2(){
id=1;
Main.level = 2;
Player s = new Player(new Vector2(0,100));
components.add(s);
components.add(new Goal(new Vector2(400,-100)));
components.add(new Ground(new Vector2(400,0)));
components.add(new Ground(new Vector2(120,200)));
}
}
static class Level3 extends Scene{
public Level3(){
Player s = new Player(new Vector2(0,-100));
id=2;
Main.level = 3;
components.add(s);
components.add(new Ground(new Vector2(0,0)));
components.add(new Ground(new Vector2(400,-200)));
components.add(new Ground(new Vector2(0,-400)));
components.add(new Goal(new Vector2(-100,-500)));
}
}
static class End extends Scene{
public End(){
JButton b = new JButton("Restart");
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
Main.setSelectedScene(new Start());
level = 0;
}
});
add(b);
b.setBounds(400,200,100,50);
Main.level = 4;
}
}
static class T extends GameObject{
public T(){
SquareCollider s = new SquareCollider();
addChild(s);
}
}
}