java游戏2
ImageIterm.java
import
java.awt.Image;
public class ImageIterm
{
/** *//** 作图区ID */
private String id;
/** *//** 图像 */
private Image img;
/** *//** 目标图像顶部X坐标 */
private int xTargetTop;
/** *//** 目标图像顶部Y坐标 */
private int yTargetTop;
/** *//** 目标图像底部X坐标 */
private int xTargetBot;
/** *//** 目标图像底部Y坐标 */
private int yTargetBot;
/** *//** 源图像顶部X坐标 */
private int xSourceTop;
/** *//** 源图像顶部Y坐标 */
private int ySourceTop;
/** *//** 源图像底部Y坐标 */
private int xSourceBot;
/** *//** 源图像顶部Y坐标 */
private int ySourceBot;
public ImageIterm() {
}
public Image getImg() {
return img;
}
public void setImg(Image img) {
this.img = img;
}
public int getXTargetTop() {
return xTargetTop;
}
public void setXTargetTop(int targetTop) {
xTargetTop = targetTop;
}
public int getYTargetTop() {
return yTargetTop;
}
public void setYTargetTop(int targetTop) {
yTargetTop = targetTop;
}
public int getXTargetBot() {
return xTargetBot;
}
public void setXTargetBot(int targetBot) {
xTargetBot = targetBot;
}
public int getYTargetBot() {
return yTargetBot;
}
public void setYTargetBot(int targetBot) {
yTargetBot = targetBot;
}
public int getXSourceTop() {
return xSourceTop;
}
public void setXSourceTop(int sourceTop) {
xSourceTop = sourceTop;
}
public int getYSourceTop() {
return ySourceTop;
}
public void setYSourceTop(int sourceTop) {
ySourceTop = sourceTop;
}
public int getXSourceBot() {
return xSourceBot;
}
public void setXSourceBot(int sourceBot) {
xSourceBot = sourceBot;
}
public int getYSourceBot() {
return ySourceBot;
}
public void setYSourceBot(int sourceBot) {
ySourceBot = sourceBot;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
public class ImageIterm
{
/** *//** 作图区ID */
private String id;
/** *//** 图像 */
private Image img;
/** *//** 目标图像顶部X坐标 */
private int xTargetTop;
/** *//** 目标图像顶部Y坐标 */
private int yTargetTop;
/** *//** 目标图像底部X坐标 */
private int xTargetBot;
/** *//** 目标图像底部Y坐标 */
private int yTargetBot;
/** *//** 源图像顶部X坐标 */
private int xSourceTop;
/** *//** 源图像顶部Y坐标 */
private int ySourceTop;
/** *//** 源图像底部Y坐标 */
private int xSourceBot;
/** *//** 源图像顶部Y坐标 */
private int ySourceBot;
public ImageIterm() {
}
public Image getImg() {
return img;
}
public void setImg(Image img) {
this.img = img;
}
public int getXTargetTop() {
return xTargetTop;
}
public void setXTargetTop(int targetTop) {
xTargetTop = targetTop;
}
public int getYTargetTop() {
return yTargetTop;
}
public void setYTargetTop(int targetTop) {
yTargetTop = targetTop;
}
public int getXTargetBot() {
return xTargetBot;
}
public void setXTargetBot(int targetBot) {
xTargetBot = targetBot;
}
public int getYTargetBot() {
return yTargetBot;
}
public void setYTargetBot(int targetBot) {
yTargetBot = targetBot;
}
public int getXSourceTop() {
return xSourceTop;
}
public void setXSourceTop(int sourceTop) {
xSourceTop = sourceTop;
}
public int getYSourceTop() {
return ySourceTop;
}
public void setYSourceTop(int sourceTop) {
ySourceTop = sourceTop;
}
public int getXSourceBot() {
return xSourceBot;
}
public void setXSourceBot(int sourceBot) {
xSourceBot = sourceBot;
}
public int getYSourceBot() {
return ySourceBot;
}
public void setYSourceBot(int sourceBot) {
ySourceBot = sourceBot;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
import
java.awt.Image;
import java.awt.Toolkit;
public class Scene implements Runnable
{
private Thread thread = new Thread(this);
public Scene()
{
this.thread.start();
}
public void run()
{
Image image = Toolkit.getDefaultToolkit().getImage("c:/tree.png");
ImageIterm imageIterm = new ImageIterm();
imageIterm.setId("1");
imageIterm.setImg(image);
imageIterm.setXTargetTop(0);
imageIterm.setYTargetTop(0);
imageIterm.setXTargetBot(785);
imageIterm.setYTargetBot(360);
imageIterm.setXSourceTop(0);
imageIterm.setYSourceTop(0);
imageIterm.setXSourceBot(785);
imageIterm.setYSourceBot(360);
GameEngine.imageItermCache.addIterm(imageIterm);
ImageIterm imageIterm2 = new ImageIterm();
imageIterm2.setId("2");
imageIterm2.setImg(image);
imageIterm2.setXTargetTop(0);
imageIterm2.setYTargetTop(0);
imageIterm2.setXTargetBot(0);
imageIterm2.setYTargetBot(0);
imageIterm2.setXSourceTop(0);
imageIterm2.setYSourceTop(0);
imageIterm2.setXSourceBot(0);
imageIterm2.setYSourceBot(0);
GameEngine.imageItermCache.addIterm(imageIterm2);
int sourceTopX = 0;
while(true)
{
sourceTopX += 1;
if(sourceTopX>785)
{
sourceTopX =1;
}
imageIterm.setXTargetTop(sourceTopX);
imageIterm.setYTargetTop(0);
imageIterm.setXTargetBot(785);
imageIterm.setYTargetBot(360);
imageIterm.setXSourceTop(0);
imageIterm.setYSourceTop(0);
imageIterm.setXSourceBot(785-sourceTopX);
imageIterm.setYSourceBot(360);
imageIterm2.setXTargetTop(0);
imageIterm2.setYTargetTop(0);
imageIterm2.setXTargetBot(sourceTopX);
imageIterm2.setYTargetBot(360);
imageIterm2.setXSourceTop(785-sourceTopX);
imageIterm2.setYSourceTop(0);
imageIterm2.setXSourceBot(785);
imageIterm2.setYSourceBot(360);
try
{
Thread.sleep(20);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
}
import java.awt.Toolkit;
public class Scene implements Runnable
{
private Thread thread = new Thread(this);
public Scene()
{
this.thread.start();
}
public void run()
{
Image image = Toolkit.getDefaultToolkit().getImage("c:/tree.png");
ImageIterm imageIterm = new ImageIterm();
imageIterm.setId("1");
imageIterm.setImg(image);
imageIterm.setXTargetTop(0);
imageIterm.setYTargetTop(0);
imageIterm.setXTargetBot(785);
imageIterm.setYTargetBot(360);
imageIterm.setXSourceTop(0);
imageIterm.setYSourceTop(0);
imageIterm.setXSourceBot(785);
imageIterm.setYSourceBot(360);
GameEngine.imageItermCache.addIterm(imageIterm);
ImageIterm imageIterm2 = new ImageIterm();
imageIterm2.setId("2");
imageIterm2.setImg(image);
imageIterm2.setXTargetTop(0);
imageIterm2.setYTargetTop(0);
imageIterm2.setXTargetBot(0);
imageIterm2.setYTargetBot(0);
imageIterm2.setXSourceTop(0);
imageIterm2.setYSourceTop(0);
imageIterm2.setXSourceBot(0);
imageIterm2.setYSourceBot(0);
GameEngine.imageItermCache.addIterm(imageIterm2);
int sourceTopX = 0;
while(true)
{
sourceTopX += 1;
if(sourceTopX>785)
{
sourceTopX =1;
}
imageIterm.setXTargetTop(sourceTopX);
imageIterm.setYTargetTop(0);
imageIterm.setXTargetBot(785);
imageIterm.setYTargetBot(360);
imageIterm.setXSourceTop(0);
imageIterm.setYSourceTop(0);
imageIterm.setXSourceBot(785-sourceTopX);
imageIterm.setYSourceBot(360);
imageIterm2.setXTargetTop(0);
imageIterm2.setYTargetTop(0);
imageIterm2.setXTargetBot(sourceTopX);
imageIterm2.setYTargetBot(360);
imageIterm2.setXSourceTop(785-sourceTopX);
imageIterm2.setYSourceTop(0);
imageIterm2.setXSourceBot(785);
imageIterm2.setYSourceBot(360);
try
{
Thread.sleep(20);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
}
import
java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
public class ImageItermCahe
{
private ConcurrentMap<String, ImageIterm> imgItermMap = new ConcurrentHashMap<String, ImageIterm>();
private ConcurrentLinkedQueue<ImageIterm> imgItermLst = new ConcurrentLinkedQueue<ImageIterm>();
public ImageItermCahe()
{}
public void addIterm(ImageIterm imageIterm)
{
if(imageIterm != null)
{
this.imgItermMap.put(imageIterm.getId(), imageIterm);
this.imgItermLst.add(imageIterm);
}
}
public void remove(String imageItermId)
{
this.imgItermMap.remove(imageItermId);
}
public ConcurrentMap<String, ImageIterm> getImgItermMap() {
return imgItermMap;
}
public ConcurrentLinkedQueue<ImageIterm> getImgItermLst() {
return imgItermLst;
}
}
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
public class ImageItermCahe
{
private ConcurrentMap<String, ImageIterm> imgItermMap = new ConcurrentHashMap<String, ImageIterm>();
private ConcurrentLinkedQueue<ImageIterm> imgItermLst = new ConcurrentLinkedQueue<ImageIterm>();
public ImageItermCahe()
{}
public void addIterm(ImageIterm imageIterm)
{
if(imageIterm != null)
{
this.imgItermMap.put(imageIterm.getId(), imageIterm);
this.imgItermLst.add(imageIterm);
}
}
public void remove(String imageItermId)
{
this.imgItermMap.remove(imageItermId);
}
public ConcurrentMap<String, ImageIterm> getImgItermMap() {
return imgItermMap;
}
public ConcurrentLinkedQueue<ImageIterm> getImgItermLst() {
return imgItermLst;
}
}