1.课设课题

组长: 沈宇涛

组员: 唐洪俊, 蔡丰骏

1.1 基于java swing开发的魂斗罗

可实现的功能: 人物的移动射击以及跳跃

人物武器的切换

人物的死亡与重生

敌人的行为设定

1.2 UML设计图

1.3 程序运行展示

uploading-image-813493.png

2.代码展示

2.1 重点代码展示

难度选择模块

独立一个窗口控制难度, 通过线程传参启动frame窗口

该部分代码运行结果如下:

图像绘制模块

绘制相关图片

键盘监听模块

根据玩家操控角色的操作, 判断是否做出相应的指令

角色的移动

private void heroMove()

{

if ((this.hero.state != 4) && (this.hero.state != 5))

if ((!this.hero.jumping) && (!this.jumpDown) && (!this.leftDown) && (!this.rightDown) && (!this.upDown) && (!this.downDown))

{

this.hero.state = 0;

if (this.hero.towardsLeft)

{

this.hero.direction = 6;

}

else if (this.hero.towardsRight)

{

this.hero.direction = 2;

}

}

else if (this.hero.jumping)

{

if (this.upDown)

{

this.hero.direction = 0;

this.hero.state = 2;

if ((this.leftDown) && (!this.showBossScene))

{

this.hero.direction = 7;

this.hero.towardsLeft = true;

this.hero.towardsRight = false;

if (this.hero.position.x > 8.0F + this.mapPosition)

this.hero.position.x -= this.heroSpeed;

}

else if ((this.rightDown) && (!this.showBossScene)) {

this.hero.direction = 1;

this.hero.towardsLeft = false;

this.hero.towardsRight = true;

moveForwardToRight();

}

}

else if (this.downDown)

{

this.hero.direction = 4;

this.hero.state = 2;

if (this.leftDown)

{

this.hero.direction = 5;

this.hero.towardsLeft = true;

this.hero.towardsRight = false;

if (this.hero.position.x > 8.0F + this.mapPosition)

this.hero.position.x -= this.heroSpeed;

}

else if ((this.rightDown) && (!this.showBossScene))

{

this.hero.direction = 3;

this.hero.towardsLeft = false;

this.hero.towardsRight = true;

moveForwardToRight();

}

}

else if ((this.leftDown) && (!this.showBossScene))

{

this.hero.direction = 6;

this.hero.state = 2;

this.hero.towardsLeft = true;

this.hero.towardsRight = false;

if (this.hero.position.x > 8.0F + this.mapPosition)

this.hero.position.x -= this.heroSpeed;

}

else if ((this.rightDown) && (!this.showBossScene)) {

this.hero.direction = 2;

this.hero.state = 2;

this.hero.towardsLeft = false;

this.hero.towardsRight = true;

moveForwardToRight();

}

}

else if ((this.leftDown) && (!this.showBossScene))

{

if ((this.jumpDown) && (isGrassLand(this.hero.position.x, this.hero.position.y + 1.0F)))

{

this.hero.direction = 6;

this.hero.state = 2;

this.hero.towardsLeft = true;

this.hero.towardsRight = false;

this.hero.jumping = true;

this.hero.jumpFinished = false;

}

else if (this.upDown) {

this.hero.state = 1;

this.hero.direction = 7;

this.hero.towardsLeft = true;

this.hero.towardsRight = false;

if (this.hero.position.x > 8.0F + this.mapPosition)

this.hero.position.x -= this.heroSpeed;

}

else if (this.downDown) {

this.hero.direction = 5;

this.hero.state = 1;

this.hero.towardsLeft = true;

this.hero.towardsRight = false;

if (this.hero.position.x > 8.0F + this.mapPosition)

this.hero.position.x -= this.heroSpeed;

}

else

{

this.hero.state = 1;

this.hero.direction = 6;

this.hero.towardsLeft = true;

this.hero.towardsRight = false;

if (this.hero.position.x > 8.0F + this.mapPosition)

this.hero.position.x -= this.heroSpeed;

}

}

else if ((this.rightDown) && (!this.showBossScene))

{

if ((this.jumpDown) && (isGrassLand(this.hero.position.x, this.hero.position.y + 1.0F))) {

this.hero.direction = 2;

this.hero.state = 2;

this.hero.towardsLeft = false;

this.hero.towardsRight = true;

this.hero.jumping = true;

this.hero.jumpFinished = false;

}

else if (this.upDown) {

this.hero.direction = 1;

this.hero.state = 1;

this.hero.towardsLeft = false;

this.hero.towardsRight = true;

moveForwardToRight();

}

else if (this.downDown)

{

this.hero.direction = 3;

this.hero.state = 1;

this.hero.towardsLeft = false;

this.hero.towardsRight = true;

moveForwardToRight();

}

else

{

this.hero.direction = 2;

this.hero.state = 1;

this.hero.towardsLeft = false;

this.hero.towardsRight = true;

moveForwardToRight();

}

}

else if (this.upDown) {

if ((this.jumpDown) && (isGrassLand(this.hero.position.x, this.hero.position.y + 1.0F))) {

this.hero.direction = 0;

this.hero.state = 2;

this.hero.jumpFinished = false;

this.hero.jumping = true;

}

else

{

this.hero.state = 0;

this.hero.direction = 0;

}

}

else if (this.downDown)

{

if (this.jumpDown)

{

this.hero.state = 1;

}

else

{

this.hero.state = 3;

if (this.hero.direction == 3) {

this.hero.direction = 2;

}

else if (this.hero.direction == 5) {

this.hero.direction = 6;

}

}

}

else if ((this.jumpDown) && (isGrassLand(this.hero.position.x, this.hero.position.y + 1.0F)))

{

this.hero.state = 2;

this.hero.jumping = true;

this.hero.jumpFinished = false;

}

}

