package org.wn.mario;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
public class BackGround {
//当前场景图片
private BufferedImage bgImage = null;
//场景顺序
private int sort;
//是否为最后的场景
private boolean flag;
//游戏结束标记
private boolean isOver = false;
//定义降旗结束
private boolean isDown = false;
//用集合保存敌人
private List<Enemy> allEnemy = new ArrayList<Enemy>();
//用集合保存障碍物
private List<Obstruction> allObstruction = new ArrayList<Obstruction>();
//被消灭的敌人
private List<Enemy> removeEnemy = new ArrayList<Enemy>();
//被消灭的障碍物
private List<Obstruction> removeObstruction = new ArrayList<Obstruction>();
//敌人开始移动
public void enemyStartMove(){
for(int i=0;i<this.allEnemy.size();i++){
this.allEnemy.get(i).startMove();
}
}
//构造方法
public BackGround(int sort,boolean flag){
this.sort = sort;
this.flag = flag;
if(flag){
bgImage = StaticValue.endImage;
}else{
bgImage = StaticValue.bgImage;
}
//第一个场景
if(sort==1){
for(int i=0;i<15;i++){
this.allObstruction.add(new Obstruction(i*60, 540, 9,this));
}
//绘制砖块和问号
this.allObstruction.add(new Obstruction(120, 360, 4,this));
this.allObstruction.add(new Obstruction(300, 360, 0,this));
this.allObstruction.add(new Obstruction(360, 360, 4,this));
this.allObstruction.add(new Obstruction(420, 360, 0,this));
this.allObstruction.add(new Obstruction(480, 360, 4,this));
this.allObstruction.add(new Obstruction(540, 360, 0,this));
this.allObstruction.add(new Obstruction(420, 180, 4,this));
//绘制水管
this.allObstruction.add(new Obstruction(660, 540, 6,this));
this.allObstruction.add(new Obstruction(720, 540, 5,this));
this.allObstruction.add(new Obstruction(660, 480, 8,this));
this.allObstruction.add(new Obstruction(720, 480, 7,this));
//隐藏砖块
this.allObstruction.add(new Obstruction(660, 300, 3,this));
//绘制怪物
this.allEnemy.add(new Enemy(600, 480, true, 1,this));
this.allEnemy.add(new Enemy(690, 540, true, 2, 420, 540,this));
}
//第二个场景
if(sort==2){
for(int i=0;i<15;i++){
if(i != 9 && i != 10 && i != 11 ){
this.allObstruction.add(new Obstruction(i*60, 540, 9,this));
}
}
//绘制水管
this.allObstruction.add(new Obstruction(60, 540, 6,this));
this.allObstruction.add(new Obstruction(120, 540, 5,this));
this.allObstruction.add(new Obstruction(60, 480, 6,this));
this.allObstruction.add(new Obstruction(120, 480, 5,this));
this.allObstruction.add(new Obstruction(60, 420, 8,this));
this.allObstruction.add(new Obstruction(120, 420, 7,this));
this.allObstruction.add(new Obstruction(300, 540, 6,this));
this.allObstruction.add(new Obstruction(360, 540, 5,this));
this.allObstruction.add(new Obstruction(300, 480, 6,this));
this.allObstruction.add(new Obstruction(360, 480, 5,this));
this.allObstruction.add(new Obstruction(300, 420, 6,this));
this.allObstruction.add(new Obstruction(360, 420, 5,this));
this.allObstruction.add(new Obstruction(300, 360, 8,this));
this.allObstruction.add(new Obstruction(360, 360, 7,this));
//绘制怪物
this.allEnemy.add(new Enemy(330, 360, true, 2, 300, 420,this));
}
//第三个场景
if(sort==3){
for(int i=0;i<15;i++){
this.allObstruction.add(new Obstruction(i*60, 540, 9,this));
}
//绘制砖块和问号
this.allObstruction.add(new Obstruction(180, 360, 4,this));
this.allObstruction.add(new Obstruction(420, 360, 4,this));
this.allObstruction.add(new Obstruction(660, 360, 4,this));
this.allObstruction.add(new Obstruction(420, 180, 4,this));
}
//第四个场景
if(sort==4){
for(int i=0;i<15;i++){
if(i<2||i>12){
this.allObstruction.add(new Obstruction(i*60, 540, 9,this));
}
}
this.allObstruction.add(new Obstruction(120, 360, 0,this));
this.allObstruction.add(new Obstruction(180, 360, 0,this));
this.allObstruction.add(new Obstruction(300, 180, 0,this));
this.allObstruction.add(new Obstruction(360, 180, 0,this));
this.allObstruction.add(new Obstruction(420, 180, 0,this));
this.allObstruction.add(new Obstruction(480, 180, 0,this));
this.allObstruction.add(new Obstruction(540, 180, 0,this));
this.allObstruction.add(new Obstruction(660, 360, 0,this));
this.allObstruction.add(new Obstruction(720, 360, 0,this));
}
//第五个场景
if(sort==5){
int z = 2;
for(int i=0;i<15;i++){
if(i%2==0 && i<7){
this.allObstruction.add(new Obstruction(i*60, 540-(i*60), 9,this));
for(int x=i;x>0;x--){
this.allObstruction.add(new Obstruction(i*60, 540-(x*60)+60, 10,this));
}
}
if(i%2==0 && i>7){
this.allObstruction.add(new Obstruction(i*60, 540-((i-z)*60), 9,this));
for(int x=i-z;x>0;x--){
this.allObstruction.add(new Obstruction(i*60, 540-(x*60)+60, 10,this));
}
z+=4;
}
}
}
//第六个场景
if(sort==6){
for(int i=0;i<15;i++){
this.allObstruction.add(new Obstruction(i*60, 540, 9,this));
}
this.allObstruction.add(new Obstruction(480, 480, 1,this));
this.allObstruction.add(new Obstruction(480, 420, 1,this));
this.allObstruction.add(new Obstruction(480, 360, 1,this));
this.allObstruction.add(new Obstruction(480, 300, 1,this));
this.allObstruction.add(new Obstruction(480, 240, 1,this));
this.allObstruction.add(new Obstruction(480, 180, 1,this));
this.allObstruction.add(new Obstruction(540, 240, 1,this));
this.allObstruction.add(new Obstruction(540, 300, 1,this));
this.allObstruction.add(new Obstruction(540, 360, 1,this));
this.allObstruction.add(new Obstruction(540, 420, 1,this));
this.allObstruction.add(new Obstruction(540, 480, 1,this));
this.allObstruction.add(new Obstruction(600, 300, 1,this));
this.allObstruction.add(new Obstruction(600, 360, 1,this));
this.allObstruction.add(new Obstruction(600, 420, 1,this));
this.allObstruction.add(new Obstruction(600, 480, 1,this));
this.allObstruction.add(new Obstruction(660, 360, 1,this));
this.allObstruction.add(new Obstruction(660, 420, 1,this));
this.allObstruction.add(new Obstruction(660, 480, 1,this));
this.allObstruction.add(new Obstruction(720, 420, 1,this));
this.allObstruction.add(new Obstruction(720, 480, 1,this));
this.allObstruction.add(new Obstruction(780, 480, 1,this));
//通关要点,隐形砖块
this.allObstruction.add(new Obstruction(300, 360, 3,this));
}
//第七个场景
if(sort==7){
for(int i=0;i<15;i++){
this.allObstruction.add(new Obstruction(i*60, 540, 9,this));
}
this.allObstruction.add(new Obstruction(490, 180, 11,this));
this.allObstruction.add(new Obstruction(520, 480, 2,this));
//地上障碍物
this.allObstruction.add(new Obstruction(240, 360, 1,this));
this.allObstruction.add(new Obstruction(240, 420, 1,this));
this.allObstruction.add(new Obstruction(240, 480, 1,this));
this.allObstruction.add(new Obstruction(180, 420, 1,this));
this.allObstruction.add(new Obstruction(180, 480, 1,this));
this.allObstruction.add(new Obstruction(120, 480, 1,this));
}
}
//重置方法,重置障碍物和敌人
public void reset(){
//将移除的障碍物和敌人还原
this.allEnemy.addAll(this.removeEnemy);
this.allObstruction.addAll(this.removeObstruction);
//调用障碍物和敌人的重置方法
for(int i=0;i<this.allEnemy.size();i++){
this.allEnemy.get(i).reset();
}
for(int i=0;i<this.allObstruction.size();i++){
this.allObstruction.get(i).reset();
}
}
public BufferedImage getBgImage() {
return bgImage;
}
public List<Obstruction> getAllObstruction() {
return allObstruction;
}
public List<Obstruction> getRemoveObstruction() {
return removeObstruction;
}
public int getSort()
没有合适的资源?快使用搜索试试~ 我知道了~
Java实现超级马里奥小游戏
共94个文件
png:66个
jpg:12个
class:6个
1 下载量 138 浏览量
2023-12-21
22:09:35
上传
评论
收藏 2.22MB ZIP 举报
温馨提示
源代码、背景
资源推荐
资源详情
资源评论
收起资源包目录
超级马里奥.zip (94个子文件)
新建文件夹
.classpath 301B
.settings
org.eclipse.jdt.core.prefs 598B
src
flower1.png 7KB
triangle2.png 10KB
ob1.png 6KB
背景2.jpg 100KB
turtle5.png 7KB
ob9.png 4KB
10.png 8KB
9.png 7KB
ob11.png 7KB
3.png 8KB
triangle3.png 5KB
ob3.png 5KB
ob7.png 3KB
ob10.png 9KB
start.jpg 582KB
1.png 7KB
ob8.png 4KB
turtle2.png 7KB
flower2.png 6KB
ob2.png 8KB
6.png 7KB
firststageend.jpg 91KB
turtle1.png 7KB
turtle3.png 7KB
over.png 8KB
5.png 8KB
4.png 7KB
8.png 8KB
firststage.jpg 33KB
ob5.png 7KB
turtle4.png 7KB
7.png 8KB
背景3.jpg 52KB
2.png 8KB
triangle1.png 10KB
org
wn
mario
Mario.java 7KB
Obstruction.java 1KB
MyFrame.java 4KB
BackGround.java 8KB
StaticValue.java 2KB
Enemy.java 4KB
ob12.png 5KB
背景4.jpg 114KB
ob6.png 3KB
ob4.png 3KB
bin
flower1.png 7KB
收藏夹.lnk 327B
triangle2.png 10KB
ob1.png 6KB
背景2.jpg 100KB
turtle5.png 7KB
ob9.png 4KB
10.png 8KB
9.png 7KB
ob11.png 7KB
3.png 8KB
triangle3.png 5KB
ob3.png 5KB
ob7.png 3KB
ob10.png 9KB
start.jpg 582KB
1.png 7KB
ob8.png 4KB
turtle2.png 7KB
flower2.png 6KB
ob2.png 8KB
6.png 7KB
firststageend.jpg 91KB
turtle1.png 7KB
turtle3.png 7KB
over.png 8KB
5.png 8KB
4.png 7KB
8.png 8KB
firststage.jpg 73KB
ob5.png 7KB
turtle4.png 7KB
7.png 8KB
背景3.jpg 52KB
2.png 8KB
triangle1.png 10KB
org
wn
mario
MyFrame.class 5KB
Enemy.class 4KB
Mario.class 6KB
StaticValue.class 3KB
BackGround.class 6KB
Obstruction.class 2KB
ob12.png 5KB
背景4.jpg 114KB
ob6.png 3KB
ob4.png 3KB
.project 381B
共 94 条
- 1
资源评论
♟彦♟
- 粉丝: 77
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功