资源预览内容
亲,该文档总共2页全部预览完了,如果喜欢就下载吧!
资源描述
二维图像游戏基础 耿卫东 陈为 浙江大学CADCG国家重点实验室 课程资料耿卫 东,陈为。计算机游戏程序设计。电子工业出版社。 图像文 件结构以BMP为例)图像显示(例程)典型图像操作 典型的图像特效原理 二维 游戏(例程)课程冃标理解图像概念图像操作的实现简单的图像特效简单的二 维游戏游戏循环的基本步骤1.初始化2.进入游戏循环初始化过程循环3.查询用 户输入状态4.执行游戏逻辑和AI判断5.绘制图像按键处理图像绘制6.循环7. 退出AI逻辑退出游戏游戏循环的基本步骤1.初始化2.进入游戏循环初始化 过程循环3.查询用户输入状态4.执行游戏逻辑和AI判断5.笔制图像按键处理图 像绘制6.循环7.退出AI逻辑退岀游戏Demo: Airplane演示Game In it Game Menu Game Starting Game Restart Game Game Run Exit/ defines for game loop statesdefine GAME_INIT 1 / the game is initializingdefine GAME_MENU 2 / the game is in the menudefine GAME_STARTING 3 / the game is about to rundefine GAME_RUN 4 / the game is now runningdefine GAME_RESTART 5 / the game is going to restartdefine GAME_EXIT 6 / the game is exiting/ game global si nt game_state GAME_INIT / start off in this statelnt error 0 / used to send errors back to OS/ main begins hereVoid main / implementation of main game loopWhile game_state GAME_EXIT / implementation of main game loop switchgame_state case GAME_INIT: / the game is irdtializing / allocate all memory and resources Init game_state GAME_MENU breakcase GAME_MENU: / the game is in the menu / call the main menu function and let it switch states game_state Menu / note: we could force a RUN state here breakcase GAME_STARTING: / the game is about to run / this state is optional but usually used to set things up right / before the game is run you might do a little more housekeeping Setup_For_Run / switch to run state game_state GAME_RUN breakcase GAME_RUN: / the game is now running / this section contains the entire game logic loop Clear / clear the display Get_Input / get the input Do_Logic / perform logic and AI Render_Frame / display the next frame of animation Wait / synchronize the display / the only way that state can be changed is thru user interaction / in the input section or by maybe losing the game, breakcase GAME_RESTART: / the game is restarting / this section is a cleanup state used to fix up any loose ends / before running again Fixup / switch states back to the menu game_state GAME_MENU break case GAME_EXIT: / the game is exiting / if the game is in this state then its time to bail kill everything / and cross your fingers Release_And_C 1 eanup error 0 / set the error word to whatever / note: we do not have to switch states since we are already in this state / on the next loop iteration the code will fall out of the main while and / exit back to the OS break default: break / end switch returnerror / return error code to operating system / end main二纟隹游戏技术 二纟隹游戏 概览地图的创建与显示 颜色混合与半透明精灵动画 碰撞检测 游戏循环概念及 实例解析二维游戏早期的游戏都是二维的如Diablo暗黑破坏神只有两个轴(上 下,左右)很多RPG游戏是固定视角的二维半二维游戏(续)二维游戏对现在的 编程仍然有意义(特别是现在的手机游戏):如内存、分辨率木质上视频游戏是 一个连续的循环,执行逻辑指令,并将图像输岀到屏幕。这和电影的播放非常类 似,但是这个电影是用户指定的。地图的创建与显示为实现一个基本的二维游戏 框架,首先耍实现游戏地图的齐种加载和编辑操作,为角色提供游戏环境。4种通用地图实现的方法:固定地图、滚屏地图、多层次地图、菱形地图固定地图使 用固定的背景作为地图将屏幕切割成棋盘状的一系列小块在内存中保持一个二维 数组,保存每个小块对应的编号绘制吋根据数组提供的信息,在每个小块画上相 应图块固定地图拼接算法实现foryi Oyi
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号