《嵌入式系统导论》课程设计小游戏之小鸡快跑_第1页
《嵌入式系统导论》课程设计小游戏之小鸡快跑_第2页
《嵌入式系统导论》课程设计小游戏之小鸡快跑_第3页
《嵌入式系统导论》课程设计小游戏之小鸡快跑_第4页
《嵌入式系统导论》课程设计小游戏之小鸡快跑_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

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

文档简介

1、嵌入式系统导论嵌入式系统导论课程设课程设计计名称 小游戏之小鸡快跑姓名院系电气工程系班级电子二班学号时间2014 年 12 月 19 日目录目录设计目的-3设计器件-3设计步骤-3仿真步骤与结果-3 1.小鸡行走-62.小鸡停止下坠-6设计程序(部分)-71. 计时器程序-72. 操作程序-8 3. 行走路径程序-94.主程序-12总结-15设计目的:设计目的:通过过此次实验,让大家更熟 visual studio 软件的使用。同时通过小组讨论的方式,增强大家的沟通、合作能力。学会在遇到问题时与他人协作的能力。设计设计器件:器件:计算机一台 visual studio 软件设计设计步骤:步骤:

2、1. 确立题目,选择方向2. 进行编写程序3. 打开 visual studio 软件,加载程序4. 点击运行按钮,进行软件的仿真5. 根据仿真结果进行调试仿真步骤与结果:仿真步骤与结果:步骤一步骤二步骤三步骤四步骤五 小鸡行走:小鸡停止下坠:实验程序(部分)计时器程序namespace chickrun partial class form1 / / private system.componentmodel.icontainer components = null; / / / protected override void dispose(bool disposing) if (disp

3、osing & (components != null) components.dispose(); base.dispose(disposing); #region windows private void initializecomponent() ponents = new system.componentmodel.container(); this.picturebox1 = new system.windows.forms.picturebox(); this.timer1 = new system.windows.forms.timer(ponents); (system.com

4、ponentmodel.isupportinitialize)(this.picturebox1).begininit(); this.suspendlayout(); / / picturebox1 / this.picturebox1.dock = system.windows.forms.dockstyle.fill; this.picturebox1.location = new system.drawing.point(0, 0); this.picturebox1.name = picturebox1; this.picturebox1.size = new system.draw

5、ing.size(530, 346); this.picturebox1.tabindex = 0; this.picturebox1.tabstop = false; this.picturebox1.mouseclick += new system.windows.forms.mouseeventhandler(this.picturebox1_mouseclick); this.picturebox1.paint += new system.windows.forms.painteventhandler(this.picturebox1_paint); / / timer1 / this

6、.timer1.tick += new system.eventhandler(this.timer1_tick); / / form1 / this.autoscaledimensions = new system.drawing.sizef(6f, 12f); this.autoscalemode = system.windows.forms.autoscalemode.font; this.clientsize = new system.drawing.size(530, 346); this.controls.add(this.picturebox1); this.name = for

7、m1; this.text = form1; this.load += new system.eventhandler(this.form1_load); this.keyup += new system.windows.forms.keyeventhandler(this.form1_keyup); this.keydown += new system.windows.forms.keyeventhandler(this.form1_keydown); (system.componentmodel.isupportinitialize)(this.picturebox1).endinit()

8、; this.resumelayout(false); #endregion private system.windows.forms.picturebox picturebox1; private system.windows.forms.timer timer1; 操作程序:using system;using system.collections.generic;using system.text;using system.drawing;namespace chickrun public class chick public float g = 150.0f; public float

9、 speedx; public float speedy = 100.0f; public float dt = 0.1f; public bool isruning = false; public bool isjumping = false; public bool isspeeding = false; public bool isfalling = false; public bitmap bmp; public chick() using (bitmap bmpt = (bitmap)bitmap.fromfile(chick.png) bmp = bmpt.clone() as b

10、itmap; public void update() if (!isruning) return; if (isspeeding) this.point.x += (int)(speedx *2) * dt+0.9); else this.point.x += (int)(speedx * dt+0.9); if (isjumping | isfalling) this.point.y += (int)(-speedy * dt+0.9); speedy -= (int)(g * dt); public point point; 行走路径程序:using system;using syste

11、m.collections.generic;using system.text;using system.drawing;namespace chickrun public class road static random rand = new random(); public int itemlen; public list landbmp = new list(); public road(int itemnum, int itemlen) if (itemlen 2) throw new exception(); this.itemlen = itemlen; roaditem item

12、00 = new roaditem(0,this.itemlen); item00.imageindex = 0; item00.type = 1; _roads.add(item00); for (int i = 0; i itemnum-2; i+) int temp = rand.next(0, 3); int index = 0; int ang = 0; if (temp = 0) ang = -20; index = 2; else if (temp = 1) ang = 0; index = 0; else ang = 20; index = 1; roaditem item =

13、 new roaditem(ang, this.itemlen); if (rand.next(0, 4) = 1) item.type = 0; else item.type = 1; item.imageindex = index; _roads.add(item); roaditem item11 = new roaditem(0, this.itemlen); item11.imageindex = 0; item11.type = 1; _roads.add(item11); for (int i = 0; i _roads.count; i+) roaditem item = _r

14、oadsi; if (i = 0) item.start = new point(0, 100); else item.start = _roadsi - 1.end; item.end = new point(item.start.x + item.length, item.start.y + (int)(math.tan(item.angle * math.pi / 180) * item.length+0.9); using (image bmp1 = image.fromfile(land0.png) landbmp.add(bmp1.clone() as image); using

15、(image bmp2 = image.fromfile(land20.png) landbmp.add(bmp2.clone() as image); using (image bmp3 = image.fromfile(land-20.png) landbmp.add(bmp3.clone() as image); /public int gety(int x) / / int i = x / itemlen; / int y = 0; / if (i + 1 roaditems.count) / / roaditem item = roaditemsi; / float k = (x -

16、 item.start.x) / (float)(item.end.x - item.start.x); / y = item.start.y + (int)k * (item.end.y - item.start.y); / / return y; / roaditems _roads = new roaditems(); public roaditems roaditems get return _roads; public class roaditems : list public class roaditem public int angle; public int length; p

17、ublic int type;/0为空,1为陆地 public roaditem(int angle, int length) this.angle = angle; this.length = length; public point start; public point end; public int gety(int x) roaditem item = this;/ roaditemsi; float k = (x - item.start.x) / (float)(item.end.x - item.start.x); int y = item.start.y + (int)(k

18、* (item.end.y - item.start.y)+0.9); return y; public int imageindex = 0; 主程序using system;using system.collections.generic;using system.componentmodel;using system.data;using system.drawing;using system.text;using system.windows.forms;namespace chickrun public partial class form1 : form public form1(

19、) initializecomponent(); scene sc; private void form1_load(object sender, eventargs e) sc = new scene(picturebox1 .size); sc.statechange += new statechange(sc_statechange); sc.refresh(); void sc_statechange(int v,float p) if (v = 1) this.text=跳起; else if (v = 2) jumpnum = 0; this.text = 落到地面; else i

20、f (v = 3) this.text = 正在下落; else if (v = 4) this.text = 行走; else if (v = 5) this.text = 下坠; else if (v = 6) this.text = 停止下坠game over; else if (v = 7) this.text = 停止,到达终点; this.text+=+(int)(p*100)+%; private void picturebox1_paint(object sender, painteventargs e) if (sc = null) return; e.graphics.dr

21、awimage(sc.bitmap, new point(0, 0); private void picturebox1_mouseclick(object sender, mouseeventargs e) timer1.enabled = !timer1.enabled; if (timer1.enabled) sc.chick.isruning = true; private void timer1_tick(object sender, eventargs e) sc.refresh(); picturebox1.refresh(); int jumpnum = 0; private

22、void form1_keydown(object sender, keyeventargs e) if (e.keydata = keys.space) if (sc.currentroadsindex + 1 = sc.road.roaditems.count) return; jumpnum+; if (jumpnum 2) return; sc.chick.speedy = 150; sc.chick.isjumping = true; else if (e.keydata = keys.s) if (sc.chick.isruning) sc.chick.isspeeding = true; /+5+1+a+s+

温馨提示

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

评论

0/150

提交评论