Java怎么做超级马里奥3d怎么下载奥

航行在黑客道路上的小白
马里奥是站在游戏界顶峰的超人气多面角色。现在已经较热门的是Wii版课程简介1、超级马里奥01_游戏演示以及知识准备)&2、超级马里奥02_游戏中各个类的关系设计3、超级马里奥03_第一部分_开发窗体类与静态类4、超级马里奥03_第二部分_开发窗体类与静态类5、超级马里奥04_开发游戏场景类6、超级马里奥05_第一部分_开发场景中的物体_017、超级马里奥05_第二部分_开发场景中的物体_028、超级马里奥06_第一部分_开发Mario类019、超级马里奥06_第二部分_开发Mario类0210、超级马里奥06_第三部分_开发Mario类0311、超级马里奥06_第四部分_开发Mario类0412、超级马里奥06_第五部分_开发Mario类0513、超级马里奥06_第一部分_开发敌人类0114、超级马里奥07_第二部分_开发敌人类0215、超级马里奥07_第三部分_开发敌人类0316、超级马里奥07_第四部分_开发敌人类0417、超级马里奥08_第一部分_游戏的开始与结束18、超级马里奥08_第二部分_游戏的开始与结束19、超级马里奥08_第三部分_游戏的开始与结束下载地址:
链接:&&密码: itue解压密码:
很喜欢此文字
&&&|&Powered by8603人阅读
Java基础(16)
自己修改别人的程序,
本来是一个全屏游戏,我把它改正窗口的,不过只有部分功能
Hufan.java
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedI
import java.io.*;
import java.util.V
public class Hufan extends JFrame implements Runnable{
public static void main(String[] args) {
// TODO Auto-generated method stub
new Hufan();
public Hufan(){
manager=new Manager();
hp=new HuPanel();
new Thread(this).start();
new Thread(hp).start();
this.add(hp);
this.addKeyListener(hp);
this.setTitle(&Java超级玛丽&);
this.setSize(800, 700);
this.setLocation(500, 200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
public void run() {
// TODO Auto-generated method stub
while(true){
hp.repaint();
manager.updateCreature(hp.player, 25);
Thread.sleep(20);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
class HuPanel extends JPanel implements KeyListener,Runnable{
BufferedImage bground,playerI
P//玛丽对象
float offsetX;
float offsetY;
int mapWidth = Manager.newMap.getWidth()*64;//地图的宽度
GameAction[] keyActions = new GameAction[600];//按键数组
GameAction moveL//左移动按键
GameAction moveR//右移动按键
GameA//跳跃
public HuPanel(){
player = new Player();
moveLeft = new GameAction(&moveLeft&);
moveRight = new GameAction(&moveRight&);
jump = new GameAction(&jump&);
keyActions[KeyEvent.VK_LEFT] = moveL
keyActions[KeyEvent.VK_RIGHT] = moveR
keyActions[KeyEvent.VK_SPACE] =
bground=ImageIO.read(new File(&background.png&));
playerImg=ImageIO.read(new File(&player1.png&));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
public void paint(Graphics g){
super.paint(g);
//画界面时,都是相对坐标,
offsetX = 400 -player.x-64;//JFrame宽度的一半减去玛丽的坐标,再减去玛丽自己的宽度。
offsetX = Math.min(offsetX, 0);//返回两个 double 值中较小的一个。
offsetX = Math.max(offsetX, 800 -mapWidth);//返回两个 double 值中较大的一个。
offsetY = 600 -Manager.newMap.getHeight()*64;
if (bground != null) {
float x = offsetX * (800 - 1600)/ (800 - mapWidth);
g.drawImage(bground, (int)x, 0, null);
//画地板砖
int firstTileX =(int)-offsetX/64;
int lastTileX = (int)firstTileX +800/64 + 1;
for (int y=0; y&Manager.newMap.getHeight(); y++) {
for (int x=firstTileX; x &= lastTileX; x++) {
Image image = Manager.newMap.getTile(x, y);
if (image != null) {
g.drawImage(image,x*64 + (int)offsetX,y*64 + (int)offsetY,null);
g.drawImage(playerImg,(int)player.x + (int)offsetX, (int)player.y + (int)offsetY,null);
private GameAction getKeyAction(KeyEvent e) {
int keyCode = e.getKeyCode();
if (keyCode & keyActions.length) {
return keyActions[keyCode];
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
//从keyActions数组得到按键对象
GameAction gameAction = this.getKeyAction(e);
if (gameAction != null) {
gameAction.press();
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
GameAction gameAction = getKeyAction(e);
if (gameAction != null) {
gameAction.release();
public void keyTyped(KeyEvent e) {}
public void run() {//检测哪些键被按下
// TODO Auto-generated method stub
while(true){
float velocityX = 0;
if (moveLeft.isPressed()) {
velocityX-=0.5f;
if (moveRight.isPressed()) {
velocityX+=0.5f;
if (jump.isPressed()) {
player.jump(false);
player.dx=velocityX;
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
GameAction.java
* @author Administrator
public class GameAction {
public static final int NORMAL = 0;//正常的
int DETECT_INITAL_PRESS_ONLY = 1;//检测初步按
int RELEASED = 0;//释放
int PRESSED = 1;//按下
int WAITING_FOR_RELEASE = 2;//等待释放
//行为;态度;(机器等的)运转状态;(事物的)反应
//按键次数量
public GameAction(String name) {
this.name=
public synchronized void press() {
public synchronized void press(int amount) {
if (state != WAITING_FOR_RELEASE) {
this.amount+=
state = PRESSED;
public synchronized boolean isPressed() {
return (getAmount() != 0);
public synchronized void release() {
state = RELEASED;
public synchronized int getAmount() {
int retVal =
if (retVal != 0) {
if (state == RELEASED) {
amount = 0;
else if (behavior == DETECT_INITAL_PRESS_ONLY) {
state = WAITING_FOR_RELEASE;
amount = 0;
return retV
Manager.java
import java.awt.*;
import java.io.*;
import java.util.*;
import javax.swing.ImageI
* @author Administrator
public class Manager{
ArrayL//地板砖图像的集合
ArrayL//地图的每行数据
int width = 0;//地图的宽
int height = 0;//地图的高
BufferedR//缓存地图文本
static float GRAVITY = 0.0015f;//重力
Point pointCache = new Point();
static TileMap newM//地图对象
public Manager(){
lines = new ArrayList();
tiles = new ArrayList();
//读取地图
reader = new BufferedReader(new FileReader(&map1.txt&));
while(true){
String line = reader.readLine();//读取一行
if (line == null) {//如果读取的一行为空
reader.close();
lines.add(line);
//主要是为了读取最下面一行的个数,也就是地图和宽度
width = Math.max(width, line.length());// 取两者最大的数
//读取地板砖图片到内存
char cha = 'A';
while (true) {
String name = &tile_& + cha + &.png&;
File file = new File(name);
if (!file.exists()) {//读取的文件不存在,就退出循环
tiles.add(loadImage(name));//将图片加到集合
height = lines.size();
newMap = new TileMap(width, height);
//设置地图中。每个位置的数据
for (int y=0; y& y++) {//循环每一列
String line = (String)lines.get(y);
for (int x=0; x&line.length(); x++) {//循环每一行
char ch = line.charAt(x);//返回指定索引处的 char 值。
//检查字符是否有效
int tile = ch - 'A';
//得到的字母是否大于A,并且小于地板图片的个数 时,说明字符有效
if (tile &= 0 && tile & tiles.size()) {
newMap.setTile(x, y, (Image)tiles.get(tile));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
public Image loadImage(String name) {
String filename =
return new ImageIcon(filename).getImage();
public void updateCreature(Player player,long elapsedTime)
player.dy=player.dy+GRAVITY * elapsedT
// change x 改变×
float dx = player.//x速度
float oldX = player.x;//x坐标
float newX = oldX + dx * elapsedT//
Point tile =getTileCollision(player, newX, player.y);
if (tile == null) {
player.x=newX;
// line up with the tile boundary线与瓦片边界
if (dx & 0) {
player.setX(tile.x/64-80);
}else if (dx & 0) {
player.setX((tile.x + 1)64);
player.collideHorizontal();
// change y
float dy = player.
float oldY = player.y;
float newY = oldY + dy * elapsedT
tile = getTileCollision(player, player.x, newY);
if (tile == null) {
player.y=newY;
// line up with the tile boundary
//线与瓦片边界
if (player.dy & 0) {
player.setY(tile.y/64-64);
else if (player.dy & 0) {
player.setY((tile.y + 1)/64);
player.collideVertical();
//获取瓷砖碰撞
public Point getTileCollision(Player sprite,float newX, float newY)
float fromX = Math.min(sprite.x, newX);
float fromY = Math.min(sprite.y, newY);
float toX = Math.max(sprite.x, newX);
float toY = Math.max(sprite.y, newY);
// get the tile locations
//获取瓷砖的位置
int fromTileX = (int)fromX/64;
int fromTileY =(int)fromY/64;
int toTileX =(int)(toX + 80 - 1)/64;
int toTileY =(int)(toY + 64 - 1)/64;
// check each tile for a collision
//检查每个瓷砖的碰撞
for (int x=fromTileX; x&=toTileX; x++) {
for (int y=fromTileY; y&=toTileY; y++) {
if (x & 0 || x &= newMap.getWidth() ||newMap.getTile(x, y) != null){
// collision found, return the tile
//碰撞发现,返回瓦
pointCache.setLocation(x, y);
return pointC
// no collision found
//发现无碰撞
Player.java
import java.awt.P
public class Player{
//玛丽的X坐标
//玛丽的X速度
float JUMP_SPEED = -.95f;//跳跃速度
boolean onG//在地面上
float GRAVITY = 0.002f;//重力
public Player(){
public void collideHorizontal() {
//垂直碰撞
public void collideVertical() {
// check if collided with ground
//检查如果撞到地面
if (dy & 0) {
onGround =
dy=0;//设置Y速度为0
public void jump(boolean forceJump) {
if (onGround || forceJump) {
onGround =//false为不在地面上
dy=JUMP_SPEED;
TileMap.java
* 地板砖地图类
import java.awt.I
import java.util.*;
public class TileMap {
Image[][]//图片数组
public TileMap(int width, int height) {
tiles = new Image[width][height];
public void setTile(int x, int y, Image tile) {
tiles[x][y] =
public Image getTile(int x, int y) {
if (x & 0 || x &= getWidth() ||y & 0 || y &= getHeight()){
return tiles[x][y];
public int getWidth() {
return tiles.
public int getHeight() {
return tiles[0].
& & & & & & & & & & & & & & & & & & &
& & & & & & & & & & & IIIIIII & & &IIIIIII&
& & & & & & & & & & & & & & & & & & & & & & & & & & & & & &&
& & & & & & & & & & & & & & & & & & & & & & & & & & &EF
& & & & & & & & &EF & & & & & & & & & & & & & & & & EGD
& & & & EF & & & CD & & & & & & & & & & & & & & & &EGAD & & &
BBBBBBBBGHBBBBBBBGHBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGAAHBBBBBBBBBBB
background.png
player1.png
tile_A.png
tile_B.png
tile_C.png
tile_D.png
tile_E.png
tile_F.png
tile_G.png
tile_H.png
tile_I.png
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:379545次
积分:3874
积分:3874
排名:第8979名
原创:81篇
评论:85条
(3)(9)(3)(5)(2)(1)(1)(8)(1)(1)(2)(4)(2)(1)(2)(1)(1)(1)(1)(2)(2)(2)(1)(1)(5)(1)(2)(1)(2)(1)(1)(1)(1)(1)(2)(6)
(window.slotbydup = window.slotbydup || []).push({
id: '4740887',
container: s,
size: '250,250',
display: 'inlay-fix'湖北晨风网络科技有限公司 版权所有

我要回帖

更多关于 超级马里奥 的文章

 

随机推荐