Funcionalitat basica acabada

This commit is contained in:
2016-05-17 19:56:16 +02:00
parent 78983f2fda
commit c2e376b529

View File

@@ -121,17 +121,16 @@ void Init() {
int r = 0, g = 0, b = 0;
for (int ty = 0; ty < tile_width; ty++) {
for (int tx = 0; tx < tile_height; tx++) {
const Uint32 color = buffer[(bx + tx) + (by + ty)*tilemap_width];
r += color & 0xff;
g += (color >> 8) & 0xff;
b += (color >> 16) & 0xff;
const Uint32 offset = (bx + tx) * 4 + (by + ty)*(tilemap_width * 4);
r += buffer[offset];
g += buffer[offset+1];
b += buffer[offset+2];
}
}
r /= tile_width*tile_height;
g /= tile_width*tile_height;
b /= tile_width*tile_height;
minitiles[tmx + tmy*tmtw] = 0xff000000 + r + (b << 8) + (g << 16);
//minitiles[tmx + tmy*tmtw] = 0xff + (r << 24) + (b << 8) + (g << 16);
r /= (tile_width*tile_height);
g /= (tile_width*tile_height);
b /= (tile_width*tile_height);
minitiles[tmx + tmy*tmtw] = 0xFF000000 + b + (g << 8) + (r << 16);
}
}
stbi_image_free(buffer);
@@ -145,7 +144,7 @@ void Init() {
fread(map, map_width*map_height, 1, f);
fclose(f);
sdlMinimapTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, map_width, map_height);
sdlMinimapTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, map_width, map_height);
pixels = (Uint32*)malloc(map_width * map_height*sizeof(Uint32));
for (int y = 0; y < map_height; y++) {
for (int x = 0; x < map_width; x++) {
@@ -294,6 +293,7 @@ void DoTileMap() {
const int cur_y = mouse.y / tile_height;
DrawRect(cur_x*tile_width-1, cur_y*tile_height-1, tile_width + 2, tile_height + 2, 255, 255, 255, 128);
if (keyJustPressed == SDL_SCANCODE_Q) state = STATE_TILEPAL;
if (keyJustPressed == SDL_SCANCODE_E) state = STATE_MINIMAP;
if (keyJustPressed == SDL_SCANCODE_RIGHT || keyJustPressed == SDL_SCANCODE_D) if (map_x < map_width - width_in_tiles) map_x += width_in_tiles;
if (keyJustPressed == SDL_SCANCODE_LEFT || keyJustPressed == SDL_SCANCODE_A) if (map_x > 0) map_x -= width_in_tiles;
if (keyJustPressed == SDL_SCANCODE_DOWN || keyJustPressed == SDL_SCANCODE_S) if (map_y < map_height - height_in_tiles) map_y += height_in_tiles;
@@ -305,7 +305,37 @@ void DoTileMap() {
}
void DoMiniMap() {
Draw(sdlMinimapTexture, 0, 0, 0, 0, map_width, map_height);
int ox = 0, oy = 0;
if (map_width <= screen_width) {
ox = (screen_width - map_width) / 2;
}
else {
const int max_offset = map_width - screen_width;
const float mouse_ratio = float(mouse.x) / float(screen_width);
ox = -(mouse_ratio * max_offset);
}
if (map_height <= screen_height) {
oy = (screen_height - map_height) / 2;
}
else {
const int max_offset = map_height - screen_height;
const float mouse_ratio = float(mouse.y) / float(screen_height);
oy = -(mouse_ratio * max_offset);
}
Draw(sdlMinimapTexture, ox, oy, 0, 0, map_width, map_height);
const int screen_width_in_tiles = screen_width / tile_width;
const int screen_height_in_tiles = screen_height / tile_height;
DrawRect((ox + map_x) - 1, (oy + map_y) - 1, screen_width_in_tiles + 2, screen_height_in_tiles + 2, 255, 255, 255);
//DrawRect(ox + (tile_sel % tiles_per_row)*tile_width - 1, oy + (tile_sel / tiles_per_row)*tile_height - 1, tile_width + 2, tile_height + 2, 255, 255, 255);
if (mouse.buttons[0]) {
map_x = int((mouse.x-ox) / screen_width_in_tiles) * screen_width_in_tiles;
map_y = int((mouse.y - oy) / screen_height_in_tiles) * screen_height_in_tiles;
state = STATE_TILEMAP;
ignoreMouse = true;
}
if (keyJustPressed == SDL_SCANCODE_E) state = STATE_TILEMAP;
}
int main(int argc, char* argv[]) {