Example #1
0
File: item.c Project: odrevet/GE
void on_warp_in(warp* p_warp, game* p_game)
{
  sample_play(warp_snd);
  //walk slowly
  p_game->p_unit->p_sprite->x = p_warp->dest_index_x * TILE_WIDTH;
  p_game->p_unit->p_sprite->y = p_warp->dest_index_y * TILE_HEIGHT;
}
Example #2
0
File: item.c Project: odrevet/GE
void item_apply(item *p_item, unit* p_unit)
{
  switch(p_item->type){
  case COIN :
    sample_play(coin);
    p_unit->coin++;
    break;
  case POWERUP :
    unit_powerup(p_unit);
    break;
  case FLOWER :
    unit_powerup(p_unit);
    break;
  }
}
Example #3
0
void rfcmd_execute(unsigned char *rbuf, unsigned char rlen)
{
	unsigned char cmd, crc, sender, rx_socvec;
	
	if(rlen < 3) {
	   return;
	}
	
	cmd = rbuf[0];
	sender = rbuf[1];
	rx_socvec = rbuf[2];
	
	
	crc = cmd & 0xc0;
	cmd = cmd^crc;
	
	
	if(cmd != RFCMD_BEACON) {
	
		if(!(crc&0x80)) {
			if(rx_socvec != MyBadgeID) {
				return;
			}
		} else {
			if((rx_socvec != MyBadgeID) && (rx_socvec != 0)) {
				return;
			}
		}
		if((crc == 0) && (std_imaslut() == 0)) {
			return;
		}
	}
	
	if(cmd != RFCMD_BEACON) {
			lastrfsender = sender;
	}
	
	
	
	
	switch (cmd) {
	  case RFCMD_BEACON:
	  
	    std_proc_beacon(rx_socvec, sender);
	    curbeacon_density++;
	    break;
	  case RFCMD_PLAYDONG: // Dong
	    sample_play();
	    break;
	  case RFCMD_PLAYRICK:  // Rick Roll
	    songselect(SONG_RICK);
	    goto songcommon;
	  case RFCMD_PLAYNYAN:  // Nyan Song
	    songselect(SONG_NYAN);
	    light_show(LIGHTSHOW_RAINBOW, 5);
	    goto songcommon;
	  case RFCMD_PLAYRAIN:  // Slayer Raining
	    songselect(SONG_RAINING);
	    goto songcommon;
	  case RFCMD_PLAYJOUR:  // Journey Don't Stop Believing (main)
	    if(!(crc & 0xc0)) break;
	    songselect(SONG_JOURNEY1);
	    goto songcommon;
	  case RFCMD_PLAYCANT:  // Star Wars Cantina
	    songselect(SONG_CANTINA);
	    goto songcommon;
	  case RFCMD_PLAYSECR:  // Song Secret
	    songselect(SONG_SECRET);
	    goto songcommon;
	  case RFCMD_PLAYKRY0:  // Long Ass Chiptune Annoyance Song 
	    if(!(crc & 0xc0)) break;
	    songselect(SONG_KRY0);
	    goto songcommon;	
	  case RFCMD_PLAYPAC:   // Pacman Sound
	    songselect(SONG_PACMAN);
	    goto songcommon;
	  case RFCMD_PLAYPEW:   // Pew Pew
	    songselect(SONG_PEWPEW);
	    goto songcommon;
	  case RFCMD_PLAYKLAX:  // Klaxon
	    songselect(SONG_KLAXON);
	    goto songcommon;
	  case RFCMD_PLAYSIREN: // Siren
	    songselect(SONG_SIREN);	    
songcommon:
        tune_startsong(0xff);	// Start song with previously selected items. 
        break;
	
	  case RFCMD_ADMNSOC0:   // Set Social vector bit (**)
	  case RFCMD_ADMNSOC1:   // Set Social vector bit (**)
	  case RFCMD_ADMNSOC2:   // Set Social vector bit (**)
	  case RFCMD_ADMNSOC3:   // Set Social vector bit (**)
	  case RFCMD_ADMNSOC4:   // Set Social vector bit (**)
	  case RFCMD_ADMNSOC5:   // Set Social vector bit (**)
	    if((crc & 0x80) == 0) break;
	    
		mysoc = nvget_socvec1();
		mysoc |= (1<< (cmd & 0x07));
		if(cmd & 0x01) clear_chlam = elapsed_msecs + (3600*1000);
		if(cmd & 0x02) clear_syph = elapsed_msecs + (3600*1000);
		if(cmd & 0x03) clear_ghon = elapsed_msecs + (3600*1000);
		nvset_socvec1(mysoc);
		nvsavebuf();
	    break;
	  case RFCMD_ADMNSOCC:   // Clear Social Vector Bit
	    if((crc & 0x80) == 0) break;
	    nvset_socvec1(0);	// Cured
	    nvsavebuf();
	    break;
	  case RFCMD_ESET:  // Send Special (**)
	    if((crc & 0x80) == 0) break;
	    mysoc = nvget_badgeperm();
	    mysoc |= NBPRMELEV;
	    nvset_badgeperm(mysoc);
	    nvsavebuf();
	    break;
	  case RFCMD_ECLR:  // Send Special (**)
	    if((crc & 0x80) == 0) break;
	    mysoc = nvget_badgeperm();
	    mysoc &= ~NBPRMELEV;
	    nvset_badgeperm(mysoc);
	    nvsavebuf();
	    break;
	  case RFCMD_DON1:      // Special Reserved (**)
		  foo();
	    break;
	  case RFCMD_ATTEN:     // Special Alert (**)
	    if(!(crc & 0x80)) break;
	      MyMode = MODE_ATTEN;
	      modelights();
	    break;
	  case RFCMD_PERF1:     // Special Performance (**)
	    if(!(crc & 0x80)) break;
	    if((MyBadgeID % 3) == 0) {
			tune_startsong(SONG_JOURNEY1);
		}
		else if((MyBadgeID % 3) == 1) {
			tune_startsong(SONG_JOURNEY2);
		}
		else {
			tune_startsong(SONG_JOURNEY3);
		}

	} // switch cmd		
	
	if(cmd != RFCMD_BEACON) {
			lastrfsender = sender;
	}
	
}
Example #4
0
File: main.c Project: odrevet/GE
int state_options(SDL_Surface *screen)
{
    TTF_Font *font_menu = font_load("res/asia.ttf", 50);
    image *bg_image = image_load("res/options.jpg");
    Mix_Chunk *select = sample_load("res/select.wav");

    int i;
	//int initial_unit_nb = g_game.unit_nb;
    int font_quality = SOLID;
    int choice_current=1;
    SDL_Rect cur_pos;
    bool done = false;

    cur_pos.x = 10;
    cur_pos.y = 0;
    char sz_choice[20];

    #ifdef GEKKO
        unsigned int start=0;
        int timerset = false;
    #endif
SDL_EnableKeyRepeat(50, 10);
    while (!done)
    {
        #ifdef GEKKO
       unsigned int start=0;
       if (!timerset) {
            timerset=true;
            start=SDL_GetTicks();
        }

       unsigned int now=SDL_GetTicks();
           if ((now-start)>50) {
                timerset=false;
                SDL_JoystickUpdate();
                int joystate = SDL_JoystickGetHat(g_game.v_unit[0].joystick, 0);
                switch (joystate){
                    case SDL_HAT_DOWN:
                       if (choice_current <= 1){
                        sample_play(select);
                        choice_current++;
                        }
                    break;
                    case SDL_HAT_UP:
                        if (choice_current > 1){
                            sample_play(select);
                            choice_current--;
                        }
                    break;
                    case SDL_HAT_LEFT:
                        if (choice_current == 2)
                        {
                            if (g_game.block_fill >= 0.01)
                                g_game.block_fill -= 0.01;
                        }
                        else if (choice_current == 1)
                        {
                            if (g_game.unit_nb > 2)
                            {
                                g_game.unit_nb -= 1;
                            }
                        }
                    break;
                    case SDL_HAT_RIGHT:
                        if (choice_current == 2)
                        {
                            if (g_game.block_fill < 0.99)
                                g_game.block_fill += 0.01;
                        }
                        else if (choice_current == 1)
                        {
                            if (g_game.unit_nb < UNIT_MAX)
                            {
                                g_game.unit_nb++;
                            }
                        }
                    break;
                    default:
                    break;
                }
           }
        #endif


        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            switch ( event.type )
            {
            case SDL_QUIT:
                exit(EXIT_SUCCESS);
                break;
                case SDL_JOYBUTTONDOWN:
                    if(event.jbutton.button == 6){
                        done = true;
                    }
                break;
            case SDL_KEYDOWN:
                switch ( event.key.keysym.sym )
                {
                case SDLK_DOWN:
                    if (choice_current <= 1){
                        sample_play(select);
                        choice_current++;
                    }
                    break;
                case SDLK_UP:
                    if (choice_current > 1)
                    {
                        sample_play(select);
                        choice_current--;
                    }
                    break;
                case SDLK_LEFT:
                    if (choice_current == 2)
                    {
                        if (g_game.block_fill >= 0.01)
                            g_game.block_fill -= 0.01;
                    }
                    else if (choice_current == 1)
                    {
                        if (g_game.unit_nb > 2)
                        {
                            g_game.unit_nb--;
                        }
                    }
                    break;
                case SDLK_RIGHT:
                    if (choice_current == 2)
                    {
                        if (g_game.block_fill < 0.99)
                            g_game.block_fill += 0.01;
                    }
                    else if (choice_current == 1)
                    {
                        if (g_game.unit_nb < UNIT_MAX)
                        {
                            g_game.unit_nb++;
                        }
                    }
                    break;
                case SDLK_ESCAPE:
                    done = true;
                    break;
                default:
                    break;
                }
                break;
            }

            if(event.type == SDL_JOYBUTTONDOWN && event.jbutton.button == 6)done=true;
        }

        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 20, 20, 20));
        image_draw(bg_image, screen, 0, 0);


        for (i=1;i<=2;i++)
        {
            if (i == 1)
            {
                sprintf(sz_choice, "%s < %.d >", "Player", g_game.unit_nb);
            }
            else if ( i == 2)
            {

                sprintf(sz_choice, "%s < %.0f%% >", "Block fill", g_game.block_fill * 100);
            }

            if (choice_current == i)
            {
                font_quality = SHADED;
            }
            else font_quality = SOLID;

            cur_pos.y = i*100;
            SDL_Surface *font_surface;
            font_surface = font_create_surface(font_menu, 250, 120, 35, 10, 100, 100, 100, 0, sz_choice, font_quality);
            SDL_BlitSurface(font_surface, NULL, screen, &cur_pos);
            SDL_FreeSurface(font_surface);
        }
        SDL_Flip(screen);
    }
    TTF_CloseFont(font_menu);
    SDL_FreeSurface(bg_image->surface);
    SDL_EnableKeyRepeat(0, 0);
    return OPTION;
}
Example #5
0
File: main.c Project: odrevet/GE
int state_in_game(SDL_Surface *screen)
{
    SDL_Rect srcrect = {0, 0, 480, 480};                      //the part of the screen to be stretched, must be sup 0 and inf screen surface Height and Width
    SDL_Rect dstrect = set_rect(0, 0, SCREEN_HEIGHT, SCREEN_WIDTH);    //equals screen resolution

    int bomb_nb=0;
    int flame_nb=0;
    bool done = false;
    int i=0;                     //generic accumulator 1
    int j=0;                     //generic accumulator 2
    int k=0;                     //unit accumulator
    int tick_count=0;
    int tick_trigger=0;
    int time_elapsed=0;         //time elapsed in this round (in secondes)
    int last_time=0;
    int current_game_status=-1;

    timer *timer_battle = timer_init();
    timer_start(timer_battle);

    // load sample.wav in to sample
    Mix_Chunk *sample = sample_load("res/boom.wav");
    Mix_Music* music = music_load("res/music.xm");
    music_play(music);

    //initialize map
    map *p_map = malloc(sizeof(map));
    p_map->tile_height = 32;
    p_map->tile_width = 32;
    map_load_level(p_map, "res/level_01.map");
    p_map->p_chipset = image_load("res/classic.png");
    SDL_Surface* surface_menu = IMG_Load("./res/menu.png");
    SDL_SetColorKey(surface_menu, SDL_SRCCOLORKEY, SDL_MapRGB(surface_menu->format, 255, 0, 255));

    for (k=0;k<g_game.unit_nb;k++)
    {
        unit_tile_protect(g_game.v_unit+k, p_map);
    }

    int block_nb = map_block_add(p_map, g_game.block_fill, .5);         ///@todo the disp % is not implemented yet
    int panel_nb = panel_add(g_game.v_panel, p_map, block_nb);

    int random_comment = rand() % 9;
    char sz_comment[32];
    SDL_Rect pos_comment = set_rect(10, 465, 0, 0);
    int comment_time_elapsed;
    timer *timer_comment = timer_init();

    //Menu
    TTF_Font *font_menu = font_load("res/asia.ttf", 20);
    TTF_Font *font_result = font_load("res/asia.ttf", 75);

    SDL_Rect cur_pos;
    cur_pos.x = 42;
    cur_pos.y = 425;

    char sz_time[10];

    while (!done)
    {
        SDL_Event event;
        SDL_JoystickUpdate();
        while(SDL_PollEvent(&event)){
            for (k=0;k<g_game.unit_nb;k++)
            {
                if (!g_game.v_unit[k].is_dead)
                {
                    unit_handle_key(g_game.v_unit+k, &event, k, g_game.v_bomb, p_map, &bomb_nb);
                }
            }
           if(event.type == SDL_QUIT || ((event.type == SDL_KEYDOWN) && (event.key.keysym.sym == SDLK_ESCAPE)) || (event.type == SDL_JOYBUTTONDOWN && event.jbutton.button == 6)){
                    done = true;
                    current_game_status = MAIN_MENU;
            }
            else if((event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN)|| (event.type == SDL_JOYBUTTONDOWN && event.jbutton.button == 5)){
                    Mix_PauseMusic();
                    state_paused(screen);
                    Mix_ResumeMusic();
            }
        }

        for (k=0;k<g_game.unit_nb;k++){
            if(!g_game.v_unit[k].use_keyboard){
                int joystate = SDL_JoystickGetHat(g_game.v_unit[k].joystick, 0);
                switch (joystate){
                    case SDL_HAT_DOWN:
                        unit_set_vel_y(g_game.v_unit+k, g_game.v_unit[k].speed);
                        unit_set_vel_x(g_game.v_unit+k, 0);
                        g_game.v_unit[k].p_sprite->animation_current = DOWN;
                    break;
                    case SDL_HAT_UP:
                        unit_set_vel_y(g_game.v_unit+k, -g_game.v_unit[k].speed);
                        unit_set_vel_x(g_game.v_unit+k, 0);
                        g_game.v_unit[k].p_sprite->animation_current = UP;
                    break;
                    case SDL_HAT_RIGHT:
                        unit_set_vel_x(g_game.v_unit+k, g_game.v_unit[k].speed);
                        unit_set_vel_y(g_game.v_unit+k, 0);
                        g_game.v_unit[k].p_sprite->animation_current = RIGHT;
                    break;
                    case SDL_HAT_LEFT:
                        unit_set_vel_x(g_game.v_unit+k, -g_game.v_unit[k].speed);
                        unit_set_vel_y(g_game.v_unit+k, 0);
                        g_game.v_unit[k].p_sprite->animation_current = LEFT;
                    break;
                    default:
                        if ( g_game.v_unit[k].vel_x != 0 ){
                            unit_set_vel_x(g_game.v_unit+k, 0);
                            g_game.v_unit[k].p_sprite->v_anim[g_game.v_unit[k].p_sprite->animation_current].frame_current = 1;
                        }
                        if ( g_game.v_unit[k].vel_y != 0 ){
                            unit_set_vel_y(g_game.v_unit+k, 0);
                            g_game.v_unit[k].p_sprite->v_anim[g_game.v_unit[k].p_sprite->animation_current].frame_current = 1;
                        }

                    break;
                }
            }
        }

        tick_count = SDL_GetTicks();
        if (tick_count > tick_trigger / 60){
            tick_trigger = tick_count;
            SDL_FillRect(backbuffer, 0, SDL_MapRGB(backbuffer->format, 10, 20, 80));


            //draw the map
            map_draw(p_map, backbuffer);
            for (i=0;i<panel_nb;i++)
            {
                if(p_map->pp_tile[g_game.v_panel[i]->p_sprite->y / TILE_SIZE][g_game.v_panel[i]->p_sprite->x / TILE_SIZE].type != BLOCK)panel_draw(g_game.v_panel[i], backbuffer);
            }


            //check panels
            for (i=0;i<panel_nb;i++)
            {
                // for all units
                for (k=0;k<g_game.unit_nb;k++)
                {
                    //Check for bonus
                    if (g_game.v_panel[i]->p_sprite->y / TILE_SIZE == unit_get_bounding_index_center_y(g_game.v_unit+k)
                            && (g_game.v_panel[i]->p_sprite->x / TILE_SIZE == unit_get_bounding_index_center_x(g_game.v_unit+k)))
                    {
                        panel_apply(g_game.v_panel[i], g_game.v_unit+k);

                        panel_free(g_game.v_panel[i]);
                        panel_nb--;

                        //Left shift the vector
                        for (j=i;j<panel_nb;j++)
                        {
                            g_game.v_panel[j] = g_game.v_panel[j+1];
                        }
                    }
                }
            }

            //Draw and update bombs
            for (i=0;i<bomb_nb;i++)
            {
                bomb_draw(g_game.v_bomb[i], backbuffer);
                anim_sprite_update_frame(g_game.v_bomb[i]->p_sprite);
                bomb_update_timer(g_game.v_bomb[i]);

                if ((g_game.v_bomb[i]->time_left <= 0) || (p_map->pp_tile[g_game.v_bomb[i]->p_sprite->y / TILE_SIZE][g_game.v_bomb[i]->p_sprite->x / TILE_SIZE].type == FLAME))
                {
                    sample_play(sample);
                    bomb_explode(g_game.v_bomb[i], p_map, g_game.v_flame, &flame_nb);
                    bomb_nb--;

                    bomb_free(g_game.v_bomb[i]);

                    //Left shift the vector
                    for (j=i;j<bomb_nb;j++)
                    {
                        g_game.v_bomb[j] = g_game.v_bomb[j+1];
                    }
                }
            }

            //Check flame
            for (i=0;i<p_map->height;i++)
            {
                for (j=0;j<p_map->width[i];j++)
                {
                    // for all units, check if hitten (if unit center is on a tile with a flame flag)
                    for (k=0;k<g_game.unit_nb;k++)
                    {
                        if ((p_map->pp_tile[i][j].type == FLAME) &&
                                ((unit_get_index_x(g_game.v_unit+k) == j) &&
                                (unit_get_index_y(g_game.v_unit+k) == i)) &&
                                g_game.v_unit[k].is_dead == false)
                        {
                            g_game.v_unit[k].is_dead = true;
                            timer_start(timer_comment);

                            switch(random_comment)
                            {
                                case(0):sprintf(sz_comment, "Say goodbye, %s ", g_game.v_unit[k].name);
                                break;
                                case(1):sprintf(sz_comment, "burn %s, burn ! ", g_game.v_unit[k].name);
                                break;
                                case(2):sprintf(sz_comment, "%s vanished !!!!!! ", g_game.v_unit[k].name);
                                break;
                                case(3):sprintf(sz_comment, "unit_free(%s); //^^ ", g_game.v_unit[k].name);
                                break;
                                case(4):sprintf(sz_comment, "%s ? Where are you ? ", g_game.v_unit[k].name);
                                break;
                                case(5):sprintf(sz_comment, "%s was a good guy ", g_game.v_unit[k].name);
                                break;
                                case(6):sprintf(sz_comment, "HE says : \"HELLO, %s\" ", g_game.v_unit[k].name);
                                break;
                                case(7):sprintf(sz_comment, "%s has meet his programmer ", g_game.v_unit[k].name);
                                break;
                                case(8):sprintf(sz_comment, "$ %s>/dev/null ", g_game.v_unit[k].name);
                                break;
                                case(9):sprintf(sz_comment, "%s was not ignifugated ", g_game.v_unit[k].name);
                                break;
                            }
                        }
                    }
                }
            }

            //Draw and update flames
            for (i=0;i<flame_nb;i++)
            {
                flame_draw(g_game.v_flame[i], p_map, backbuffer);
                g_game.v_flame[i]->time_left--;
                if (g_game.v_flame[i]->time_left <= 0)
                {
                    flame_free(g_game.v_flame[i], p_map);
                    flame_nb--;

                    //Left shift the vector
                    for (j=i;j<flame_nb;j++)
                    {
                        g_game.v_flame[j] = g_game.v_flame[j+1];
                    }
                }
            }



            for (k=0;k<g_game.unit_nb;k++)
            {
                if (!g_game.v_unit[k].is_dead)
                {
                    unit_calc_bounding_box(g_game.v_unit+k);
                    unit_update(g_game.v_unit+k, p_map);
                }
            }
            // draw and update units
            unit_draw_from_z_index(g_game.v_unit, g_game.unit_nb, backbuffer);

            //Change every 1 second
            time_elapsed = timer_get_ticks (timer_battle) / 1000;
            if (time_elapsed != last_time){
                last_time = time_elapsed;       //Update current time

        /* Check if any unit won
                    This function is performed every second in order to dont call it to often, and
                    have a little delay if two or more units died almost in the same time (even ms, in the case
                    a unit is at the left of a bomb and an other at the right, the right unit win because the
                    flame is first put to the left...)
                */

                int unit_win;
                unit_win = unit_check_victory(g_game.v_unit, g_game.unit_nb);

                if (unit_win >= 0)
                {
                    //print win, sound, etc
                    g_game.v_unit[unit_win].victory++;
                    time_elapsed = 0;
                    ///@todo set a victories limit (from 1 to 5) and display a special image if win... for the moment, another battle
                    font_printf(font_result, TILE_SIZE * 2, TILE_SIZE * 5, 50, 150, 100, backbuffer, "%s wins", g_game.v_unit[unit_win].name);
                    done = true;
                    current_game_status = IN_GAME;
                    SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
                    SDL_Flip(screen);
                    SDL_Delay(2000);
                    break;
                }
                else if (unit_win == -1)
                {
                    font_printf(font_result, (3)*TILE_SIZE, (6)*TILE_SIZE, 50, 150, 100, backbuffer, "DRAW !");
                    done = true;
                    current_game_status = IN_GAME;
                    SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
                    SDL_Flip(screen);
                    SDL_Delay(2000);
                }

                if (g_game.time - time_elapsed <= 0)
                {
                    cur_pos.x = 240;
                    cur_pos.y = 140;
                    font_printf(font_result, (3)*TILE_SIZE, (6)*TILE_SIZE, 50, 150, 100, backbuffer, "TIMES UP !");
                    done = true;
                    ///@todo select action in times up (blocks falling, etc) for the moment, just a draw...
                    current_game_status = IN_GAME;
                    SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
                    SDL_Flip(screen);
                    SDL_Delay(2000);
                }

            }

            ////////////////////  MENU  ////////////////////
            //TIME
            sprintf(sz_time, "%.3d", g_game.time - time_elapsed);
            SDL_Surface *surface_time = font_create_surface(font_menu, 200, 200, 200, 10, 100, 100, 100, 0, sz_time, SOLID);
            SDL_BlitSurface(surface_time, NULL, backbuffer, &cur_pos);
            SDL_FreeSurface(surface_time);
            SDL_Rect menu_src, menu_dest;
            menu_src.h = 32;
            menu_src.w = 32;
            menu_src.x = 0;
            menu_src.y = 0;

            menu_dest.x = 5;
            menu_dest.y = 420;

            SDL_BlitSurface(surface_menu, &menu_src, backbuffer, &menu_dest);

            //VICTORIES
            for (k=0;k<g_game.unit_nb;k++)
            {
                char sz_victory_nb[20];
                SDL_Rect vic_pos = set_rect(10, 450, 0, 0);
                sprintf(sz_victory_nb, "%s: %d", g_game.v_unit[k].name, g_game.v_unit[k].victory);

                vic_pos.x += k * 100;
                SDL_Surface *surface_victory = font_create_surface(font_menu, 200, 200, 200, 10, 100, 100, 100, 0, sz_victory_nb, SOLID);
                SDL_BlitSurface(surface_victory, NULL, backbuffer, &vic_pos);
                SDL_FreeSurface(surface_victory);
            }

            //Comment
            if(timer_comment->started){
                comment_time_elapsed = timer_get_ticks(timer_comment) / 1000;
                if (comment_time_elapsed < 3)   //Display the comment 3 seconds
                {
                    font_printf(font_menu, pos_comment.x, pos_comment.y, 200, 200, 200, backbuffer, sz_comment);
                }
                else{   //done
                    timer_stop(timer_comment);
                    random_comment = rand() % 9;

                }
            }

            //DEBUG
#ifdef DEBUG
            font_printf(font_menu, 10, 10, 255, 255, 200, backbuffer, "flame nb : %d", flame_nb);
            font_printf(font_menu, 10, 30, 255, 255, 200, backbuffer, "bomb nb : %d", bomb_nb);
            font_printf(font_menu, 10, 50, 255, 255, 200, backbuffer, "unit nb : %d", g_game.unit_nb);
            font_printf(font_menu, 10, 70, 255, 255, 200, backbuffer, "fill nb : %.2f", g_game.block_fill);
            font_printf(font_menu, 10, 90, 255, 255, 200, backbuffer, "Blocks at startup : %d", block_nb);
            font_printf(font_menu, 10, 110, 255, 255, 200, backbuffer, "Time elapsed : %d", timer_get_ticks(timer_battle)/1000);
            font_printf(font_menu, 10, 130, 255, 255, 200, backbuffer, "unit 1 index: %d %d", unit_get_bounding_index_center_x(g_game.v_unit+0), unit_get_bounding_index_center_y(g_game.v_unit+0));


            SDL_Rect rect = unit_get_bounding_box(g_game.v_unit+0);
            SDL_FillRect(backbuffer, &rect, SDL_MapRGB(backbuffer->format, 255, 255, 0));
#endif

            SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
            SDL_Flip(screen);
        }//end thick
    }   //end while



    //Free the memory
    for (i=0;i<bomb_nb;i++)
    {
        bomb_free(g_game.v_bomb[i]);
    }
    for (i=0;i<panel_nb;i++)
    {
        panel_free(g_game.v_panel[i]);
    }
    for (i=0;i<flame_nb;i++)
    {
        flame_free(g_game.v_flame[i], p_map);
    }
    map_free(p_map);

    free(timer_battle);
    free(timer_comment);

    Mix_FreeChunk(sample);
    Mix_FreeMusic(music);

    TTF_CloseFont(font_menu);
    font_menu=NULL; // to be safe...

    TTF_CloseFont(font_result);
    font_result=NULL; // to be safe...

    return current_game_status;

}
Example #6
0
File: main.c Project: odrevet/GE
int state_main_menu(SDL_Surface *screen)
{
    TTF_Font *font_menu = font_load("res/asia.ttf", 50);
    TTF_Font *font_credit = font_load("res/asia.ttf", 20);
    image *bg_image = image_load("res/main.jpg");
    Mix_Chunk *select = sample_load("res/select.wav");

    int i;
    const int item_nb = 2;
    int font_quality = SOLID;
    int choice_current=1;
    SDL_Rect cur_pos;
    bool done = false;
	//bool is_in_game = false;

    cur_pos.x = 10;
    cur_pos.y = 0;
    char sz_choice[20];

    #ifdef GEKKO
    bool timerset = false;
    #endif

    while (!done)
    {
        #ifdef GEKKO
       unsigned int start=0;
       if (!timerset) {
            timerset=true;
            start=SDL_GetTicks();
        }

       unsigned int now=SDL_GetTicks();
       if ((now-start)>50) {
            timerset=false;
            SDL_JoystickUpdate();
            int joystate = SDL_JoystickGetHat(g_game.v_unit[0].joystick, 0);
            switch (joystate){
                case SDL_HAT_DOWN:
                    if (choice_current < item_nb){
                        choice_current++;
                        sample_play(select);
                    }
                break;
                case SDL_HAT_UP:
                    if (choice_current > 1){
                        choice_current--;
                        sample_play(select);
                    }
                break;
            }
       }
       #endif



        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            switch ( event.type )
            {
            case SDL_QUIT:
                done = true;
                break;
            case SDL_KEYUP:
                switch ( event.key.keysym.sym )
                {
                case SDLK_DOWN:
                    if (choice_current < item_nb){
                        choice_current++;
                        sample_play(select);
                    }
                    break;
                case SDLK_UP:
                    if (choice_current > 1){
                        choice_current--;
                        sample_play(select);
                    }
                    break;
                case SDLK_RETURN:
                    while (choice_current == IN_GAME)
                    {
                        unit_default_param(g_game.v_unit, g_game.unit_nb);
                        choice_current = state_in_game(screen);
                        if (choice_current == MAIN_MENU)    //The current state is main menu, select in game as default choice and quit
                        {
                            choice_current = IN_GAME;
                            break;
                        }
                    }
                    if (choice_current == OPTION)state_options(screen);
                    break;

                default:
                    break;
                }
            break;
            case SDL_JOYBUTTONDOWN:
                switch(event.jbutton.button)
                {
                    case 0:
                    break;
                    case 1:
                    break;

                    case 2:
                        while (choice_current == IN_GAME)
                        {
                            unit_default_param(g_game.v_unit, g_game.unit_nb);
                            choice_current = state_in_game(screen);
                            if (choice_current == MAIN_MENU)    //The current state is main menu, select in game as default choice and quit
                            {
                                choice_current = IN_GAME;
                                break;
                            }
                        }
                        if (choice_current == OPTION)state_options(screen);
                    break;

                    case 3:
                    break;

                    case 4:
                    break;

                    case 5:
                    break;

                    case 6:
                        done = true;
                    break;
                }
            break;
            default:
            break;
            }
        }

        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
        image_draw(bg_image, screen, 0, 0);

        int top_shift = 150;

        for (i=1;i<=2;i++)
        {
            if (i == 1)
            {
                strncpy(sz_choice, "Play", 20);
                sz_choice[19] = '\0';
            }
            else if ( i == 2)
            {
                strncpy(sz_choice, "Options", 20);
                sz_choice[19] = '\0';
            }

            if (choice_current == i)
            {
                font_quality = SHADED;
            }
            else font_quality = SOLID;

            cur_pos.y = top_shift + i*50;
            SDL_Surface *font_surface= font_create_surface(font_menu, 250, 120, 35, 10, 100, 100, 100, 0, sz_choice, font_quality);
            SDL_BlitSurface(font_surface, NULL, screen, &cur_pos);
            SDL_FreeSurface (font_surface);
        }

        cur_pos.y = 450;
        SDL_Surface *font_surface= font_create_surface(font_credit, 250, 120, 35, 10, 100, 100, 100, 0, "2010 - 2015 TheDrev", SOLID);
        SDL_BlitSurface(font_surface, NULL, screen, &cur_pos);
        SDL_FreeSurface (font_surface);

        SDL_Flip(screen);
    }

    //free font
    if(font_menu != NULL)TTF_CloseFont(font_menu);
    if(font_credit != NULL)TTF_CloseFont(font_credit);
    SDL_FreeSurface(bg_image->surface);
    Mix_FreeChunk(select);

    //free ressouces
    element* p_browse = images;
    while (p_browse) {
        ressource *res = p_browse->data;
        free(res->name);
        image_free(res->data);
        p_browse = p_browse->next;
    }

    linked_list_clear(&images);

    return EXIT_SUCCESS;
}
Example #7
0
void main()
{
	unsigned char i;
	unsigned char savemode;
	

	//
	// Core Hardware Initialization
	

	
	mcu_initialize();	// Initialize MCU resources and 8KHz interrupt...
	
	nvreadbuf();		// Load the NV buffer from flash (get badge Addr and properties)
	proc_btn1();		// Process Buttons
	
	sound_config_polled(); 		// Configure the sound subsystem chip
	




	etoh_init();			// Initialize the Alcohol Sensor Subsystem
	MRF49XA_Init();			// Initialize the RF tranceiver
	usb_ser_init(); 		// Initialize the serial port
	light_init();
	
	

	
	
	//
	// Preliminary setup and interaction
	// These setup a precurser items will occur prior to going into the main worker loop. 
	// This is mainly the one-time powerup and "boot" sequence
	//

    // Show the address of the badge on the LEDs (since there are only 7 LED's
    // the binary number will show in green if the badge is < 128 and red if >  
    // 128 with the badge addresses 0 and 128 showing up as nothing (typically illegal 
    // numbers anyway
    
    // Note, led_showbin does not interact with the interrupt driven light show well. 
    // So only use if you may not be in interrupt mode yet of if a show is not running
    delay_s(1);
    led_showbin(LED_SHOW_RED, nvget_badgetype() | 0x40); // Startup Indicator
    delay_10us(100);
    led_showbin(LED_SHOW_RED, 0);
    delay_s(1);
    led_showbin(LED_SHOW_RED, nvget_badgeperm() | 0x40); // Same
    delay_10us(100);
    led_showbin(LED_SHOW_RED, 0);
    delay_s(1);
    
    
    // 
    // Shows address as described above
    //
    MyBadgeID = nvget_badgeid();
    led_showbin(MyBadgeID & 0x80 ? LED_SHOW_RED : LED_SHOW_GRN, MyBadgeID & 0x7f );
    delay_s(TIME_ADDR);
    led_showbin(LED_SHOW_NONE, 0);
    
    init_rnd(nvget_badgetype()+1, MyBadgeID, 0x55); // Seed tha random number generator
    
    
    //
    // Perform POV credits (spin the badge on your wrist :)
    //
    led_pov(LED_SHOW_AUTO, TIME_POV);
    
    // Enable Global Interrupts
	// Use Interrupts. ISR is interrupt(), below	
	intcon.GIE=1;
    




	//sample_play();
	
	//delay_s(2);
	
	
	MyMode = MODE_IDLE;
	
	
	modelights();  // Sets lightshow based on a few state parameters

	
	// Calculate initial elevation time
	elevatemsecs = elapsed_msecs + ELEVATE_BASE + (unsigned long) rnd_randomize() * ELEVATE_VAR;

	
	
	// 
	// Main Worker Loop
	//	
	while(1) {
		//
		// Handle the elapsed time clocks
		//
		clear_bit(intcon, TMR0IE);
		loop_msecs = intr_msecs; // Take copy to avoid race conditions
		intr_msecs = 0;
		set_bit(intcon, TMR0IE);
		elapsed_msecs += loop_msecs; // Update elapsed time in msecs
		
		
		savemode = MyMode;	// Used to detact mode changes when command processers set new mode
		switch(MyMode) {
		  case MODE_IDLE:
		    // If button pressed, handle it
		    if(btn_commandwork(loop_msecs) == BTN_WORKING) {
				MyMode = MODE_GETCMD;
				modelights();
				playsong = 0;
				//light_pause();
				break;
		    }
		    // Look for incoming RF packet
		    if(MRF49XA_Receive_Packet(rfrxbuf,&rfrxlen) == PACKET_RECEIVED) {
				MRF49XA_Reset_Radio();
				//led_showbin(LED_SHOW_RED, 2);
				//delay_10us(10);
				//led_showbin(LED_SHOW_RED, 0);
				rfcmd_execute(rfrxbuf, rfrxlen);
		        
			}
			if(savemode != MyMode) {	// Don't process remainder of idle switch if state change
				break;
			}
			// If time to send a beacon, send it. Also process quorum sounds. 
			if(elapsed_msecs > (last_beacon + (unsigned long)BEACON_BASE +  ((unsigned long)rnd_randomize()* BEACON_RNDSCALE))) { // time for beacon
				rfcmd_3send(RFCMD_BEACON, MyBadgeID, nvget_socvec1());

				last_beacon = elapsed_msecs;
				rfcmd_clrcden();
				if(have_quorum) {
					if(rfcmd_getdensity() <= DENSITY_QUORUM_LO) {
						have_quorum = 0;
						 if(!playsong) tune_startsong(SONG_CHIRP2);
					}
				}
				else {
					if(rfcmd_getdensity() >= DENSITY_QUORUM_HI) {
						have_quorum = 1;
						if (!playsong) tune_startsong(SONG_303);
					}
				}
				modelights();
			}
			break;
		case MODE_ETOH:  // Run the alcohol sensor state machine
		  if(etoh_breathtest(ETOH_DOWORK,  loop_msecs ) == ETOH_DONE) {  // worker for ETOH
			switch(etoh_getreward()) {
			  case REWARD_SOBER:
			    tune_startsong(SONG_BUZZER);
			    break;
			  case REWARD_TIPSY: 
			    tune_startsong(SONG_PEWPEW);
			    break;
			  case REWARD_DRUNK:
			    tune_startsong(SONG_CACTUS);
			    break;
			    
			 }
			 MyMode = MODE_IDLE;
		 
			 light_show(LIGHTSHOW_SOCFLASH, 5);
			 break;	 
	      }
	      break;
	    case MODE_ATTEN:
	        // Puts all badges into visual attention mode to see who's in range
	        if(MyMode != lastmode) {
				attelapsed  = 0;
			}
			attelapsed += loop_msecs;
			if(attelapsed > 120000) {	// Stays there 2 min (should be in #def)
				MyMode = MODE_IDLE;
			}
			
			if(MRF49XA_Receive_Packet(rfrxbuf,&rfrxlen) == PACKET_RECEIVED) {
				MRF49XA_Reset_Radio();
			
				rfcmd_execute(rfrxbuf, rfrxlen);
		        
			}
			modelights();
	      break;
	    case MODE_GETCMD:
	      if (btn_commandwork( loop_msecs) != BTN_WORKING) {
			MyMode = MODE_IDLE;
			modelights();
		  }
	      break;	     
		    
		} // switch
		  
		tune_songwork();					// Worker thread for songs				 
		light_animate(loop_msecs);			// worker thread for lights
		
		if(MyElev) {	// Handle the privilege elevation timer
			if(elapsed_msecs > (elevatemsecs + ELEVATE_DUR)) {
			    MyElev = 0;
			    elevatemsecs = elapsed_msecs + ELEVATE_BASE + (unsigned long) rnd_randomize() * ELEVATE_VAR;
			    modelights();
			}
		} else {
			if(elapsed_msecs > elevatemsecs) {
				MyElev = 1;
				sample_play();
				modelights();
			}
		}

				
		lastmode = MyMode;
		
	}	
	
    	
}