📄 koules.c
字号:
float xp, yp;
int frocket = 0;
for (i = 0; i < koulesnobjects; i++)
{
if (koulesobject[i].live)
{
if (koulesobject[i].lineto != -1)
{
if (!koulesobject[koulesobject[i].lineto].live)
koulesobject[i].lineto = -1;
else if (koulesobject[i].lineto == i)
koulesobject[i].lineto = -1;
else
{
int force;
xp = koulesobject[i].x -
koulesobject[koulesobject[i].lineto].x;
yp = koulesobject[i].y -
koulesobject[koulesobject[i].lineto].y;
force = (int) sqrt(xp * xp + yp * yp);
if (force >= 2 * SPRINGSIZE ||
koulesgameplan == COOPERATIVE)
{
force = force - SPRINGSIZE;
if (force < 0)
force *= 3;
force = force / SPRINGSTRENGTH;
Koules_normalize(&xp, &yp,
force * BALL_SPEED / koulesobject[i].M);
koulesobject[i].fx -= xp;
koulesobject[i].fy -= yp;
Koules_normalize(&xp, &yp,
force * BALL_SPEED /
koulesobject[koulesobject[i].lineto].M);
koulesobject[koulesobject[i].lineto].fx += xp;
koulesobject[koulesobject[i].lineto].fy += yp;
}
}
}
if (koulesobject[i].type == ROCKET && koulesobject[i].time)
koulesobject[i].time--;
if (koulesobject[i].type == ROCKET && !koulesobject[i].time)
{
d = 640 * 640;
frocket = -1;
for (r = 0; r < koulesnobjects; r++)
{
if (koulesobject[r].live &&
!koulesobject[r].time &&
koulesobject[r].type == EHOLE)
{
int distance;
float gravity;
xp = koulesobject[r].x - koulesobject[i].x;
yp = koulesobject[r].y - koulesobject[i].y;
distance = (int) sqrt(xp * xp + yp * yp);
gravity = BALL_SPEED * (koulesgameplan ==
COOPERATIVE ?
200 :
50) /
distance;
if (gravity > BALL_SPEED * 4 / 5)
gravity = BALL_SPEED * 4 / 5;
Koules_normalize(&xp, &yp, gravity);
koulesobject[i].fx += xp;
koulesobject[i].fy += yp;
}
}
}
if (koulesobject[i].type == BALL ||
koulesobject[i].type == LBALL ||
koulesobject[i].type == BBALL ||
koulesobject[i].type == LUNATIC)
{
frocket = -1;
d = 640 * 640;
for (r = 0; r < koulesnrockets; r++)
{
if (koulesobject[r].live && !koulesobject[r].time)
{
xp = koulesobject[r].x - koulesobject[i].x;
yp = koulesobject[r].y - koulesobject[i].y;
if (xp * xp + yp * yp < d)
d = xp * xp + yp * yp, frocket = r;
}
}
if (frocket != -1)
xp = koulesobject[frocket].x - koulesobject[i].x,
yp = koulesobject[frocket].y - koulesobject[i].y;
else
xp = KOULESGAMEWIDTH / 2 - koulesobject[i].x,
yp = KOULESMAPHEIGHT / 2 - koulesobject[i].y;
if (koulesobject[i].type == LUNATIC && !KoulesGetRand() % 4)
{
xp = (float) KoulesGetRand();
yp = (float)(KoulesGetRand() + 1);
}
switch (koulesobject[i].type)
{
case BBALL:
Koules_normalize(&xp, &yp, BBALL_SPEED);
break;
case BALL:
case LUNATIC:
case LBALL:
Koules_normalize(&xp, &yp, BALL_SPEED);
break;
}
koulesobject[i].fx += xp;
koulesobject[i].fy += yp;
}
koulesobject[i].fx *= SLOWDOWN,
koulesobject[i].fy *= SLOWDOWN;
}
}
}
static void Koules_colisions(void)
{
int i, y;
int colize = 0;
static int ctime = 0;
float xp, yp, gummfactor;
for (i = 0; i < koulesnobjects; i++)
if (koulesobject[i].live)
for (y = i + 1; y < koulesnobjects; y++)
if (koulesobject[y].live)
{
xp = koulesobject[y].x - koulesobject[i].x;
yp = koulesobject[y].y - koulesobject[i].y;
if (xp * xp +
yp * yp <
(koulesobject[y].radius + koulesobject[i].radius) * (koulesobject[y].radius +
koulesobject[i].radius))
{
colize = 1;
if (koulesobject[i].type == HOLE ||
koulesobject[i].type == EHOLE)
{
if (koulesobject[y].type != APPLE)
Koules_destroy(y);
if (koulesobject[i].type == EHOLE)
Koules_destroy(i);
continue;
}
if (koulesobject[y].type == HOLE ||
koulesobject[y].type == EHOLE)
{
if (koulesobject[i].type != APPLE)
Koules_destroy(i);
if (koulesobject[y].type == EHOLE)
Koules_destroy(y);
continue;
}
if (koulesobject[i].type == ROCKET)
{
if (koulesobject[y].thief == 1 &&
koulesobject[i].thief == 1)
{
float tmp;
tmp = koulesobject[i].M;
koulesobject[i].M = koulesobject[y].M;
koulesobject[y].M = tmp;
koulesobject[i].thief = 0;
koulesobject[y].thief = 0;
}
if (koulesobject[y].type == BBALL &&
koulesobject[i].thief == 1)
{
koulesobject[i].M += koulesobject[y].M -
Koules_M(BALL);
koulesobject[i].thief = 0;
koulesobject[y].M = Koules_M(BALL);
}
else if (koulesobject[y].type == ROCKET &&
koulesobject[i].thief == 1)
{
koulesobject[i].M += koulesobject[y].M -
Koules_M(ROCKET);
koulesobject[i].accel += koulesobject[y].accel -
ROCKET_SPEED;
koulesobject[i].thief = 0;
koulesobject[y].M = Koules_M(koulesobject[i].type);
koulesobject[y].accel = ROCKET_SPEED - A_ADD;
}
if (koulesobject[i].type == ROCKET &&
koulesobject[y].thief == 1)
{
koulesobject[y].M += koulesobject[i].M -
Koules_M(ROCKET);
koulesobject[y].accel += koulesobject[i].accel -
ROCKET_SPEED;
koulesobject[y].thief = 0;
koulesobject[i].M = Koules_M(koulesobject[y].type);
koulesobject[i].accel = ROCKET_SPEED - A_ADD;
}
if (koulesgameplan == COOPERATIVE)
koulesobject[i].score++;
if (koulesobject[y].letter == L_ACCEL)
koulesobject[i].accel += A_ADD,
koulesobject[i].score += 10;
if (koulesobject[y].letter == L_GUMM)
koulesobject[i].M += M_ADD,
koulesobject[i].score += 10;
if (koulesobject[y].letter == L_THIEF)
koulesobject[i].M = Koules_M(koulesobject[i].type),
koulesobject[i].accel = ROCKET_SPEED -
A_ADD,
koulesobject[i].score -= 30;
if (koulesobject[y].letter == L_FINDER)
{
koulesobject[i].accel += A_ADD * (KoulesGetRand() % 5);
koulesobject[i].M += M_ADD * (KoulesGetRand() % 10);
koulesobject[i].score += 30;
}
if (koulesobject[y].letter == L_TTOOL)
{
koulesobject[i].thief = 1;
koulesobject[i].score += 30;
}
koulesobject[y].letter = ' ';
if (koulesobject[y].type == LBALL)
koulesobject[y].type = BALL;
if (koulesobject[y].type == BALL &&
koulesdosprings &&
!(KoulesGetRand() % koulesrandsprings))
koulesobject[y].lineto = i;
if (koulesgameplan == DEATHMATCH &&
koulesobject[y].type == ROCKET &&
koulesdosprings &&
!(KoulesGetRand() % (2 * koulesrandsprings)))
koulesobject[y].lineto = i;
}
if (koulesobject[y].type == LUNATIC)
{
gummfactor = -ROCKETM / LUNATICM;
}
else if (koulesobject[i].type == LUNATIC)
{
gummfactor = -LUNATICM / ROCKETM;
}
else
gummfactor = koulesobject[i].M /
koulesobject[y].M;
Koules_normalize(&xp, &yp, gummfactor * GUMM);
koulesobject[y].fx += xp;
koulesobject[y].fy += yp;
Koules_normalize(&xp, &yp, 1 / gummfactor * GUMM);
koulesobject[i].fx -= xp;
koulesobject[i].fy -= yp;
if (koulesobject[i].type == ROCKET &&
koulesobject[i].time)
koulesobject[i].fx = 0,
koulesobject[i].fy = 0;
if (koulesobject[y].type == ROCKET &&
koulesobject[y].time)
koulesobject[y].fx = 0,
koulesobject[y].fy = 0;
if (koulesobject[y].type == INSPECTOR &&
koulesobject[i].type == ROCKET)
{
koulesobject[y].fx = 0,
koulesobject[y].fy = 0;
koulesobject[i].fx *= -2,
koulesobject[i].fy *= -2;
}
}
}
if (colize && !ctime)
{
Koulesplay_sound(S_COLIZE);
ctime = 4;
}
if (ctime)
ctime--;
}
//void KoulesGameCycle(void)
BOOLEAN KoulesGameCycle(ROCK_MSG_ID id, void* msg)
{
// int i;
if (id == AS_GUVI_KOULESGAME_START)
{
koulesinloop = TRUE;
DISPUPDATE_DISABLE();
while (koulesinloop)
{
if (koules_key_pause)
{
KoulesDrawShadowText((KOULESMAPWIDTH / 2) - (4 * 6), 140, "PAUSED");
Koules_updatescreen();
if (koules_key_esc)
{
koulesgamemode = KOULESMODEMENU;
koules_key_esc = 0;
koules_key_pause = 0;
}
DelayMs_nops(100);
}
else
{
Koules_process_keys();
Koules_sprocess_keys();
Koules_update_values();
Koules_update_game();
Koules_update_forces();
Koules_colisions();
Koules_move_objects();
Koules_check_limit();
// gettimeofday (&VnewClk, NULL);
// if (VnewClk.tv_usec < VendSleep)
// { VendSleep -= 1000000;
// }
// wait = (VfTime - VnewClk.tv_usec + VendSleep);
// if (wait > 0 || tbreak)
// {
Koules_draw_objects(1);
// } else
// { Koules_draw_objects (0);
// }
// gettimeofday (&VnewClk, NULL);
// if (VnewClk.tv_usec < VendSleep)
// { VendSleep -= 1000000;
// }
// wait = (VfTime - VnewClk.tv_usec + VendSleep);
// if (tbreak)
// { wait = VfTime;
// }
// if (wait > 0)
// { usleep(wait);
// }
// VendSleep = VnewClk.tv_usec + wait;
// gettimeofday (&VlastClk, NULL);
// if (tbreak)
// { tbreak = 0;
// VendSleep = VlastClk.tv_usec;
//}
//Sleep(5);
// DelayMs_nops(100);
}
}
while (koules_key_esc == 1)DelayMs_nops(100);
if (pkouleswin != NULL)
WindowSendMessage(pkouleswin, WM_USER, NULL, NULL);
DISPUPDATE_ENABLE();
}
return TRUE;
}
void Koules_clearpoints(void)
{
int i;
for (i = 0; i < MAXPOINT; i++)
{
koulespoint[i].time = 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -