⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bdirectdrawsurface.h

📁 用VC++及DirectX实现的SuperMario小游戏
💻 H
字号:
/*
Author: Bear

This source is free to anybody.
If you have any problem with this or some advice to me, please:
    mailto: heyang22118952.student@sina.com
        or  yang45249.student@sina.com
or you can contact me through my QQ:     261570581

Welcome to discuss game programming techniques with me :)
And I like to play games!
*/
#pragma once

#include "BHeader.h"
#include "BBitmap.h"

class BDLL_API BDirectDrawSurface
{
public:
	BDirectDrawSurface(LPDIRECTDRAWSURFACE7 lpdds);
	~BDirectDrawSurface(void);
	bool Fill(int color);
	bool Draw(BDirectDrawSurface* source, int x, int y, float scale = 1, bool transparent = true);
	bool DrawMirror(BDirectDrawSurface* source, int x, int y, float scale = 1, bool transparent = true);
	bool DrawTextGDI(char* text, int x, int y, int color);
	bool LoadBitmap(BBitmap* pBitmap, int cellX, int cellY);
	//this method can only be used in fullscreen mode
	void Flip(void);
	int GetWidth(void);
	int GetHeight(void);
	bool IsLost(void);
	void Restore(void);
	bool DrawLine(int x1, int y1, int x2, int y2, int color);
	void SetClipRect(const RECT& rect);
	//this method must be called after Lock()
	bool DrawHorizontalLine(int startX, int endX, int y, int color)
	{
		if(startX > endX) {
			int temp = startX;
			startX = endX;
			endX = temp;
		}
		if(startX>this->m_rcClip.right || endX<this->m_rcClip.left || y<this->m_rcClip.top || y>this->m_rcClip.bottom)
			return true;
		if(startX<this->m_rcClip.left)
			startX = this->m_rcClip.left;
		if(endX>this->m_rcClip.right)
			endX = this->m_rcClip.right;

		switch(m_bpp) {
			case 8:
				assert((color>>8) == 0);
				memset((UCHAR*)ddsd.lpSurface + ddsd.lPitch*y + startX, (UCHAR)color, endX - startX);
				break;
			case 16:
				assert((color>>16) == 0);
				for(int i=startX; i<=endX; i++) {
					((USHORT*)ddsd.lpSurface)[y*(ddsd.lPitch>>1) + i] = (USHORT)color;
				}
				break;
			case 32:
				for(int i=startX; i<=endX; i++) {
					((UINT*)ddsd.lpSurface)[y*(ddsd.lPitch>>2) + i] = (UINT)color;
				}
				break;
			default:
				DXTRACE_MSG("Unsupported rgb bit count");
				break;
		}
		return true;
	}
	bool Lock(void);
	bool UnLock(void);
private:
	LPDIRECTDRAWSURFACE7 m_lpdds;
	DDBLTFX ddbltfx;
	DDSURFACEDESC2 ddsd;
	int m_width, m_height, m_bpp;
	RECT m_rcClip;

	void PlotPixel(int x, int y, long int lPitch, LPVOID buffer, int color);
	bool ClipLine(int &x1,int &y1,int &x2, int &y2);
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -