在Java游戏中让一个人物走动的代码是什么?代码主要为以下java代码汇成人物:
package com.lovo.game.frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import javax.swing.JFrame;
import com.lovo.game.role.Fire;
import com.lovo.game.role.GameMap;
import com.lovo.game.role.ZhaoYun;
import com.lovo.game.util.TrackerInit;
public class GameStartFrame extends JFrame implements Runnable{
private Image memoryImage;
private Graphics memoryGraphics;
public static boolean isRun = true;
private static GameMap gameMap = new GameMap();
private ZhaoYun zy = new ZhaoYun();
private Fire fire = new Fire();
public GameStartFrame(){
this.setSize(900,700);
this.setVisible(true);
this.setDefaultCloseOperation(3);
//设置居中
this.setLocationRelativeTo(null);
//初始化双缓冲画布、画笔
this.memoryImage = this.createImage(900,700);
this.memoryGraphics = this.memoryImage.getGraphics();
//媒体追踪器
MediaTracker tracker = new MediaTracker(this);
TrackerInit.initImage(tracker);
//启动线程
Thread th = new Thread(this);
th.start();
}
public static void main(String[] args) {
GameStartFrame game = new GameStartFrame();
}
public void run() {
while(isRun){
this.flushFrame();
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private void flushFrame(){
gameMap.drawMap(memoryGraphics);
zy.drawImage(memoryGraphics);
fire.drawImage(memoryGraphics);
//将双缓冲画布中java代码汇成人物的图片显示在窗体
this.getGraphics().drawImage(this.memoryImage,0,0,this);
}
}
package com.lovo.game.role;
import java.awt.Graphics;
import java.awt.Image;
public class GameMap {
public static Image mapImg;
public static int mapx;
public void drawMap(Graphics memoryGraphics){
mapx -=5;
if(mapx =-17100){
mapx = -17100;
}
memoryGraphics.drawImage(mapImg,mapx,0,null);
}
}
package com.lovo.game.role;
import java.awt.Graphics;
import java.awt.Image;
import com.lovo.game.util.MoveImageChange;
public class Fire {
public static Image[]fireImage;
private int x =100;
private int y =300;
private int width = 200;
private int height = 130;
private MoveImageChange moveChange = new MoveImageChange(3);
public void drawImage(Graphics memoryGraphics){
Image img = moveChange.imageChange(fireImage);
memoryGraphics.drawImage(img,this.x,this.y,this.width,this.height,null);
}
}
package com.lovo.game.util;
import java.awt.MediaTracker;
import com.lovo.game.role.Fire;
import com.lovo.game.role.GameMap;
import com.lovo.game.role.ZhaoYun;
public class TrackerInit {
public static void initImage(MediaTracker tracker){
//初始化地图图片
GameMap.mapImg = CutImage.getSingleImage("image/map.jpg", tracker);
//赵云
ZhaoYun.zyImage = CutImage.cutOneImage("image/boss/playSpear.png",18, 236, 134,tracker);
//火
Fire.fireImage = CutImage.cutOneImage("image/fireImg.png", 6, 283, 161,tracker);
try {
//0组java代码汇成人物的图片全部等待加载完毕后java代码汇成人物,在显示
tracker.waitForID(0);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
package com.lovo.game.util;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.image.CropImageFilter;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageProducer;
【java代码汇成人物 java整人代码】import javax.swing.ImageIcon;
import javax.swing.JFrame;
public class CutImage {
public staticImage[][] cutManyImage(String filePath, int row, int col,
int imageWidth, int imageHight,MediaTracker tracker) {
Image[][] img = new Image[row][col];
ImageIcon imIcon = new ImageIcon(filePath);// 创建图像数组对象
Image imgTemp = imIcon.getImage();// 创建源图像
// 为源 图象获取ImageProducer源
ImageProducer sourceProducer = imgTemp.getSource();
for (int i = 0; irow; i) {
for (int j = 0; jcol; j) {
// 创建图片分割图像对象,第一、二个参数为分割图像起始坐标 。后两个参数为图像大小
CropImageFilter cropImg = new CropImageFilter(j * imageWidth, i * imageHight,imageWidth, imageHight);
ImageProducer imgProducer = new FilteredImageSource(sourceProducer, cropImg);
img[i][j] = new JFrame().createImage(imgProducer);
tracker.addImage(img[i][j], 0);
}
}
return img;
}
public staticImage[] cutOneImage(String filePath,int col,
int imageWidth, int imageHight,MediaTracker tracker) {
Image[] img = new Image[col];
ImageIcon imIcon = new ImageIcon(filePath);// 创建图像数组对象
Image imgTemp = imIcon.getImage();// 创建源图像
// 为源 图象获取ImageProducer源
ImageProducer sourceProducer = imgTemp.getSource();
for (int j = 0; jcol; j) {
// 创建图片分割图像对象,第一、二个参数为分割图像起始坐标 。后两个参数为图像大小
CropImageFilter cropImg = new CropImageFilter(j * imageWidth, 0,imageWidth, imageHight);
ImageProducer imgProducer = new FilteredImageSource(sourceProducer, cropImg);
img[j] = new JFrame().createImage(imgProducer);
tracker.addImage(img[j], 0);
}
return img;
}
public static Image getSingleImage(String imgPath,MediaTracker tracker){
Image img = new ImageIcon(imgPath).getImage();
tracker.addImage(img, 0);
return img;
}
}
package com.lovo.game.util;
import java.awt.Image;
public class MoveImageChange {
private int count;
private Image img;
private int frequency;
private int loopCount;
public MoveImageChange(int frequency){
this.frequency=frequency;
}
public MoveImageChange(int frequency,int count){
this.frequency=frequency;
this.count = count;
}
publicImage imageChange(Image[] images){
if(img==null){//初始图片为第一张图片
img=images[0];
}
count;
if(countfrequency){//当记数器大于频率时
count=0;
loopCount;
if(loopCount = images.length){//图片下标越界时
loopCount=0;
}
img=images[loopCount];
}
return img;
}
public void setLoopCount(int loopCount){
this.loopCount = loopCount;
}
}
package com.lovo.game.role;
import java.awt.Graphics;
import java.awt.Image;
import com.lovo.game.util.MoveImageChange;
public class ZhaoYun {
public static Image[] zyImage;
private int x =600;
private int y =300;
private int width =200;
private int height =130;
private MoveImageChange moveChange = new MoveImageChange(3);
public void drawImage(Graphics memoryGraphics){
Image img = moveChange.imageChange(zyImage);
memoryGraphics.drawImage(img,this.x,this.y,this.width,this.height,null);
JAVA代码编写 , 多态第一步:创建一个父类 , 如Animal(动物) 类,这个方法中只有方法的定义,没有实现 。第二步:创建一个子类,如cat(猫)类,这个方法中实现父类中的所有方法,并进行重写 。
第三步:创建一个子类,如dog(狗)类,这个方法中实现父类中的所有方法,并进行重写 。
备注:多态实际上是一个父类有特定的属性,如动物有名称、年龄、所属科目 , 之后由子类去实现具体的,如猫,名称是猫 , 年龄是5岁,所属科目为猫科,然后狗同样有这些属性,只不过是值不同,这个就是一个多态的形式 。子类可以有无限多 , 在步骤三后面添加即可 。
java编写代码,定义一个4个元素的字符串数组,保存“Mike” , “jimmy”,“tommy” , “jerry”四个人名String[] names = {"Mike", "jimmy", "jimmy", "jimmy"};
String[] names = new String[4];
names[0]="Mike";
names[1]="jimmy";
names[2]="jimmy";
names[3]="jimmy";
有关java的出名人物有哪些Java 语言之父:詹姆斯·高斯林(James Gosling,1955年5月19日-,出生于加拿大)
测试驱动开发和 JUnit 的创办人:Kent Beck
Java 集合框架创办人:Joshua Bloch
Tomcat 创办人:James Duncan Davidson
Hibernate 创始人:Gavin King 。
Spring 创始人:Rod Johnson
Struts 创始人:Craig Mcclanahan
java代码汇成人物的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java整人代码、java代码汇成人物的信息别忘了在本站进行查找喔 。
推荐阅读
- 视频分为什么和什么形式,视频分哪些类型
- 荣耀30青春版升鸿蒙,荣耀30青春版升级鸿蒙系统教程
- p45电脑配什么cpu,p41配什么cpu
- 快手直播就卡,快手直播就卡怎么解决
- vb.net扫描仪 扫描仪的代码
- 怎么建小程序推荐学习,如何推荐小程序
- 竞速赛车游戏手游排行榜,竞速类赛车游戏手游
- oracle怎么写方法 oracle并且怎么写
- 沛喆微路由器怎么设置密码,沛喆路由器怎么登录