⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 koules.c

📁 瑞星微公司RK27XX系列芯片的SDK开发包
💻 C
📖 第 1 页 / 共 4 页
字号:
                    a_bballs++;
acase HOLE :
                    a_holes++;
acase EHOLE :
                    a_eholes++;
acase ROCKET :
                    a_rockets++;
acase LBALL :
                case BALL :
                    a_balls++;
acase APPLE :
                    a_apples++;
acase INSPECTOR :
                    a_inspectors++;
acase LUNATIC :
                    a_lunatics++;
                    break;
            }
        }
    }
}

// accelerate rocket
void Koules_accel(const int i, const double howmuch)
{
    int y;
    float p;

    /* howmuch is between 0 and 1, everything else is cheating */

    koulesobject[i].time = 0;
    koulesobject[i].fx += (float)
                          (howmuch * sin(koulesobject[i].rotation) * koulesobject[i].accel),
                          koulesobject[i].fy += (float)
                                                (howmuch * cos(koulesobject[i].rotation) * koulesobject[i].accel);

    for (y = 0; y < 5; y++)
    {
        p = KOULESRAD(KoulesGetRand() % 45 - 22);
        Koules_addpoint((int)
                        (koulesobject[i].x * 256),
                        (int)
                        (koulesobject[i].y * 256),
                        (int)
                        (koulesobject[i].fx -
                         howmuch * sin(koulesobject[i].rotation + p) * koulesobject[i].accel * 10) * (KoulesGetRand() %
                                 512),
                        (int)
                        (koulesobject[i].fy -
                         howmuch * cos(koulesobject[i].rotation + p) * koulesobject[i].accel * 10) * (KoulesGetRand() %
                                 512),
                        KOULESROCKET(KoulesGetRand() % 16), 10);
    }
}

static void Koules_sprocess_keys(void)
{
    int i;

    if (koulesgamemode != KOULESMODEGAME)
    {
        return;
    }

    for (i = 0; i < MAXROCKETS; i++)
    {
        if (koulesobject[i].live && koulesobject[i].type == ROCKET)
        {
            switch (koulescontroller[i])
            {
                case RELLTKYBD:
                case RELMDKYBD:
                case RELRTKYBD:
                    if (koulescontrols[i].mask & 1)
                        koulesobject[i].rotation += KOULESROTSTEP;
                    if (koulescontrols[i].mask & 2)
                        koulesobject[i].rotation -= KOULESROTSTEP;
                    if (koulescontrols[i].mask & 4)
                        Koules_accel(i, 1.0);
                    break;
                case ABSLTKYBD:
                case ABSMDKYBD:
                case ABSRTKYBD:
                case JOY1:
                case JOY2:
                    switch (koulescontrols[i].mask)
                    {
                        case 1:
                            koulesobject[i].rotation = KOULESRAD(-135),
                                                       Koules_accel(i, 1.0);
                            break;
                        case 2:
                            koulesobject[i].rotation = KOULESRAD(135), Koules_accel(i,
                                                       1.0);
                            break;
                        case 3:
                            koulesobject[i].rotation = KOULESRAD(45), Koules_accel(i,
                                                       1.0);
                            break;
                        case 4:
                            koulesobject[i].rotation = KOULESRAD(-45), Koules_accel(i,
                                                       1.0);
                            break;
                        case 5:
                            koulesobject[i].rotation = KOULESRAD(-90), Koules_accel(i,
                                                       1.0);
                            break;
                        case 6:
                            koulesobject[i].rotation = KOULESRAD(90), Koules_accel(i,
                                                       1.0);
                            break;
                        case 7:
                            koulesobject[i].rotation = KOULESRAD(180), Koules_accel(i,
                                                       1.0);
                            break;
                        case 8:
                            koulesobject[i].rotation = KOULESRAD(0), Koules_accel(i,
                                                       1.0);
                            break;
                    }
            }
        }
    }
}