通过对角色当前状态的属性进行判定, 以此为依据来控制角色的移动. 以及角色是否处于可站立的位置

地图移动模块(只可向右移动)

判定角色在屏幕中所处的位置, 当角色处于屏幕中央位置及向右移动时, 地图随之向右移动.

角色死亡后的出生点判断

角色死亡后将会出生在屏幕最左端的可站立的方块上

需要对角色位置进行判定的是是否通过移动方块, 若未通过, 佳能复活在移动方块左端的方块之上

角色的死亡判定(碰撞检测)

private void heroDeathCheck()

{

if ((this.hero.state != 4) && (this.hero.state != 5))

{

for (int i = 0; i < this.enemyBullets.size(); i++)

{

Bullet b = (Bullet)this.enemyBullets.get(i);

if ((b.position.x > this.hero.position.x - this.hero.width / 2 / 3) && (b.position.x < this.hero.position.x + this.hero.width / 2 / 3) &&

(b.position.y > this.hero.position.y - this.hero.height / 3) && (b.position.y < this.hero.position.y) &&

(this.hero.visible))

{

this.hero.state = 4;

this.hero.deathEventType = 0;

this.enemyBullets.remove(i);

}

}

for (int i = 0; i < this.enemys.size(); i++)

{

SimpleEnemy e = (SimpleEnemy)this.enemys.get(i);

if ((e.state != 4) && (e.state != 5) &&

(this.hero.position.x > e.position.x - this.hero.width / 2 / 3 - 11.0F) && (this.hero.position.x < e.position.x + 11.0F + this.hero.width / 2 / 3) &&

(this.hero.position.y > e.position.y - 26.0F) && (this.hero.position.y < e.position.y + this.hero.height / 3)) {

if (this.hero.visible) {

this.hero.state = 4;

this.hero.deathEventType = 2;

}

else {

e.state = 4;

}

}

}

for (int i = 0; i < this.bossChildren.size(); i++)

{

BossChild e = (BossChild)this.bossChildren.get(i);

if ((e.state != 4) && (e.state != 5) &&

(this.hero.position.x > e.position.x - this.hero.width / 2 / 3 - 15.0F) && (this.hero.position.x < e.position.x + 15.0F + this.hero.width / 2 / 3) &&

(this.hero.position.y > e.position.y - 10.0F) && (this.hero.position.y < e.position.y + this.hero.height / 3) &&

(this.hero.visible)) {

this.hero.state = 4;

this.hero.deathEventType = 2;

}

}

}

}

