Esempio n. 1
0
File: map.c Progetto: slaeshjag/Muon
void map_init(char *filename) {
	int w, h;
	unsigned int i, j;
	
	powergrid=NULL;
	powergrid_lines=0;
	
	home_x=home_y=-1;
	
	map_selected.border=d_render_line_new(4, 1);
	map_selected.index=-1;
	map_selected.owner=-1;
	map_selected.building=0;
	map_selected.circle=NULL;
	
	map_grid_chunk=NULL;
	map_grid_chunks=0;
	
	game_attacklist=NULL;
	for(i=0; i<MAX_PLAYERS; i++) {
		game_attacklist_render[i].length=0;
		game_attacklist_render[i].lines=NULL;
	}
	
	map=d_map_load(filename);
	map_w=map->layer->tilemap->w*map->layer->tile_w;
	map_h=map->layer->tilemap->h*map->layer->tile_h;
	d_render_tilesheet_geometrics(map->layer->ts, &w, &h, NULL, NULL);
	tilesx=w/map->layer->tile_w;
	tilesy=h/map->layer->tile_h;
	
	DARNIT_MAP_LAYER *building_layer=&map->layer[map->layers-2];
	d_render_line_move(map_selected.border, 0, 0, 0, building_layer->tile_w, 0);
	d_render_line_move(map_selected.border, 1, 0, building_layer->tile_h, building_layer->tile_w, building_layer->tile_h);
	d_render_line_move(map_selected.border, 2, 0, 0, 0, building_layer->tile_h);
	d_render_line_move(map_selected.border, 3, building_layer->tile_w, 0, building_layer->tile_w, building_layer->tile_h);
	
	minimap_viewport=d_render_line_new(4, 1);
	
	for(i=0; i<(sidebar_width-8)*(sidebar_width-8); i++)
		((unsigned int *)minimap_data)[i]=0;
	
	for(i=0; i<map->layer->tilemap->w*map->layer->tilemap->h; i++) {
		for(j=0; j<map->layers-2; j++)
			if(map->layer[j].tilemap->data[i]&0xFFF)
				break;
		if(j>=map->layers-2)
			map->layer[map->layers-2].tilemap->data[i]|=1<<17;
	}
	map_update_grid();
	
	//TODO: move somewhere else
	//Update abilities
	ability[0].ready=100;
	ability[0].button->enabled=1;
	ability[1].ready=-1;
	ability[1].button->enabled=0;
	ability[2].ready=-1;
	ability[2].button->enabled=0;
}
Esempio n. 2
0
File: map.c Progetto: slaeshjag/Muon
void map_calculate_powergrid() {
	DARNIT_MAP_LAYER *toplayer=&map->layer[map->layers-1];
	DARNIT_TILEMAP *toplayer_tilemap=map->layer[map->layers-1].tilemap;
	unsigned int *toplayer_data=map->layer[map->layers-1].tilemap->data;
	
	int tile_w=toplayer->tile_w;
	int tile_h=toplayer->tile_h;

	if(powergrid)
		d_render_line_free(powergrid);
	powergrid=d_render_line_new(toplayer_tilemap->w*toplayer_tilemap->h*3, 1);
	
	int x, y, i=0;
	for(y=0; y<toplayer_tilemap->h; y++) {
		for(x=0; x<toplayer_tilemap->w; x++) {
			if(x+1<toplayer_tilemap->w&&(toplayer_data[MAP_INDEX(x, y)]^toplayer_data[MAP_INDEX(x+1, y)])&0x1000000) {
				d_render_line_move(powergrid, i, (x+1)*tile_w, y*tile_h, (x+1)*tile_w, (y+1)*tile_h);
				i++;
			}
			if(y+1<toplayer_tilemap->h&&(toplayer_data[MAP_INDEX(x, y)]^toplayer_data[MAP_INDEX(x, y+1)])&0x1000000) {
				d_render_line_move(powergrid, i, x*tile_w, (y+1)*tile_h, (x+1)*tile_w, (y+1)*tile_h);
				i++;
			}
		}
	}
	powergrid_lines=i;
}
Esempio n. 3
0
void ui_pane_resize(UI_PANE *pane, int x, int y, int w, int h) {
	pane->x = x;
	pane->y = y;
	pane->w = w;
	pane->h = h;

	d_render_rect_move(pane->background, 0, x, y, x + w, y + h);
	d_render_line_move(pane->border, 0, x, y, x + w, y);
	d_render_line_move(pane->border, 1, x, y + h, x + w, y + h);
	d_render_line_move(pane->border, 2, x, y, x, y + h);
	d_render_line_move(pane->border, 3, x + w, y, x + w, y + h);
	if(pane->root_widget != NULL)
		pane->root_widget->resize(pane->root_widget, x + ui_padding, y + ui_padding, w - ui_padding * 2, h - ui_padding * 2);
}
Esempio n. 4
0
File: map.c Progetto: slaeshjag/Muon
void map_minimap_update_viewport() {
	int x=game_sidebar_minimap->w*map->cam_x/map_w+game_sidebar_minimap->x;
	int y=game_sidebar_minimap->h*map->cam_y/map_h+game_sidebar_minimap->y;
	int w=game_sidebar_minimap->w*platform.screen_w/map_w;
	int h=game_sidebar_minimap->h*platform.screen_h/map_h;
	int x1=MAX(x, game_sidebar_minimap->x);
	int x2=MIN(x+w, game_sidebar_minimap->x+game_sidebar_minimap->w);
	int y1=MAX(y, game_sidebar_minimap->y);
	int y2=MIN(y+h, game_sidebar_minimap->y+game_sidebar_minimap->h);
	d_render_line_move(minimap_viewport, 0, x1, y1, x2, y1);
	d_render_line_move(minimap_viewport, 1, x1, y2, x2, y2);
	d_render_line_move(minimap_viewport, 2, x1, y1, x1, y2);
	d_render_line_move(minimap_viewport, 3, x2, y1, x2, y2);
}
Esempio n. 5
0
int bullet_update(BULLET *bullet) {
	int x1, y1, x2, y2;
	
	bullet->x += bullet->vel_x;
	bullet->y += bullet->vel_y;
	bullet->time += d_last_frame_time();
	if (bullet->time >= BULLET_LIFE)
		return 0;

	if (bullet->x < 0)
		bullet->x += 800000;
	if (bullet->x >= 800000)
		bullet->x -= 800000;
	if (bullet->y < 0)
		bullet->y += 480000;
	if (bullet->y >= 480000)
		bullet->y -= 480000;
	
	x1 = (d_util_sin(bullet->angle + 900) * BULLET_LENGTH) >> 16;
	y1 = (d_util_sin(bullet->angle) * BULLET_LENGTH) >> 16;
	x2 = (d_util_sin(bullet->angle + 900) * BULLET_LENGTH) >> 16;
	y2 = (d_util_sin(bullet->angle) * BULLET_LENGTH) >> 16;
	x1 *= -1;
	y1 *= -1;
	d_render_line_move(bullet->line, 0, x1, y1, x2, y2);

	render_line_wrap(bullet->line, bullet->x / 1000, bullet->y / 1000, 15, -15);
	return 1;
}
Esempio n. 6
0
File: map.c Progetto: slaeshjag/Muon
void map_update_grid() {
	DARNIT_MAP_LAYER *building_layer=&map->layer[map->layers-2];
	DARNIT_TILEMAP *building_tilemap=building_layer->tilemap;
	int i, x, y, cols, rows;
	int tile_w=map->layer[map->layers-2].tile_w;
	int tile_h=map->layer[map->layers-2].tile_h;
	for(i=0; i<map_grid_chunks; i++)
		d_render_line_free(map_grid_chunk[i].lines);
	cols=(building_tilemap->w+(building_tilemap->w%8>0?8:0))/8;
	rows=(building_tilemap->h+(building_tilemap->h%8>0?8:0))/8;
	map_grid_chunks=cols*rows;
	free(map_grid_chunk);
	if((map_grid_chunk=malloc(map_grid_chunks*sizeof(struct MAP_GRID_CHUNK)))==NULL)
		return;
	for(i=0; i<map_grid_chunks; i++) {
		map_grid_chunk[i].lines=d_render_line_new(128, 1);
		map_grid_chunk[i].size=0;
		map_grid_chunk[i].x=(i%cols)*8*building_layer->tile_w;
		map_grid_chunk[i].y=(i/cols)*8*building_layer->tile_h;
		map_grid_chunk[i].w=8*building_layer->tile_w;
		map_grid_chunk[i].h=8*building_layer->tile_h;
		//printf("map grid chunk %i (%i, %i) w: %i h: %i\n", i, map_grid_chunk[i].x, map_grid_chunk[i].y, map_grid_chunk[i].w, map_grid_chunk[i].h);
	}
	
	int chunk;
	for(y=0; y<building_tilemap->h; y++) {
		chunk=(y/8)*cols;
		for(x=0; x<building_tilemap->w; x++) {
			if(x+1<building_tilemap->w&&!((building_tilemap->data[y*building_tilemap->w+x]&(1<<17))&(building_tilemap->data[y*building_tilemap->w+x+1]&(1<<17)))) {
				d_render_line_move(map_grid_chunk[chunk].lines, map_grid_chunk[chunk].size, (x+1)*tile_w, y*tile_h, (x+1)*tile_w, (y+1)*tile_h);
				map_grid_chunk[chunk].size++;
			}
			if(y+1<building_tilemap->h&&!((building_tilemap->data[y*building_tilemap->w+x]&(1<<17))&(building_tilemap->data[(y+1)*building_tilemap->w+x]&(1<<17)))) {
				d_render_line_move(map_grid_chunk[chunk].lines, map_grid_chunk[chunk].size, x*tile_w, (y+1)*tile_h, (x+1)*tile_w, (y+1)*tile_h);
				map_grid_chunk[chunk].size++;
			}
			if((x+1)%8==0)
				chunk++;
		}
	}
}
Esempio n. 7
0
void shape_copy_rotate(SHAPE_COPY *copy, int angle) {
	int i;

	if (!copy)
		return;

	memcpy(copy->rot, copy->coord, sizeof(int) * (copy->lines * 2 + 2));
	i = 0;
	rotate_coord(angle, &copy->rot[i * 2], &copy->rot[i * 2 + 1]);
	for (; i < copy->lines; i++) {
		rotate_coord(angle, &copy->rot[i * 2 + 2], &copy->rot[i * 2 + 3]);
		if (i < copy->lines)
			d_render_line_move(copy->line, i, copy->rot[i * 2], copy->rot[i * 2 + 1], copy->rot[i * 2 + 2], copy->rot[i * 2 + 3]);
	}

	return;
}
Esempio n. 8
0
void draw_graph(struct GRAPH *g) {
	int i, j;
	int a, b;
	struct EDGE *e;
	vertices=edges=0;
	if(!g)
		return;
	for(i=0, j=0; g; g=g->next, i++) {
		d_render_circle_move(circle[i], g->vertex->point.x, g->vertex->point.y, 10);
		for(e=g->vertex->neighbour; e; e=e->next, j++) {
			d_render_line_move(line[j], 0, g->vertex->point.x, g->vertex->point.y, e->vertex->point.x, e->vertex->point.y);
			a=MAX(g->vertex->point.x, e->vertex->point.x)-MIN(g->vertex->point.x, e->vertex->point.x);
			b=MAX(g->vertex->point.y, e->vertex->point.y)-MIN(g->vertex->point.y, e->vertex->point.y);
			length[i]=(a+b)/4;
			printf("length %i\n", length[i]);
		}
	}
	vertices=i;
	edges=j;
}
Esempio n. 9
0
void lobby_init() {
	lobby.line = d_render_line_new(1, 2);
	d_render_line_move(lobby.line, 0, config.platform.screen_w - 320, 0, config.platform.screen_w - 320, config.platform.screen_h);
	
	lobby.list_players = d_text_surface_color_new(config.font_std, 2048, 300, 64, 0);
	lobby.list_games = d_text_surface_color_new(config.font_std, 2048, 300, config.platform.screen_w - 300, 0);
	
	lobby_join.list_players = d_text_surface_color_new(config.font_std, 2048, 300, 64, 0);
	lobby_host.start_game = d_text_surface_color_new(config.font_std, 32, 300, 64, config.platform.screen_h - 96);
	d_text_surface_color_next(lobby_host.start_game, 255, 0, 0);
	d_text_surface_string_append(lobby_host.start_game, "Press enter to start game");
	
	update_lists(NULL, lobby_client.client);
	
	lobby_playername.text_playername = d_text_surface_new(config.font_std, 64, 1024, 64, 64);
	lobby_playername.inputfield_playername = d_menu_textinput_new(64, 128, config.font_std, config.player_name, PROTO_PLAYER_NAME - 1, config.platform.screen_w);
	
	d_text_surface_string_append(lobby_playername.text_playername, "Enter your player name:");
	
	lobby.selected_game = 0;
	lobby.selected_player = 0;
}
Esempio n. 10
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;
}
Esempio n. 11
0
void ui_button_resize(UI_WIDGET *widget, int x, int y, int w, int h) {
	struct UI_BUTTON_PROPERTIES *p = widget->properties;
	widget->x = x;
	widget->y = y;
	widget->w = w;
	widget->h = h;
	p->child->resize(p->child, x + 2 + ui_padding, y + 2 + ui_padding, w - 4 - ui_padding * 2, h - 4 - ui_padding * 2);

	d_render_line_move(p->border, 0, x, y, x + w - 1, y);
	d_render_line_move(p->border, 1, x, y + h, x + w - 1, y + h);
	d_render_line_move(p->border, 2, x, y, x, y + h - 1);
	d_render_line_move(p->border, 3, x + w, y, x + w, y + h - 1);
	d_render_line_move(p->border, 4, x + 2, y + 2, x + w - 3, y + 2);
	d_render_line_move(p->border, 5, x + 2, y + h - 2, x + w - 3, y + h - 2);
	d_render_line_move(p->border, 6, x + 2, y + 2, x + 2, y + h - 3);
	d_render_line_move(p->border, 7, x + w - 2, y + 2, x + w - 2, y + h - 3);

	d_render_line_move(p->active_border, 0, x, y + 1, x + w - 1, y + 1);
	d_render_line_move(p->active_border, 1, x, y + h - 1, x + w - 1, y + h - 1);
	d_render_line_move(p->active_border, 2, x + 1, y, x + 1, y + h - 1);
	d_render_line_move(p->active_border, 3, x + w - 1, y, x + w - 1, y + h - 1);
}