Java游戏 - 敌人AI

时间:2013-09-30 05:33:16

标签: java

我正在使用libgdx在java中进行我的第一场比赛。这是一个射击游戏,我的敌人AI有一个问题:我不能让他们移动或射击子弹,他们只是随机产生并留在那里。这就是我在Enemy课程中的内容:

import java.util.Random;

import View.World;

import com.badlogic.gdx.math.Vector2;

public class Enemy {

private static final Random r = new Random();
    float ROTATION_SPEED = 500;
    int x = r.nextInt(36); //top x
    int y = r.nextInt(24); //top y
    Vector2 vect = new Vector2(x,y);




    public Follower(float SPEED, float rotation, float width, float height,
                    Vector2 position) {
            super(SPEED, rotation, width, height, position);
    }

    public void move (Vector2 position){
        getPosition().x =+ 5;
        getPosition().y =+ 5;
    }
    @Override
    public void advance(float delta, Esfera ship) {

      position.lerp(vect, delta);

        rotation += delta * ROTATION_SPEED;

        if(rotation > 360)
                rotation -= 360;

        super.update(ship);
       if(vect.equals(this.getPosition())){
            x = r.nextInt(36);
            y = r.nextInt(24);

       }

}

在我的世界级中,我得到了它来产生敌人:

public class World {

//More variable declarations

Iterator<Follower> eIter;
int Timer = 0;
int counter;
float x = 0;
float y = 0;

public float randFloat(float Min, float Max) {
    return Min + (float)(Math.random() * (Max - Min + 1));
}
public void update(){
    Timer++;
    if(counter < 40){
        if(Timer % 100 == 0){
            float x = randFloat(0, 50.0f);
            float y = randFloat(0, 50.0f);
            enemies.add(new Follower(5f, 0, 1, 1, new Vector2(x, y)));

            counter++;
        }
    }

}

我应该如何实施以至少不断地移动我的敌人?

0 个答案:

没有答案
相关问题