Gra Java Problem

0
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Random;

public class Gameplay extends JPanel implements ActionListener, KeyListener {
    private int x = 200;
    private int wr = 5;
    private int ex[] = new int[wr];
    private Random random = new Random();
    private int i = 0;


    private int od = 100;
    private boolean ziemia = false;
    private int y = 450;
    private int delay = 10;
    private int ey = 10;
    private Entity entity;


    private Timer time;
    private Graphics2D ge;
    public Gameplay(){
        ex[0] = random.nextInt(60)*10;
        ex[1] = random.nextInt(60)*10;
        ex[2] = random.nextInt(60)*10;
        ex[3] = random.nextInt(60)*10;
        ex[4] = random.nextInt(60)*10;
        entity = new Entity();
        addKeyListener(this);
        setFocusable(true);
        setFocusTraversalKeysEnabled(false);
        time = new Timer(delay,this);
        time.start();
    }
    public void paint(Graphics g) {
        g.setColor(Color.BLACK);
        g.fillRect(0, 0, 700, 600);

        g.setColor(Color.green);
        g.fillRect(x, y, 75,75);

        //Przeszkody

            g.setColor(Color.red);
            g.fillRect(ex[0],ey, 50, 50);
            g.fillRect(ex[1],ey,50,50);
            g.fillRect(ex[2],ey,50,50);
            g.fillRect(ex[3],ey,50,50);
        g.dispose();
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        time.start();
        Rectangle en[] = new Rectangle[5];
        en[0] = new Rectangle(ex[0],ey,50,50);
        en[1] = new Rectangle(ex[1],ey,50,50);
        en[2] = new Rectangle(ex[2],ey,50,50);
        en[3] = new Rectangle(ex[3],ey,50,50);
        en[4] = new Rectangle(ex[4],ey,50,50);
        ey+=5;


        Rectangle pl = new Rectangle(x,y,75,75);
        if(pl.intersects(en[0]) || pl.intersects(en[1]) || pl.intersects(en[2]) || pl.intersects(en[3]) || pl.intersects(en[4])){
            System.out.println("wykryto");
        }
        if(ey == 570){```java

        ex[0] = random.nextInt(60)*10;
        ex[1] = random.nextInt(60)*10;
        ex[2] = random.nextInt(60)*10;
        ex[3] = random.nextInt(60)*10;
        ex[4] = random.nextInt(60)*10;
        System.out.println(ex[1]);
        repaint();
    }
    repaint();
}

@Override
public void keyTyped(KeyEvent e) {

}

@Override
public void keyPressed(KeyEvent e) {
    if(e.getKeyCode() == KeyEvent.VK_A){
        x-=10;
    }
    if(e.getKeyCode() == KeyEvent.VK_D){
        x+=10;
    }
}
@Override
public void keyReleased(KeyEvent e) {

    }

}

Dzień dobry, Nie wiem czemu kostki nie ustawiają się do nowego punktu, może ktoś pomóc?
0

Za każdym razem używasz tych samych współrzędnych. Chociaż nie, źle spojrzałem :| chodzi o ten kawałek okomentowany jako "przeszkody"?

0

Gra w awt? Piszesz do nas z przeszlosci?

0

@baant: Znaczy o ten: ``` if(ey == 570){

    ex[0] = random.nextInt(60)*10;
    ex[1] = random.nextInt(60)*10;
    ex[2] = random.nextInt(60)*10;
    ex[3] = random.nextInt(60)*10;
    ex[4] = random.nextInt(60)*10;

1 użytkowników online, w tym zalogowanych: 0, gości: 1