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

📄 koules.cpp

📁 Clear Mine扫雷游戏: 这是一个模拟扫雷游戏的vc编码程序 编码思想: 通过几个数组设定好雷区的位置
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/***********************************************************
*                      K O U L E S                         *
*  koules.c main game routines                             *
 ***********************************************************/
#define VARIABLES_HERE
#include "koules.h"
#include "interface.h"
#include "framebuffer.h"
#include "input.h"
#include "sound.h"

int             nobjects = 8;
int             nrockets = 1;
int             drawpointer = 1;
int             difficulty = 2;
int             cit = 0;
Object          object[MAXOBJECT];
Point           point[MAXPOINT];
extern BOOL		show_playerdata=FALSE;
extern int		show_player=0;

void Restore()
{
	if(background->IsLost())
	{
		background->Restore();
		createbackground ();
	}
	if(starbackground->IsLost())
	{
		starbackground->Restore();
		drawstarbackground ();
	}
	surf_queue *p=surf_header.next;
	DDCOLORKEY ddc;
	ddc.dwColorSpaceLowValue=0;
	ddc.dwColorSpaceHighValue=0;
			
	while(p)
	{
		if(p->lpsurf->IsLost())
		{
			p->lpsurf->Restore();
			GetDDWin()->Copy_Bmp08_Surface08(p->lpsurf,
			(LPBYTE)p->bitmap,p->sx,p->sy);
			p->lpsurf->SetColorKey(DDCKEY_SRCBLT,&ddc);
		}
		p=p->next;
	}
}


unsigned char   rocketcolor[5] =
{96, 160, 64, 96, 128};

int             lastlevel = 0, maxlevel = 0;
char			control[MAXROCKETS];
struct			control  controls[MAXROCKETS];
int             dosprings = 0;
int             randsprings = 0;
int             textcolor;
int             tbreak;
int             gameplan = COOPERATIVE;
int             npoint = 0;
int             gamemode;
int             keys[5][4];
int             rotation[MAXROCKETS];
int             a_bballs, a_rockets, a_balls, a_holes, a_apples, a_inspectors,
                a_lunatics, a_eholes;
int             mouseplayer = -1;
double          ROCKET_SPEED = 1.2;
double          BALL_SPEED = 1.2;
double          BBALL_SPEED = 1.2;
double          SLOWDOWN = 0.8;
double          GUMM = 20;
double          BALLM = 10;
double          LBALLM = 3;
double          BBALLM = 8;
double          APPLEM = 34;
double          INSPECTORM = 2;
double          LUNATICM = 3.14;
double          ROCKETM = 4;

void addpoint (CONST int x, CONST int y, CONST int xp, CONST int yp, CONST int color, CONST int time)
{
	point[npoint].x = x / DIV;
	point[npoint].y = y / DIV;
	point[npoint].xp = xp / DIV;
	point[npoint].yp = yp / DIV;
	point[npoint].time = time;

	point[npoint].color = color;
	npoint++;
	if (npoint >= MAXPOINT)
		npoint = 0;
}

void points ()
{
	int x, y;
	Point          *p, *lp;
	lp = &point[MAXPOINT];
	DDSURFACEDESC desc;
	ZeroMemory( &desc, sizeof(desc) );
	desc.dwSize = sizeof(desc);
	HRESULT r=draw_surf->Lock( 0, &desc, DDLOCK_WAIT | DDLOCK_WRITEONLY, 0 );
	if (r!=DD_OK)
		return ;//can't lock so return 
	BYTE* surfbits = (BYTE*)desc.lpSurface;

	for (p = point; p < lp; p++)
	{
		if (p->time > 0)
		{
			p->time--;
			x = (p->x += p->xp) >> 8;
			y = (p->y += p->yp) >> 8;
			////////////////!!!!!!!!!!!!!!!!!!!!!!
			if (x > 0 && x < MAPWIDTH &&
				y > 0 && y < MAPHEIGHT)
				*(surfbits+y*desc.lPitch+x)=p->color;
			else
				p->time = 0;
		}
    } 
	
	draw_surf->Unlock( 0 );
}

