资源简介
用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++技术》
相关资源
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
- c++ 画图(14Qt-XPS)
- c++多边形交并差运算
- VC++基于OpenGL模拟的一个3维空间模型
评论
共有 条评论