资源简介
一个类似超级玛丽界面和玩法的Java游戏,并不是真正的超级玛丽,也算是学编程这么长时间的一点总结吧,想学习Java游戏的朋友可要好好研究一番了,还带有音效,相信你会从中学到不少知识的。
代码片段和文件信息
package com.brackeen.javagamebook.graphics;
//Download by http://www.codefans.net
import java.awt.Image;
import java.util.ArrayList;
public class Animation {
private ArrayList frames;
private int currframeIndex;
private long animTime;
private long totalDuration;
/**
Creates a new empty Animation.
*/
public Animation() {
this(new ArrayList() 0);
}
private Animation(ArrayList frames long totalDuration) {
this.frames = frames;
this.totalDuration = totalDuration;
start();
}
/**
Creates a duplicate of this animation. The list of frames
are shared between the two Animations but each Animation
can be animated independently.
*/
public object clone() {
return new Animation(frames totalDuration);
}
/**
Adds an image to the animation with the specified
duration (time to display the image).
*/
public synchronized void addframe(Image image
long duration)
{
totalDuration += duration;
frames.add(new Animframe(image totalDuration));
}
/**
Starts this animation over from the beginning.
*/
public synchronized void start() {
animTime = 0;
currframeIndex = 0;
}
/**
Updates this animation‘s current image (frame) if
neccesary.
*/
public synchronized void update(long elapsedTime) {
if (frames.size() > 1) {
animTime += elapsedTime;
if (animTime >= totalDuration) {
animTime = animTime % totalDuration;
currframeIndex = 0;
}
while (animTime > getframe(currframeIndex).endTime) {
currframeIndex++;
}
}
}
/**
Gets this Animation‘s current image. Returns null if this
animation has no images.
*/
public synchronized Image getImage() {
if (frames.size() == 0) {
return null;
}
else {
return getframe(currframeIndex).image;
}
}
private Animframe getframe(int i) {
return (Animframe)frames.get(i);
}
private class Animframe {
Image image;
long endTime;
public Animframe(Image image long endTime) {
this.image = image;
this.endTime = endTime;
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
----------- --------- ---------- ----- ----
1930881 135
评论
共有 条评论