计算机实习报告.docx_第1页
计算机实习报告.docx_第2页
计算机实习报告.docx_第3页
计算机实习报告.docx_第4页
计算机实习报告.docx_第5页
已阅读5页,还剩38页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

计算机实习报告学院:班级:学号:姓名: 1、题目要求:作一个两辆赛车比赛的游戏,要求可以用A,S,D,W和小键盘的上下左右键控制小汽车的运行方向进行比赛。设计方案 :所用软件为Adobe Flash CS5设置控制键,通过按键对小车进行控制,在控制的同时判断小车的位置使其行驶在跑道上,当有一辆赛车跑完三圈时,比赛结束,并输出比赛结果。开始流程图:方向键控制对两小车是否碰到跑道进行判断小车停止Y N判断比赛是否完成NY显示比赛的输赢结束设计过程:1. 首先要让赛车能够动起来。让赛车运动不是最难的一部分首先在defs的图层里打开actions窗口,设定好赛车的加速度,减速度,最大速度,以及圈数等基本常量值。 Flash中使用的的是经典的直角坐标系,所以我们在计算赛车实际的速度时要把速度分解到X轴和Y轴上,得到X分量和Y分量(如下图)。计算上述分量就要知道角度,Flash中对角度和弧度要进行转化:angle_radians = angle_degrees *(PI/180)。再加上函数,就可以让我们的车动起来。这里我用了两个类似的函数来分别控制两辆赛车,他们只有控制方向的按键不同的。2还需要处理碰撞的问题。碰撞时整个赛车游戏中十分重要的一部分,因为我们必须把赛车限制在跑道内,并且让玩家可以在最快的时间内完成比赛。在车的四边分别设置一个点,用来检测它是否碰到了不可进入的区域。如果碰到了赛道,那么赛车的速度将会降低,并且赛车的方向会得到纠正。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;currentCheckpoint2 = 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._rotation -= _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.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.pointRight = 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;thislpy+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.hitTest(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(thisbpx+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 line - 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) & thisspeed+who0.3) _rootcar+who._rotation -= _root.rotationStep*(thisspeed+who/_root.maxSpeed);/右转 if (Key.isDown(68) & 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.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.pointRight = 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;thislpy+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.hitTest(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(thisbpx+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 line - 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 setTimes() timeElapsed = getTimer()-_root.initialTime;milliseconds = timeElapsed;seconds = Math.floor(milliseconds/1000);minutes = Math.floor(seconds/60);minutesTXT = minutes;secondsTXT = seconds-minutes*60;tensTXT = Math.round(milliseconds-seconds*1000)/10);if (minutesTXT10) minutesTXT = 0+minutesTXT;if (secondsTXT10) secondsTXT = 0+secondsTXT;if (tensTXTmilliseconds | oldMilliseconds = null) oldMilliseconds = milliseconds;seconds = Math.floor(milliseconds/1000);minutes = Math.floor(seconds/60);minutesTXT = minutes;secondsTXT = seconds-minutes*60;tensTXT = Math.round(milliseconds-seconds*1000)/10);if (minutesTXT10) minutesTXT = 0+minutesTXT;if (secondsTXT10) secondsTXT = 0+secondsTXT;if (tensTXTLoadIcon(IDR_MAINFRAME);void CCalculatorDlg:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CCalculatorDlg)DDX_Text(pDX, IDC_EDIT1, m_EDIT);/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CCalculatorDlg, CDialog)/AFX_MSG_MAP(CCalculatorDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON0, OnButton0)ON_BN_CLICKED(IDC_BUTTON1, OnButton1)ON_BN_CLICKED(IDC_BUTTON2, OnButton2)ON_BN_CLICKED(IDC_BUTTON3, OnButton3)ON_BN_CLICKED(IDC_BUTTON4, OnButton4)ON_BN_CLICKED(IDC_BUTTON5, OnButton5)ON_BN_CLICKED(IDC_BUTTON6, OnButton6)ON_BN_CLICKED(IDC_BUTTON7, OnButton7)ON_BN_CLICKED(IDC_BUTTON8, OnButton8)ON_BN_CLICKED(IDC_BUTTON9, OnButton9)ON_BN_CLICKED(IDC_BUTTONA, OnButtona)ON_BN_CLICKED(IDC_BUTTONB, OnButtonb)ON_BN_CLICKED(IDC_BUTTONC, OnButtonc)ON_BN_CLICKED(IDC_BUTTOND, OnButtond)ON_BN_CLICKED(IDC_BUTTONE, OnButtone)ON_BN_CLICKED(IDC_BUTTONF, OnButtonf)ON_BN_CLICKED(IDC_BTN_BACK, OnBtnBack)ON_BN_CLICKED(IDC_BTN_DOT, OnBtnDot)ON_BN_CLICKED(IDC_BTN_AC, OnBtnAc)ON_BN_CLICKED(IDC_BTN_ADD, OnBtnAdd)ON_BN_CLICKED(IDC_BTN_DECREASE, OnBtnDecrease)ON_BN_CLICKED(IDC_BTN_MULTI, OnBtnMulti)ON_BN_CLICKED(IDC_BTN_DIV, OnBtnDiv)ON_BN_CLICKED(IDC_BTN_EQUAL, OnBtnEqual)ON_BN_CLICKED(IDC_BTN_SIGN, OnBtnSign)ON_BN_CLICKED(IDC_BTN_HEX, OnBtnHex)ON_BN_CLICKED(IDC_BTN_DEC, OnBtnDec)ON_BN_CLICKED(IDC_BTN_OCT, OnBtnOct)ON_BN_CLICKED(IDC_BTN_BIN, OnBtnBin)/AFX_MSG_MAPON_EN_CHANGE(IDC_EDIT1, &CCalculatorDlg:OnEnChangeEdit1)END_MESSAGE_MAP()/ CCalculatorDlg message handlers/初始化对话框BOOL CCalculatorDlg:OnInitDialog()CDialog:OnInitDialog();/ Add About. menu item to system menu./ IDM_ABOUTBOX must be in the system command range.ASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX AppendMenu(MF_SEPARATOR);pSysMenu-AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);/ Set the icon for this dialog. The framework does this automatically/ when the applications main window is not a dialogSetIcon(m_hIcon, TRUE);/ Set big iconSetIcon(m_hIcon, FALSE);/ Set small icon/ TODO: Add extra initialization here form=D;point=false;GetDlgItem(IDC_BUTTONA)-EnableWindow(0);GetDlgItem(IDC_BUTTONB)-EnableWindow(0);GetDlgItem(IDC_BUTTONC)-EnableWindow(0);GetDlgItem(IDC_BUTTOND)-EnableWindow(0);GetDlgItem(IDC_BUTTONE)-EnableWindow(0);GetDlgItem(IDC_BUTTONF)-EnableWindow(0);return TRUE; / return TRUE unless you set the focus to a controlvoid CCalculatorDlg:OnSysCommand(UINT nID, LPARAM lParam)if (nID & 0xFFF0) = IDM_ABOUTBOX)CAboutDlg dlgAbout;dlgAbout.DoModal();elseCDialog:OnSysCommand(nID, lParam);/ If you add a minimize button to your dialog, you will need the code below/ to draw the icon. For MFC applications using the document/view model,/ this is automatically done for you by the framework.void CCalculatorDlg:OnPaint() if (IsIconic()CPaintDC dc(this); / device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);/ Center icon in client rectangleint cxIcon = GetSystemMetrics(SM_CXICON);int cyIcon = GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(&rect);int x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;/ Draw the icondc.DrawIcon(x, y, m_hIcon);elseCDialog:OnPaint();/ The system calls this to obtain the cursor to display while the user drags/ the minimized window.HCURSOR CCalculatorDlg:OnQueryDragIcon()return (HCURSOR) m_hIcon;/控件触发void CCalculatorDlg:OnButton0() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+0;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton1() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+1;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton2() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+2;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton3() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+3;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton4() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+4;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton5() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+5;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton6() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+6;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton7() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+7;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton8() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+8;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton9() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+9;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButtona() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+A;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButtonb() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+B;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButtonc() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+C;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButtond() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+D;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButtone() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+E;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButtonf() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+F;SetDlgItemText(IDC_EDIT1,m_EDIT);/退格void CCalculatorDlg:OnBtnBack() / TODO: Add your control notification handler code here

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论