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

📄 gremlin.c

📁 Space Invaders game
💻 C
字号:
#pragma hdrstop
#include "invaders.h"

GREMLIN      Gremlins[5][11];
GREMLINPTR   LastGremlinMoved;
int          LastGremlinRow;		  // Y index of Gremlins for last move

GREMLINPTR   RowEndLeft[5];
GREMLINPTR   RowEndRight[5];

struct gremtype {
	 unsigned char *GremlinOne;
	 unsigned char *GremlinTwo;
	 unsigned char *GremlinThree;
	 int            val;
} GremType[2][5] = {
	{{Gremlin0b, Gremlin0, Gremlin1, 30},
	 {Gremlin2b, Gremlin2, Gremlin3, 20},
	 {Gremlin4b, Gremlin4, Gremlin5, 20},
	 {Gremlin6b, Gremlin6, Gremlin7, 10},
	 {Gremlin8b, Gremlin8, Gremlin9, 10}},

	{{Gremlin0b, Gremlin0, Gremlin1, 30},
	 {Gremlin2b, Gremlin2, Gremlin3, 20},
	 {Gremlin2b, Gremlin2, Gremlin3, 20},
	 {Gremlin6b, Gremlin6, Gremlin7, 10},
	 {Gremlin6b, Gremlin6, Gremlin7, 10}}
};

struct init {
	 GREMLINPTR Gremlin;
	 int        LastGremlinRow;
	 int       *Direction;
	 int        StartRow;
	 int        offset;
	 int        GremTypeIndex;
	 int        xoff;
	 int        yoff;
} InitTable[] = {
	 {&Gremlins[0][10], 0, &MovingDownLeft,   3, FALSE, 0, 18, -27},
	 {&Gremlins[0][10], 0, &MovingDownLeft,   6, FALSE, 0,  0, -27},
	 {&Gremlins[0][10], 0, &MovingDownLeft,   3, FALSE, 1,  9,   3},
	 {&Gremlins[0][0],  0, &MovingDownRight,  9, TRUE,  1,  0, -27},
	 {&Gremlins[0][0],  0, &MovingDownRight,  9, TRUE,  1,  0, -27},
	 {&Gremlins[0][0],  0, &MovingDownRight,  9, TRUE,  1,  0, -27},
	 {&Gremlins[0][10], 0, &MovingDownLeft,  12, FALSE, 1,  0, -27},
	 {&Gremlins[0][10], 0, &MovingDownLeft,  12, FALSE, 1,  0, -27},
	 {&Gremlins[0][0],  0, &MovingDownRight, 15, TRUE,  0,  0, -27}
};


void InitGremlins()
{
	 int VFrame, x, y, val, xoffset, yoffset, soffset;
	 unsigned char *obj0, *obj1, *objb;

	 if (Frame > 9)
		  VFrame = 1+((Frame-2)%8);
	 else
		  VFrame = Frame-1;

	 if (VFrame == 2) {
		  TimerFrame = TRUE;
		  TimerSeconds = TimerFrameLength;
	 } else
		  TimerFrame = FALSE;

	 Tick = 0;
	 GremlinsHitWall = FALSE;
	 MovingDown = TRUE;

	 xoffset = InitTable[VFrame].xoff;
	 yoffset = InitTable[VFrame].yoff;
	 LastGremlinMoved = InitTable[VFrame].Gremlin;
	 LastGremlinRow = InitTable[VFrame].LastGremlinRow;
	 StartFrameRow = InitTable[VFrame].StartRow;

	 MovingLeft = FALSE;
	 MovingRight = FALSE;
	 MovingDownLeft = FALSE;
	 MovingDownRight = FALSE;
	 *(InitTable[VFrame].Direction) = TRUE;

	 for (y = 0; y < 5; y++) {
		  RowEndLeft[y] = &Gremlins[y][0];
		  RowEndRight[y] = &Gremlins[y][10];
		  objb = GremType[InitTable[VFrame].GremTypeIndex][y].GremlinOne;
		  obj0 = GremType[InitTable[VFrame].GremTypeIndex][y].GremlinTwo;
		  obj1 = GremType[InitTable[VFrame].GremTypeIndex][y].GremlinThree;
		  val  = GremType[InitTable[VFrame].GremTypeIndex][y].val;
		  if (InitTable[VFrame].offset)
				soffset = 10 - *obj0;
		  else
				soffset = 0;
		  for (x = 0; x < 11; x++) {
				if (x == 0)
					 Gremlins[y][x].left = NULL;
				else
					 Gremlins[y][x].left = &Gremlins[y][x-1];
				if (x == 10)
					 Gremlins[y][x].right = NULL;
				else
					 Gremlins[y][x].right = &Gremlins[y][x+1];
				Gremlins[y][x].xpos = x*10+xoffset+soffset;
				Gremlins[y][x].ypos = y*6+yoffset;
				Gremlins[y][x].value = val;
				Gremlins[y][x].alive = TRUE;
				Gremlins[y][x].object[0] = obj0;
				Gremlins[y][x].object[1] = obj1;
				Gremlins[y][x].object[2] = objb;
		  }
	 }
}


⌨️ 快捷键说明

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