/***********************************************************
* 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) (ob
评论2