コード例 #1
0
void deroul_cmb(SDL_Surface *ecran, int mstr)
{
	cmb = 1;
	int continu = 1;
	init_enemy(mstr);
	choix_att = 0;
	img_cmb(ecran, mstr);
	void (* type_att[3])(SDL_Surface *ecran,int mstr) = {attaque_phy, attaque_mag, obj};
	while(continu && cmb)
	{
		aff_men(ecran);
	  	SDL_Event event;
		SDL_WaitEvent(&event);
		if(event.type == SDL_QUIT)
			continu = 0;
		else if (event.type == SDL_KEYDOWN)
        {
            SDLKey touche = event.key.keysym.sym;
			if (choix_att == 3 && ( touche == SDLK_a))
				continu = fuite(ecran, mstr);
			else if ( touche == SDLK_a)
				type_att[choix_att](ecran, mstr);
			else
				choix_menu(touche);
		}
	}
	lvl_up(ecran);
}
コード例 #2
0
ファイル: game.c プロジェクト: tivervac/UGentProjects
void init_spawning(GameState* state) {
	if (!state->spells.frost_wave_active && state->wave.spawn_counter == state->wave.spawn_interval) {
		state->wave.spawn_counter = 0;
		if (state->wave.nr_of_spawned_enemies != state->wave.nr_of_enemies) {
			//nieuwe entity aanmaken en checken welk type vijand er moer gespawned worden
			Entity enemy;
			init_entity(&enemy, ENEMY, state->world.spawn->spawn_location.world_x, state->world.spawn->spawn_location.world_y, ENEMY_SIZE, ENEMY_SIZE);
			if (state->wave.nr_of_spawned_enemies % 5 == 1  && (state->wave.boss_wave && state->wave.nr_of_enemies - 1 != state->wave.nr_of_spawned_enemies)) {
				init_enemy(&enemy, ELITE);
				enemy.enemy.health_max = ENEMY_ELITE_HEALTH + (state->wave.wave_number * (state->wave.wave_number / 3) * (ENEMY_ELITE_HEALTH * 0.1));
			} else if (state->wave.boss_wave == 1 && state->wave.nr_of_enemies - 1 == state->wave.nr_of_spawned_enemies) {
				init_enemy(&enemy, BOSS);
				enemy.enemy.health_max = ENEMY_BOSS_HEALTH + (state->wave.wave_number * (state->wave.wave_number / 3) * (ENEMY_BOSS_HEALTH * 0.1));
			} else if (state->wave.wave_number >= 4) {
				int random = rand() % 100;
				if (state->wave.wave_number >= 8) {
					//5% kans op FAST
					if (random < 5) {
						init_enemy(&enemy, FAST);
						enemy.enemy.health_max = ENEMY_FAST_HEALTH + (state->wave.wave_number * (state->wave.wave_number / 3) * (ENEMY_FAST_HEALTH * 0.1));
					} //Ook nog eens 10% kans op AIR
					else if (random < 15) {
						init_enemy(&enemy, AIR);
						enemy.enemy.health_max = ENEMY_AIR_HEALTH + (state->wave.wave_number * (state->wave.wave_number / 3) * (ENEMY_AIR_HEALTH * 0.1));
					}
					else{
						init_enemy(&enemy, NORMAL);
						enemy.enemy.health_max = ENEMY_NORMAL_HEALTH + (state->wave.wave_number * (state->wave.wave_number / 3) * (ENEMY_NORMAL_HEALTH * 0.1));
					}
				} else {
					// 10% kans op AIR
					if (random < 10) {
						init_enemy(&enemy, AIR);
						enemy.enemy.health_max = ENEMY_AIR_HEALTH + (state->wave.wave_number * (state->wave.wave_number / 3) * (ENEMY_AIR_HEALTH * 0.1));
					}else {
						init_enemy(&enemy, NORMAL);
						enemy.enemy.health_max = ENEMY_NORMAL_HEALTH + (state->wave.wave_number * (state->wave.wave_number / 3) * (ENEMY_NORMAL_HEALTH * 0.1));
					}
				}
			} else {
				init_enemy(&enemy, NORMAL);
				enemy.enemy.health_max = ENEMY_NORMAL_HEALTH + (state->wave.wave_number * (state->wave.wave_number / 3) * (ENEMY_NORMAL_HEALTH * 0.1));
			}
			//verdere algemene eigenschappen instellen
			enemy.enemy.health = enemy.enemy.health_max;
			state->enemies = (Entity*) realloc(state->enemies, (state->enemies_length + 1) * sizeof(Entity));
			create_path(&enemy.enemy.path, &state->world, &enemy, state->world.castle, enemy.enemy.path.trajectory_type);
			state->enemies[state->enemies_length] = enemy;
			state->enemies[state->enemies_length].type = ENEMY;
			state->enemies_length++;
			state->wave.nr_of_spawned_enemies++;
		}
	} else if (!state->spells.frost_wave_active) {
		state->wave.spawn_counter++;
	}
}
コード例 #3
0
ファイル: invaders.c プロジェクト: miloh/f1rmware
static void init_game(void) {
	game.player = POS_PLAYER_X;
	game.shot_x = DISABLED;
	game.shot_y = 0;
	game.alive = ENEMY_ROWS*ENEMY_COLUMNS;
	game.move = 0;
	if (getRandom()%2 == 0) {
		game.direction = -1;
		game.lastcol = ENEMY_COLUMNS-1;
	} else {
		game.direction = 1;
		game.lastcol = 0;
	}
	game.killed = 0;
	game.step = false;
	game.ufo = DISABLED;
	init_enemy();

	for (int col=0; col<ENEMY_COLUMNS; col++){
	   game.shots_x[col] = DISABLED;
   	}

	for (int b=0; b<BUNKERS; b++){
		//for (int slice=0; slice<BUNKER_WIDTH; slice++){
		//	game.bunker[b][slice] = 255<<2;
		//}
		game.bunker[b][0] = 0b00111100;
		game.bunker[b][1] = 0b01111100;
		game.bunker[b][2] = 0b11111100;
		game.bunker[b][3] = 0b11100000;
		game.bunker[b][4] = 0b11100000;
		game.bunker[b][5] = 0b11100000;
		game.bunker[b][6] = 0b11100000;
		game.bunker[b][7] = 0b11111100;
		game.bunker[b][8] = 0b01111100;
		game.bunker[b][9] = 0b00111100;
	}
}
コード例 #4
0
ファイル: enemytag.c プロジェクト: rofl0r/openDOW
static void enemy_tag_loop() {
	update_caption = tag_update_caption;
	tag_enemy_current_route = 0;
	tag_enemy_current_shot = 0;
	tag_enemy_spawnline = map_spawn_line;
	tag_enemy_y = 0;
	tag_enemy_upscrolled = 0;
	reset_tag_enemy();
	tag_enemy_id = init_enemy(&tag_enemy);
	
	SDL_Event sdl_event;
	while(1) {
		if(!obj_slot_used[tag_enemy_id]) update_tag_enemy(0);
			//tag_enemy_id = init_enemy(&tag_enemy);
		unsigned need_redraw = 1;
		while (SDL_PollEvent(&sdl_event)) {
			need_redraw = 0;
			int dir = -1;
			switch (sdl_event.type) {
				case SDL_KEYUP:
					switch(sdl_event.key.keysym.sym) {
						case SDLK_e: dump_enemy(); return;
						case SDLK_g: toggle_gun(); break;
						case SDLK_d: enter_direction(); break;
						case SDLK_i: insert_steps(); break;
						case SDLK_s: insert_shot(); break;
						case SDLK_p: do_pause(); break;
						case SDLK_c: clear_screen(); video_update(); need_redraw = 1; break;
						case SDLK_SPACE: update_tag_enemy(1); break;
						case SDLK_PAGEUP: scrollup(); break;
						case SDLK_KP_PLUS:
							dir = 1;
						case SDLK_KP_MINUS:
							if((sdl_event.key.keysym.mod & KMOD_RSHIFT) ||
							   (sdl_event.key.keysym.mod & KMOD_LSHIFT))
								toggle_shape(dir);
							else
							if((sdl_event.key.keysym.mod & KMOD_RALT) ||
							   (sdl_event.key.keysym.mod & KMOD_LALT))
								toggle_route(dir);
							else
							if((sdl_event.key.keysym.mod & KMOD_RCTRL) ||
							   (sdl_event.key.keysym.mod & KMOD_LCTRL))
								toggle_shot(dir);
							else
								toggle_vel(dir);
							break;
						default: break;
					}
				case SDL_KEYDOWN:
					switch(sdl_event.key.keysym.sym) {
						case SDLK_RIGHT: dir = 1;
						case SDLK_LEFT:
							if((sdl_event.key.keysym.mod & KMOD_RSHIFT) ||
							   (sdl_event.key.keysym.mod & KMOD_LSHIFT)) dir *= 4;
							tag_enemy.x += dir;
							update_tag_enemy(1);
							break;
						case SDLK_DOWN:
							dir = 1;
						case SDLK_UP:
							if((sdl_event.key.keysym.mod & KMOD_RSHIFT) ||
							   (sdl_event.key.keysym.mod & KMOD_LSHIFT)) dir *= 4;
							tag_enemy_y += dir;
							update_tag_enemy(1);
							break;
						default: ;
					}
				break;
				default: ;
			}
		}
		game_tick(need_redraw);
	}
}
コード例 #5
0
ファイル: enemytag.c プロジェクト: rofl0r/openDOW
static void update_tag_enemy(int doremove) {
	if(doremove) remove_enemy(tag_enemy_id);
	tag_enemy.y = tag_enemy_y + tag_enemy_upscrolled;
	tag_enemy_id = init_enemy(&tag_enemy);
}
コード例 #6
0
ファイル: rungame.c プロジェクト: jiangshang716/TheGreatWall
int run()
{

    /* Initialize the random number generator */
    srand(time(NULL));
    bool quit = false;
    printf("running\n");

    if(!init_game())
    {
        exit(2);
    }
head:
    if(!load_data())
    {
        printf("data load error\n");
        exit(2);
    }
    init_common_num();
    apply_background();
    init_player();
    draw_player();
    SDL_Color textColor = { 255, 255, 255 };
    //Update the screen
    if( SDL_Flip( screen ) == -1 )
    {
        return 1;
    }
    //While the user hasn't quit
    while( quit == false )
    {
//		printf("%d\n" , rand()%2);
        wait_frame();
        //While there's an event to handle
        while( SDL_PollEvent( &event ) )
        {
            //If the user has Xed out the window
            if( event.type == SDL_QUIT )
            {
                quit = true;
            }

            if( apear_enemy > ENEMY_NUM)
            {
                complete_level(event);
            }
            else
            {
                if( player.alive == 1)
                {
                    player_input(event);
                }

            }
        }
        if(enemy.alive == 0)
        {
            init_enemy();

        }
        if(enemy.alive == 1)
        {
            enemy_move();
        }

        if(bullet.alive == 1)
        {
            bullet_move();
        }

        if(knock(bullet , enemy)) {
            enemy.image = load_image("data/boom.gif", 1);
            bullet.image = load_image("data/boom.gif", 1);
            //		draw_enemy();
            //		draw_bullet();
            enemy.alive = 0;
            bullet.alive = 0;
            bullet.x = -1000;
            bullet.y = -1000;
            score ++;
            final_score ++;
        }
        if(knock(player , enemy)) {
            enemy.image = load_image("data/boom.gif", 1);
            player.image = load_image("data/boom.gif", 1);
            //		draw_enemy();
            //		draw_bullet();
            player.alive = 0;
            enemy.alive = 0;
            quit = true;
        }
        player_move();
        apply_background();
        draw_enemy();

        if(bullet.alive == 1)
        {
            draw_bullet();
        }
        draw_player();
        if(apear_enemy > ENEMY_NUM)
        {

            char text0[256] = "";
            sprintf(text0, "      LEVEL   %d", GAME_LEVEL);
            message = TTF_RenderText_Solid( font, text0, textColor );
            apply_surface( 20 , 50 ,  message , screen);
            char text1[256] = "PRESS \"n\" TO NEXT LEVEL";
            message = TTF_RenderText_Solid( font, text1, textColor );
            apply_surface( 20 , 150 ,  message , screen);
            char text2[256] = "";
            sprintf(text2, "        SCORE:%d", score);
            message = TTF_RenderText_Solid( font, text2, textColor );
            apply_surface( 20 , 250 ,  message , screen);
            char text3[256] = "";

            if(score ==0 || shoot_time == 0)
            {
                sprintf(text3, "     ACCURATE:%d" , 0);
            }
            else
            {
                sprintf(text3, "     ACCURATE:%.2lf%%",(double)score/shoot_time*100);
            }
            message = TTF_RenderText_Solid( font, text3, textColor );
            apply_surface( 20 , 350 ,  message , screen);

        }



        if( SDL_Flip( screen ) == -1 )
        {
            return 1;
        }
        if(player.alive == 0) {
            quit = true;
        }
        if(enemy.alive == 0)
        {
            init_enemy();
        }


    }

    char text1[256] = "       GAME  OVER   ";
    message = TTF_RenderText_Solid( font, text1, textColor );
    apply_surface( 20 , 50 ,  message , screen);
    char text2[256] = "";
    sprintf(text2, "       FINAL_SCORE:%d", final_score);
    message = TTF_RenderText_Solid( font, text2, textColor );
    apply_surface( 20 , 150 ,  message , screen);
    char text3[256] = "    PRESS \"r\" TO RESTART";
    message = TTF_RenderText_Solid( font, text3, textColor );
    apply_surface( 20 , 250 ,  message , screen);
    char text4[256] = "    PRESS \"q\" TO EXIT";
    message = TTF_RenderText_Solid( font, text4, textColor );
    apply_surface( 20 , 350 ,  message , screen);
    if( SDL_Flip( screen ) == -1 )
    {
        return 1;
    }

    quit = false;
    while( quit == false )
    {
//		printf("%d\n" , rand()%2);
//		wait_frame();
        //While there's an event to handle
        while( SDL_PollEvent( &event ) )
        {
            //If the user has Xed out the window
            if( event.type == SDL_QUIT )
            {
                quit = true;
            }
            if( event.type == SDL_KEYDOWN ) {
                //Adjust the velocity
                switch( event.key.keysym.sym ) {
                case SDLK_r:
                    goto head;
                    break;
                case SDLK_q:
                    quit = true;
                    break;
                }
            }
        }
    }

    //Close the font that was used
    TTF_CloseFont( font );
    //Quit SDL_ttf
    TTF_Quit();
    //Quit SDL
    SDL_Quit();
}