如何按随机决定的顺序排列动画图像



我尝试用成对的图像制作自己的简单游戏,玩家试图猜测相同图像的位置,我不知道如何将 2 个相同的缓冲图像动画放在帧上随机位置,不会扩展帧大小,以及需要对图像做什么才能不要将它们放在与以前的图像相同的 x 和 y 上。碰撞系统可以完成工作并删除放在类似 x 和 y 上的图像,或者是否有更好的解决方案。

我现在得到的是完整的一个动画图像,可以被 覆盖图像。

我做了什么来实现这一目标。

public Rozmiar(Game game, Textures tex) {
this.game = game;
this.tex = tex;
for (int x = 128; x < (Game.WIDTH * Game.SCALE - 128); x += 128) {
for (int y = 96; y < (Game.HEIGHT * Game.SCALE - 96); y += 128) {
addOdkryte(new Odkryte(x, y, tex));
}
}
}


public void addOdkryte(Odkryte block) {
os.add(block);
}


package com.game.src.main;
import java.awt.Graphics;
import java.util.LinkedList;
public class Odkryte {
private double x;
private double y;
private Textures tex;
Animation anim;
Animation anim1;
private int counter;
public Odkryte(double x, double y, Textures tex) {
this.x = x;
this.y = y;
this.tex = tex;
anim = new Animation(3, tex.odkimg1px128[0], tex.odkimg1px128[1], tex.odkimg1px128[2], tex.odkimg1px128[3],
tex.odkimg1px128[4], tex.odkimg1px128[5], tex.odkimg1px128[6], tex.odkimg1px128[7], tex.odkimg1px128[8],
tex.odkimg1px128[9]);
}
public void tick() {
anim.runAnimation();
}
public void render(Graphics g) {
anim.drawAnimation(g, x, y, 0);
}

}

  1. 将图像对添加到 ArrayList
  2. 使用 ArrayList 上的 Collections.shuffle(...( 方法随机化图像
  3. 循环访问 ArrayList 并将每个图像添加到帧中。

最新更新