• 大小: 10.74MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-04
  • 语言: C/C++
  • 标签: C++  

资源简介

用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个文件信息

评论

共有 条评论