improved layering

pull/1/head
Sara 2023-04-07 23:25:46 +02:00
parent 93b6b898cf
commit 6e09b0f61e
3 changed files with 24 additions and 14 deletions

View File

@ -2,6 +2,7 @@
#include "input.h" #include "input.h"
#include "render.h" #include "render.h"
#include "assets.h" #include "assets.h"
#include "layers.h"
#include "tilemap.hpp" #include "tilemap.hpp"
#include "SDL2/SDL_mouse.h" #include "SDL2/SDL_mouse.h"
#include <SDL2/SDL_scancode.h> #include <SDL2/SDL_scancode.h>
@ -63,11 +64,11 @@ void load_game() {
g_tilemap.width = g_tilemap.height = 10; g_tilemap.width = g_tilemap.height = 10;
player = make_sprite("tilemap.png", 0, 0); player = make_sprite("tilemap.png", 0, 0);
player.depth = -10;
current_tile_display = make_sprite("tilemap.png", 0, 0); current_tile_display = make_sprite("tilemap.png", 0, 0);
current_tile_display.sx = 0.3f; current_tile_display.depth = 0;
current_tile_display.sy = 0.3f; current_tile_display.sx = 0.15f;
current_tile_display.sy = 0.15f;
world_sheet = make_spritesheet("tilemap.png", 16, 16); world_sheet = make_spritesheet("tilemap.png", 16, 16);
@ -81,10 +82,9 @@ void load_game() {
for(int i=0;i<g_tilemap.width*g_tilemap.height;++i) { for(int i=0;i<g_tilemap.width*g_tilemap.height;++i) {
g_tilemap.tiles[i].value = i%3; g_tilemap.tiles[i].value = i%3;
} }
on_cycle_tile(0);
}
void start_game() { on_cycle_tile(0);
input_init(); input_init();
add_listener_for(SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_W, &on_save_key); add_listener_for(SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_W, &on_save_key);
add_listener_for(SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_R, &on_load_key); add_listener_for(SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_R, &on_load_key);
@ -94,6 +94,10 @@ void start_game() {
add_mouse_button_listener(SDL_BUTTON_LMASK, &on_click); add_mouse_button_listener(SDL_BUTTON_LMASK, &on_click);
add_mouse_button_listener(SDL_BUTTON_MMASK, &on_middle_mouse); add_mouse_button_listener(SDL_BUTTON_MMASK, &on_middle_mouse);
add_mouse_listener(0, &on_drag_world); add_mouse_listener(0, &on_drag_world);
}
void start_game() {
g_active_view.width = 21; g_active_view.width = 21;
} }
@ -114,16 +118,23 @@ void update_game() {
void draw_game() { void draw_game() {
rectshape_t world_outline = { rectshape_t world_outline = {
g_tilemap.x, g_tilemap.y, float(g_tilemap.width), float(g_tilemap.height), g_tilemap.x, g_tilemap.y, float(g_tilemap.width), float(g_tilemap.height),
0.1f, 0, {0,0,0,0}, {255, 255, 255, 255} 0.1f, RLAYER_TILEMAP-1, {0,0,0,0}, {255, 255, 255, 255}
}; };
rectshape_t cursor_outline = {
player.x, player.y, 1.0f, 1.0f, 0.05f, RLAYER_SPRITES-1,
{0, 0, 0, 0}, {255, 255, 255, 255}
};
draw_rect(&world_outline); draw_rect(&world_outline);
draw_rect(&cursor_outline);
draw_sprite(&player); draw_sprite(&player);
draw_tilemap(); draw_tilemap();
} }
void draw_game_ui() { void draw_game_ui() {
rectshape_t shape = (rectshape_t){ rectshape_t shape = (rectshape_t){
0.0, 0.0, 0.2, 0.2, 0, 0, {255,255,255,255}, {0,0,0,0} 0.0f, 0.0f, 0.15f, 0.15f, 0, 1,
{100,100,100,255}, {0,0,0,0}
}; };
draw_rect(&shape); draw_rect(&shape);
draw_sprite(&current_tile_display); draw_sprite(&current_tile_display);

View File

@ -5,8 +5,8 @@
extern "C" { extern "C" {
#endif #endif
#define RLAYER_TILEMAP 10 #define RLAYER_TILEMAP 200
#define RLAYER_SPRITES 0 #define RLAYER_SPRITES 100
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -34,7 +34,7 @@ void screen_to_view(float *x, float *y) {
} }
void clear_buffer() { void clear_buffer() {
SDL_SetRenderDrawBlendMode(g_context.renderer, SDL_BLENDMODE_ADD); SDL_SetRenderDrawBlendMode(g_context.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(g_context.renderer, 0, 0, 0, 255); SDL_SetRenderDrawColor(g_context.renderer, 0, 0, 0, 255);
SDL_RenderClear(g_context.renderer); SDL_RenderClear(g_context.renderer);
} }
@ -86,7 +86,6 @@ void exec_rect_cmd(const drawcmd_t* cmd) {
rect.y = cmd->rect.y * hm; rect.y = cmd->rect.y * hm;
} }
SDL_Color c = cmd->rect.background; SDL_Color c = cmd->rect.background;
//SDL_SetRenderDrawBlendMode(g_context.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(g_context.renderer, c.r, c.g, c.b, c.a); SDL_SetRenderDrawColor(g_context.renderer, c.r, c.g, c.b, c.a);
SDL_RenderFillRectF(g_context.renderer, &rect); SDL_RenderFillRectF(g_context.renderer, &rect);
c = cmd->rect.line; c = cmd->rect.line;
@ -161,9 +160,9 @@ void draw(const drawcmd_t* cmd) {
if(top != bot) { if(top != bot) {
while(bot <= top) { while(bot <= top) {
med = floor((float)(top + bot) / 2); med = floor((float)(top + bot) / 2);
if(g_drawdata[med].ui > ui || g_drawdata[med].depth > cmd->depth) { if(g_drawdata[med].ui < ui || g_drawdata[med].depth > cmd->depth) {
bot = med+1; bot = med+1;
} else if(g_drawdata[med].ui <= ui || g_drawdata[med].depth < cmd->depth) { } else if(g_drawdata[med].ui >= ui || g_drawdata[med].depth < cmd->depth) {
top = med-1; top = med-1;
} else { } else {
break; break;