void Koules_process_keys(void)
{
    auto   int i, s = 0;
    static int lasth = 0;

    KoulesUpdateInput();
    if (koules_key_help && !lasth)
    {
        kouleshelpmode ^= 1;
    }
    lasth = koules_key_help;
// if (koules_key_pause)
// {
//  KoulesDrawShadowText((KOULESMAPWIDTH / 2) - (4 * 6), 140, "PAUSED");
//  Koules_updatescreen();
//  return;
// }

    switch (koulesgamemode)
    {
        case KOULESMODEMENU:
            Koules_menu_keys();
            break;
        case KOULESMODEGAME:
            if (koules_key_esc)
            {
                koulesgamemode = KOULESMODEMENU;
                //   while (koules_key_esc)
                //   {
                //    KoulesUpdateInput();
                //   }
                koules_key_esc = 0;
                return;
            }
            for (i = 0; i < koulesnrockets; i++)
            {
                if (koulesobject[i].type != ROCKET)
                    continue;

                s = 0;
                switch (koulescontroller[i])
                {
                    case RELLTKYBD:
                        if (KoulesIsPressed(kouleskeys[0][1]))
                            s = 1;
                        if (KoulesIsPressed(kouleskeys[0][2]))
                            s |= 2;
                        if (KoulesIsPressed(kouleskeys[0][0]))
                            s |= 4;
acase RELMDKYBD :
                        if (KoulesIsPressed(kouleskeys[1][1]))
                            s = 1;
                        if (KoulesIsPressed(kouleskeys[1][2]))
                            s |= 2;
                        if (KoulesIsPressed(kouleskeys[1][0]))
                            s |= 4;
acase RELRTKYBD :
                        if (KoulesIsPressed(kouleskeys[2][1]))
                            s = 1;
                        if (KoulesIsPressed(kouleskeys[2][2]))
                            s |= 2;
                        if (KoulesIsPressed(kouleskeys[2][0]))
                            s |= 4;
acase ABSLTKYBD :
                        if (KoulesIsPressed(kouleskeys[0][2]) &&
                                KoulesIsPressed(kouleskeys[0][0]))
                            s = 1;
                        else if (KoulesIsPressed(kouleskeys[0][3]) &&
                                 KoulesIsPressed(kouleskeys[0][0]))
                            s = 2;
                        else if (KoulesIsPressed(kouleskeys[0][1]) &&
                                 KoulesIsPressed(kouleskeys[0][3]))
                            s = 3;
                        else if (KoulesIsPressed(kouleskeys[0][1]) &&
                                 KoulesIsPressed(kouleskeys[0][2]))
                            s = 4;
                        else if (KoulesIsPressed(kouleskeys[0][2]))
                            s = 5;
                        else if (KoulesIsPressed(kouleskeys[0][3]))
                            s = 6;
                        else if (KoulesIsPressed(kouleskeys[0][0]))
                            s = 7;
                        else if (KoulesIsPressed(kouleskeys[0][1]))
                            s = 8;
acase ABSMDKYBD :
                        if (KoulesIsPressed(kouleskeys[1][2]) &&
                                KoulesIsPressed(kouleskeys[1][0]))
                            s = 1;
                        else if (KoulesIsPressed(kouleskeys[1][3]) &&
                                 KoulesIsPressed(kouleskeys[1][0]))
                            s = 2;
                        else if (KoulesIsPressed(kouleskeys[1][1]) &&
                                 KoulesIsPressed(kouleskeys[1][3]))
                            s = 3;
                        else if (KoulesIsPressed(kouleskeys[1][1]) &&
                                 KoulesIsPressed(kouleskeys[1][2]))
                            s = 4;
                        else if (KoulesIsPressed(kouleskeys[1][2]))
                            s = 5;
                        else if (KoulesIsPressed(kouleskeys[1][3]))
                            s = 6;
                        else if (KoulesIsPressed(kouleskeys[1][0]))
                            s = 7;
                        else if (KoulesIsPressed(kouleskeys[1][1]))
                            s = 8;
acase ABSRTKYBD :
                        if (KoulesIsPressed(kouleskeys[2][2]) &&
                                KoulesIsPressed(kouleskeys[2][0]))
                            s = 1;
                        else if (KoulesIsPressed(kouleskeys[2][3]) &&
                                 KoulesIsPressed(kouleskeys[2][0]))
                            s = 2;
                        else if (KoulesIsPressed(kouleskeys[2][1]) &&
                                 KoulesIsPressed(kouleskeys[2][3]))
                            s = 3;
                        else if (KoulesIsPressed(kouleskeys[2][1]) &&
                                 KoulesIsPressed(kouleskeys[2][2]))
                            s = 4;
                        else if (KoulesIsPressed(kouleskeys[2][2]))
                            s = 5;
                        else if (KoulesIsPressed(kouleskeys[2][3]))
                            s = 6;
                        else if (KoulesIsPressed(kouleskeys[2][0]))
                            s = 7;
                        else if (KoulesIsPressed(kouleskeys[2][1]))
                            s = 8;
                        //acase JOY1 : s = ReadJoystick(0);
                        //acase JOY2 : s = ReadJoystick(1);
adefault :
                        break;
                }
                koulescontrols[i].mask = s;
            }
            break;
    }
}

