/***********************************************************
* 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
没有合适的资源?快使用搜索试试~ 我知道了~
koules游戏的示例源码(vc)
共48个文件
cpp:17个
h:13个
raw:7个
需积分: 9 2 下载量 90 浏览量
2009-09-26
19:11:02
上传
评论
收藏 175KB ZIP 举报
温馨提示
对于研究和学习游戏开发的看,看一个相对简单的源码是比较快的入门方法。该示例包含键盘鼠标的控制,物体的移动,爆炸、烟雾等粒子效果,当然还有音响。使用了DirectDraw技术。
资源推荐
资源详情
资源评论
收起资源包目录
koules.zip (48个子文件)
Koules
DirectDrawApp.h 470B
DirectDrawWin.cpp 30KB
koules.bmp 36KB
resource.h 1KB
AboutDlg.cpp 2KB
KoulesWin.cpp 3KB
Koules.rc 6KB
kou.msk 3KB
KoulesWin.h 596B
Koules.dsp 6KB
Headers.cpp 22B
Zm 4KB
AboutDlg.h 1KB
Headers.h 227B
DirectDrawWin.h 4KB
KoulesApp.cpp 476B
Hand-m.cur 326B
Koules.dsw 535B
KSRC
KOULES.H 5KB
TEXT.H 8KB
Input.cpp 5KB
Interface.cpp 4KB
Framebuffer.h 333B
Sound.cpp 3KB
CMAP.CPP 4KB
INTRO.CPP 11KB
Sound.h 346B
Koules.cpp 33KB
Interface.h 2KB
SOUNDS
Creator2.raw 8KB
Destroy2.raw 33KB
End.raw 20KB
Destroy1.raw 9KB
Colize.raw 2KB
Start.raw 54KB
AUHEAD 79B
Creator1.raw 28KB
Framebuffer.cpp 8KB
Input.h 2KB
KSRC.PLG 2KB
MENU.CPP 12KB
GAMEPLAN.CPP 12KB
RCFILES.CPP 2KB
INIT.CPP 2KB
KoulesApp.h 243B
Koules.plg 1KB
DirectDrawApp.cpp 1KB
icon1.ico 766B
共 48 条
- 1
资源评论
ycyuan3
- 粉丝: 3
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功