Esempio n. 1
0
/*
 * update the swarm's leaders and actors
 */
void swarm_update(Swarm *s){
	int i, verbose = 1;
	if(verbose) printf("updating swarm\n");
	for (i = 0; i < s->numActors; i++)
		actor_update(&(s->actors[i]), &(s->actors[i+1]), s->numActors);
	for (i = 0; i < s->numLeaders; i++)
		leader_update(&(s->leaders[i]));
}
Esempio n. 2
0
void update(void)
{
    static int time = 0;
    if(SDL_GetTicks() - time > 16){
        flicker = !flicker;
        time = SDL_GetTicks();

        float pos[2] = {0.0f, 1.0f};
        float vel[2] = {0.0f, 0.0f};

        float ang = angle + (1.0f -  2.0f*(float)rand() / (float) RAND_MAX) * log(scale[player->state]) * - 5;
        float rad = 175.0f + 250 * exp(scale[player->state] / scale[elephant]);
        pos[0] = cos(3.0f*PI/2.0f-ang) * rad;
        pos[1] = sin(3.0f*PI/2.0f-ang) * rad;
        particle_add(pos, vel);
    }
    if(!title){
        actor_update(player);
        particle_update();
    }
}
Esempio n. 3
0
int main()
{
    // Ressources
    unsigned long t_debut, t_fin;
    float dt, waitShoot = 0;
    BITMAP *buffer;
    int fin = 0, v = 200;
    Map *map;
    DepthList *depthList;
    Rect screen_pos, map_pos;
    Actor *joueur;

    // Initialisation
    fprintf(stderr,"Initialisation ...\n");
    timeBeginPeriod(1);
    set_uformat(U_ASCII);
    set_color_depth(32);
    allegro_init();
    install_keyboard();
    install_mouse();
    srand(time(NULL));

    if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1024, 768, 0, 0))
        ERREUR("Echec du lancement du mode graphique.");
    buffer = create_bitmap(SCREEN_W, SCREEN_H);
    resman_loadSprites();

    fprintf(stderr,"Chargement des ressources ...\n");
    map = new_map("media/map/test1");
    map_pos.x = map_pos.y = 0;
    map_pos.w = map->w;
    map_pos.h = map->h;
    actList = new_glist();
    root = new_tree(map_pos);
    map_addEntities(map, actList, root);
    depthList = new_dlist();
    screen_pos.w = SCREEN_W;
    screen_pos.h = SCREEN_H;

    // Ajout du joueur
    joueur = actor_addJoueur(actList, root, 500, 500);

    // Intro
    debut();

    // Boucle principale
    fprintf(stderr,"Debut !\n");
    t_debut = timeGetTime();
    while(!fin)
    {
        // Gestion clavier
        if(key[KEY_ESC])
        {
            fin = 1;
        }
        if(key[KEY_W])
        {
            joueur->vit_y = -v;
            joueur->direction_regard = HAUT;
            joueur->etat = ETAT_MARCHE;
        }
        else if(key[KEY_S])
        {
            joueur->vit_y = v;
            joueur->direction_regard = BAS;
            joueur->etat = ETAT_MARCHE;
        }
        else
            joueur->vit_y = 0;
        if(key[KEY_A])
        {
            joueur->vit_x = -v;
            joueur->direction_regard = GAUCHE;
            joueur->etat = ETAT_MARCHE;
        }
        else if(key[KEY_D])
        {
            joueur->vit_x = v;
            joueur->direction_regard = DROITE;
            joueur->etat = ETAT_MARCHE;
        }
        else
            joueur->vit_x = 0;
        if(joueur->vit_x != 0 && joueur->vit_y != 0)
        {
            joueur->vit_x /= sqrt(2);
            joueur->vit_y /= sqrt(2);
        }
        if(!key[KEY_W] && !key[KEY_D] && !key[KEY_S] && !key[KEY_A])
            joueur->etat = ETAT_REPOS;
        if(key[KEY_Q])
        {
            if(waitShoot <= 0)
            {
                waitShoot = .1;
                actor_addTree(actList, root, mouse_x + screen_pos.x, mouse_y + screen_pos.y);
            }
        }
        waitShoot -= dt;
        if(mouse_b&1)
        {
            float vx, vy, v;
            if(waitShoot <= 0)
            {
                waitShoot = .3;
                vx = mouse_x - (joueur->pos_x - screen_pos.x);
                vy = mouse_y - (joueur->pos_y - screen_pos.y);
                v = sqrt(vx*vx + vy*vy);
                vx = vx/v;
                vy = vy/v;
                actor_addMissile(actList, root, joueur->pos_x + vx*joueur->w*1.5, joueur->pos_y + vy*joueur->h*1.5, vx*300, vy*300);
            }
        }
        if(key[KEY_P])
        {
            FILE *fd = fopen("arbres.txt", "w+");
            Actor *act;
            glist_startIter(actList);
            while(!glist_endIter(actList))
            {
                act = glist_getCurrentData(actList);
                if(act->type == ACT_TREE)
                    fprintf(fd, "%d\n%d\n", (int) act->pos_x, (int) act->pos_y);
                glist_iter(actList);
            }
            fclose(fd);
        }


        // Double buffer
        clear_bitmap(buffer);
        render_map(buffer, map, screen_pos.x, screen_pos.y);


        // Mises à jour
        resman_updateSprites(&dt);
        actor_spawnMonster(actList, root);
        actor_ia(actList, joueur);
        // Deplacement
        glist_startIter(actList);
        while(!glist_endIter(actList))
        {
            actor_update(glist_getCurrentData(actList), map_pos, map, dt);
            if( ((Actor*) glist_getCurrentData(actList))->deleting)
            {
                glist_remCell(actList, glist_getCurrentId(actList));
            }
            else
                glist_iter(actList);
        }
        // Cadrage ecran
        screen_pos.x = joueur->pos_x - SCREEN_W/2;
        screen_pos.y = joueur->pos_y - SCREEN_H/2;

        // Collision
        tree_collisionDetection(root);

        // Affichage
        tree_update(root);
        dlist_getActorsFromTree(depthList, root, screen_pos);
        dlist_update(depthList, screen_pos);
        dlist_blit(depthList, buffer, screen_pos);
        draw_cursor(buffer);
        textprintf_centre_ex(buffer, font, SCREEN_W/2, 5, makecol(0, 0, 0), makecol(255, 0, 0), "   Vies restantes : %d   |   Score : %d   ", joueur->vie, score);

        // Rafraichissement écran
        vsync();
        blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

        // Gestion du temps
        t_fin = timeGetTime();
        dt = ((float)t_fin - t_debut)/1000;
        t_debut = t_fin;

        // Test fin de jeu
        if(joueur->deleting)
            fin = 1;
        resman_freeList();
    }
    // Game over
    gameover();

    // Fin
    timeEndPeriod(1);
    delete_map(map);
    del_tree(root);
    del_dlist(depthList);
    del_glist(actList);
    destroy_bitmap(buffer);
    resman_freeSprites();
    allegro_exit();
    return 0;
}