`
bolutes
  • 浏览: 870887 次
文章分类
社区版块
存档分类
最新评论

Amazed游戏学习二 坐标的分析

 
阅读更多

对于这种和贪吃蛇类似的游戏,坐标的计算在程序中占了很大的比重,只有坐标算对了,才能在正确的时间、正确的地点画出来正确的东西。

下面是Maze迷宫的坐标计算

这个一维数组存放所有的tile的类型

而这个坐标的读取是通过从文件读取的,当然也可以通过写几个数组的形式,但是以文件的形式的话就不需要修改代码就可以实现软件的修改是一种比在代码中写几个大的数组要好的形式。

mMazeData数组存放了每个tile是什么类型的,MAZE_ROWS一共有多少行,MAZE_COLS一共多少列,TILE_SIZE每个tile的宽度,这样就可以在界面上画出来整个界面的布局

获得第i个点所在的行号和列号

已知行号和列号,知道在屏幕上的位置,但是并不是实际屏幕上的位置,通过乘以每个tile的宽度,获得在屏幕上实际的位置,这个位置是可以画在屏幕上的位置。

上面onDraw的过程是根据mMazeData[i]的第i个点计算在屏幕上的实际位置,而下面的getCellType则是根据在屏幕上的实际的x/y坐标点,计算出在mMazeData中的位置,也就是上面过程的逆过程,函数getCellType(int x, int y)的作用也就是计算出现在Marble所在的屏幕的位置所在的tile是什么类型的。

下面是Marble小球的坐标计算

在AmazedView中的onDraw()调用gameTick()的时候会更新小球Marble的坐标:

在Marble中更新小球坐标:

if-else中是对左右边界的处理,同样的是对上下边界的处理。

分享到:
评论

相关推荐

    Amazed游戏

    Android Amazed 游戏 源码

    Android游戏源码---Amazed

    Android完整游戏代码,想学习的进来下载吧。

    Amazed开源项目工程

    Amazed开源项目工程,资源http://code.google.com/p/apps-for-android/

    Amazed

    Amazed

    Amazed-crx插件

    语言:English 通过轻松查看产品的Reddit讨论来增强Amazon 显示有关Amazon产品的Reddit帖子。 程序加载按评论排序的Reddit链接,并显示每个帖子的subreddit和作者。 非常适合通过Reddit Posts获得有关产品的更多信息...

    Amazed-开源

    Amazed是用Java编写的图像编辑器。 它的主要功能是简单地查看和操作不同格式的图像,包括在目录中的图像之间轻松导航。 其他功能:调整大小,翻转,过滤,添加文本,打印,op

    外研社高中英语必修二单词表

    amazed /ə'meizd/ adj. 吃惊的;惊讶的 embarrassing /im'bærəsiŋ/ adj. 令人尴尬的;令人难 technology /tek'nɒlədʒi/ n. 技术 impress /im'pres/ vt. 使印象深刻 correction /kə'rekʃən/ n. 改正;...

    表情英语happy sad angry sleepy幼儿园PPT课件.pptx

    表情英语happy sad angry sleepy幼儿园PPT课件.pptx

    apps-for-android

    •Amazed:一个简单但令人上瘾的加速度为基础的大理石指导游戏。 •AndroidGlobalTime:地球全表示,你可以不停地旋转。 •AnyCut:一种实用工具,可以让用户创建主屏幕快捷方式到系统中几乎任何东西。 •Clickin2...

    Murach's MySQL(第二版)

    "I was amazed at how much information was packed into this book." "As a developer with almost 10 years of MySQL experience, I still picked up a lot of new detail on things I thought I knew." "I ...

    Michael Jackson

    Michael Jackson, 1958-2009: He Amazed the World With His Music and Dancing

    Android代码-android-gesture-detectors

    Since I was amazed Android has a ScaleGestureDetector since API level 8 but (still) no such thing as a RotateGestureDetector I decided to create this class myself. In the process I decided to create...

    project-2016-for-dummies-1st-edition 英文原版

    Once you discover Project 2016 you'll be amazed at how efficient and effective the project management process can be. Written by an expert author who knows project management processes backward and ...

    Getting Started with Grails Second Edition

    First-time developers are amazed at how quickly you can get a page-centric MVC web site up and running thanks to the scaffolding and convention over configuration that Grails provides. Advanced web ...

    The Book of F#(NoStarch,2014)

    As you learn to take advantage of features like default immutability, pipelining, type inference, and pattern matching, you'll be amazed at how efficient and elegant your code can be.

    concurrent-patterns-best-practices-synchronization

    I was amazed by the creativity and power brought about by the command line. I was working with concurrent programs. Then, there was a change of project and I was thrown headlong into writing code ...

    Classic Computer Science Problems in Python pdf+azw3格式

    would be amazed at how many different kinds of reviews a technical book by a traditional publisher goes through and how many people have their part in critiquing and revising it. From the technical ...

Global site tag (gtag.js) - Google Analytics