void points1 ()
{
	Point          *p, *lp;
	lp = &point[MAXPOINT];
	for (p = point; p < lp; p++)
    {
		if (p->time > 0)
		{
			p->time--;
			p->x += p->xp;
			p->y += p->yp;
		}
    }
}

INLINE int radius (CONST int type)
{
	switch (type)
    {
	case EHOLE:
	case HOLE:
		return (HOLE_RADIUS);
    case ROCKET:
      return (ROCKET_RADIUS);
    case BALL:
    case LBALL:
      return (BALL_RADIUS);
    case BBALL:
      return (BBALL_RADIUS);
    case APPLE:
      return (APPLE_RADIUS);
    case INSPECTOR:
      return (INSPECTOR_RADIUS);
    case LUNATIC:
      return (LUNATIC_RADIUS);
    }
  return (0);
}

static INLINE int color (CONST int type, CONST int i, CONST int letter)
{
  switch (type)
    {
    case EHOLE:
      return (128);
    case HOLE:
      return (64);
    case ROCKET:
      return (rocketcolor[i]);
    case BALL:
      return (64);
    case LBALL:
      switch (letter)
	{
	case L_ACCEL:
	  return (128);
	case L_GUMM:
	  return (160);
	case L_THIEF:
	  return (192);
	case L_FINDER:
	  return (3 * 32);
	case L_TTOOL:
	  return (3 * 32);
	}

    case BBALL:
      return (128);
    case APPLE:
      return (64);
    case INSPECTOR:
      return (160);
    case LUNATIC:
      return (3 * 32);
    }
  return (0);
}

INLINE double M (CONST int type)
{
  switch (type)
    {
    case APPLE:
      return (APPLEM);
    case INSPECTOR:
      return (INSPECTORM);
    case LUNATIC:
      return (LUNATICM);
    case HOLE:
    case EHOLE:
      return (BBALLM);
    case ROCKET:
      return (ROCKETM);
    case BALL:
    case LBALL:
      return (BALLM);
    case BBALL:
      return (BBALLM);
    }
  return (0);
}

int find_possition (double *x, double *y, CONST double radius)
{
  int             x1, y1, i, y2 = 0;
  double           xp, yp;
rerand:;
  x1 = rand () % (GAMEWIDTH - 60) + 30;
  y1 = rand () % (GAMEHEIGHT - 60) + 30;
  for (i = 0; i < nobjects; i++)
    {
      xp = x1 - object[i].x;
      yp = y1 - object[i].y;
      if (xp * xp + yp * yp < (radius + object[i].radius) *
	  (radius + object[i].radius))
	{
	  y2++;
	  if (y2 > 10000)
	    return (0);
	  goto rerand;

	}
    }
  *x = (double) x1;
  *y = (double) y1;
  return (1);
}

INLINE void normalize (double *x, double *y, double size)
{
  double           length = sqrt ((*x) * (*x) + (*y) * (*y));
  if (length == 0)
    length = 1;
  *x *= size / length;
  *y *= size / length;
}


static void move_objects ()
{
	int             i;
	for (i = 0; i < nobjects; i++)
    if (object[i].type == CREATOR)
    {
		object[i].time--;
		if (object[i].time <= 0)
		{
	    Effect (S_CREATOR2);
			object[i].live = object[i].live1;
			object[i].type = object[i].ctype;
			if (object[i].type == ROCKET)
				object[i].time = 200;
			object[i].radius = radius (object[i].ctype);
			object[i].M = M (object[i].ctype);
		}
    }
	else if (object[i].live)
    {
		object[i].x += object[i].fx * (GAMEWIDTH / 640.0 + 1) / 2;
		object[i].y += object[i].fy * (GAMEWIDTH / 640.0 + 1) / 2;
    }
}

