资源简介
用VC设计的贪吃鱼游戏,对于游戏的学习很有帮助。
代码片段和文件信息
/************************************************************************/
/* */
/* 由图块组成的游戏地图处理类 */
/* 作者:万立中 (C)2011-06-3 */
/* www.wanlizhong.com */
/* */
/************************************************************************/
#pragma once
#include “stdafx.h“
#include “CImageMap.h“
//静态图像背景
CImageMap::CImageMap(LPTSTR fileName HWND hWnd):RhlCGdiBmp(fileName)
{
MainWnd = hWnd;
RECT wRect;
GetWindowRect(hWnd &wRect);
GameWinSize.cx = wRect.right-wRect.left;
GameWinSize.cy = wRect.bottom-wRect.top;
POINT pos;
if(this->getbmpWidth() > GameWinSize.cx)
pos.x = -(this->getbmpWidth()-GameWinSize.cx)/2;
else
pos.x = (GameWinSize.cx - this->getbmpWidth())/2;
if(this->getBmpHeight() > GameWinSize.cy)
pos.y = -(this->getBmpHeight() - GameWinSize.cy)/2;
else
pos.y = (GameWinSize.cy - this->getBmpHeight())/2;
NowMapPos = pos;
MapOriginPoint = pos;
RECT rec;
GetClientRect(MainWnd &rec);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//如果鱼在NoScrollArea的边界则只移动背景 鱼不移动
//如果鱼在NoScrollArea的边界以内 鱼移动 背景不移动
//如果背景到达了边缘则鱼可以移动
int EdgeH = rec.right/5;
int EdgeV = rec.bottom/5;
NoScrollArea.left = EdgeH;
NoScrollArea.top = EdgeV;
NoScrollArea.right = rec.right - EdgeH;
NoScrollArea.bottom = rec.bottom - EdgeV;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
}
CImageMap::~CImageMap()
{
}
void CImageMap::DrawGameMap(HDC hdc)
{
this->DrawMirror(hdc NowMapPos.x NowMapPos.y 0);
}
BOOL CImageMap::ScrollMap(int nowPlayerDir int playerSpeed
POINT nowPlayerPos SpriteSet& EnemySpriteSet)
{
BOOL MapScrolling = FALSE;
bool enemyScrolled = false;
int xSpeed = playerSpeed;
double ratio = (double)this->getBmpHeight()/(double)this->getbmpWidth();
int ySpeed = ratio * playerSpeed;
SIZE BackSize;
BackSize.cx = this->getbmpWidth();
BackSize.cy = this->getBmpHeight();
switch(nowPlayerDir)
{
case RhlCSprite::DIR_UP://上
if(nowPlayerPos.y < NoScrollArea.top)
{
enemyScrolled = true;
MapScrolling = TRUE;
NowMapPos.y = NowMapPos.y + playerSpeed;
if(NowMapPos.y >= 0)
{
NowMapPos.y = 0;
enemyScrolled = false;
MapScrolling = FALSE;
}
}
break;
case RhlCSprite::DIR_DOWN://下
if(nowPlayerPos.y >= NoScrollArea.bottom)
{
enemyScrolled = true;
MapScrolling = TRUE;
NowMapPos.y = NowMapPos.y - playerSpeed;
if(NowMapPos.y <= -(BackSize.cy - GameWinSize.cy))
{
NowMapPos.y = -(BackSize.cy - GameWinSize.cy);
enemyScrolled = false;
MapScrolling = FALSE;
}
}
break;
case RhlCSprite::DIR_LEFT://左
if( nowPlayerPos.x < NoScrollArea.left)
{
enemyScrolled = true;
MapScrolling = TRUE;
NowMapPos.x = NowMapPos.x + playerSpeed;
if(NowMapPos.x >= 0)
{
No
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 773 2011-05-22 18:31 RhlFishGame2\StdAfx.h
文件 298 2011-05-22 18:31 RhlFishGame2\StdAfx.cpp
文件 1239 2011-05-22 18:31 RhlFishGame2\ReadMe.txt
文件 530 2011-05-22 18:31 RhlFishGame2\RhlFishGame.dsw
文件 222208 2011-06-10 20:23 RhlFishGame2\RhlFishGame.ncb
文件 289 2011-04-28 23:23 RhlFishGame2\RhlCDesktop.h
文件 8993 2011-04-30 21:16 RhlFishGame2\RhlCDxSound.cpp
文件 2389 2011-04-30 21:16 RhlFishGame2\RhlCDxSound.h
文件 5676 2011-05-11 17:17 RhlFishGame2\RhlCGdiBmp.cpp
文件 1280 2011-05-11 17:17 RhlFishGame2\RhlCGdiBmp.h
文件 7716 2011-05-09 17:16 RhlFishGame2\RhlCSprite.cpp
文件 0 2011-05-22 18:39 RhlFishGame2\新建 文本文档.txt
文件 1896 2011-06-10 20:21 RhlFishGame2\RhlFishGame.plg
文件 137 2011-05-22 19:18 RhlFishGame2\RhlFishGame.h
文件 1408 2011-05-22 20:36 RhlFishGame2\RhlCDesktop.cpp
文件 1390 2011-05-23 22:14 RhlFishGame2\RhlFishGame.cpp
文件 8671 2011-05-27 10:40 RhlFishGame2\RhlCEngine.cpp
文件 4996 2011-06-10 11:50 RhlFishGame2\RhlCSprite.h
文件 2359 2011-06-10 11:50 RhlFishGame2\RhlCEngine.h
文件 1288 2011-06-10 11:50 RhlFishGame2\CImageMap.h
文件 5133 2011-06-10 11:53 RhlFishGame2\RhlCManager.h
文件 5228 2011-06-10 11:58 RhlFishGame2\RhlFishGame.dsp
文件 7475 2011-06-10 20:18 RhlFishGame2\CImageMap.cpp
文件 25899 2011-06-10 20:21 RhlFishGame2\RhlCManager.cpp
文件 52736 2011-06-10 20:23 RhlFishGame2\RhlFishGame.opt
文件 312320 2011-06-10 20:22 RhlFishGame2\Debug\vc60.idb
文件 2574264 2011-05-22 19:12 RhlFishGame2\Debug\RhlFishGame.pch
文件 356352 2011-06-10 20:21 RhlFishGame2\Debug\vc60.pdb
文件 434057 2011-05-22 19:12 RhlFishGame2\Debug\StdAfx.sbr
文件 55091 2011-05-22 19:12 RhlFishGame2\Debug\StdAfx.obj
............此处省略67个文件信息
- 上一篇:常用算法程序集(C语言描述) 第三版.rar
- 下一篇:《Qt中的C++技术》
相关资源
- 《Qt中的C++技术》
- C++培训课程资料1
- C++编写的邮局选址问题
- C++全英文授课课件
- c++音乐播放器
- C++程序设计谭浩强PDF完整版
- Visual C++音频-视频技术开发与实战1-
- VC++计算器源代码
- Boost.Asio C++ Network Programming(2nd) az
- Accelerated C++ 无水印pdf
- MFC电子邮箱
- EffectiveC++ 中文版 & EffectiveC++ 3rd 英文
- VC++实现悬浮窗 迅雷360悬浮球
- 简单HTTP代理服务器-源码c++
- Visual.Assist.X助手及其注册码 VC++
- C++程序设计_谭浩强_PDF电子书
- 全国计算机二级题库 c++ 二级
- MFC网络聊天工具
- VS2015 C++操作WebService
- 数据结构与算法分析C++语言描述第二
- C++ 学生成绩管理系统125548
- C++面向对象程序设计龚晓庆课后习题
- 五子棋大作业C++实现
- 《Visual C++ MFC棋牌类游戏编程》的源代
- VC++实现的软件自动更新模块Updater源码
- 计算器MFC+VC++
- vc++2010学习版Microsoft Visual C++ 2010 Exp
- New C++基础与提高-王桂林 .pdf
- 哈夫曼编码压缩文件,c/c++课程设计
- 学生管理系统 mfc 数据库 c++
评论
共有 条评论