void Koules_creators_points(int radius, int x1, int y1, int color1)
{
    int z, x, y, x2, y2;
    double r;
    int time = 35;
    int midX, midY, r2, r1;

    midX = KOULESGAMEWIDTH / 2;
    midY = KOULESMAPHEIGHT / 2;
    r2 = r1 = MIN(midX, midY);
    r2 *= r2;

    z = (int)(radius * radius * M_PI);
    while (z--)
    {
        do
        {
            x = KoulesGetRand() % KOULESGAMEWIDTH;
            y = KoulesGetRand() % KOULESMAPHEIGHT;
        }
        while (((x - midX) * (x - midX) + (y - midY) * (y - midY)) > r2);
        r = sqrt((double)((x - midX) * (x - midX) + (y - midY) * (y - midY)));
        r = (r * radius / r1) / r * 0.9;
        x2 = (int)(x1 + (x - midX) * r);
        y2 = (int)(y1 + (y - midY) * r);

        Koules_addpoint(x * 256, y * 256, (x2 - x) * 256 / (time),
                        (y2 - y) * 256 / (time), color1 + (KoulesGetRand() % 16), time);
    }
}

void Koules_creator(const int type)
{
    int i;
    int color1 = Koules_color(type, 0, 0);

    for (i = koulesnrockets;
            i < koulesnobjects &&
            (koulesobject[i].live || koulesobject[i].type == CREATOR);
            i++)
        ;
    if (i >= MAXOBJECT)
    {
        return;
    }
    if (!Koules_find_possition(&koulesobject[i].x, &koulesobject[i].y,
                               (float) Koules_radius(type)))
    {
        return;
    }
    if (i >= koulesnobjects)
    {
        koulesnobjects = i + 1;
    }
    koulesobject[i].live = 0;
    koulesobject[i].live1 = 1;
    koulesobject[i].lineto = -1;
    koulesobject[i].ctype = type;
    koulesobject[i].fx = 0.0;
    koulesobject[i].fy = 0.0;
    koulesobject[i].time = 50;
    koulesobject[i].rotation = 0;
    koulesobject[i].type = CREATOR;
    koulesobject[i].M = Koules_M(type);
    koulesobject[i].radius = Koules_radius(type);
    koulesobject[i].accel = ROCKET_SPEED;
    koulesobject[i].letter = ' ';
    Koules_creators_points(koulesobject[i].radius, (int) koulesobject[i].x,
                           (int) koulesobject[i].y, color1);
    Koulesplay_sound(S_CREATOR1);
}

void Koules_creator_rocket(const int i)
{
    int type = ROCKET;
    int color1 = Koules_color(ROCKET, i, 0);

    if (!Koules_find_possition(&koulesobject[i].x, &koulesobject[i].y,
                               (float) Koules_radius(type)))
    {
        return;
    }

    koulesobject[i].live1 = koulesobject[i].live;
    koulesobject[i].live = 0;
    koulesobject[i].thief = 0;
    koulesobject[i].ctype = type;
    koulesobject[i].lineto = -1;
    koulesobject[i].fx = 0.0;
    koulesobject[i].fy = 0.0;
    koulesobject[i].time = 50;
    koulesobject[i].rotation = 0;
    koulesobject[i].type = CREATOR;
    koulesobject[i].M = ROCKETM;
    koulesobject[i].radius = ROCKET_RADIUS;
    koulesobject[i].accel = ROCKET_SPEED;
    koulesobject[i].letter = ' ';
    Koules_creators_points(ROCKET_RADIUS, (int) koulesobject[i].x,
                           (int) koulesobject[i].y, color1);
}

static void Koules_update_forces(void)
{
    int i;
    int r;
    float d;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -