📄 koules.cpp
字号:
case MENU:
draw_menu (draw);
break;
case KEYS:
draw_keys (draw);
break;
default:
break;
}
if (draw && (gamemode == MENU || (gamemode == GAME && mouseplayer != -1)) &&
MouseX () >= 0 && MouseY () >= 0 && MouseX () < MAPWIDTH &&
MouseY () < MAPHEIGHT && drawpointer)
{
PutBitmap (MouseX () - MOUSE_RADIUS, MouseY () - MOUSE_RADIUS,
MOUSE_RADIUS * 2, MOUSE_RADIUS * 2, mouse_bitmap);
}
if (draw)
{
if (gameplan == COOPERATIVE && gamemode == GAME && DIV == 1)
{
sprintf (s, "level: %3i", lastlevel + 1);
DrawWhiteMaskedText ((MAPWIDTH / 3 - 38 * 4) / 2 - TextLen(s) /2, MAPHEIGHT + 1, s);
}
sprintf (s, " lives: %6i%6i%6i%6i%6i",
nrockets >= 1 ? object[0].live1 : 0,
nrockets >= 2 ? object[1].live1 : 0,
nrockets >= 3 ? object[2].live1 : 0,
nrockets >= 4 ? object[3].live1 : 0,
nrockets >= 5 ? object[4].live1 : 0);
DrawWhiteMaskedText (MAPWIDTH / 2 - TextLen(s) /2, MAPHEIGHT + 1, s);
sprintf (s, "scores: %6i%6i%6i%6i%6i",
object[0].score,
object[1].score,
object[2].score,
object[3].score,
object[4].score);
DrawWhiteMaskedText (MAPWIDTH / 2 - TextLen(s) /2, MAPHEIGHT + 12, s);
if(show_playerdata)
{
sprintf (s, "Weight: %5.2f", object[0].M);
int l=MAPWIDTH - TextLen(s);
DrawWhiteMaskedText (l, MAPHEIGHT , s);
sprintf (s, " Accel: %5.2f", object[0].accel);
DrawWhiteMaskedText (MAPWIDTH - TextLen(s), MAPHEIGHT + 13, s);
sprintf (s, "Player %1i:", show_player);
DrawWhiteMaskedText (l - TextLen(s) - 10, MAPHEIGHT , s);
}
}
}
void explosion (CONST int x, CONST int y, CONST int type, CONST int letter, CONST int n)
{
double i;
int speed;
int color1;
int radius1 = radius (type);
for (i = 0; i < RAD (360); i += RAD (360.0) * DIV * DIV / radius1 / radius1 / M_PI)
{
speed = rand () % 3096 + 10;
if (DIV == 1)
color1 = color (type, n, letter) + (rand () % 16);
else
color1 = color (type, n, letter) + (rand () % 32);
addpoint (x * 256, y * 256,
(int)(sin (i) * (speed)),
(int)(cos (i) * (speed)),
color1,
rand () % 100 + 10);
}
}
static void rocket_destroyed (CONST int player)
{
int i, nalive = 0, igagnant = 0;
if (gamemode == GAME)
switch (gameplan)
{
case DEATHMATCH:
if (nrockets == 1)
return;
for (i = 0; i < nrockets; i++)
if (object[i].type == ROCKET && object[i].live && i != player)
{
object[i].score += 100;
nalive++;
igagnant = i;
}
if (nalive == 1) /* winner bonus */
object[igagnant].score += 50;
}
}
void destroy (CONST int i)
{
int y;
if (object[i].x - object[i].radius < 0)
object[i].x = object[i].radius + 1, object[i].fx *= -1;
if (object[i].y - object[i].radius < 0)
object[i].y = object[i].radius + 1, object[i].fy *= -1;
if (object[i].x + object[i].radius > GAMEWIDTH)
object[i].x = GAMEWIDTH - object[i].radius - 1, object[i].fx *= -1;
if (object[i].y + object[i].radius > GAMEHEIGHT)
object[i].y = GAMEHEIGHT - object[i].radius - 1, object[i].fy *= -1;
switch (object[i].type)
{
case LBALL:
Effect (S_DESTROY_BALL);
object[i].live = 0, explosion ((int)(object[i].x), (int)(object[i].y), object[i].type, object[i].letter, i);
if (object[i].letter == L_THIEF && allow_finder ())
{
object[i].live = 1;
object[i].letter = L_FINDER;
}
break;
case APPLE:
Effect (S_DESTROY_ROCKET);
object[i].live = 0, explosion ((int)(object[i].x), (int)(object[i].y), object[i].type, object[i].letter, i);
break;
case BALL:
case EHOLE:
case BBALL:
case INSPECTOR:
case LUNATIC:
Effect (S_DESTROY_BALL);
if ((y = create_letter ()) != 0)
{
object[i].type = LBALL;
object[i].M = LBALLM;
switch (y)
{
case 1:
object[i].letter = L_ACCEL;
break;
case 2:
object[i].letter = L_GUMM;
break;
case 3:
object[i].letter = L_THIEF;
break;
case 4:
object[i].letter = L_FINDER;
break;
case 5:
object[i].letter = L_TTOOL;
break;
}
}
else
object[i].live = 0, explosion ((int)(object[i].x),(int)( object[i].y), object[i].type, object[i].letter, i);
break;
case ROCKET:
Effect (S_DESTROY_ROCKET);
object[i].live1--, object[i].live--, explosion ((int)(object[i].x),(int)( object[i].y), object[i].type, object[i].letter, i);
rocket_destroyed (i);
if (object[i].live)
{
object[i].fx = 0;
object[i].fy = 0;
object[i].rotation = 0;
object[i].type = ROCKET;
object[i].accel = ROCKET_SPEED;
creator_rocket (i);
}
break;
}
}
static void check_limit ()
{
int i;
for (i = 0; i < nobjects; i++)
if (object[i].live)
{
if (object[i].x - object[i].radius < 0 || object[i].x + object[i].radius >= GAMEWIDTH ||
object[i].y - object[i].radius <= 0 || object[i].y + object[i].radius >= GAMEHEIGHT)
{
destroy (i);
}
}
}
/*
* count number of creatures
*/
static void update_values ()
{
int i;
a_holes = 0;
a_rockets = 0;
a_balls = 0;
a_bballs = 0;
a_apples = 0;
a_eholes = 0;
a_inspectors = 0;
a_lunatics = 0;
for (i = 0; i < nobjects; i++)
{
if (object[i].live)
{
switch (object[i].type)
{
case HOLE:
a_holes++;
break;
case EHOLE:
a_eholes++;
break;
case ROCKET:
a_rockets++;
break;
case LBALL:
case BALL:
a_balls++;
break;
case BBALL:
a_bballs++;
break;
case APPLE:
a_apples++;
break;
case INSPECTOR:
a_inspectors++;
break;
case LUNATIC:
a_lunatics++;
break;
}
}
if (object[i].type == CREATOR)
{
switch (object[i].ctype)
{
case BBALL:
a_bballs++;
break;
case HOLE:
a_holes++;
break;
case EHOLE:
a_eholes++;
break;
case ROCKET:
a_rockets++;
break;
case LBALL:
case BALL:
a_balls++;
break;
case APPLE:
a_apples++;
break;
case INSPECTOR:
a_inspectors++;
break;
case LUNATIC:
a_lunatics++;
break;
}
}
}
}
/*
* accelerate rocket
*/
void accel (CONST int i)
{
int y;
{
object[i].time = 0;
object[i].fx += sin (object[i].rotation) * object[i].accel,
object[i].fy += cos (object[i].rotation) * object[i].accel;
for (y = 0; y < 5 / DIV / DIV; y++)
{
double p;
p = RAD (rand () % 45 - 22);
addpoint ((int)(object[i].x * 256),
(int)(object[i].y * 256),
(int)((object[i].fx - sin (object[i].rotation + p) * object[i].accel * 10) * (rand () % 512)),
(int)((object[i].fy - cos (object[i].rotation + p) * object[i].accel * 10) * (rand () % 512)),
rocket (rand () % 16), 10);
}
}
}
static void sprocess_keys ()
{
int i;
if (gamemode != GAME)
return;
for (i = 0; i < MAXROCKETS; i++)
{
if (object[i].live && object[i].type == ROCKET)
{
switch (controls[i].type)
{
case C_JOYSTICK1:
{
double a, x = controls[i].jx, y = controls[i].jy;
a = atan (fabs (y) / fabs (x));
if (x < 0 && y >= 0)
object[i].rotation = a + RAD (90);
else if (x < 0 && y < 0)
object[i].rotation = RAD (90) - a;
else if (x >= 0 && y < 0)
object[i].rotation = a + RAD (270);
else if (x >= 0 && y >= 0)
object[i].rotation = RAD (270) - a;
if (controls[i].mask)
accel (i);
}
break;
case C_MOUSE:
{
double dx, dy, a;
dx = object[i].x - controls[i].mx;
dy = object[i].y - controls[i].my;
if (dx == 0)
dx = 0.001;
a = atan (fabs (dy) / fabs (dx));
if (dx < 0 && dy >= 0)
object[i].rotation = a + RAD (90);
else if (dx < 0 && dy < 0)
object[i].rotation = RAD (90) - a;
else if (dx >= 0 && dy < 0)
object[i].rotation = a + RAD (270);
else if (dx >= 0 && dy >= 0)
object[i].rotation = RAD (270) - a;
if (controls[i].mask)
accel (i);
}
break;
case C_RKEYBOARD:
if (controls[i].mask & 1)
object[i].rotation += ROTSTEP;
if (controls[i].mask & 2)
object[i].rotation -= ROTSTEP;
if (controls[i].mask & 4)
accel (i);
break;
case C_KEYBOARD:
switch (controls[i].mask)
{
case 1:
object[i].rotation = RAD (-135), accel (i);
break;
case 2:
object[i].rotation = RAD (135), accel (i);
break;
case 3:
object[i].rotation = RAD (45), accel (i);
break;
case 4:
object[i].rotation = RAD (-45), accel (i);
break;
case 5:
object[i].rotation = RAD (-90), accel (i);
break;
case 6:
object[i].rotation = RAD (90), accel (i);
break;
case 7:
object[i].rotation = RAD (180), accel (i);
break;
case 8:
object[i].rotation = RAD (0), accel (i);
break;
}
}
}
}
}
void process_keys ()
{
int i;
if (IsPressedP () && gamemode!=MENU)
{
SetScreen (GetDDWin()->backsurf);
DrawWhiteMaskedText (MAPWIDTH / 2 - 20, MAPHEIGHT / 2 - 4, "PAUSE");
CopyToScreen(GetDDWin()->backsurf);
tbreak = 1;
while(IsPressedP())
UpdateInput();
while(!IsPressedP())
UpdateInput();
while(IsPressedP())
UpdateInput();
}
switch (gamemode)
{
case MENU:
menu_keys ();
break;
case KEYS:
keys_keys ();
break;
case GAME:
/* Move. */
if (mouseplayer != -1 && object[mouseplayer].type == ROCKET)
{
controls[mouseplayer].mx = MouseX () * DIV;
controls[mouseplayer].my = MouseY () * DIV;
controls[mouseplayer].mask = MouseButtons () != 0;
controls[mouseplayer].type = C_MOUSE;
}
if (IsPressedEsc ())
{
gamemode = MENU;
while(IsPressedEsc())
UpdateInput();
}
if (IsPressed (SCANCODE_TAB))
{
show_player++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -