now can walk out of house + random

This commit is contained in:
bgiraudr 2021-08-27 22:50:00 +02:00
parent f3dade60bf
commit 6303b713d7
14 changed files with 186 additions and 80 deletions

View File

@ -13,13 +13,20 @@ fxconv_declare_converters(assets-cg/converters.py)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_LIST_DIR}/assets-cg/maps/testCarte.json"
"${CMAKE_CURRENT_LIST_DIR}/assets-cg/maps/inside/interior_1.json"
"${CMAKE_CURRENT_LIST_DIR}/assets-cg/maps/inside/1.json"
"${CMAKE_CURRENT_LIST_DIR}/assets-cg/maps/inside/2.json"
COMMENT "Convert tmx map to json"
COMMAND tiled --export-tileset json tileset.tsx tileset.json
COMMAND tiled --export-map json testCarte.tmx testCarte.json
COMMAND tiled --export-map json inside/interior_1.tmx inside/interior_1.json
COMMAND tiled --export-map json inside/1.tmx inside/1.json
COMMAND tiled --export-map json inside/2.tmx inside/2.json
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/assets-cg/maps/
DEPENDS assets-cg/maps/testCarte.tmx assets-cg/tileset.png assets-cg/maps/tileset.tsx assets-cg/converters.py assets-cg/maps/inside/interior_1.tmx)
DEPENDS assets-cg/maps/testCarte.tmx
assets-cg/tileset.png
assets-cg/maps/tileset.tsx
assets-cg/converters.py
assets-cg/maps/inside/1.tmx
assets-cg/maps/inside/2.tmx)
set(SOURCES
src/main.c
@ -37,7 +44,8 @@ set(SOURCES
set(ASSETS_cg
assets-cg/tileset.png
assets-cg/maps/testCarte.json
assets-cg/maps/inside/interior_1.json
assets-cg/maps/inside/1.json
assets-cg/maps/inside/2.json
assets-cg/spritesheet.png
)

View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="12" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="11" nextobjectid="32">
<editorsettings>
<export target="interior_1.json" format="json"/>
</editorsettings>
<tileset firstgid="1" source="../tileset.tsx"/>
<layer id="5" name="1" width="12" height="10">
<data encoding="csv">
2,3,2,1,3,3,2,3,2,1,1,3,
1,6,6,6,156,157,157,158,2,1,2,2,
3,6,156,157,159,233,235,160,158,3,1,1,
1,6,185,233,234,236,237,235,187,1,6,1,
1,6,185,291,292,265,301,264,187,1,6,1,
1,6,214,215,188,291,292,293,160,158,6,1,
2,6,3,1,214,215,215,215,215,216,6,1,
2,3,2,2,1,5,3,109,2,6,6,3,
2,3,2,1,3,2,3,2,6,6,6,3,
1,2,0,1,2,2,2,1,3,3,1,3
</data>
</layer>
<layer id="1" name="2" width="12" height="10">
<data encoding="csv">
248,249,249,249,249,249,249,249,249,249,249,251,
277,0,0,0,0,0,0,0,0,20,21,280,
277,0,0,0,0,0,0,0,0,49,50,280,
277,0,0,0,0,0,0,0,0,0,0,280,
277,0,0,0,0,0,0,0,0,0,0,280,
277,0,0,26,0,0,0,0,0,0,0,280,
277,0,0,55,0,0,0,0,0,0,0,280,
277,0,0,0,0,0,0,0,0,0,0,280,
277,0,0,0,0,0,0,0,0,0,0,280,
306,278,238,279,250,250,250,250,250,250,250,309
</data>
</layer>
<layer id="9" name="3" width="12" height="10">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,29,0,0,0,0,
0,0,0,0,0,0,0,58,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
<objectgroup id="10" name="dialog">
<object id="25" gid="267" x="112" y="112" width="16" height="16">
<properties>
<property name="name" value="Tituya"/>
<property name="text">Salutation !
Ça va ?</property>
</properties>
</object>
<object id="30" gid="267" x="144" y="48" width="16" height="16">
<properties>
<property name="text" value="Oui oui c'est un interieur"/>
</properties>
</object>
<object id="31" gid="267" x="160" y="48" width="16" height="16">
<properties>
<property name="text" value="Planete Casio FTW"/>
</properties>
</object>
</objectgroup>
</map>

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="15" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="13" nextobjectid="32">
<editorsettings>
<export target="interior_1.json" format="json"/>
</editorsettings>
<tileset firstgid="1" source="../tileset.tsx"/>
<layer id="11" name="1" width="15" height="10">
<data encoding="csv">
94,94,94,94,94,94,94,94,94,94,94,94,94,94,94,
94,94,94,94,94,94,94,94,94,94,94,94,94,94,94,
94,94,94,94,94,94,94,94,94,94,94,94,94,94,94,
94,94,97,123,123,123,123,123,123,123,123,123,96,94,94,
94,94,95,161,162,162,162,162,162,162,162,163,93,94,94,
94,94,95,190,191,191,191,223,191,223,223,192,93,94,94,
94,94,95,219,220,220,193,223,194,220,220,221,93,94,94,
94,94,68,65,65,66,190,191,192,64,65,65,67,94,94,
94,94,94,94,94,95,190,191,192,93,94,94,94,94,94,
94,94,94,94,94,95,190,222,192,93,94,94,94,94,94
</data>
</layer>
<layer id="12" name="2" width="15" height="10">
<data encoding="csv">
224,225,225,225,225,225,225,225,225,225,225,225,225,225,226,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,323,324,325,246,0,0,0,0,0,
0,0,0,0,22,23,352,353,354,275,0,0,0,0,0,
0,0,0,0,51,52,381,382,383,304,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,238,0,0,0,0,0,0,0
</data>
</layer>
</map>

View File

@ -1,3 +1,3 @@
interior_1.json:
*.json:
custom-type: map
name: in_1
name_regex: (.*)\.json in_\1

View File

@ -1,58 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="12" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="11" nextobjectid="30">
<editorsettings>
<export target="interior_1.json" format="json"/>
</editorsettings>
<tileset firstgid="1" source="../tileset.tsx"/>
<layer id="5" name="1" width="12" height="10">
<data encoding="csv">
2,3,2,1,3,3,2,3,2,1,1,3,
1,6,6,6,1,3,2,3,2,1,2,2,
3,6,6,74,76,1,1,74,76,3,1,1,
1,6,2,103,105,1,1,103,105,1,1,1,
1,6,2,103,105,39,1,103,105,33,1,1,
1,6,1,103,78,75,75,77,105,1,1,1,
2,6,3,132,133,106,107,133,134,1,3,1,
2,3,2,2,1,132,134,3,2,2,1,3,
2,3,2,1,3,2,3,2,2,1,1,3,
1,2,0,1,2,2,2,1,3,3,1,3
</data>
</layer>
<layer id="1" name="2" width="12" height="10">
<data encoding="csv">
248,249,249,249,249,249,249,249,249,249,249,251,
277,0,0,0,635,636,637,638,0,0,0,280,
277,0,0,0,664,665,666,667,0,0,0,280,
277,0,0,0,693,694,695,696,0,0,0,280,
277,0,0,245,722,723,724,725,245,0,0,280,
277,0,0,274,751,752,753,754,274,0,0,280,
277,0,0,303,0,0,0,0,303,0,0,280,
277,0,0,0,0,0,0,0,0,0,0,280,
277,0,0,0,0,0,0,0,0,0,0,280,
306,307,238,308,250,250,250,250,250,250,250,309
</data>
</layer>
<layer id="9" name="3" width="12" height="10">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,294,294,294,0,
0,0,0,0,0,0,0,0,0,294,294,0,
0,0,0,0,0,0,0,0,0,294,294,0,
0,0,0,0,0,0,0,0,0,0,294,0,
0,0,0,0,0,0,0,29,0,0,294,0,
0,0,0,0,0,0,0,58,0,0,294,0,
0,0,0,0,0,0,0,0,0,0,294,0,
0,0,0,0,0,0,0,0,0,0,294,0,
0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
<objectgroup id="10" name="dialog">
<object id="25" gid="267" x="112" y="112" width="16" height="16">
<properties>
<property name="name" value="Tituya"/>
<property name="text">Salutation !
Ça va ?</property>
</properties>
</object>
</objectgroup>
</map>

View File

@ -19,3 +19,4 @@ void engine_set_background(struct Game *game, int color);
void engine_action(struct Game const *game, int action);
/*check the current position of the player. To perform action depends of his location*/
void engine_check_position(struct Game *game);
void engine_center_camera(struct Game *game);

View File

@ -28,4 +28,8 @@ int map_walkable(struct Map const *map, int x, int y);
/*get the tile under the player*/
int map_get_player_tile(struct Game const *game);
void generate_interior_map(struct Game *game);
void generate_interior_map(struct Game *game);
void set_map(struct Game *game, int id);
struct Vec2 locate_tile(struct Map const *map, int tile);

View File

@ -23,5 +23,4 @@ struct Player {
/*return the info tile value the player is facing to*/
int player_facing(struct Game const *game);
void set_player_xy(struct Player *player, int x, int y);
struct Player init_player(void);

View File

@ -1,4 +1,6 @@
#pragma once
/*wait for a specified input key*/
void wait_for_input(int input);
void wait_for_input(int input);
int rand_range(int low, int high);

View File

@ -1,5 +1,8 @@
#include "vec2.h"
#include "camera.h"
#include "game.h"
#include "define.h"
#include "player.h"
struct Camera camera_new(struct Vec2f *target) {
return (struct Camera) {
@ -12,4 +15,4 @@ struct Camera camera_new(struct Vec2f *target) {
void camera_update(struct Camera *c) {
c->pos = vec2f_lerp(c->pos, *c->target, 0.08);
c->offset = vec2f_vec2(c->pos);
}
}

View File

@ -119,12 +119,27 @@ void engine_action(struct Game const *game, int action) {
/*check the current position of the player. To perform action depends of his location*/
void engine_check_position(struct Game *game) {
static struct Map *old_map;
static struct Vec2 old_pos;
int player_curr_tile = map_get_player_tile(game);
if(player_curr_tile == TILE_DOOR_IN) {
old_map = game->map;
old_pos = game->player->pos;
engine_set_background(game, C_BLACK);
generate_interior_map(game);
}
if(player_curr_tile == TILE_DOOR_OUT) {
game->map = old_map;
game->player->pos = old_pos;
engine_center_camera(game);
engine_set_background(game, C_WHITE);
}
}
void engine_center_camera(struct Game *game) {
game->camera.pos.x = game->player->pos.x * TILE_SIZE + game->player->x_mid;
game->camera.pos.y = game->player->pos.y * TILE_SIZE + game->player->y_mid;
}

View File

@ -1,6 +1,9 @@
#include <gint/std/stdlib.h>
#include "map.h"
#include "player.h"
#include "define.h"
#include "util.h"
extern struct Map map_1;
@ -22,10 +25,38 @@ int map_get_player_tile(struct Game const *game) {
/*generate the interior*/
void generate_interior_map(struct Game *game) {
extern struct Map in_1;
const int NB_INTERIORS = 2;
game->map = &in_1;
set_player_xy(game->player, 3,3);
game->camera.pos.x = in_1.w/2 * TILE_SIZE + game->player->x_mid;
game->camera.pos.y = in_1.h/2 * TILE_SIZE + game->player->y_mid;
extern struct Map in_1;
extern struct Map in_2;
struct Map *interiors[] = {
&in_1,
&in_2
};
srand(game->player->pos.x * game->player->pos.y);
game->map = interiors[rand_range(0,NB_INTERIORS)];
game->player->pos = locate_tile(game->map, TILE_DOOR_OUT);
engine_center_camera(game);
}
/*may be useful later*/
void set_map(struct Game *game, int id) {
game->map = maps[id];
game->camera.pos = vec2f_lerp(game->camera.pos, *game->camera.target, 1);
}
/*locate the first occurence of a tile in a specified map*/
struct Vec2 locate_tile(struct Map const *map, int tile) {
for(int x = 0; x < map->w; x++) {
for(int y = 0; y < map->h; y++) {
int tile_id = map->info_map[x + y * map->w];
if(tile_id == tile) {
return VEC2(x,y);
}
}
}
return VEC2(0,0);
}

View File

@ -36,9 +36,4 @@ int player_facing(struct Game const *game) {
return game->map->info_map[index];
}
return TILE_SOLID;
}
void set_player_xy(struct Player *p, int x, int y) {
p->pos.x = x;
p->pos.y = y;
}
}

View File

@ -1,4 +1,5 @@
#include <gint/keyboard.h>
#include <gint/std/stdlib.h>
#include "util.h"
@ -13,4 +14,6 @@ void wait_for_input(int input) {
}
while(keydown(input)) clearevents();
}
}
}
int rand_range(int low, int high) { return (rand() % (high - low)) + low; }