`
javasee
  • 浏览: 922981 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

Java版AVG游戏开发入门[1] —— CG的绘制

阅读更多
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL /> <w:BalanceSingleByteDoubleByteWidth /> <w:DoNotLeaveBackslashAlone /> <w:ULTrailSpace /> <w:DoNotExpandShiftReturn /> <w:AdjustLineHeightInTable /> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:UseFELayout /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]-->

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"\@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

<!--[if gte mso 10]> <mce:style><! /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} --> <!--[endif]-->

作为Adventure Game,AVG的图文部分向来便是整个游戏的核心之一,所以本回将以图像绘制为中心讲解AVG的CG生成问题。(CG,即Computer Graphics,直译可称[计算机图形],此处以其为AVG开发中图形部分的代称)。

人物对话

在小时候,我们或许会被AVG游戏的华丽特效所折服。但现在,我们都知道完成那些不过是程序员的最基本能力罢了,即使不是专业的游戏开发者,也可以轻易做到。

众所周知,Java中图像绘制是非常容易的事情,无论您是通过ImageIO、ImageIcon或Toolkit.getDefaultToolkit().createImage乃至其他方式取得Image(或BufferedImage),处理的方式都完全相同的,即通过Graphics。

Graphics是一个抽象类,因此通常需要Image来引入其实例。

在Java AWT相关包内,Graphics的基本用法如下所示。

<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL /> <w:BalanceSingleByteDoubleByteWidth /> <w:DoNotLeaveBackslashAlone /> <w:ULTrailSpace /> <w:DoNotExpandShiftReturn /> <w:AdjustLineHeightInTable /> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:UseFELayout /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"\@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} --><!--[if gte mso 10]> <mce:style><! /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} --> <!--[endif]-->

但是,对于一些高级效果,则需要通过Graphics2D解决。

Graphics2D同样是一个抽象类, 继承自Graphics ,并且扩展了 Graphics,提供了对几何形状、坐标转换、颜色管理和文本布局更为复杂的控制。它是用于在Java平台上呈现二维形状、文本和图像高级特性的基础类。

由于Graphics2DGraphics的子类,故此可以直接转换Graphics获得。

Java AWT相关包内,Graphics2D的基本用法如下所示。

<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL /> <w:BalanceSingleByteDoubleByteWidth /> <w:DoNotLeaveBackslashAlone /> <w:ULTrailSpace /> <w:DoNotExpandShiftReturn /> <w:AdjustLineHeightInTable /> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:UseFELayout /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"\@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} --><!--[if gte mso 10]> <mce:style><! /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} --> <!--[endif]-->

无论代码构建的如何复杂,Java绘图的基本流程也仅仅是Image-> Graphics->Paint罢了,只需利用一个循环的repaint函数,我们就可以无数次重复这一流程。由于在我先前其它博文中已多有涉及,故此处不再赘述。

说到底,AVG游戏中的CG产生,也无非是一次次将图像混合后展现出来,是这一流程的简单再现。

具体合成关系如下图所示:

图像混成

就我个人认为,在2D的AVG中,分层仅需区别前景及背景两层即可。

原因在于,Graphics或Graphics2D在drawImage时,将顺序绘制图像,旧图会被新图所覆盖。故此,即使图像再多,也不过是在交替背景前景产生的过程,一次次覆盖,一次次交替,最终令唯一的CG被绘制到屏幕上去。

因而我们也可以得出一个AVG游戏开发的最基本概念,即图像添加时,背景图像添加应始终在前,前景图像添加需始终在后,图像的活动部分始终作为前景,而将非活动部分始终作为背景。

在本文的示例程序中,具体实现代码如下(详细请下载):

下一次,我们将开始讲解AVG的剧情发展及脚本定制。

示例代码界面如下图:

初始界面

问题选择

小游戏切换

不同游戏模式切换

示例程序下载地址:http://download.csdn.net/source/999273(源码在jar内)

分享到:
评论

相关推荐

    Java版AVG游戏开发入门示例

    这是一个Java版的桌面AVG游戏入门示例程序(源码在Jar内),演示了一个AVG游戏需要的基本功能。

    魍魉校园(Java版AVG游戏开发入门)源码分析

    NULL 博文链接:https://xpenxpen.iteye.com/blog/2171032

    免费杀毒软件——avg_free_stb免费版在线安装

    免费杀毒软件——avg_free_stb免费版在线安装

    AVG游戏演示程序

    本演示程序是使用VB+ViceScript 制作的AVG游戏。亦是ViceScript的一个使用实例。由于制作仓促,程序中不免有许多错误,还望见谅。 注:ViceScript 是由鄙人使用PowerBASIC 10 开发的一款脚本语言。

    易语言AVG游戏选择例程源码

    资源介绍:。易语言AVG游戏选择例程源码。资源作者:。@游戏开发。资源界面:。资源下载:。

    起司工具(avg游戏制作工具)v0.25.3.11中文官方安装版

    起司工具是一款非常好用且功能强大的avg游戏制作工具,不需要专业的编程能力就可以轻松的使用起司游戏制作工具制作各种文字冒险游戏,像玩游戏一样做游戏,只要你有编故事的能力都可以制作属于自己的游戏,欢迎有...

    AVG游戏选择例程.rar

    AVG游戏选择例程.rar

    AVG游戏素材.rar

    版权在唤境引擎手中,用唤境引擎做avg游戏可以免费使用

    强大的unity3d集成Ink语言插件用于avg文字游戏

    强大的unity3d集成Ink语言插件用于avg文字游戏 Ink Objects是一个简单的包,可以让对C#和Unity有基本理解的开发人员采用面向对象的方法编写广受喜爱的Ink语言。在Unity编辑器中构建对象库并将其导出到Ink中,就可以...

    AVG游戏演示程序 VB+ViceScript

    本演示程序是使用VB+ViceScript 制作的AVG游戏。亦是ViceScript的一个使用实例。开发时间3天。由于制作仓促,程序中不免有许多错误,还望见谅。 游戏中剧情、对话、图片均来自GBA游戏《逆转裁判》。 注:...

    真正的AVG电脑防护软件官方卸载工具——感谢大家支持并评论

    今天被CCleaner摆了一道,强制安装了个AVG电脑防护软件,也让我重新审视了目前网上可以查到的卸载工具,很遗憾最终的结果都是卸载不了,不过从博文中也获得了不少信息,该流氓软件的确有卸载工具并曾在官网上发布过...

    AVG游戏引擎pyMO.zip

    pymo (Python Memories Off) 是一个针对手机设计的AVG游戏引擎。可以使您不用懂得编程也可以较为方便地制作出一款简单的AVG游戏。 pymo是由chen_xin_ming开发的开源软件。pymo遵循BSD许可证,欢迎任何人下载代码或对...

    AVG游戏Android移植框架源码(吉里吉里与NS)

    AVG游戏Android移植框架源码(吉里吉里与NS),其中包含了ONS-Android与KAS两个Android开源项目,以及NS的打包与解包工具。

    易语言AVG游戏选择例程

    易语言AVG游戏选择例程源码,AVG游戏选择例程,程序,程序1,程序2,程序3,程序4,执行子程序,最近的输入虚拟键状态_

    AVG2013网络版密钥

    AVG 2013 网络版 密钥 是从某个论坛上找来的(10月31号的) 我不用AVG 你可以试试

    AVG 游戏引擎

    一个演示程序,它可以用来制作《心跳回忆》类型的游戏,这些都不需要你修改程序的源代码。而且作者也提供程序的源代码给大家下载。作者网站:http://yahle.yeah.net

    易语言源码AVG游戏选择例程源码.rar

    易语言源码AVG游戏选择例程源码.rar

    C#全能速查宝典

    《C#全能速查宝典》共分为8章,分别介绍了C#语言基础、Windows窗体及常用控件、Windows高级控件、控件公共属性、方法及事件、数据库开发、文件、数据流与注册表、GDI+绘图技术和C#高级编程,共包含562个C#编程中常用...

    AVG Anti-Virus Free Edition v17.8.3036.zip

    A5下载站向大家推荐一款来自捷克的知名杀毒软件——AVG Anti-Virus Free。AVG Anti-Virus Free强大的全功能网站防护解决方案,强大的全功能网站防护解决方案,,无论网上冲浪、搜索、下载、聊天,还是在线游戏、...

Global site tag (gtag.js) - Google Analytics