判断角色是否与子弹或敌人相撞, 或判定角色是否出界

可站立方块的设定

private void initGrassLands()

{

FloatPoint[] points =

{

new FloatPoint(1.0F, 110.0F), new FloatPoint(5.0F, 142.0F), new FloatPoint(8.0F, 174.0F),

new FloatPoint(9.0F, 206.0F), new FloatPoint(11.0F, 174.0F), new FloatPoint(13.0F, 142.0F), new FloatPoint(18.0F, 206.0F),

new FloatPoint(19.0F, 158.0F), new FloatPoint(27.0F, 110.0F), new FloatPoint(36.0F, 110.0F), new FloatPoint(42.0F, 78.0F),

new FloatPoint(43.0F, 206.0F), new FloatPoint(46.0F, 160.0F), new FloatPoint(49.0F, 142.0F), new FloatPoint(53.0F, 206.0F),

new FloatPoint(57.0F, 110.0F), new FloatPoint(59.0F, 174.0F), new FloatPoint(62.0F, 174.0F), new FloatPoint(63.0F, 78.0F),

new FloatPoint(65.0F, 158.0F), new FloatPoint(67.0F, 142.0F), new FloatPoint(69.0F, 110.0F), new FloatPoint(72.0F, 142.0F),

new FloatPoint(72.0F, 206.0F), new FloatPoint(73.0F, 174.0F), new FloatPoint(76.0F, 110.0F), new FloatPoint(77.0F, 78.0F),

new FloatPoint(77.0F, 206.0F), new FloatPoint(78.0F, 158.0F), new FloatPoint(80.0F, 110.0F), new FloatPoint(81.0F, 142.0F),

new FloatPoint(84.0F, 206.0F), new FloatPoint(88.0F, 174.0F), new FloatPoint(91.0F, 142.0F), new FloatPoint(93.0F, 110.0F),

new FloatPoint(93.0F, 206.0F), new FloatPoint(94.0F, 158.0F), new FloatPoint(98.0F, 142.0F), new FloatPoint(99.0F, 174.0F),

new FloatPoint(24.0F, 110.0F), new FloatPoint(33.0F, 110.0F)

};

int[] lengths = { 22, 3, 1, 2, 1, 2, 2, 3, 5, 8, 16, 3, 2, 7, 6, 7, 2, 2, 5, 1, 3, 2, 2, 1, 3, 2, 2, 1, 1, 2, 5, 3, 2, 2, 5, 22, 4, 1, 1, 1, 1 };

for (int i = 0; i < points.length - 2; i++) {

GrassLand gl = new GrassLand(points[i], lengths[i]);

this.grassLands[i] = gl;

}

GrassLand movingGrassLand1 = new GrassLand(new FloatPoint(24.0F, 110.0F), 1);

GrassLand movingGrassLand2 = new GrassLand(new FloatPoint(33.0F, 110.0F), 1);

movingGrassLand1.movingDirection = 3;

movingGrassLand2.movingDirection = 3;

this.grassLands[(this.grassLands.length - 2)] = movingGrassLand1;

this.grassLands[(this.grassLands.length - 1)] = movingGrassLand2;

}

private void drawNPC(Graphics2D g)

{

this.grassLands[(this.grassLands.length - 2)].drawMovingGrassLand(this.hero, 23.4F, 25.799999F, (int)this.mapPosition, this.backgroundSizeOfWidth, this, g);

this.grassLands[(this.grassLands.length - 1)].drawMovingGrassLand(this.hero, 32.400002F, 34.799999F, (int)this.mapPosition, this.backgroundSizeOfWidth, this, g);

}