char            str[2]={0,0};
static void draw_objects (CONST int draw)
{
	char            s[80];
	int             i;
	if (draw)
    {
		CopyVSToVS (background,draw_surf);
      /* Now draw the objects in backscreen. */
		points ();
		for (i = 0; i < nobjects; i++)
		if (object[i].live && object[i].lineto != -1 && object[object[i].lineto].live)
			Line ((int)(object[i].x / DIV),
			(int)(object[i].y / DIV),
			(int)(object[object[i].lineto].x / DIV),
			(int)(object[object[i].lineto].y / DIV),
			255);
		for (i = 0; i < nobjects; i++)
			if (object[i].live)
			{
			    switch (object[i].type)
				{
				case BALL:
					PutBitmap ((int) (object[i].x - BALL_RADIUS) / DIV, (int) (object[i].y - BALL_RADIUS) / DIV,
					BALL_RADIUS * 2 / DIV, BALL_RADIUS * 2 / DIV, ball_bitmap);
				break;
				case LBALL:
					switch (object[i].letter)
					{
					case L_ACCEL:
						PutBitmap ((int) (object[i].x - BALL_RADIUS) / DIV, (int) (object[i].y - BALL_RADIUS) / DIV,
						BALL_RADIUS * 2 / DIV, BALL_RADIUS * 2 / DIV, lball_bitmap[0]);
					break;
					case L_GUMM:
						PutBitmap ((int) (object[i].x - BALL_RADIUS) / DIV, (int) (object[i].y - BALL_RADIUS) / DIV,
							BALL_RADIUS * 2 / DIV, BALL_RADIUS * 2 / DIV, lball_bitmap[1]);
					break;
					case L_THIEF:
						PutBitmap ((int) (object[i].x - BALL_RADIUS) / DIV, (int) (object[i].y - BALL_RADIUS) / DIV,
						BALL_RADIUS * 2 / DIV, BALL_RADIUS * 2 / DIV, lball_bitmap[2]);
					break;
					case L_FINDER:
						PutBitmap ((int) (object[i].x - BALL_RADIUS) / DIV, (int) (object[i].y - BALL_RADIUS) / DIV,
						BALL_RADIUS * 2 / DIV, BALL_RADIUS * 2 / DIV, lball_bitmap[3]);
					break;
					case L_TTOOL:
						PutBitmap ((int) (object[i].x - BALL_RADIUS) / DIV, (int) (object[i].y - BALL_RADIUS) / DIV,
						BALL_RADIUS * 2 / DIV, BALL_RADIUS * 2 / DIV, lball_bitmap[4]);
						if (DIV == 1)
						{
							str[0] = object[i].letter;
							DrawBlackMaskedText ((int) object[i].x / DIV - 4, (int) object[i].y / DIV - 6, str);
						}

					break;
					}
				break;
				case HOLE:
					PutBitmap ((int) (object[i].x - HOLE_RADIUS) / DIV, (int) (object[i].y - HOLE_RADIUS) / DIV,
					HOLE_RADIUS * 2, HOLE_RADIUS * 2, hole_bitmap);
				break;
				case EHOLE:
					PutBitmap ((int) (object[i].x - HOLE_RADIUS) / DIV, (int) (object[i].y - HOLE_RADIUS) / DIV,
					HOLE_RADIUS * 2, HOLE_RADIUS * 2, ehole_bitmap);
				break;
				case BBALL:
					PutBitmap ((int) (object[i].x - BBALL_RADIUS) / DIV, (int) (object[i].y - BBALL_RADIUS) / DIV,
					BBALL_RADIUS * 2 / DIV, BBALL_RADIUS * 2 / DIV, bball_bitmap);
				break;
				case INSPECTOR:
					PutBitmap ((int) (object[i].x - INSPECTOR_RADIUS) / DIV, (int) (object[i].y - INSPECTOR_RADIUS) / DIV,
					INSPECTOR_RADIUS * 2 / DIV, INSPECTOR_RADIUS * 2 / DIV, inspector_bitmap);
				break;
				case LUNATIC:
					PutBitmap ((int) (object[i].x - LUNATIC_RADIUS) / DIV, (int) (object[i].y - LUNATIC_RADIUS) / DIV,
					LUNATIC_RADIUS * 2 / DIV, LUNATIC_RADIUS * 2 / DIV, lunatic_bitmap);
				break;
				case APPLE:
					PutBitmap ((int) (object[i].x - APPLE_RADIUS) / DIV, (int) (object[i].y - APPLE_RADIUS) / DIV,
					APPLE_RADIUS * 2 / DIV, APPLE_RADIUS * 2 / DIV, apple_bitmap);
					Line ((int) (object[i].x + 10) / DIV, (int) (object[i].y - APPLE_RADIUS - 10) / DIV,
					(int) (object[i].x) / DIV, (int) (object[i].y - APPLE_RADIUS + 10) / DIV, 150);
					Line ((int) (object[i].x + 10) / DIV + 1, (int) (object[i].y - APPLE_RADIUS - 10) / DIV,
					(int) (object[i].x) / DIV + 1, (int) (object[i].y - APPLE_RADIUS + 10) / DIV, 150);
					if (DIV == 1)
						Line ((int) (object[i].x + 10) / DIV + 2, (int) (object[i].y - APPLE_RADIUS - 10) / DIV,
						(int) (object[i].x) / DIV + 2, (int) (object[i].y - APPLE_RADIUS + 10) / DIV, 150);
					PutBitmap ((int) (object[i].x - EYE_RADIUS) / DIV,
					(int) (object[i].y + APPLE_RADIUS - 15) / DIV,
					EYE_RADIUS * 2 / DIV, EYE_RADIUS * 2 / DIV, eye_bitmap[0]);
				break;
				case ROCKET:
				{
					int             x1, y1;
					PutBitmap ((int) (object[i].x - ROCKET_RADIUS) / DIV, (int) (object[i].y - ROCKET_RADIUS) / DIV,
						ROCKET_RADIUS * 2 / DIV, ROCKET_RADIUS * 2 / DIV, rocket_bitmap[i]);
					if (!object[i].thief)
					{
						x1 =(int)( object[i].x + sin (object[i].rotation - RAD (30)) * EYE_RADIUS1 - EYE_RADIUS);
						y1 =(int)( object[i].y + cos (object[i].rotation - RAD (30)) * EYE_RADIUS1 - EYE_RADIUS);
						PutBitmap ((int) (x1 / DIV), (int) (y1 / DIV),
						(int) (EYE_RADIUS * 2 / DIV), (EYE_RADIUS * 2 / DIV), eye_bitmap[i]);
						x1 =(int)( object[i].x + sin (object[i].rotation + RAD (30)) * EYE_RADIUS1 - EYE_RADIUS);
						y1 =(int)( object[i].y + cos (object[i].rotation + RAD (30)) * EYE_RADIUS1 - EYE_RADIUS);
						PutBitmap ((int) (x1 / DIV), (int) (y1 / DIV),
						(int) (EYE_RADIUS * 2 / DIV), (EYE_RADIUS * 2 / DIV), eye_bitmap[i]);
					}
					else
					{
						x1 =(int)( object[i].x + sin (object[i].rotation - RAD (30)) * EYE_RADIUS1 - BALL_RADIUS);
						y1 =(int)( object[i].y + cos (object[i].rotation - RAD (30)) * EYE_RADIUS1 - BALL_RADIUS);
	
					    PutBitmap ((int) (x1 / DIV), (int) (y1 / DIV),
							(int) (BALL_RADIUS * 2 / DIV), (BALL_RADIUS * 2 / DIV), lball_bitmap[2]);
						x1 =(int)( object[i].x + sin (object[i].rotation + RAD (30)) * EYE_RADIUS1 - BALL_RADIUS);
						y1 =(int)( object[i].y + cos (object[i].rotation + RAD (30)) * EYE_RADIUS1 - BALL_RADIUS);
						PutBitmap ((int) (x1 / DIV), (int) (y1 / DIV),
						(int) (BALL_RADIUS * 2 / DIV), (BALL_RADIUS * 2 / DIV), lball_bitmap[2]);
					}
				}
				break;
			}
		}
    }
  /*if draw */
	else
	points1 ();
	switch (gamemode)
    {

⌨️ 快捷键说明

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