robotgroup.java
来自「java learn PPT java learn PPT java learn」· Java 代码 · 共 100 行
JAVA
100 行
import java.awt.*;
public class RobotGroup extends ActorGroup2D
{
// 预先定义的动画序列
public static final int WALKING_NORTH = 0;
public static final int SHOOTING_NORTH = 1;
public static final int WALKING_SOUTH = 2;
public static final int SHOOTING_SOUTH = 3;
public static final int WALKING_EAST = 4;
public static final int SHOOTING_EAST = 5;
public static final int WALKING_WEST = 6;
public static final int SHOOTING_WEST = 7;
// 创建一个新的RobotGroup对象
public RobotGroup()
{
super();
animations = new AnimationStrip[8];
}
// 初始化八个动画序列
public void init(Frame a)
{
ImageLoader loader;
int i;
// 北
loader = new ImageLoader(a, "robot_north.gif", true);
animations[WALKING_NORTH] = new AnimationStrip();
for(i = 0; i < 4; i++)
{
animations[WALKING_NORTH].addFrame(loader.extractCell((i*72)+(i+1), 1, 72, 80));
}
animations[WALKING_NORTH].setAnimator(new Animator.Looped());
animations[SHOOTING_NORTH] = new AnimationStrip();
for(i = 0; i < 2; i++)
{
animations[SHOOTING_NORTH].addFrame(loader.extractCell((i*72)+(i+1), 82, 72, 80));
}
animations[SHOOTING_NORTH].setAnimator(new Animator.Looped());
// 南
loader = new ImageLoader(a, "robot_south.gif", true);
animations[WALKING_SOUTH] = new AnimationStrip();
for(i = 0; i < 4; i++)
{
animations[WALKING_SOUTH].addFrame(loader.extractCell((i*72)+(i+1), 1, 72, 80));
}
animations[WALKING_SOUTH].setAnimator(new Animator.Looped());
animations[SHOOTING_SOUTH] = new AnimationStrip();
for(i = 0; i < 2; i++)
{
animations[SHOOTING_SOUTH].addFrame(loader.extractCell((i*72)+(i+1), 82, 72, 80));
}
animations[SHOOTING_SOUTH].setAnimator(new Animator.Looped());
// 东
loader = new ImageLoader(a, "robot_east.gif", true);
animations[WALKING_EAST] = new AnimationStrip();
for(i = 0; i < 4; i++)
{
animations[WALKING_EAST].addFrame(loader.extractCell((i*72)+(i+1), 1, 72, 80));
}
animations[WALKING_EAST].setAnimator(new Animator.Looped());
animations[SHOOTING_EAST] = new AnimationStrip();
for(i = 0; i < 2; i++)
{
animations[SHOOTING_EAST].addFrame(loader.extractCell((i*72)+(i+1), 82, 72, 80));
}
animations[SHOOTING_EAST].setAnimator(new Animator.Looped());
// 西
loader = new ImageLoader(a, "robot_west.gif", true);
animations[WALKING_WEST] = new AnimationStrip();
for(i = 0; i < 4; i++)
{
animations[WALKING_WEST].addFrame(loader.extractCell((i*72)+(i+1), 1, 72, 80));
}
animations[WALKING_WEST].setAnimator(new Animator.Looped());
animations[SHOOTING_WEST] = new AnimationStrip();
for(i = 0; i < 2; i++)
{
animations[SHOOTING_WEST].addFrame(loader.extractCell((i*72)+(i+1), 82, 72, 80));
}
animations[SHOOTING_WEST].setAnimator(new Animator.Looped());
}
} // RobotGroup2D
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?