private boolean isGrassLand(float x, float y) {

if (this.hero.towardsRight) {

for (int i = 0; i < this.grassLands.length; i++) {

if ((x > this.grassLands[i].position.x * 32.0F - 7.0F) && (x < (this.grassLands[i].position.x + this.grassLands[i].length) * 32.0F + 3.0F) &&

(y > this.grassLands[i].position.y) && (y < this.grassLands[i].position.y + 5.0F))

return true;

}

}

else if (this.hero.towardsLeft) {

for (int i = 0; i < this.grassLands.length; i++) {

if ((x > this.grassLands[i].position.x * 32.0F - 7.0F) && (x < (this.grassLands[i].position.x + this.grassLands[i].length) * 32.0F + 1.0F) &&

(y > this.grassLands[i].position.y) && (y < this.grassLands[i].position.y + 5.0F))

return true;

}

}

else if ((!this.hero.towardsLeft) && (!this.hero.towardsRight)) {

for (int i = 0; i < this.grassLands.length; i++) {

if ((x > this.grassLands[i].position.x * 32.0F) && (x < (this.grassLands[i].position.x + this.grassLands[i].length) * 32.0F) &&

(y > this.grassLands[i].position.y) && (y < this.grassLands[i].position.y + 5.0F))

return true;

}

}

return false;

}

规定角色可以站立而不死亡的位置

3.代码改进及任务的分配

3.1

在学习了借鉴的代码之后, 我们对其进行了一定程度的优化, 增加了一些原来没有的功能

1.增加了难度的设置, 让玩家有了更多的选择

2.使用了缓存的技术, 解决了闪屏的问题

3.增加了角色的死亡位置判定, 使其能在移动方块左方出生

3.2小组任务分配

沈宇涛: Frame窗口, 绘制动画, 地图设定, weapon类

唐洪俊: 人物类设计, 难度调整, 解决Java运行时的闪屏问题

蔡丰骏: Bulet类, 键盘监听, 素材绘制

4.课设总结

Java代码的团队合作不同于之前的c, 需要大家的配合, 规范的命名以及写法, 让我受益匪浅. 在这次课设中我锻炼了我自己, 也知道了自己的很多不足, 在编写的过程之中我们也遇到了很多困难, 在很多我不会的地方, 其他组员也对我伸出了援手. 在共同的努力之下完成了这次的课程设计.

