import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
import java.awt.event.*;
public class Main extends JFrame {
ImageIcon imgpla = new ImageIcon("전투기.png");
JLabel l = new JLabel(imgpla);
ImageIcon imgsky = new ImageIcon("밤하늘.png");
JLabel sky = new JLabel(imgsky);
ImageIcon imgal2 = new ImageIcon("적2.png");
JLabel al2 = new JLabel(imgal2);
ImageIcon imgbg = new ImageIcon("갤러그배경.png");
JLabel bg = new JLabel(imgbg);
JLabel pc = new JLabel();
JLabel b_count = new JLabel();
JLabel scl = new JLabel();
int cnt=50;
int sc;
int score;
int a1life=3;
int a2life=3;
int a3life=4;
int a4life=4;
boolean is_true=true;
boolean is_col = false;
boolean u=false,d=false,le=false,ri=false,sp=false;
Container c;
class P extends Thread {//Player
private int x=330;
private int y=830;
public void run() {
c.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {}
public void keyReleased(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_UP)
u = false;
if(e.getKeyCode() == KeyEvent.VK_RIGHT)
ri = false;
if(e.getKeyCode() == KeyEvent.VK_DOWN)
d = false;
if(e.getKeyCode() == KeyEvent.VK_LEFT)
le = false;
}
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_UP) {
u = true;
if(ri==true) x+=10;
if(le==true) x-=10;
y-=10;
}
if(e.getKeyCode() == KeyEvent.VK_RIGHT) {
ri = true;
if(u==true) y-=10;
if(d==true) y+=10;
x+=10;
}
if(e.getKeyCode() == KeyEvent.VK_DOWN) {
d = true;
if(ri==true) x+=10;
if(le==true) x-=10;
y+=10;
}
if(e.getKeyCode() == KeyEvent.VK_LEFT) {
le = true;
if(u==true) y-=10;
if(d==true) y+=10;
x-=10;
}
}
});
while(true) {
l.setLocation(x,y);
l.repaint();
}
}
}
class P_Attack extends Thread { // 총알
ImageIcon imgbul = new ImageIcon("총알.png");
JLabel b = new JLabel(imgbul);
private int x;
private int y;
public P_Attack(int x, int y) {
//System.out.println("총알 스레드 생성!");
this.x=x;
this.y=y;
b.setSize(2,12);
b.setLocation(x,y);
c.add(b);
//sky.setSize(550,750);
//sky.setLocation(0,0);
//c.add(sky);
}
public void run() {
cnt--;
b_count.setFont(new Font("DungGeunMo", Font.PLAIN, 20));
b_count.setForeground(Color.WHITE);
b_count.setText("Bullet : "+cnt);
b_count.repaint();
while(true) {
if(cnt<=0) {
cnt=1;
b.setVisible(false);
b_count.setText("Reroad");
System.out.println("Reroad...");
c.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {}
public void keyPressed(KeyEvent e) {
if(e.getKeyChar() == 'r') {
cnt=50;
}
}
public void keyReleased(KeyEvent e) {}
});
}
if() { //충돌 했을 때
System.out.println("추우웅도오올 해애앴다아아.");
score+=10;
a1life--;
if(a1life==0) {
al.setVisible(false);
//al의 스레드 종료
}
}
try {
sleep(1);
b.setLocation(x,y);
y-=2;
//System.out.println(x+", "+y);
if(y<=0) {
b.setVisible(false);
return;
}
// 총알 쓰레드를 언제 멈출지
} catch (InterruptedException e1) {
return;
}
b.repaint();
}
}
}
class A1 extends Thread { //말벌
ImageIcon imgal = new ImageIcon("적1.png");
JLabel al = new JLabel(imgal);
private int x=120;
private int y=0;
public A1() {
al.setSize(50,50);
al.setLocation(x,y);
c.add(al);
}
public void run() {
while(true) {
y++;
// if(y>=500) {
// al.setLocation(120,0);
// }
try {
sleep(10);
al.setLocation(x,y);
} catch (InterruptedException e1) {
return;
}
al.repaint();
}
}
}
class A2 extends Thread {
private int x=240;
private int y=0;
public void run() {
while(true) {
y++;
// if(y>=500) {
// al2.setLocation(240,0);
// }
try {
sleep(10);
al2.setLocation(x,y);
} catch (InterruptedException e1) {
return;
}
al2.repaint();
}
}
}
class A3 extends Thread {
public void run() {
while(true) {
}
}
}
class Tim extends Thread {
public Tim() {
pc.setSize(200,25);
pc.setLocation(20,10);
c.add(pc);
}
public void run() {
while(true) {
sc++;
try {
sleep(100);
pc.setFont(new Font("DungGeunMo", Font.PLAIN, 40));
pc .setForeground(Color.WHITE);
pc.setText(""+sc);
} catch (InterruptedException e1) {
return;
}
pc.repaint();
}
}
}
public Main() {
setTitle("피융");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c = getContentPane();
c.setLayout(null);
b_count.setFont(new Font("DungGeunMo", Font.PLAIN, 20));
b_count .setForeground(Color.WHITE);
b_count.setText("Bullet : 50");
//c.setBackground(Color.BLACK);
l.setSize(38,38);
l.setLocation(330,830);
al2.setSize(50,50);
al2.setLocation(240,0);
b_count.setSize(200,15);
b_count.setLocation(550,920);
bg.setSize(700,1000);
bg.setLocation(0,0);
c.add(l);
c.add(al2);
c.add(b_count);
c.requestFocus();
c.setFocusable(true);
setSize(700,1000);
setVisible(true);
c.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {}
public void keyReleased(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_SPACE) {
P_Attack th2 = new P_Attack(l.getX()+16,l.getY());
th2.start();
c.add(bg);
}
}
public void keyPressed(KeyEvent e) {}
});
A1 th3 = new A1();
th3.start();
A2 th4 = new A2();
th4.start();
if(th3.al.getY()>=400) {
th3.start();
th4.start();
}
P th1 = new P();
th1.start();
//스페이스 눌릴때마다 th2 생성하고 시작
c.add(bg);
Tim tm = new Tim();
tm.start();
}
public static void main(String[] args) {
new Main();
}
}



