Use libimg for drawing

This will come handy later on.
This commit is contained in:
KikooDX 2021-04-07 11:45:47 +02:00
parent 7d60263052
commit 184498f947
5 changed files with 20 additions and 15 deletions

View File

@ -6,7 +6,9 @@ project(MTEM)
include(GenerateG3A)
include(Fxconv)
find_package(Gint 2.3 REQUIRED)
find_package(LibImg 2.2 REQUIRED)
include_directories(include)
@ -37,6 +39,7 @@ fxconv_declare_assets(${ASSETS} WITH_METADATA)
add_executable(${PROJECT_NAME} ${SOURCES} ${ASSETS})
target_compile_options(${PROJECT_NAME} PRIVATE ${FLAGS})
target_link_libraries(${PROJECT_NAME} Gint::Gint)
target_link_libraries(${PROJECT_NAME} LibImg::LibImg)
generate_g3a(TARGET ${PROJECT_NAME}
OUTPUT "${PROJECT_NAME}.g3a"

View File

@ -1,9 +1,9 @@
tileset.png:
type: bopti-image
name: bimg_tileset
type: libimg-image
name: img_tileset
player.png:
type: bopti-image
name: bimg_player
type: libimg-image
name: img_player
burst.png:
type: bopti-image
name: bimg_burst

View File

@ -3,26 +3,25 @@
#include "conf.h"
#include "level.h"
#include <gint/display.h>
#include <libimg.h>
extern struct Level level;
extern bopti_image_t bimg_tileset;
extern img_t const img_tileset;
void level_draw(void)
{
int x;
int y;
const int tileset_width = bimg_tileset.width / TILE_WIDTH;
const int tileset_width = img_tileset.width / TILE_WIDTH;
for (y = 0; y < level.height; y += 1)
for (x = 0; x < level.width; x += 1) {
const int draw_x = x * TILE_WIDTH;
const int draw_y = y * TILE_HEIGHT;
const Tile tile =
level.data[x + y * level.width];
dsubimage(
draw_x, draw_y, &bimg_tileset,
img_render_vram(img_sub(img_tileset,
(int)(tile % tileset_width) * TILE_WIDTH,
(int)(tile / tileset_width) * TILE_HEIGHT,
TILE_WIDTH, TILE_HEIGHT, DIMAGE_NONE);
TILE_WIDTH, TILE_HEIGHT), draw_x, draw_y);
}
}

View File

@ -5,15 +5,16 @@
#include "level.h"
#include "player.h"
#include <gint/display.h>
#include <libimg.h>
extern struct Level level;
extern bopti_image_t bimg_player;
extern bopti_image_t bimg_burst;
extern img_t const img_player;
extern bopti_image_t const bimg_burst;
void player_draw(struct Player player)
{
dimage(player.x, player.y, &bimg_player);
img_render_vram(img_player, player.x, player.y);
if (player.air_state == AirRising &&
player.jumps_left < AIR_JUMPS)
dimage(player.x, player.y + PLAYER_HEIGHT, &bimg_burst);

View File

@ -119,11 +119,13 @@ int player_update(struct Player *player)
/* check for death and exit */
if (!level.exit_locked &&
player_collide_tile(collisions, player->x, player->y,
TILE_EXIT, 0, 1))
TILE_EXIT, 0, 1)) {
return 1;
}
if (player_collide_tile(collisions, player->x, player->y,
TILE_LETAL, MARGIN_LETAL, 0))
TILE_LETAL, MARGIN_LETAL, 1)) {
return -1;
}
return 0;
}