java魂斗罗_java 魂斗罗相关推荐

  1. 用java的io做一个代码计数器,如何制作Java页面计数器_java

    大庆采油六厂采油工艺研究所 王兵 王波 常常逛WWW的人,一定对许多起始页上的计数器感兴趣.每当你光临某个站点的起始页时,它的计数器就很亲切地告诉你,从某年某月某日开始,你是第几位光临的人.你可能也想 ...

  2. 【源码+图片素材+详细教程】Java游戏开发_Java开发经典游戏飞翔的小鸟_飞扬的小鸟_Java游戏项目Flappy Bird像素鸟游戏_Java课程设计项目

    课程目标: 1.通过本课程的学习巩固Java的相关基础知识,例如循环判断,数组和集合的使用,对象的继承,接口的实现,窗口的创建,事件监听,图形绘制. 2.完成小鸟的移动,管道自动生成.碰撞死亡,计分系 ...

  3. 【源码+教程】Java桌球游戏_Java初级项目_Java练手项目_Java项目实战_Java游戏开发

    今天分享的Java开源游戏项目是桌球游戏,初学者也可以用来练习喔~课程详细讲解了一个桌球游戏的编写思路和流程,即使你刚学Java没多久,也可以跟随该教程视频完成属于你自己的桌球游戏!同时,还可以加深和 ...

  4. 【源码+项目部署】Java课程设计项目_Java人力资源管理系统

    对就业和毕业都有帮助的Java实战项目来咯--人力资源管理系统! 人力资源管理系统 |Java项目2小时上手编写_源码+数据库拿走不谢!Java实战项目_Java开发https://www.bilib ...

  5. LINUX装魂斗罗游戏,魂斗罗战甲1-支援形态装置搭配思路及攻略

    哈喽,老伙计们大家好,虽然真魂战甲这个机制已经出了有段时间了,但是今天我还是要给大家搞一个深度攻略,别问!问就是真男人必须开机甲!其实是很多小伙伴向我吐槽血隼副本和虚空副本太过变态,自己又不会配装.那 ...

  6. 魂动罗java源码_魂斗罗源码(VC版)

    [实例简介] 魂斗罗小游戏VC版代码,实测可编译,能正常 [实例截图] [核心代码] zdschong_8266141 └── contra_c ├── BGMS.dat ├── Release │  ...

  7. 我的世界java版匠魂_匠魂进化(Tinker's Evolution)|我的世界1.12.2版本

    匠魂进化(Tinker's Evolution)mod是匠魂的附属mod,赋予你的工具真正意义上的多样性. 它将拥有的更精美的熔炼方式,以及更加丰富的工具. 他将使你的匠魂工具能够带有其他mod的特性 ...

  8. java 怪物猎人ol_黑魂三还能中途改变性别吗 | 手游网游页游攻略大全

    发布时间:2016-07-22 "德拉诺之王"6.1版中痛苦术士应该怎么玩?下面99单机小编就分享一篇痛苦术黑魂雕文和各天赋适用性心得攻略,希望对大家有帮助. 前言: 一开始让我用 ...

  9. java高并发之魂:Synchronize

    synchronize在高并发领域可谓是元老级别了,博主最近整理了一下synchronize的用法,和简单的概念. 概念 对象锁:包括 方法锁(默认锁对象为this当前实例对象)和同步代码块锁(自己指 ...

最新文章

  1. 力扣(LeetCode)刷题,简单题(第5期)
  2. 静态方法里面不能调用非静态属性
  3. 单页vue路由router
  4. 状态空间模型中实际参数估计
  5. java jexl_利用Jexl实现数据库的计算公式在Java中执行
  6. 小学计算机教师德育工作计划,小学教师个人德育工作计划
  7. I00016 打印等腰三角形字符图案(底边在左或右)
  8. 解决本地工具无法连接服务器上的mysql的问题
  9. hdu 1709 (母函数,有些特殊)
  10. 春Phone计划 51cto沙龙郑州站活动
  11. Javascript小程序 向浏览者问好(转)
  12. 4.8 putsgets函数
  13. linux上热编译react,reactos终于被成功编译通过
  14. ASP.NET 2.0收集
  15. 20.创新与企业家精神——结论,企业家社会
  16. Sonya and Matrix Beauty
  17. 2022-2027年中国棉纱行业市场全景评估及发展战略规划报告
  18. MOV格式的视频应该如何转换成MP4格式的
  19. Oracle 11g Data Guard 物理备库快速配置指南(下)
  20. AS导入安卓源码步骤

热门文章

  1. show attend and tell 计算bleu分数(1到4)
  2. time库python_Python的time库的一些简单函数以及用法
  3. Spring配置数据源(连接池)
  4. Struts2-获取值栈对象与结构
  5. rabbitmq+redis在优化秒杀商品接口中的使用实例
  6. 【springboot异常处理】用异常信息枚举类处理异常,使用自定义异常封装异常对象,返回统一异常处理结果
  7. vue响应的res.data和res.data.data
  8. Spring-学习笔记06【Spring的新注解】
  9. 数据结构Java03【(时间、空间复杂度),排序(冒泡、快速、插入、希尔、选择、归并、基数、队列基数)】
  10. 13-NSPersistentContainer性能比较