计算机实习报告

上传人:壹****1 文档编号:464362113 上传时间:2023-09-02 格式:DOCX 页数:42 大小:568.74KB
返回 下载 相关 举报
计算机实习报告_第1页
第1页 / 共42页
计算机实习报告_第2页
第2页 / 共42页
计算机实习报告_第3页
第3页 / 共42页
计算机实习报告_第4页
第4页 / 共42页
计算机实习报告_第5页
第5页 / 共42页
点击查看更多>>
资源描述

《计算机实习报告》由会员分享,可在线阅读,更多相关《计算机实习报告(42页珍藏版)》请在金锄头文库上搜索。

1、计算机实习报告学院:班级:学号:姓名: 1、题目要求:作一个两辆赛车比赛的游戏,要求可以用A,S,D,W和小键盘的上下左右键控制小汽车的运行方向进行比赛。设计方案 :所用软件为Adobe Flash CS5设置控制键,通过按键对小车进行控制,在控制的同时判断小车的位置使其行驶在跑道上,当有一辆赛车跑完三圈时,比赛结束,并输出比赛结果。开始流程图:方向键控制对两小车是否碰到跑道进行判断小车停止Y N判断比赛是否完成NY显示比赛的输赢结束设计过程:1. 首先要让赛车能够动起来。让赛车运动不是最难的一部分首先在defs的图层里打开actions窗口,设定好赛车的加速度,减速度,最大速度,以及圈数等基

2、本常量值。 Flash中使用的的是经典的直角坐标系,所以我们在计算赛车实际的速度时要把速度分解到X轴和Y轴上,得到X分量和Y分量(如下图)。计算上述分量就要知道角度,Flash中对角度和弧度要进行转化:angle_radians = angle_degrees *(PI/180)。再加上函数,就可以让我们的车动起来。这里我用了两个类似的函数来分别控制两辆赛车,他们只有控制方向的按键不同的。2还需要处理碰撞的问题。碰撞时整个赛车游戏中十分重要的一部分,因为我们必须把赛车限制在跑道内,并且让玩家可以在最快的时间内完成比赛。在车的四边分别设置一个点,用来检测它是否碰到了不可进入的区域。如果碰到了赛道

3、,那么赛车的速度将会降低,并且赛车的方向会得到纠正。3处理圈数和计时的问题。设置了两个函数来分别计算总的比赛时间setTimes和单圈最好成绩setBestLap。当赛车连续经过两次检查点checkpoint时则完成一圈,当完成三圈时游戏结束,显示游戏结果。源代码:Defs:car1.code = player;car2.code = playertotalLaps = 3;acceleration = 0.4;speedDecay = 0.96;rotationStep = 10;maxSpeed = 10;backSpeed = 1;currentCheckpoint1 = 1;curre

4、ntCheckpoint2 = 1;currentLap1 = 0;currentLap2 = 0;checkpoints = 2;currentLapTXT = 1/3;Actions:function step(who) if (_rootcar+who.code = player) if (thisspeed+who0.3) thisspeed+who *= _root.speedDecay; else thisspeed+who = 0;/赛车控制按键的设置/加速if (Key.isDown(Key.UP) & thisspeed+who0.3) _rootcar+who._rotat

5、ion -= _root.rotationStep*(thisspeed+who/_root.maxSpeed);/右转 if (Key.isDown(Key.RIGHT) & Math.abs(thisspeed+who)0.3) _rootcar+who._rotation += _root.rotationStep*(thisspeed+who/_root.maxSpeed);thisrotation+who = _rootcar+who._rotation;/计算赛车X方向和Y方向的速度分量thisspeedx+who = Math.sin(thisrotation+who*(Math

6、.PI/180)*thisspeed+who;thisspeedy+who = Math.cos(thisrotation+who*(Math.PI/180)*thisspeed+who*-1;/让这两个分量具体的作用到赛车的位置上_rootcar+who._x += thisspeedx+who;_rootcar+who._y += thisspeedy+who;/碰撞/定义四个碰撞点的位置_rootcar+who.pointLeft = x:-20, y:0;_rootcar+who.localToGlobal(_rootcar+who.pointLeft);_rootcar+who.po

7、intRight = x:20, y:0;_rootcar+who.localToGlobal(_rootcar+who.pointRight);_rootcar+who.pointFront = x:0, y:-25;_rootcar+who.localToGlobal(_rootcar+who.pointFront);_rootcar+who.pointBack = x:0, y:25;_rootcar+who.localToGlobal(_rootcar+who.pointBack);/简写上述变量thislpx+who = _rootcar+who.pointLeft.x;thislp

8、y+who = _rootcar+who.pointLeft.y;thisrpx+who = _rootcar+who.pointRight.x;thisrpy+who = _rootcar+who.pointRight.y;thisfpx+who = _rootcar+who.pointFront.x;thisfpy+who = _rootcar+who.pointFront.y;thisbpx+who = _rootcar+who.pointBack.x;thisbpy+who = _rootcar+who.pointBack.y;/检查是否发生碰撞if (_root.terrain.hi

9、tTest(thislpx+who, thislpy+who, true) _rootcar+who._rotation += 5;thisspeed+who *= 0.85;if (_root.terrain.hitTest(thisrpx+who, thisrpy+who, true) _rootcar+who._rotation -= 5;thisspeed+who *= 0.85;if (_root.terrain.hitTest(thisfpx+who, thisfpy+who, true) thisspeed+who = -1;if (_root.terrain.hitTest(t

10、hisbpx+who, thisbpy+who, true) thisspeed+who = 1;/阴影的位置 _rootshadow+who._x = _rootcar+who._x-4;_rootshadow+who._y = _rootcar+who._y+2;_rootshadow+who._rotation = _rootcar+who._rotation;/检查点if (_rootcar+who.hitTest(_rootcheckpoint+_rootcurrentCheckpoint+who) /if the current checkpoint is the start li

11、ne - increase the lap numberif (_rootcurrentCheckpoint+who = 1) if (_rootcurrentLap+who != 0) _root.setBestLap();if (_rootcurrentLap+who = _root.totalLaps) _root.gotoAndStop(finish); else _rootcurrentLap+who+;_root.currentLapTXT = _rootcurrentLap+who+/3;_rootcurrentCheckpoint+who+;if (_rootcurrentCheckpoint+who_root.checkpoints) _rootcurrentCheckpoint+who = 1;if (_rootcar+who.code = computer) function step2(who) if (_rootcar+who.code = player) if (thisspeed+who0.3) thisspeed+who *= _root.speedDecay; else thisspeed+who = 0;/赛车控制按键的设置/加速if (Key.isDown(87

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 幼儿/小学教育 > 幼儿教育

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号