java人物移动代码 java绘制一个能移动的圆

java课程设计题目及代码是什么?java课程设计题目及代码分别是:
1、题目:计算器 。设计内容是设计一个图形界面(GUI)的计算器应用程序,完成简单的算术运算 。
设计要求是设计的计算器应用程序可以完成家法、减法、乘法、除法和取余运算 。且有小数点、正负号、求倒数、退格和清零功能 。
2、代码:
数字按钮NumberButton类如下:
import java.awt.
import java.awt.event.
import javax.swing.
public class NumberButton extends Button.
{
int number.
public NumberButton(int number).
{
super("" number).
this.number=number.
setForeground(Color.blue).
}
public int getNumber().
{
return number;
}
}
其它java课程设计题目及代码是:
题目:华容道 。编写一个按钮的子类,使用该子类创建的对象代表华容道中的人物 。通过焦点事件控制人物颜色 , 当人物获得焦点时颜色为蓝色,当失去焦点时颜色为灰色 。
通过键盘事件和鼠标事件来实现曹操、关羽等人物的移动 。当人物上发生鼠标事件或键盘事件时 , 如果鼠标指针的位置是在人物的下方(也就是组件的下半部分)或按下键盘的“↓“键,该人物向下移动 。向左、向右和向上的移动原理类似 。
代码是:
String name[]={"曹操","关羽","张","刘","马","许","兵","兵","兵","兵"}.
for(int i=0;iname.length;i).
{
person[i]=new Person(i,name[i]).
person[i].addKeyListener(this).
person[i].addMouseListener(this).
//person[i].addFocusListener(new Person).
add(person[i]).
}
person[0].setBounds(104,54,100,100).
person[1].setBounds(104,154,100,50).
person[2].setBounds(54,154,50,100).
person[3].setBounds(204,154,50,100).
person[4].setBounds(54,54,50,100).
person[5].setBounds(204,54,50,100);
person[6].setBounds(54,254,50,50);
person[7].setBounds(204,254,50,50);
person[8].setBounds(104,204,50,50);
person[9].setBounds(154,204,50,50);
java游戏编程-怪物跟着人移动问题只需要让怪物得到当前人的坐标java人物移动代码,然后向这个方向移动就行java人物移动代码了 。比如说java人物移动代码你可以用一个方向向量来代表怪物的运行状态,如:
class MoveDirection{
int dx;
int dy;
}
根据java人物移动代码你人物和怪物的相对位置,计算出dx,dy 。比如说人物坐标是(300,300),怪物坐标是(400,200),怪物每次移动20 。那么dx = -20, dy = 20 。
然后你的怪物每次运动的时候增加方向向量就可以了 。
class Monster{
public void move(MoveDirection direction){
this.x= direction.dx;
this.y= direction.dy;
}
}
如果你的人和怪物是在复杂的地图当中也是一样的 。只不过要先判定是否可以向某个方向移动就行了 。
在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人物移动代码,在显示
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;
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代码实现人物在整个窗口中间不动 , 场景进行移动?类似于超级玛丽那样的import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class WalkMian extends JFrame implements KeyListener {
Image img;
Image back;
int x = 80, y = 450, dir = 0, num = 0;
// Main
public static void main(String args[]) {
new WalkMian();
}
// Constructor
WalkMian() {
super("Character");
img = getToolkit().getImage("c:\\IMAGE\\walk.png");
back = getToolkit().getImage("c:\\IMAGE\\back.jpg");
addKeyListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBackground(Color.gray);
setSize(800, 610);
setVisible(true);
}
// Paint
public void paint(Graphics g) {
int yoff;
g.drawImage(back, 0, 0, this);
if (img != null) {
yoff = 144;
g.drawImage(img, x, y, x144, y144, 144, -144 144*dir, yoff144, 144*dir,
this);
}
}
求助一个关于判断人物移动方向的Java算法给你一个函数java人物移动代码,计算在两线所在方向上离第一个点指定距离java人物移动代码的点的函数
// 在两点所在直线上,以从startPoint到endPoint为方向,离startPoint的距离disToStartPoint的点
public static Point2D extentPoint(Point2D startPoint, Point2D endPoint, double disToStartPoint) {
double disX = endPoint.getX() - startPoint.getX();
double disY = endPoint.getY() - startPoint.getY();
double dis = Math.sqrt(disX * disXdisY * disY);
double sin = (endPoint.getY() - startPoint.getY()) / dis;
double cos = (endPoint.getX() - startPoint.getX()) / dis;
double deltaX = disToStartPoint * cos;
double deltaY = disToStartPoint * sin;
return new Point2D.Double(startPoint.getX()deltaX, startPoint.getY()deltaY);
}
Java 鼠标控制人物移动 , 地图随人物移动去学习A星寻路,可以得到最短路径,其中也包括java人物移动代码了绕开障碍物java人物移动代码的代码,然后就是动画的图片切换了,如果说要地图跟随主角移动,那个应该是滚屏操作,也就是说java人物移动代码你主角往右走,超过窗口或者屏幕(全屏)坐标一半的时候,地图整个往左移动,速度和主角的一样就出来效果了 。如果你看不懂A星的话,那咂就给你一段BFS的C语言代码,自己转换成JAVA代码写法(就是改些关键字,有不少经典的游戏算法都来自C/C)就可以了,这个是简化版的A星寻路,一样可以找到最近的路径,你把path 这个路径记录下来再换算成像素位置就可以得到行走的具体步伐了...
#include "stdafx.h"
#include iostream
using namespace std;
const int rows = 10;//行数
const int cols = 10;//列数
const int nummax = 4;//每一步,下一步可以走的方向java人物移动代码:4个
//四种移动方向(左、右、上、下)对x、y坐标的影响
//x坐标java人物移动代码:竖直方向,y坐标:水平方向
const char dx[nummax] = {0,0,-1,1};
const char dy[nummax] = {-1,1,0,0};
//障碍表
char block[rows][cols] = {
0,1,0,0,0,0,0,0,0,0,
0,1,1,0,1,1,1,0,0,0,
0,0,0,0,0,0,0,0,0,0,
1,0,1,0,0,0,0,0,0,0,
0,0,0,0,0,0,1,1,1,0,
0,1,0,0,0,0,1,0,0,0,
0,0,0,0,0,0,1,1,0,1,
0,1,0,0,0,1,0,1,0,1,
0,1,1,1,0,0,0,1,0,1,
0,0,0,0,0,0,0,0,0,0,
};
char block2[rows][cols] = {
0,1,0,0,0,0,0,0,0,0,
0,1,1,0,1,1,1,0,0,0,
0,0,0,0,0,0,0,0,0,0,
1,0,1,0,0,0,0,0,0,0,
0,0,0,0,0,0,1,1,1,0,
0,1,0,0,0,0,1,0,0,0,
0,0,0,0,0,0,1,1,0,1,
0,1,0,0,0,1,0,1,0,1,
0,1,1,1,0,0,0,1,0,1,
0,0,0,0,0,0,0,0,0,0,
};
char path[rows][cols] = {0};//记录路径
int startX = 0,startY = 0;//起始点坐标
int endX = rows - 1,endY = cols - 1;//目标点坐标
//保存节点位置坐标的数据结构
typedef struct tagQNode{
char x,y;
int parentNode;//父节点索引
}QNode;
//打印路径
void printPath()
{
cout""endl;
for (int i = 0;irows;i)
{
for (int j = 0;jcols;j)
{
if (1 == path[i][j])
{
cout"♀";
}
else if(block2[i][j]==0)
cout"∷";
else if(block2[i][j]==1)
cout"■";
}
coutendl;
}
coutendl;
coutendl;
}
void BFS()
{
int num = rows * cols;
//利用数组来模拟队列
QNode *queue = (QNode *)malloc(num * sizeof(QNode));
//起始点入队列
queue[0].x = queue[0].y = 0;
queue[0].parentNode = -1;//起始点没有父节点
int front = 0,rear = 1;//队列的头和尾
while(front != rear)//队列不为空
{
for (int i = 0;inummax;i)
{
char nextX,nextY;//下一步的坐标
nextX = queue[front].xdx[i];
nextY = queue[front].ydy[i];
//下一个节点可行
if (nextX = 0nextXrowsnextY = 0nextYcols0 == block[nextX][nextY])
{
//寻找到目标点
if (nextX == endXnextY == endY)
{
//生成路径
path[nextX][nextY] = 1;
int ParIn = front;
while(ParIn != -1)
{
path[queue[ParIn].x][queue[ParIn].y] = 1;
ParIn = queue[ParIn].parentNode;
}
//printPath();
}
//入栈
queue[rear].x = nextX;
queue[rear].y = nextY;
queue[rear].parentNode = front;
rear;
//标记此点已被访问
block[nextX][nextY] = 1;
}
}
front;
}
free(queue);
}
int _tmain(int argc, _TCHAR* argv[])
{
BFS();
printPath();
system("pause");
return 0;
}
【java人物移动代码 java绘制一个能移动的圆】关于java人物移动代码和java绘制一个能移动的圆的介绍到此就结束了 , 不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读