📄 koules.c
字号:
/***********************************************************
Copyright(C)2007,Rockchip Co., Ltd. All Rights Reserved.
File:koules.c
Desc:实现Koules游戏
Note:
Author:czs
$Log: koules.c,v $
Revision 1.2 2008/06/19 04:42:27 Administrator
代码整理!
Revision 1.1.1.1 2008/05/07 04:14:50 Administrator
no message
Revision 1.1.1.1 2008/03/06 13:28:24 Lingzhaojun
no message
Revision 1.7 2008/01/14 07:43:57 Chenzushang
修改延时函数
Revision 1.6 2008/01/10 12:58:50 Chenzushang
增加游戏暂停时的退出功能
Revision 1.5 2008/01/07 08:19:16 Chenzushang
修改koules游戏的启动方式,直接启动而不再启动一个应用
添加koules游戏声音
Revision 1.4 2007/11/08 01:40:17 Chenzushang
修改Koules,使其运行于VideoTask任务下
Revision 1.3 2007/10/26 03:52:01 Chenzushang
添加CVS版本自动注释脚本
**********************************************************/
//#define VARIABLES_HERE
#include "koules.h"
#include "koulesapp.h"
#define MIN(a,b) ((a)>(b)?(b):(a))
int koulesnobjects = 8;
int koulesnrockets = 1;
//int drawpointer = 1;
int koulesdifficulty = 2;
//int cit = 0;
KOULESOBJ_T koulesobject[MAXOBJECT];
KOULESPOINT_T koulespoint[MAXPOINT];
UBYTE koulesinloop = FALSE;
//ULONG mousex, mousey, mousebuttons;
MODULE int kouleshelpmode;
//MODULE char str[2];
MODULE struct KOULESCTL_T koulescontrols[5];
IMPORT int koulescontroller[5];
EXPORT UBYTE koules_hole_bitmap[HOLE_RADIUS * 2][HOLE_RADIUS * 2],
koules_ehole_bitmap[HOLE_RADIUS * 2][HOLE_RADIUS * 2],
koules_eye_bitmap[MAXROCKETS][EYE_RADIUS * 2][EYE_RADIUS * 2],
// mouse_bitmap [ MOUSE_RADIUS * 2][ MOUSE_RADIUS * 2],
koules_ball_bitmap[BALL_RADIUS * 2][BALL_RADIUS * 2],
koules_bball_bitmap[BBALL_RADIUS * 2][BBALL_RADIUS * 2],
koules_inspector_bitmap[INSPECTOR_RADIUS * 2][INSPECTOR_RADIUS * 2],
koules_lball_bitmap[NLETTERS][BALL_RADIUS * 2][BALL_RADIUS * 2],
koules_rocket_bitmap[MAXROCKETS][ROCKET_RADIUS * 2][ROCKET_RADIUS * 2],
koules_apple_bitmap[APPLE_RADIUS * 2][APPLE_RADIUS * 2],
koules_lunatic_bitmap[LUNATIC_RADIUS * 2][LUNATIC_RADIUS * 2];
unsigned char koulesrocketcolor[5] =
{
96, 160, 64, 96, 128
};
int kouleslastlevel = 0, koulesmaxlevel = 99; // means 100
int koulesdosprings = 0;
int koulesrandsprings = 0;
//int nomouse = 0;
//int textcolor;
//int tbreak;
int koulesgameplan = COOPERATIVE;
int npoint = 0;
int koulesgamemode = KOULESMODEMENU;
UBYTE* kouleskeys[3][4];
int a_bballs, a_rockets, a_balls, a_holes, a_apples, a_inspectors, a_lunatics,
a_eholes;
float ROCKET_SPEED = 1.2f;
float BALL_SPEED = 1.2f;
float BBALL_SPEED = 1.2f;
float SLOWDOWN = 0.8f / 2;
float GUMM = 20.0f / 2;
float BALLM = 3.0f / 2;
float LBALLM = 3.0f / 2;
float BBALLM = 8.0f / 2;
float APPLEM = 34.0f / 2;
float INSPECTORM = 2.0f / 2;
float LUNATICM = 3.14f;
float ROCKETM = 4.0f / 2;
void Koules_addpoint(const int x, const int y, const int xp, const int yp,
const int color, const int time)
{
koulespoint[npoint].x = x;
koulespoint[npoint].y = y;
koulespoint[npoint].xp = xp;
koulespoint[npoint].yp = yp;
koulespoint[npoint].time = time;
koulespoint[npoint].color = color;
npoint++;
if (npoint >= MAXPOINT)
{
npoint = 0;
}
}
void KoulesDrawpoints(void)
{
int i;
for (i = 0; i < MAXPOINT; i++)
{
if (koulespoint[i].time > 0)
{
koulespoint[i].time--;
koulespoint[i].x += koulespoint[i].xp;
koulespoint[i].y += koulespoint[i].yp;
if (koulespoint[i].x >= 0 &&
(koulespoint[i].x >> 8) < KOULESMAPWIDTH &&
koulespoint[i].y >= 0 &&
(koulespoint[i].y >> 8) < KOULESMAPWIDTH)
{
Koules_setpixel((koulespoint[i].x >> 8),
(koulespoint[i].y >> 8), koulespoint[i].color);
}
else
{
koulespoint[i].time = 0;
}
}
}
}
INLINE int Koules_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 Koules_color(const int type, const int i, const int letter)
{
switch (type)
{
case EHOLE:
return (128);
case HOLE:
return (64);
case ROCKET:
return (koulesrocketcolor[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 float Koules_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 Koules_find_possition(float* x, float* y, const float radius)
{
int x1, y1, i, y2 = 0;
float xp, yp;
rerand :// ;
x1 = KoulesGetRand() % (KOULESGAMEWIDTH - 60) + 30;
y1 = KoulesGetRand() % (KOULESMAPHEIGHT - 60) + 30;
for (i = 0; i < koulesnobjects; i++)
{
xp = x1 - koulesobject[i].x;
yp = y1 - koulesobject[i].y;
if (xp * xp +
yp * yp <
(radius + koulesobject[i].radius) * (radius +
koulesobject[i].radius))
{
y2++;
if (y2 > 10000)
return (0);
goto rerand;
}
}
*x = (float) x1;
*y = (float) y1;
return (1);
}
INLINE void Koules_normalize(float* x, float* y, float size)
{
float length = (float) sqrt((*x) * (*x) + (*y) * (*y));
if (length == 0)
length = 1;
*x *= size / length;
*y *= size / length;
}
static void Koules_move_objects()
{
int i;
for (i = 0; i < koulesnobjects; i++)
if (koulesobject[i].type == CREATOR)
{
koulesobject[i].time--;
if (koulesobject[i].time <= 0)
{
Koulesplay_sound(S_CREATOR2);
koulesobject[i].live = koulesobject[i].live1;
koulesobject[i].type = koulesobject[i].ctype;
// if (koulesobject[i].type == ROCKET)
// koulesobject[i].time = 200;
koulesobject[i].radius = Koules_radius(koulesobject[i].ctype);
koulesobject[i].M = Koules_M(koulesobject[i].ctype);
}
}
else if (koulesobject[i].live)
{
koulesobject[i].x += koulesobject[i].fx * (KOULESGAMEWIDTH /
640.0f +
1) /
2;
koulesobject[i].y += koulesobject[i].fy * (KOULESGAMEWIDTH /
640.0f +
1) /
2;
}
}
static void Kouleshelp(int x, int y, int radius, char* text)
{
int x1 = x + radius + 2, y1 = y - 4, x2 = x1 + strlen(text) * 8,
y2 = y1 + 8;
if (kouleshelpmode &&
x1 >= 0 &&
x2 < KOULESGAMEWIDTH &&
y1 >= 0 &&
y2 < KOULESMAPHEIGHT)
{
KoulesDrawShadowText(x1, y1, text);
}
}
static void Koules_draw_objects(const int draw)
{
//ar s[80];
int i;
if (draw)
{
KoulesClearScreen();
KoulesDrawpoints();
Kouleshelp(5, 11, 0, "HELP - PRESS 'H' TO DISABLE");
}
for (i = 0; i < koulesnobjects; i++)
{
if (koulesobject[i].live)
{
switch (koulesobject[i].type)
{
case BALL:
Koules_draw_ball((int)(koulesobject[i].x - BALL_RADIUS),
(int)(koulesobject[i].y - BALL_RADIUS), BALL_RADIUS * 2,
BALL_RADIUS * 2);
Kouleshelp((int) koulesobject[i].x, (int) koulesobject[i].y,
koulesobject[i].radius, "Koules");
acase LBALL :
switch (koulesobject[i].letter)
{
case L_ACCEL :
Koules_draw_lball((int)
(koulesobject[i].x - BALL_RADIUS),
(int)
(koulesobject[i].y - BALL_RADIUS),
BALL_RADIUS * 2,
BALL_RADIUS * 2,
0);
Kouleshelp((int) koulesobject[i].x, (int) koulesobject[i].y,
koulesobject[i].radius, "Acceleration");
acase L_GUMM :
Koules_draw_lball((int)
(koulesobject[i].x - BALL_RADIUS),
(int)
(koulesobject[i].y - BALL_RADIUS), BALL_RADIUS * 2,
BALL_RADIUS * 2, 1);
Kouleshelp((int) koulesobject[i].x, (int) koulesobject[i].y,
koulesobject[i].radius, "Weight");
acase L_THIEF :
Koules_draw_lball((int)
(koulesobject[i].x - BALL_RADIUS),
(int)
(koulesobject[i].y - BALL_RADIUS), BALL_RADIUS * 2,
BALL_RADIUS * 2, 2);
Kouleshelp((int) koulesobject[i].x, (int) koulesobject[i].y,
koulesobject[i].radius, "Thief");
acase L_FINDER :
Koules_draw_lball((int)
(koulesobject[i].x - BALL_RADIUS),
(int)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -