Ejemplo n.º 1
0
int main_deathmatch()
{
	SDL_Event e;

	SDL_ShowCursor(SDL_DISABLE);

	entity_initialize_list(1024);
	tank_initialize_list(15);

	g_current_level = level_load("leveloneconfig");
	render_set_background(g_current_level->background->image);

	g_music = audio_load_music("sounds/music/backgroundmusic.wav");
	g_sound = audio_load_sound("sounds/digital/digital.wav");
	if(g_music->file.music != NULL)
	{
		slog("Playing Music");
		//audio_play_music(g_music->file.music);
	}
	else
		slog("Could not load music file");

	player = player_spawn("Player", PLAYER);
	v2d_set(player->tank->tracks->body->position, SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
	v2d_set(player->tank->turret->body->position, SCREEN_WIDTH/2, SCREEN_HEIGHT/2);

	g_now = SDL_GetTicks();

	ui_initialize_deathmatch(rtn_renderer());

	do
	{
		//calculate deltatime
		g_last = g_now;
		g_now = SDL_GetTicks();
		g_deltatime = g_now - g_last;

		render_update(1);
		render_clear();
		entity_all_think();
		entity_all_update();
		player_move(player);
		while(SDL_PollEvent(&e))
		{
			if(e.type == SDL_KEYDOWN)
			{
				if(e.type == SDL_QUIT)
					SDL_Quit();
				if(e.key.keysym.sym == SDLK_w)
					player->keysHeld.W = 1;
				if(e.key.keysym.sym == SDLK_s)
					player->keysHeld.S = 1;
				if(e.key.keysym.sym == SDLK_a)
					player->keysHeld.A = 1;
				if(e.key.keysym.sym == SDLK_d)
					player->keysHeld.D = 1;
				if(e.key.keysym.sym == SDLK_e)
				{
					tank_weapon_change(player->tank);
					slog("Current weapon: %s", player->tank->currentweapon->name);
				}
				if(e.key.keysym.sym == SDLK_p)
				{
					audio_play_sound(g_sound->file.sound);
				}
				if(e.key.keysym.sym == SDLK_f)
				{
					Entity *sonar;
					sonar = sonar_new(sonar = entity_new(SONAR, NULL), 3.0, player->tank);
				}
				if(e.key.keysym.sym == SDLK_g)
				{
					tank_weapon_fire(player->tank);
				}
				if(e.key.keysym.sym == SDLK_h)
					player->tank->health -= 5;
				if(e.key.keysym.sym == SDLK_j)
					player->tank->armour -= 5;
				if(e.key.keysym.sym == SDLK_SPACE)
				{
					if(player->tank->is_hidden)
						player->tank->is_hidden = 0;
					else
						player->tank->is_hidden = 1;

					tank_sprite_change(player->tank);
				}
				if(e.key.keysym.sym == SDLK_ESCAPE)
				{
					playclicked = 0;
					entity_close_list();
					tank_close_list();
					player_close_list();
					currentstate = MAINMENU;
				}
			}
			if(e.type == SDL_KEYUP)
			{
				if(e.key.keysym.sym == SDLK_w)
					player->keysHeld.W = 0;
				if(e.key.keysym.sym == SDLK_s)
					player->keysHeld.S = 0;
				if(e.key.keysym.sym == SDLK_a)
					player->keysHeld.A = 0;
				if(e.key.keysym.sym == SDLK_d)
					player->keysHeld.D = 0;
			}
		}
		if(g_deltatime < 32)
			SDL_Delay(32-g_deltatime);
	} while(currentstate == DEATHMATCH);

	return 0;
}
Ejemplo n.º 2
0
void map_load(int i) {
	int x, y, layer, tmp, x2, y2;
	map.powerups=0;
	map.sections=-1;
	map.lines[0]=0;
	boss_shooting=0;
	for(x=0; x<map.map[i]->layer->tilemap->w; x++) {
		if(!(x%(MAP_SECTION_WIDTH))) {
			map.sections++;
			map.lines[map.sections]=0;
		}
		for(y=0; y<map.map[i]->layer->tilemap->h; y++) {
			switch((tmp=map.map[i]->layer->tilemap->data[y*map.map[i]->layer->tilemap->w+x])&0xF0) {
				case 0x30:
					map.enemy[map.enemies]=enemy_spawn(x*TILE_SIZE, y*TILE_SIZE, tmp&0xF, model.enemy[tmp&0xF]);
					if(tmp==0x30)
						map.enemy[map.enemies]->weapon.normal.right=shape_copy_copy(model.enemy_right);
					if(tmp==0x33)
						map.enemy[map.enemies]->health=600;
					map.enemies++;
					break;
				case 0x50:
					map.powerup[map.powerups].x=x*TILE_SIZE;
					map.powerup[map.powerups].y=y*TILE_SIZE;
					map.powerup[map.powerups].type=tmp&0xF;
					map.powerup[map.powerups].taken=0;
					map.powerup[map.powerups].shape=shape_copy_copy(model.powerup[tmp&0xF]);
					map.powerups++;
					break;
				default:
					break;
			}
			for(layer=1; layer<map.map[i]->layers; layer++) {
				switch(map.map[i]->layer[layer].tilemap->data[y*map.map[i]->layer[layer].tilemap->w+x]) {
					case 0x90:
						for(tmp=0; map.map[i]->layer[layer].tilemap->data[(y+tmp)*map.map[i]->layer[layer].tilemap->w+x]!=0xA0; tmp--);
						x2=TILE_SIZE*x;
						y2=TILE_SIZE*(y+tmp)+TILE_SIZE;
						d_render_line_move(map.line[map.sections], map.lines[map.sections], TILE_SIZE*x, TILE_SIZE*y+TILE_SIZE, x2, y2);
						break;
					case 0x91:
						for(tmp=0; map.map[i]->layer[layer].tilemap->data[y*map.map[i]->layer[layer].tilemap->w+x+tmp]!=0xA1; tmp++);
						x2=TILE_SIZE*(x+tmp)+TILE_SIZE;
						y2=TILE_SIZE*y;
						d_render_line_move(map.line[map.sections], map.lines[map.sections], TILE_SIZE*x+TILE_SIZE, TILE_SIZE*y+TILE_SIZE, x2, y2+TILE_SIZE);
						break;
					case 0x92:
						for(tmp=0; map.map[i]->layer[layer].tilemap->data[(y+tmp)*map.map[i]->layer[layer].tilemap->w+x-tmp]!=0xA2; tmp--);
						x2=TILE_SIZE*(x-tmp)+TILE_SIZE;
						y2=TILE_SIZE*(y+tmp)+TILE_SIZE;
						d_render_line_move(map.line[map.sections], map.lines[map.sections], TILE_SIZE*x+TILE_SIZE, TILE_SIZE*y+TILE_SIZE, x2, y2);
						break;
					case 0x93:
						for(tmp=0; map.map[i]->layer[layer].tilemap->data[(y+tmp)*map.map[i]->layer[layer].tilemap->w+x+tmp]!=0xA3; tmp++);
						x2=TILE_SIZE*(x+tmp)+TILE_SIZE;
						y2=TILE_SIZE*(y+tmp)+TILE_SIZE;
						d_render_line_move(map.line[map.sections], map.lines[map.sections], TILE_SIZE*x+TILE_SIZE, TILE_SIZE*y+TILE_SIZE, x2, y2);
						break;
					default:
						continue;
				}
				map.line_coord[map.sections][map.lines[map.sections]].x1=TILE_SIZE*x;
				map.line_coord[map.sections][map.lines[map.sections]].y1=TILE_SIZE*y;
				map.line_coord[map.sections][map.lines[map.sections]].x2=x2;//+TILE_SIZE/2;
				map.line_coord[map.sections][map.lines[map.sections]].y2=y2;//+TILE_SIZE/2;
				map.lines[map.sections]++;
			}
		}
	}
	map.current=i;
	player_spawn(64, 128, model.player, model.gun, model.grenade);
	camera_x = 0;
	camera_scroll_speed = CAMERA_SCROLL_SPEED;
}