Browse Source

Add Orton and the princess v1.0

master
Paquity 10 months ago
parent
commit
f6c66dff8a
100 changed files with 5157 additions and 0 deletions
  1. 77
    0
      Makefile
  2. 111
    0
      configure
  3. 13
    0
      global.mk
  4. 44
    0
      include/game/ascii.h
  5. 52
    0
      include/game/ascii_table.h
  6. 143
    0
      include/game/core.h
  7. 24
    0
      include/game/draw.h
  8. 31
    0
      include/game/end_data.h
  9. 38
    0
      include/game/endtext_bmp.h
  10. 25
    0
      include/game/game.h
  11. 13
    0
      include/game/help.h
  12. 18
    0
      include/game/kinematic.h
  13. 98
    0
      include/game/logo_bmp.h
  14. 24
    0
      include/game/memory.h
  15. 17
    0
      include/game/menu.h
  16. 14
    0
      include/game/message.h
  17. 49
    0
      include/game/message_data.h
  18. 81
    0
      include/game/s_game.h
  19. 29
    0
      include/lib/my_graphics.h
  20. 19
    0
      include/lib/my_memory.h
  21. 118
    0
      include/lib/my_stddef.h
  22. 54
    0
      include/lib/my_stdio.h
  23. 24
    0
      include/lib/my_stdlib.h
  24. 29
    0
      include/lib/my_string.h
  25. 74
    0
      include/lib/s_sfml.h
  26. 52
    0
      lib/Makefile
  27. 66
    0
      lib/my_csfml/my_circle.c
  28. 57
    0
      lib/my_csfml/my_graphics.c
  29. 63
    0
      lib/my_csfml/my_line.c
  30. 43
    0
      lib/my_csfml/my_memory.c
  31. 60
    0
      lib/my_csfml/my_polygon.c
  32. 92
    0
      lib/my_csfml/my_polygon_getline.c
  33. 92
    0
      lib/my_csfml/my_rectangle.c
  34. 45
    0
      lib/my_csfml/my_vram_zoom.c
  35. 17
    0
      lib/my_stdio/my_dprintf.c
  36. 12
    0
      lib/my_stdio/my_fprintf.c
  37. 16
    0
      lib/my_stdio/my_printf.c
  38. 14
    0
      lib/my_stdio/my_putchar.c
  39. 12
    0
      lib/my_stdio/my_vdprintf.c
  40. 69
    0
      lib/my_stdio/my_vfprintf.c
  41. 13
    0
      lib/my_stdio/my_vprintf.c
  42. 55
    0
      lib/my_stdio/vfprintf_get_arg.c
  43. 97
    0
      lib/my_stdio/vfprintf_get_option.c
  44. 83
    0
      lib/my_stdio/vfprintf_get_size.c
  45. 87
    0
      lib/my_stdio/vfprintf_print_arg.c
  46. 22
    0
      lib/my_stdlib/my_abs.c
  47. 61
    0
      lib/my_stdlib/my_atoi.c
  48. 67
    0
      lib/my_stdlib/my_strnb.c
  49. 69
    0
      lib/my_stdlib/my_strto.c
  50. 35
    0
      lib/my_string/my_strcat.c
  51. 25
    0
      lib/my_string/my_strcmp.c
  52. 26
    0
      lib/my_string/my_strcoll.c
  53. 28
    0
      lib/my_string/my_strcpy.c
  54. 69
    0
      lib/my_string/my_strdup.c
  55. 25
    0
      lib/my_string/my_strlen.c
  56. 37
    0
      lib/my_string/my_strstr.c
  57. 26
    0
      map/level_1.txt
  58. 17
    0
      map/level_2.txt
  59. 24
    0
      map/level_3.txt
  60. 17
    0
      map/level_impossible.txt
  61. BIN
      music/sikmu.ogg
  62. 63
    0
      src/core/engine.c
  63. 14
    0
      src/core/event.c
  64. 26
    0
      src/core/get_key.c
  65. 29
    0
      src/core/help.c
  66. 80
    0
      src/core/main.c
  67. 108
    0
      src/draw/draw.c
  68. 66
    0
      src/draw/draw_compresed_bmp.c
  69. 73
    0
      src/draw/draw_id.c
  70. 85
    0
      src/draw/draw_thrower.c
  71. 59
    0
      src/game/camera.c
  72. 87
    0
      src/game/collision.c
  73. 41
    0
      src/game/collision_princess.c
  74. 61
    0
      src/game/collision_show.c
  75. 57
    0
      src/game/collision_thrower.c
  76. 86
    0
      src/game/game.c
  77. 78
    0
      src/game/update_obj.c
  78. 94
    0
      src/game/update_thrower.c
  79. 32
    0
      src/kinematic/background.c
  80. 81
    0
      src/kinematic/end.c
  81. 33
    0
      src/kinematic/fade.c
  82. 73
    0
      src/kinematic/intro.c
  83. 81
    0
      src/kinematic/suicide.c
  84. 59
    0
      src/kinematic/textend.c
  85. 55
    0
      src/memory/check_map.c
  86. 89
    0
      src/memory/file.c
  87. 59
    0
      src/memory/free_game.c
  88. 57
    0
      src/memory/load_scene.c
  89. 65
    0
      src/memory/memory.c
  90. 37
    0
      src/memory/message.c
  91. 89
    0
      src/memory/thrower.c
  92. 17
    0
      src/menu/menu.c
  93. 94
    0
      src/menu/pause.c
  94. 116
    0
      src/menu/settings.c
  95. 110
    0
      src/menu/start.c
  96. 18
    0
      src/scene_map/map_end.txt
  97. 18
    0
      src/scene_map/map_intro.txt
  98. 18
    0
      src/scene_map/map_menu_start.txt
  99. 37
    0
      src/scene_map/map_suicide.txt
  100. 0
    0
      src/text/ascii.c

+ 77
- 0
Makefile View File

@@ -0,0 +1,77 @@
#!/usr/bin/make -f
# ---
# Project: my_runner
# Author: yann.magnin@epitech.eu
# ---
include global.mk


# function
# $1 module name
# $2 file
define rule-module
build/$1_$(patsubst %.c,%,$2).o: src/$1/$2
$(cc) $(cflags) -c $$< -o $$@ $(header)
endef

config = gcc.cfg
name = my_runner
header = -Iinclude/
module = core draw game memory menu text kinematic
build-dir = build
$(foreach mod,$(module), $(eval \
mod-$(mod)-src = $(notdir $(wildcard src/$(mod)/*.c)) $n\
mod-$(mod)-obj = $$(patsubst %.c,build/$(mod)_%.o,$$(mod-$(mod)-src)) \
))
target-obj = $(foreach mod, $(module), $(mod-$(mod)-obj))




# Chek configuration file
ifeq ($(wildcard $(config)),)
$(warning "Configuration file missing. skipping some compilation flags.")
cflags += -g0
else
cflags += @$(config)
endif




all: check_lib $(name)
$(target-obj): | $(build-dir)

$(name): $(target-obj)
@ printf 'link binary $@\n'
$(cc) $(cflags) -o $@ $(target-obj) $(header) $(lib-link) -lgcc

$(build-dir):
@ printf 'create build folder:\033[1;35m $@\033[0m\n'
mkdir -p $@

check_lib:
make -C lib/

$(foreach mod, $(module), \
$(foreach source,$(mod-$(mod)-src), $(eval \
$(call rule-module,$(mod),$(source)))) \
)





##
## Clean rule
##
clean:
rm -rf $(name)
make clean -C lib/
fclean: clean
rm -rf build
make fclean -C lib/
re: fclean all


.PHONY: clean re fclean

+ 111
- 0
configure View File

@@ -0,0 +1,111 @@
#! /bin/bash

# output file
file_gcc="gcc.cfg"


declare -A config
config[FILE_DEBUG]=
config[NO_WALL_MOVE]=
config[VALGRIND]=
config[WALL_SPEED]=5
config[CAMERA_SPEED]=32
config[FRAME_RATE]=64
config[PLAYER_JUMP_MAX]=7
config[PLAYER_SPEED]=6
config[CAMERA_SHAKY]=15
config[THROWER_STONE_SLEEP]=35
config[THROWER_BULLET_SLEEP]=100
config[BULLET_SPEED]=32
config[NB_STONE]=64
config[THROWER_DX_SLEEP]=20

function help()
{
echo -e "Configuration script for my_runner."
echo -e "\nOption that will print some debug log:"
echo -e "\t\033[1;32m--file-debug [default: false]\033[0m"
echo -e "\tEnable some indication when map file are loading."
echo -e "\t\033[1;32m--valgrind-debug [default: false]\033[0m"
echo -e "\tAdd some flags for debugging with valgrind."
echo -e "\t\033[1;32m--help | -h\033[0m"
echo -e "\tPrint this text."
echo -e "\nOption that will affect the game:"
echo -e "\t\033[1;32m--wall-speed=<interger> [default: 5]\033[0m"
echo -e "\tAjuste wall speed."
echo -e "\t\033[1;32m--camera-speed=<interger> [default: 32]\033[0m"
echo -e "\tAjuste camera speed."
echo -e "\t\033[1;32m--camera-shaky=<interger> [default: 15]\033[0m"
echo -e "\tAjuste camera when player's dead."
echo -e "\t\033[1;32m--player-jump-time=<interger> [default: 7]\033[0m"
echo -e "\tAjuste player jump time."
echo -e "\t\033[1;32m--frame-rate=<interger> [default: 64]\033[0m"
echo -e "\tAjust frame rate."
echo -e "\t\033[1;32m--stone-dx=<interger> [default: 20]\033[0m"
echo -e "\tAjust X axis of thrower object."
echo -e "\t\033[1;32m--stone-nb=<interger> [default:64]\033[0m"
echo -e "\tAjust number of thrower object."
echo -e "\t\033[1;32m--thrower-stone-sleep=<interger> [default: 35]\033[0m"
echo -e "\tAjust the \"sleep\" of thrower. (stone)"
echo -e "\t\033[1;32m--thrower-bullet-sleep=<interger> [default: 100]\033[0m"
echo -e "\tAjust the \"sleep\" of thrower. (bullet)"
echo -e "\t\033[1;32m--no-wall [default: false]\033[0m"
echo -e "\tDisable moving wall."
exit 0
}

function option_update()
{
if [[ "$1" -gt "0" ]]; then config[$2]=$1
else errror; fi
}

function error()
{
echo -e "\033[1;33merror\033[0m need positive interger value."
exit 1
}

function out_gcc()
{
if [ "${config[VALGRIND]}" != "" ]; then echo "-g3"
else echo "-g0"; fi
[ "${config[FILE_DEBUG]}" != "" ] && echo "-D DEBUG_LOAD_FILE"
[ "${config[NO_WALL_MOVE]}" != "" ] && echo "-D NO_WALL_MOVE"
echo "-D WALL_SPEED=${config[WALL_SPEED]}"
echo "-D CAMERA_SPEED=${config[CAMERA_SPEED]}"
echo "-D FRAME_RATE=${config[FRAME_RATE]}"
echo "-D PLAYER_MAX_JUMP=${config[PLAYER_JUMP_MAX]}"
echo "-D PLAYER_SPEED=${config[PLAYER_SPEED]}"
echo "-D CAMERA_SHAKY=${config[CAMERA_SHAKY]}"
echo "-D THROWER_STONE_SLEEP=${config[THROWER_STONE_SLEEP]}"
echo "-D THROWER_BULLET_SLEEP=${config[THROWER_BULLET_SLEEP]}"
echo "-D THROWER_DX_SLEEP=${config[THROWER_DX_SLEEP]}"
echo "-D NB_OBJECT=${config[NB_STONE]}"
}

for arg; do case "$arg" in
--help | -h) help;;
--file-debug) config[FILE_DEBUG]=true;;
--no-wall) config[NO_WALL_MOVE]=true;;
--valgrind-debug) config[VALGRIND]=true;;
--wall-speed=*) option_update ${arg#*=} WALL_SPEED;;
--camera-speed=*) option_update ${arg#*=} CAMERA_SPEED;;
--camera-shaky=*) option_update ${arg#*=} CAMERA_SHAKY;;
--player-jump-time=*) option_update ${arg#*=} PLAYER_JUMP_MAX;;
--player-speed=*) option_update ${arg#*=} PLAYER_SPEED;;
--frame-rate=*) option_update ${arg#*=} FRAME_RATE;;
--object-speed=*) option_update ${arg#*=} OBJECT_SPEED;;
--thrower-stone-sleep=*) option_update ${arg#*=} THROWER_STONE_SLEEP;;
--thrower-bullet-sleep=*) option_update ${arg#*=} THROWER_BULLET_SLEEP;;
--stone-dx=*) option_update ${arg#*=} THROWER_DX_SLEEP;;
--stone-nb=*) option_update ${arg#*=} NB_STONE;;
*)
echo -e "\033[1;33merror\033[0m unreconized argument '$arg'"
exit 1
esac; done

echo "Configuration saved in $file_gcc."
out_gcc > $file_gcc
cat $file_gcc
exit 0

+ 13
- 0
global.mk View File

@@ -0,0 +1,13 @@
# Global option use in each Makefile

cc = gcc
ar = $(cc)-ar
lmystdio = lib/libmycsfml.a
lib-link = -Llib/ -lmycsfml -Llib/ -lmystdio -Llib/ -lmystring -Llib/ -lmystdlib
cflags = -W -Werror -Wextra -Wunused-value -fno-builtin -std=c99 -pedantic \
-Os -lcsfml-graphics -lcsfml-system -lcsfml-window -lcsfml-audio

define n
# Force newline character

endef

+ 44
- 0
include/game/ascii.h View File

@@ -0,0 +1,44 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __ASCII_H__
# define __ASCII_H__

#define ASCII_DEFAULT_HEIGHT 5
#define ASCII_DEFAULT_WIDTH 4
#define ASCII_CENTER_X 0x01
#define ASCII_CENTER_Y 0x02
#define ASCII_ALPHA 0x04
#define ASCII_REVERSE 0x08

#include "lib/my_stddef.h"
#include "lib/s_sfml.h"

typedef struct ascii_s
{
int width;
int height;
int offset;
int nb_line;
char *str;
int size_str;
int x;
int y;
} ascii_t;

void my_print(sfml_t *sfml, int position[2], const char *str, uint32_t *option);
uint32_t *my_print_set_option(int size, uint32_t color_char,
uint32_t color_alpha, uint8_t action);

void my_print_set_position(int position[2], int x, int y);
void reverse_update(void *pass[2], int position[2], uint32_t *option);
void message_set_start(sfml_t *sfml, ascii_t *ascii, uint32_t *option, int size_str);
ascii_t *init_set_ascii(const char *str, uint32_t *option);
int get_line_size(const char *str, int pos);

void my_print_nbr(sfml_t *sfml, int nb, uint32_t *option, int pos[2]);
#endif

+ 52
- 0
include/game/ascii_table.h View File

@@ -0,0 +1,52 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __ASCII_TABLE_H__
# define __ASCII_TABLE_H__

#include "lib/my_stddef.h"
static const uint16_t ascii_tab[256] = {
32319, 32319, 32319, 32319, 32319, 32319, 32319,
32319, 32319, 32319, 32319, 32319, 32319, 32319,
32319, 32319, 32319, 32319, 32319, 32319, 32319,
32319, 32319, 32319, 32319, 32319, 32319, 32319,
32319, 32319, 32319, 32319, 0, 928, 24600,
32095, 12269, 9362, 11946, 768, 17856, 465,
20756, 4548, 65, 4228, 32, 24707, 31279,
2025, 9907, 10929, 31900, 19133, 24239, 25235,
32447, 31421, 320, 321, 17732, 10570, 4433,
25264, 14963, 16015, 10943, 17966, 14911, 18111,
17055, 20014, 31903, 18417, 30754, 27807, 1087,
32031, 32223, 14894, 8863, 15918, 11935, 19113,
17392, 31807, 30782, 31839, 27803, 24824, 26291,
18400, 3224, 1009, 8712, 1057, 272, 16034,
2239, 9510, 31906, 13998, 20964, 31404, 3231,
1765, 22562, 9439, 2033, 15759, 7439, 6438,
4431, 15684, 5455, 19113, 10184, 15407, 14382,
15471, 9417, 14504, 13803, 18276, 992, 4977,
4290, 32767, 22101, 21077, 21925, 5557, 27083,
4970, 9192, 3042, 4575, 32196, 4416, 324,
4356, 4164, 18738, 9801, 704, 12828, 20756,
9096, 8456, 30728, 31326, 3018, 10962, 31698,
30876, 21194, 21070, 31256, 31454, 31452, 10153,
19186, 9637, 22197, 22517, 30910, 32437, 740,
16833, 31812, 0, 0, 0, 0, 0,
0, 352, 3207, 5189, 2274, 2114, 15362,
15663, 1509, 5481, 15849, 15438, 10597, 10535,
15628, 15727, 15726, 7495, 10926, 25119, 15523,
32287, 18107, 15214, 13933, 11426, 24793, 22822,
18094, 15022, 3475, 24735, 7303, 8847, 4964,
11418, 0, 0, 0, 27972, 4443, 21956,
4565, 10564, 4426, 22179, 14005, 17966, 14005,
7603, 23971, 16043, 24243, 23731, 7843, 27947,
19054, 5494, 21862, 14190, 21878, 368, 16736,
8808, 8296, 26922, 20119, 2482, 18850, 10922,
19122, 18610, 4772, 10378, 7479, 23847, 11819,
23607, 18722, 26986, 20596
};

#endif /* ASCII_TABLE*/

+ 143
- 0
include/game/core.h View File

@@ -0,0 +1,143 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __CORE_H__
# define __CORE_H__

#define sgn(x) (x < 0 ? -1 : 1)

#define SCREEN_WIDTH 1920
#define SCREEN_HEIGHT 1080
#define MAP_WIDTH_MIN (SCREEN_WIDTH >> 6) + 1
#define MAP_HEIGHT_MIN (SCREEN_HEIGHT >> 6) + 1
#define BLOCK_LOAD_X (SCREEN_WIDTH >> 6)
#define BLOCK_LOAD_Y (SCREEN_HEIGHT >> 6) + 1

#ifndef CAMERA_SPEED
# define CAMERA_SPEED 32
#endif
#ifndef CAMERA_SHAKY
# define CAMERA_SHAKY 15
#endif

#ifndef NB_OBJECT
# define NB_OBJECT 32
#endif
#ifndef THROWER_STONE_SLEEP
# define THROWER_STONE_SLEEP 35
#endif
#ifndef THROWER_BULLET_SLEEP
# define THROWER_BULLET_SLEEP 100
#endif
#ifndef THROWER_DX_SLEEP
# define THROWER_DX_SLEEP 10
#endif
#ifndef BULLET_SPEED
# define BULLET_SPEED 32
#endif
#define BULLET_STOP 0xffff

#define PLAYER_IDLE 0x01
#define PLAYER_RUN 0x02
#define PLAYER_JUMP 0x04
#define PLAYER_WALL 0x08
#define PLAYER_LEFT 0x80
#define PLAYER_DEAD 0x40
#define PLAYER_WIN 0x20
#define PLAYER_CANT_JUMP 0x10
#define PLAYER_FALL_MAX 64
#ifndef PLAYER_SPEED
# define PLAYER_SPEED 6
#endif
#define PLAYER_DEAD_TIME 10
#ifndef PLAYER_MAX_JUMP
# define PLAYER_MAX_JUMP 7
#endif

#define ID_PLAYER 'A'
#define ID_PRINCESS 'B'
#define ID_FAKE_PRINCESS 'C'
#define ID_GROUND '1'
#define ID_FAKE_GROUND '2'
#define ID_PIK_DOWN '3'
#define ID_PIK_UP ID_PIK_DOWN + 1
#define ID_PIK_LEFT ID_PIK_DOWN + 2
#define ID_PIK_RIGHT ID_PIK_DOWN + 3
#define ID_THROWER_STONE 'V'
#define ID_THROWER_UP ID_THROWER_STONE + 1
#define ID_THROWER_DOWN ID_THROWER_STONE + 2
#define ID_THROWER_LEFT ID_THROWER_STONE + 3
#define ID_THROWER_RIGHT ID_THROWER_STONE + 4

#define WALL_SIZE 128
#ifndef WALL_SPEED
# define WALL_SPEED 5
#endif

#define KEY_LSHIFT 0x00000001
#define KEY_RSHIFT 0x00000002
#define KEY_RIGHT 0x00000004
#define KEY_LEFT 0x00000008
#define KEY_UP 0x00000010
#define KEY_SPACE 0x00000020
#define KEY_A 0x00000040
#define KEY_ESC 0x00000080
#define KEY_DOWN 0x00000100
#define KEY_ENTER 0x00000200

#define PRES_LSHIFT 0x00010000
#define PRES_RSHIFT 0x00020000
#define PRES_RIGHT 0x00040000
#define PRES_LEFT 0x00080000
#define PRES_UP 0x00100000
#define PRES_SPACE 0x00200000
#define PRES_A 0x00400000
#define PRES_ESC 0x00800000
#define PRES_DOWN 0x01000000
#define PRES_ENTER 0x02000000


#define NB_MESSAGE 20
#define MESSAGE_GAME 0
#define MESSAGE_INTRO 1
#define MESSAGE_X_TRIGGER 0x01
#define MESSAGE_BEGIN 0x02
#define MESSAGE_DEAD 0x04
#define MESSAGE_FAKE_GROUND 0x08
#define MESSAGE_FAKE_PRINCESS 0x10
#define MESSAGE_X_PRINCESS 0x20
#ifndef MESSAGE_DEFAULT_TIME
# define MESSAGE_DEFAULT_TIME 200
#endif

#define FADE_SPEED 8
#define FADE_CLOSE 0x00
#define FADE_OPEN 0x01

#define BMP_WIDTH 16
#define BMP_HEIGHT 56
#define BMP_SPEED 4

#define SOUND_ON 0x01

#define SCENE_LOAD_PLAYER 0x01
#define SCENE_LOAD_THROWER 0x02
#define SCENE_LOAD_MESSAGE_INTRO 0x04
#define SCENE_LOAD_MESSAGE_GAME 0x08
#define SCENE_LOAD_WALL 0x10
#define SCENE_LOAD_ALL_GAME (SCENE_LOAD_PLAYER | SCENE_LOAD_THROWER | \
SCENE_LOAD_WALL | SCENE_LOAD_MESSAGE_GAME)

#define NOT_SAVE_WINDOW 0
#define SAVE_WINDOW 1

#include "lib/s_sfml.h"
void map_rendering(sfml_t *sfml);
void set_exit(sfml_t *sfml);
void get_key(sfml_t *sfml);

#endif

+ 24
- 0
include/game/draw.h View File

@@ -0,0 +1,24 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __DRAW_H__
# define __DRAW_H__

#include "lib/s_sfml.h"
void player_rendering(sfml_t *sfml);
void wall_rendering(sfml_t *sfml);
void draw_monochrome(sfml_t *sfml, const uint8_t *bmp, int draw[4]);
void draw_princess(sfml_t *sfml, int x, int y);
void draw_pik(sfml_t *sfml, int x, int y, uint8_t direction);
void draw_thrower(sfml_t *sfml, int x, int y, uint8_t direction);
void draw_ground(sfml_t *sfml, int x, int y, uint8_t grass_id);
void set_background(sfml_t *sfml);

void draw_thrower_object(sfml_t *sfml);
void draw_endtext_bmp(sfml_t *sfml);
void draw_logo_bmp(sfml_t *sfml, int y);
#endif

+ 31
- 0
include/game/end_data.h View File

@@ -0,0 +1,31 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __END_DATA_H__
# define __END_DATA_H__

static const char *dialog[] ={
"Hellooo !",
"Why are you following\nme like this, sir ?",
"You're ugly, your head is\nshaped like a square.",
"Sorry, my heart goes\nto circle heads !",
" ... ",
"Hellooo !",
"Be my wife !",
" ... ",
"Yeah, ok. Wathever."
};

static uint32_t dialog_pos_x[] ={
736, 768, 504, 760, 724, 736, 678, 914, 770
};

static uint32_t dialog_pos_y[] = {
900, 860, 860, 860, 900, 900, 900, 900, 900
};

#endif

+ 38
- 0
include/game/endtext_bmp.h View File

@@ -0,0 +1,38 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __BMP_THE_END_H__
# define __BMP_THE_END_H__

#include "lib/my_stddef.h"
#define BMP_END_WIDTH 16
#define BMP_END_HEIGHT 18
static const uint8_t endtext_bmp[] = {
255, 255, 255, 255, 255, 255, 255, 255, 254, 0, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 0, 127, 255,
255, 255, 255, 255, 255, 255, 255, 255, 252, 239, 255, 255, 254, 0,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 71, 255, 255,
254, 63, 255, 255, 207, 255, 255, 255, 255, 255, 255, 252, 0, 71, 255,
255, 254, 63, 255, 255, 207, 255, 255, 255, 255, 255, 255, 240, 1,
231, 254, 31, 254, 63, 255, 255, 207, 255, 255, 255, 255, 255, 255,
240, 15, 230, 60, 15, 254, 1, 137, 255, 159, 255, 255, 255, 255, 255,
255, 249, 143, 224, 24, 7, 254, 0, 128, 240, 159, 255, 255, 255, 255,
255, 255, 255, 199, 224, 16, 199, 254, 0, 132, 224, 31, 255, 255, 255,
255, 255, 255, 255, 199, 225, 17, 143, 254, 63, 140, 192, 31, 255,
255, 255, 255, 255, 255, 255, 199, 225, 16, 31, 254, 63, 140, 199, 31,
255, 255, 255, 255, 255, 255, 255, 199, 227, 16, 127, 254, 63, 156,
143, 191, 255, 255, 255, 255, 255, 255, 255, 231, 243, 152, 199, 254,
1, 156, 143, 63, 255, 255, 255, 255, 255, 255, 255, 227, 241, 152, 7,
254, 0, 156, 134, 63, 255, 255, 255, 255, 255, 255, 255, 227, 241,
156, 15, 255, 0, 156, 192, 63, 255, 255, 255, 255, 255, 255, 255, 227,
241, 255, 255, 255, 255, 255, 224, 127, 255, 255, 255, 255, 255, 255,
255, 243, 255, 255, 255, 255, 255, 255, 248, 127, 255, 255, 255, 255,
255, 255, 255, 243, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255
};

#endif

+ 25
- 0
include/game/game.h View File

@@ -0,0 +1,25 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __GAME_H__
# define __GAME_H__

#include "lib/s_sfml.h"
void game_main(sfml_t *sfml, char *map_name);
void update_player(sfml_t *sfml);
void update_wall(sfml_t *sfml);
void update_thrower(sfml_t *sfml, thrower_t **thrower, level_t *level);
void collision_show(sfml_t *sfml);
void collision_pik(sfml_t *sfml);
void collision_princess(sfml_t *sfml);
void collision_player_run(scene_t *scene);
void collision_player_jump(scene_t *scene);
void collision_wall(sfml_t *sfml);
void collision_stone(sfml_t *sfml);
void game_camera_update(scene_t *scene, int width, int height);

#endif

+ 13
- 0
include/game/help.h View File

@@ -0,0 +1,13 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __HELP_H__
# define __HELP_H__

void man_help(const char *bin_name);

#endif

+ 18
- 0
include/game/kinematic.h View File

@@ -0,0 +1,18 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __KINEMATIC_H__
# define __KINEMATIC_H__

#include "lib/s_sfml.h"
void intro(sfml_t *sfml);
void fade(sfml_t *sfml, uint8_t action);
void end(sfml_t *sfml, int nb_dead);
void suicide(sfml_t *sfml, int nb_dead);
int text_end(sfml_t *sfml, int nb_dead);

#endif

+ 98
- 0
include/game/logo_bmp.h View File

@@ -0,0 +1,98 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __COMPRESED_BMP_H__
# define __COMPRESED_BMP_H__

#include "lib/my_stddef.h"
static const uint8_t title_bmp[] = {
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
143, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 224, 255, 255, 143, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 128, 63, 255, 135,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 0, 63, 198, 1, 195, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 254, 14, 24, 2, 1, 129, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 254, 31, 24, 3,
3, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
252, 63, 8, 35, 142, 24, 227, 255, 255, 255, 255, 255,
255, 255, 255, 255, 252, 63, 140, 115, 142, 60, 224, 127,
255, 255, 255, 255, 255, 255, 255, 255, 252, 127, 140,
127, 142, 124, 192, 63, 255, 255, 255, 255, 255, 255,
255, 255, 252, 127, 140, 127, 142, 120, 194, 63, 255,
255, 255, 255, 255, 255, 255, 255, 252, 63, 140, 127,
142, 56, 198, 127, 255, 255, 255, 255, 255, 255, 255,
255, 254, 63, 142, 127, 142, 17, 140, 127, 255, 255, 255,
255, 255, 255, 255, 255, 254, 63, 30, 127, 143, 3, 140,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 31,
30, 127, 255, 135, 153, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 14, 31, 255, 255, 255, 153, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 63,
255, 255, 255, 251, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 192, 127, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 241, 255, 254,
127, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 254, 63, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 252, 63,
255, 243, 255, 247, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 253, 60, 191, 243, 255, 247, 252, 63, 255,
255, 255, 255, 255, 255, 255, 255, 253, 188, 31, 247,
255, 243, 248, 159, 255, 255, 255, 255, 255, 255, 255,
255, 249, 188, 92, 7, 252, 243, 57, 191, 255, 255, 255,
255, 255, 255, 255, 255, 248, 28, 217, 135, 252, 114, 27,
63, 255, 255, 255, 255, 255, 255, 255, 255, 248, 28, 219,
207, 248, 48, 152, 127, 255, 255, 255, 255, 255, 255, 255,
255, 241, 157, 219, 207, 248, 57, 200, 207, 255, 255, 255,
255, 255, 255, 255, 255, 243, 205, 155, 207, 252, 249, 204,
31, 255, 255, 255, 255, 255, 255, 255, 255, 243, 253, 153,
143, 252, 249, 206, 127, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 252, 31, 252, 249, 231, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 159, 252, 249, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 252, 249, 255, 255, 255, 255, 255, 255, 255, 255, 255,
227, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 192, 255, 255, 255, 255, 255, 255, 255,
255, 15, 255, 255, 255, 255, 255, 255, 192, 127, 255, 255,
255, 255, 255, 255, 254, 7, 255, 255, 255, 255, 255, 255,
204, 63, 254, 127, 255, 255, 255, 255, 252, 39, 255, 255,
255, 255, 255, 255, 142, 63, 252, 63, 255, 255, 255, 254, 56,
255, 255, 255, 255, 255, 255, 255, 143, 63, 254, 127, 255,
255, 255, 248, 24, 255, 255, 255, 255, 255, 255, 255, 143, 63,
255, 255, 255, 255, 240, 240, 28, 3, 255, 255, 255, 255, 255, 255,
4, 57, 255, 255, 255, 255, 192, 115, 255, 225, 255, 255, 255, 255,
255, 255, 0, 120, 15, 249, 159, 7, 128, 113, 255, 241, 255, 255,
255, 255, 255, 254, 0, 240, 6, 113, 14, 3, 140, 120, 30, 67, 255,
255, 255, 255, 255, 254, 63, 240, 70, 112, 14, 51, 24, 255, 142,
3, 255, 255, 255, 255, 255, 254, 63, 241, 198, 112, 204, 127, 1,
255, 207, 15, 255, 255, 255, 255, 255, 252, 63, 241, 238, 112, 204,
127, 7, 251, 15, 255, 255, 255, 255, 255, 255, 252, 127, 227, 252,
113, 204, 255, 31, 56, 15, 255, 255, 255, 255, 255, 255, 254, 127,
227, 252, 113, 204, 255, 12, 60, 63, 255, 255, 255, 255, 255, 255,
255, 255, 227, 252, 113, 204, 49, 128, 127, 255, 255, 255, 255, 255,
255, 255, 255, 255, 227, 252, 113, 206, 1, 192, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 252, 113, 207, 7, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 249, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 253, 223, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 241, 191, 255, 237, 223,
252, 230, 207, 255, 255, 255, 255, 255, 255, 255, 255, 246, 243, 119,
101, 223, 255, 84, 175, 255, 255, 255, 255, 255, 255, 255, 255, 241,
162, 170, 173, 223, 30, 214, 175, 255, 255, 255, 255, 255, 255, 255,
255, 247, 174, 238, 173, 223, 253, 214, 175, 255, 255, 255, 255, 255,
255, 255, 255, 247, 178, 239, 116, 71, 252, 78, 159, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255
};

#endif

+ 24
- 0
include/game/memory.h View File

@@ -0,0 +1,24 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __MEMORY__
# define __MEMORY__

#include "lib/s_sfml.h"
int check_map(scene_t *scene);
void free_scene(scene_t *scene);
camera_t *init_camera(scene_t *scene);
level_t *load_map(const char *file);
wall_t *init_wall(player_t *player);
player_t *init_player(level_t *level);
thrower_t **init_thrower(level_t *level);
object_t *init_object(thrower_t *thrower);
message_t **load_message(scene_t *scene, uint8_t type);
scene_t *new_scene(char *map_name, uint8_t object);
sound_t *init_music(char *music_name);

#endif

+ 17
- 0
include/game/menu.h View File

@@ -0,0 +1,17 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __MENU_H__
# define __MENU_H__

#include "lib/s_sfml.h"
int check_pause(sfml_t *sfml);
int menu_pause(sfml_t *sfml);
int menu_start(sfml_t *sfml, int *y);
int menu_settings(sfml_t *sfml);

#endif

+ 14
- 0
include/game/message.h View File

@@ -0,0 +1,14 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __MESSAGE_H__
# define __MESSAGE_H__

#include "lib/s_sfml.h"
void check_message(sfml_t *sfml, message_t **message);

#endif

+ 49
- 0
include/game/message_data.h View File

@@ -0,0 +1,49 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __MESAGE_DATA_H__
# define __MESAGE_DATA_H__

#include "game/core.h"
static const char *default_message[NB_MESSAGE] = {
"Use the arrow keys to move.",
"Press SPACE or UP to jump\nlike a plumber.",
"Yay ! Now, go kiss\nthat princess !",
"In this game you can\nwalk through spikes\nwithout getting killed !",
"I lie.",
"And... you failed.",
"Come on...\nThis is not that difficult.",
"This is fun, isn't it?",
"That was fun.\nDo it again, please !",
"Three tries ? Really ?",
"You shouldn't drink while\nplaying this game, you know...",
"Don't you have a life ?",
"Nah, I won't say a thing.\nI'll juste watch.",
"Some walls aren't what\nthey appear to be...",
"Oops, I forgot to tell you\nabout the traps...",
"This was a fake princess !\nYou've been fooled, kiddo.",
"That was the stupidest\nway you could die.",
"Are you sure this\nis the right way ?",
"Run rabbit, run !",
"Yep, definitely not\nthe right way."
};

static const uint8_t default_action[NB_MESSAGE] = {
MESSAGE_BEGIN, MESSAGE_X_TRIGGER, MESSAGE_X_TRIGGER, MESSAGE_BEGIN,
MESSAGE_DEAD, MESSAGE_DEAD, MESSAGE_DEAD, MESSAGE_DEAD,
MESSAGE_DEAD, MESSAGE_DEAD, MESSAGE_DEAD, MESSAGE_DEAD,
MESSAGE_DEAD, MESSAGE_FAKE_GROUND, MESSAGE_DEAD,
MESSAGE_FAKE_PRINCESS, MESSAGE_DEAD, MESSAGE_DEAD,
MESSAGE_DEAD, MESSAGE_DEAD
};

static const uint16_t default_trigger_start[NB_MESSAGE] = {
0, 740, 1408, 0, 1, 12, 8, 15, 10, 3, 20, 50,
60, 22, 5, 45, 30, 40, 32, 42
};

#endif

+ 81
- 0
include/game/s_game.h View File

@@ -0,0 +1,81 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __S_GAME_H__
# define __S_GAME_H__

#include "lib/my_stddef.h"
typedef struct player_s
{
intmax_t x;
intmax_t y;
intmax_t start_x;
intmax_t start_y;
int8_t dx;
int8_t dy;
uint16_t key;
uint8_t action;
int counter_jump;
int frame_counter;
int dead_counter;
int nb_dead;
} player_t;

typedef struct object_s
{
int sleep;
int dx;
int dy;
int x;
int y;
} object_t;

typedef struct thrower_s
{
intmax_t x;
intmax_t y;
uint8_t action;
object_t **object;
} thrower_t;

typedef struct wall_s
{
intmax_t x;
intmax_t start_x;
intmax_t start_y;
} wall_t;

typedef struct camera_s
{
intmax_t x;
intmax_t y;
} camera_t;

typedef struct message_s
{
int x;
int y;
uint8_t action;
int trigger_data;
void *message;
uint32_t timer_after;
uint32_t timer_message;
} message_t;

typedef struct level_s
{
uint8_t *map;
int file_width;
int file_height;
int height;
int width;
int thrower_counter;
int timer_stone;
int timer_bullet;
} level_t;

#endif

+ 29
- 0
include/lib/my_graphics.h View File

@@ -0,0 +1,29 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __MY_GRAPHICS_H__
# define __MY_GRAPHICS_H__

#include "s_sfml.h"
void my_display_vram(sfml_t *sfml);
void my_clear_vram(sfml_t *sfml, uint32_t color);
void my_line(sfml_t *sfml, int line[4], uint32_t color);
void my_pixel(sfml_t *sfml, int x, int y, uint32_t color);
void my_horizontal_line(sfml_t *sfml, int h_line[3], uint32_t color);
void my_filled_rectangle(sfml_t *sfml, int rectangle[4], uint32_t color);
void my_vram_zoom(sfml_t *sfml, double zoom_width, double zoom_height);
void my_filled_circle(sfml_t *sfml, int circle[3], uint32_t color);
void my_filled_polygon(sfml_t *sfml, polygon_t polygon);
void copy_vram(sfml_t *sfml, uint32_t *src);
void my_draw_bmp(sfml_t *sfml, sprite_t *sprite, intmax_t x, intmax_t y);
sprite_t *my_load_sprite(const char *file);
void my_draw_sheet(sfml_t *sfml, sprite_t *sprite, int sheet[6]);
void my_rectangle(sfml_t *sfml, int rect[5],
uint32_t border_color, uint32_t fill_color);

void get_drawline(polygon_t *polygon, int *xmax, int *xmin, char *empty);
#endif

+ 19
- 0
include/lib/my_memory.h View File

@@ -0,0 +1,19 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __MY_MEMORY_H__
# define __MY_MEMORY_H__

#ifndef FRAME_RATE
# define FRAME_RATE 64
#endif

#include "lib/s_sfml.h"
sfml_t *init_sfml(int width, int height);
void free_sfml(sfml_t *sfml);

#endif

+ 118
- 0
include/lib/my_stddef.h View File

@@ -0,0 +1,118 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __MY_STDDEF_H__
# define __MY_STDDEF_H__

#ifndef __WORDSIZE
# if defined __x86_x64__ && !defined __ILP32__
# define __WORDSIZE 64
# else
# define __WORDSIZE 32
# define __WORDSIZE32_SIZE_ULONG 0
# define __WORDSIZE32_PTRDIFF_ULONG 0
# endif
#endif

#ifndef NULL
# define NULL (void*)0
#endif

#define MY_CHAR_BITS 8
#define MY_UCHAR_MIN 0
#define MY_UCHAR_MAX 0xff
#define MY_SCHAR_MIN (-0x7f - 1)
#define MY_SCHAR_MAX 0x7f

#define MY_SHORT_BITS 16
#define MY_USHORT_MIN 0
#define MY_USHORT_MAX 0xffff
#define MY_SHORT_MIN (-0x7fff - 1)
#define MY_SHORT_MAX 0x7fff

#define MY_INT_BITS 32
#define MY_UINT_MIN 0
#define MY_UINT_MAX 0xffffffff
#define MY_INT_MIN (-0x7fffffff - 1)
#define MY_INT_MAX 0x7fffffff

#if __WORDSIZE == 64
#define MY_LONG_BITS 64
#define MY_ULONG_MIN 0
#define MY_ULONG_MAX 0xffffffffffffffff
#define MY_LONG_MIN (-0x7fffffffffffffff - 1)
#define MY_LONG_MAX 0x7fffffffffffffff
#define MY_LLONG_BITS 64
#define MY_ULLONG_MIN 0
#define MY_ULLONG_MAX 0xffffffffffffffff
#define MY_LLONG_MIN (-0x7fffffffffffffff - 1)
#define MY_LLONG_MAX 0x7fffffffffffffff
#define MY_PTRDIFF_BITS 64
#define MY_PTRDIFF_MIN 0
#define MY_PRTDIFF_MAX 0xffffffffffffffff
#else
#define MY_LONG_BITS 32
#define MY_ULONG_MIN 0
#define MY_ULONG_MAX 0xffffffff
#define MY_LONG_MIN (-0x7fffffff - 1)
#define MY_LONG_MAX 0x7fffffff
#define MY_LLONG_BITS 32
#define MY_ULLONG_MIN 0
#define MY_ULLONG_MAX 0xffffffff
#define MY_LLONG_MIN (-0x7fffffff - 1)
#define MY_LLONG_MAX 0x7fffffff
#define MY_PTRDIFF_BITS 32
#define MY_PTRDIFF_MIN 0
#define MY_PTRDIFF_MAX 0xffffffff
#endif


#ifndef _BITS_STDINT_INTN_H
# define _BITS_STDINT_INTN_H
#include <bits/types.h>
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
# if __WORDSIZE == 64
typedef signed long long int int64_t;
typedef unsigned long long int uint64_t;
# else
__extension__ typedef signed long long int int64_t;
__extension__ typedef unsigned long long int uint64_t;
# endif
#endif

#ifndef _STDINT_H
typedef signed long long int intmax_t;
typedef unsigned long long int uintmax_t;
#endif

#ifndef __PTRDIFF_T
# define __PTRDIFF_T
typedef unsigned long ptrdiff_t;
#endif

#ifndef __FILE_defined
# define _FILE_defined 1
struct _IO_FILE;
typedef struct _IO_FILE FILE;
#endif

#ifndef __SIZE_T
# define __SIZE_T
typedef unsigned int size_t;
#endif

#ifndef __ssize_t_defined
# define __ssize_t_defined
typedef signed int ssize_t;
#endif

#endif

+ 54
- 0
include/lib/my_stdio.h View File

@@ -0,0 +1,54 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __MY_STDIO_H__
# define __MY_STDIO_H__

#include <stdarg.h>
#include "lib/my_stddef.h"

#define PRINT_MODE_RESET 0x00
#define PRINT_MODE_DIEZ 0x01
#define PRINT_MODE_PLUS 0x02
#define PRINT_MODE_MINUS 0x04
#define PRINT_MODE_SPACE 0x08
#define PRINT_MODE_MAJ 0x10
#define PRINT_MODE_HEXA 0x20

#define PRINT_TYPE_RESET 0x00
#define PRINT_TYPE_RESET 0x00
#define PRINT_TYPE_LLONG 0x01
#define PRINT_TYPE_LONG 0x02
#define PRINT_TYPE_CHAR 0x04
#define PRINT_TYPE_PTRD 0x08
#define PRINT_TYPE_INTM 0x10
#define PRINT_TYPE_SIZE 0x20
#define PRINT_TYPE_SINT 0x40

typedef struct printf_s
{
uint8_t mode_flags;
uintmax_t value;
int precision;
int str_width;
int nbr_width;
uint8_t base;
uint8_t type;
int cursor;
va_list ap;
int stream;
char sign;
} printf_t;

int my_putchar(int n);
void my_printf(char const *format, ...);
void my_dprintf(int fd, const char *format, ...);
void my_fprintf(FILE *stream, const char *format, ...);
void my_vdprintf(int fd, const char *format, va_list ap);
void my_vfprintf(int _stdout, char const *format, va_list ap);

#endif /*MY_STDIO*/

+ 24
- 0
include/lib/my_stdlib.h View File

@@ -0,0 +1,24 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __MY_STDLIB_H__
# define __MY_STDLIB_H__

#include "lib/my_stddef.h"
int my_abs(int j);
long int my_labs(long int j);
int my_atoi(const char *nptr);
long my_atol(const char *nptr);
int my_strnb_i(const char **str);
long long my_atoll(const char *nptr);
long int my_strnb_l(const char **str);
long long int my_llabs(long long int j);
long long int my_strnb_ll(const char **str);
long int my_strtol(char *nptr, char **endptr, int base);
long long int my_strtoll(char *nptr, char **endptr, int base);

#endif

+ 29
- 0
include/lib/my_string.h View File

@@ -0,0 +1,29 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __MY_STRING_H__
# define __MY_STRING_H__

#include "lib/my_stddef.h"
char *my_strdup(char const *s);
size_t my_strlen(const char *s);
char *my_strdupa(char const *s);
char *my_strndup(char const *s, size_t n);
char *my_strndupa(char const *s, size_t n);
char *my_strcpy(char *dest, char const *src);
char *my_strcat(char *dest, char const *src);
int my_strcmp(const char *s1, const char *s2);
int my_strcoll(const char *s1, const char *s2);
size_t my_strnlen(const char *s, size_t maxlen);
int my_strcoll_l(const char *s1, const char *s2);
char *my_strncpy(char *dest, char const *src, size_t n);
char *my_strncat(char *dest, char const *src, size_t n);
int my_strncmp(const char *s1, const char *s2, size_t n);
char *my_strstr(const char *haystack, const char *needle);
char *my_strcasestr(const char *haystack, const char *needle);

#endif /* MY_STRING */

+ 74
- 0
include/lib/s_sfml.h View File

@@ -0,0 +1,74 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/

#ifndef __S_SFML_H__
# define __S_SFML_H__

#include <SFML/Audio.h>
#include <SFML/Graphics.h>
#include <SFML/System/Time.h>
#include <SFML/System/Export.h>
#include <SFML/System/Types.h>
#include <SFML/Window/Export.h>
#include "game/s_game.h"
#include "lib/my_stddef.h"

typedef struct sprite_s
{
int width;
int height;
uint8_t *data;
} sprite_t;

typedef struct polygon_s
{
int nb_vertices;
uint32_t color;
int *x;
int *y;
int ymin;
int ymax;
int xmax;
int xmin;
double z_buffer;
} polygon_t;

typedef struct scene_s
{
int nb_message;
uint8_t message_active;
wall_t *wall;
thrower_t **thrower;
message_t **message;
player_t *player;
camera_t *camera;
level_t *level;
} scene_t;

typedef struct sound_s
{
uint8_t active;
uint8_t volume;
sfMusic *music;
} sound_t;

typedef struct sfml_s
{
sfRenderWindow *window;
sfSprite *vram_sprite;
sfTexture *texture;
sfEvent event;
int width;
int height;
uint32_t *vram;
uint32_t key;
uint8_t debug;
scene_t *scene;
sound_t *sound;
} sfml_t;

#endif

+ 52
- 0
lib/Makefile View File

@@ -0,0 +1,52 @@
#!/usr/bin/make -f
# ---
# Project: my_libc
# Author: yann.magnin@epitech.eu
# ---
include ../global.mk



build-dir = ../build
header = -I../include
target-module = my_stdio my_stdlib my_string my_csfml

$(foreach mod, $(target-module), $(eval \
target-$(mod)-src = $(wildcard $(mod)/*.c)$n\
target-$(mod)-obj = $$(patsubst %.c,$(build-dir)/lib_%.o, $$(subst \
$(mod)/,l$(subst _,,$(mod))_,$$(target-$(mod)-src))) $n\
target-$(mod)-out = $(patsubst %,lib%.a,$(subst _,,$(mod)))\
))
target-lib = $(foreach mod, $(target-module), $(target-$(mod)-out))


define rule-target
$(patsubst %.c,$(build-dir)/lib_%.o,\
$(subst $2/,l$(subst _,,$2)_,$1)): $1 | $(build-dir)
$$(cc) $(cflags) -c $$< -o $$@ $(header)
endef

define rule-link
$(patsubst %,lib%.a,$(subst _,,$1)): $2
@ printf 'link lib \033[1;35m$$@\033[0m\n'
$(ar) crs $$@ $$^
endef

all: $(target-lib)
$(build-dir):
@ printf 'create build folder:\033[1;35m $@\033[0m\n'
mkdir -p $@


$(foreach mod,$(target-module), \
$(foreach source,$(target-$(mod)-src), $(eval \
$(call rule-target,$(source),$(mod))))\
$(eval $(call rule-link,$(mod),$(target-$(mod)-obj)))\
)

clean:
rm -rf $(build-dir)
fclean: clean
rm -rf $(target-lib)
re: fclean all
.PHONY: re clean fclean all

+ 66
- 0
lib/my_csfml/my_circle.c View File

@@ -0,0 +1,66 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include "../../include/lib/s_sfml.h"
#include "../../include/lib/my_graphics.h"

static void my_circle_line(sfml_t *sfml,
int circle[3], int var[4], uint32_t color)
{
int h_line[3];

if (var[1] >= var[0]){
h_line[0] = circle[1] + var[0];
h_line[1] = circle[0] - var[1];
h_line[2] = circle[0] + var[1];
my_horizontal_line(sfml, h_line, color);
h_line[0] = circle[1] - var[0];
my_horizontal_line(sfml, h_line, color);
}
}

static void my_var_init(int var[], int circle[3])
{
var[0] = 0;
var[1] = circle[2];
}

static void draw_line_circle(sfml_t *sfml,
int circle[3], int var[4], uint32_t color)
{
int h_line[3];

h_line[0] = circle[1] + var[1] + 1;
h_line[1] = circle[0] - var[0];
h_line[2] = circle[0] + var[0];
my_horizontal_line(sfml, h_line, color);
h_line[0] = circle[1] - var[1] - 1;
my_horizontal_line(sfml, h_line, color);
}

void my_filled_circle(sfml_t *sfml, int circle[3], uint32_t color)
{
int h_line[4] = {circle[1], circle[0] - circle[2],
circle[0] + circle[2]};
int tmp = 1 - circle[2];
int var[4];

if (circle[2] < 0)
return;
my_var_init(var, circle);
my_horizontal_line(sfml, h_line, color);
while (var[1] > var[0]){
if (tmp < 0)
tmp += (var[0] << 1) + 3;
else {
tmp += ((var[0]-var[1]) << 1) + 5;
var[1]--;
draw_line_circle(sfml, circle, var, color);
}
var[0]++;
my_circle_line(sfml, circle, var, color);
}
}

+ 57
- 0
lib/my_csfml/my_graphics.c View File

@@ -0,0 +1,57 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include "../../include/lib/s_sfml.h"
#include "../../include/lib/my_graphics.h"

void my_clear_vram(sfml_t *sfml, uint32_t color)
{
uint8_t red = (color >> 24) & 0xff;
uint8_t green = (color >> 16) & 0xff;
uint8_t blue = (color >> 8) & 0xff;
uint8_t alpha = color & 0xff;
uint8_t *vram = (uint8_t*)sfml->vram;
int i;

i = -1;
while (++i < sfml->width * sfml->height){
vram[i << 2] = red;
vram[(i << 2) + 1] = green;
vram[(i << 2) + 2] = blue;
vram[(i << 2) + 3] = alpha;
}
}

void my_display_vram(sfml_t *sfml)
{
sfTexture_updateFromPixels(sfml->texture, (sfUint8*)sfml->vram, sfml->width,
sfml->height, 0, 0);
sfSprite_setTexture(sfml->vram_sprite, sfml->texture, 0);
sfRenderWindow_drawSprite(sfml->window, sfml->vram_sprite, NULL);
sfRenderWindow_display(sfml->window);
}

void my_pixel(sfml_t *sfml, int x, int y, uint32_t color)
{
uint8_t *vram = (uint8_t*)sfml->vram;
if (x < 0 || x >= sfml->width || y < 0 || y >= sfml->height)
return;
vram[(y * sfml->width + x) << 2] = (color >> 24) & 0xff;
vram[((y * sfml->width + x) << 2) + 1] = (color >> 16) & 0xff;
vram[((y * sfml->width + x) << 2) + 2] = (color >> 8) & 0xff;
vram[((y * sfml->width + x) << 2) + 3] = color & 0xff;
}

void my_horizontal_line(sfml_t *sfml, int h_line[3], uint32_t color)
{
int start;
int end;

end = (h_line[1] < h_line[2]) ? h_line[2] : h_line[1];
start = (h_line[1] < h_line[2]) ? h_line[1] - 1 : h_line[2] - 1;
while (++start < end)
my_pixel(sfml, start, h_line[0], color);
}

+ 63
- 0
lib/my_csfml/my_line.c View File

@@ -0,0 +1,63 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include "../../include/lib/s_sfml.h"
#include "../../include/lib/my_graphics.h"

static void my_line_dx(sfml_t *sfml, int var[7], uint32_t color)
{
int cumul;
int i;

i = 0;
cumul = var[2] / 2;
while (++i < var[2]){
var[0] += var[4];
cumul += var[3];
if (cumul > var[2]){
cumul -= var[2];
var[1] += var[5];
}
my_pixel(sfml, var[0], var[1], color);
}
}

static void my_line_dy(sfml_t *sfml, int var[7], uint32_t color)
{
int cumul;
int i;

i = 0;
cumul = var[3] / 2;
while (++i < var[3]){
var[1] += var[5];
cumul += var[2];
if (cumul > var[3]){
cumul -= var[3];
var[0] += var[4];
}
my_pixel(sfml, var[0], var[1], color);
}
}

void my_line(sfml_t *sfml, int line[4], uint32_t color)
{
int var[6];

var[0] = line[0];
var[1] = line[1];
var[2] = line[2] - line[0];
var[3] = line[3] - line[1];
var[4] = (var[2] > 0) ? 1 : -1;
var[5] = (var[3] > 0) ? 1 : -1;
var[2] = (var[2] > 0) ? var[2] : -var[2];
var[3] = (var[3] > 0) ? var[3] : -var[3];
my_pixel(sfml, var[0], var[1], color);
if (var[2] > var[3])
my_line_dx(sfml, var, color);
else
my_line_dy(sfml, var, color);
}

+ 43
- 0
lib/my_csfml/my_memory.c View File

@@ -0,0 +1,43 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include <stdlib.h>
#include "lib/s_sfml.h"
#include "lib/my_memory.h"
#include "game/memory.h"

sfml_t *init_sfml(int width, int height)
{
sfml_t *sfml;
sfVideoMode mode = {width, height, 32};

sfml = (sfml_t*)malloc(sizeof(sfml_t));
if (sfml == NULL)
return (NULL);
sfml->width = width;
sfml->height = height;
sfml->window = sfRenderWindow_create(mode, "runner",
sfFullscreen | sfClose, NULL);
sfRenderWindow_setMouseCursorVisible(sfml->window, 0);
sfRenderWindow_setFramerateLimit(sfml->window, FRAME_RATE);
sfml->vram = (uint32_t*)malloc(sizeof(uint32_t) * (width * height));
sfml->texture = sfTexture_create(width, height);
sfml->vram_sprite = sfSprite_create();
sfml->sound = init_music("music/sikmu.ogg");
sfml->debug = 0x00;
sfml->key = 0x0000;
return (sfml);
}

void free_sfml(sfml_t *sfml)
{
sfRenderWindow_destroy(sfml->window);
sfTexture_destroy(sfml->texture);
sfSprite_destroy(sfml->vram_sprite);
sfMusic_destroy(sfml->sound->music);
free(sfml->vram);
free(sfml);
}

+ 60
- 0
lib/my_csfml/my_polygon.c View File

@@ -0,0 +1,60 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include <stdlib.h>
#include "../../include/lib/s_sfml.h"
#include "../../include/lib/my_graphics.h"

static void draw_filled_polygon(sfml_t *sfml,
polygon_t *polygon, int *xmax, int *xmin)
{
int h_line[3];
int i;

i = -1;
while (++i < polygon->ymax - polygon->ymin + 1){
h_line[0] = polygon->ymin + i;
h_line[1] = xmin[i];
h_line[2] = xmax[i];
my_horizontal_line(sfml, h_line, polygon->color);
}
}

static void polygon_get_info(polygon_t *polygon)
{
int i;

i = 0;
polygon->ymin = polygon->y[0];
polygon->ymax = polygon->y[0];
while (++i < polygon->nb_vertices){
if (polygon->y[i] < polygon->ymin)
polygon->ymin = polygon->y[i];
if (polygon->y[i] > polygon->ymax)
polygon->ymax = polygon->y[i];
}
}

void my_filled_polygon(sfml_t *sfml, polygon_t polygon)
{
char *empty;
int *xmin;
int *xmax;
int i;

i = -1;
polygon_get_info(&polygon);
xmin = (int*)malloc(sizeof(int) * (polygon.ymax - polygon.ymin + 1));
xmax = (int*)malloc(sizeof(int) * (polygon.ymax - polygon.ymin + 1));
empty = (char*)malloc(polygon.ymax - polygon.ymin + 1);
while (++i < polygon.ymax - polygon.ymin + 1)
empty[i] = 1;
get_drawline(&polygon, xmin, xmax, empty);
draw_filled_polygon(sfml, &polygon, xmax, xmin);
free(empty);
free(xmin);
free(xmax);
}

+ 92
- 0
lib/my_csfml/my_polygon_getline.c View File

@@ -0,0 +1,92 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include "../../include/lib/s_sfml.h"
#include "../../include/lib/my_graphics.h"


static void set_line_dy(polygon_t *polygon, void *ptr[], int var[6])
{
char *empty = (char*)ptr[2];
int *xmin = (int*)ptr[1];
int *xmax = (int*)ptr[0];
int cumul;
int i;

i = 0;
cumul = var[3] >> 1;
while (++i < var[3]){
var[1] += var[5];
cumul += var[2];
if (cumul > var[3]){
cumul -= var[3];
var[0] += var[4];
}
xmax[var[1] - polygon->ymin] = var[0];
if (empty[var[1] - polygon->ymin]){
xmin[var[1] - polygon->ymin] = var[0];
empty[var[1] - polygon->ymin] = 0;
}
}
}

static void set_line_dx(polygon_t *polygon, void *ptr[], int var[6])
{
char *empty = (char*)ptr[2];
int *xmin = (int*)ptr[1];
int *xmax = (int*)ptr[0];
int cumul;
int i;

i = 0;
cumul = var[2] >> 1;
while (++i < var[2]){
var[0] += var[4];
cumul += var[3];
if (cumul > var[2]){
cumul -= var[2];
var[1] += var[5];
}
xmax[var[1] - polygon->ymin] = var[0];
if (empty[var[1] - polygon->ymin]){
xmin[var[1] - polygon->ymin] = var[0];
empty[var[1] - polygon->ymin] = 0;
}
}
}

static void polygon_init_var(polygon_t *polygon, int var[6], int i)
{
var[0] = polygon->x[i];
var[1] = polygon->y[i];
var[2] = polygon->x[(i + 1) % polygon->nb_vertices] - var[0];
var[3] = polygon->y[(i + 1) % polygon->nb_vertices] - var[1];
var[4] = (var[2] > 0) ? 1 : -1;
var[5] = (var[3] > 0) ? 1 : -1;
var[2] = (var[2] > 0) ? var[2] : -var[2];
var[3] = (var[3] > 0) ? var[3] : -var[3];
}

void get_drawline(polygon_t *polygon, int *xmax, int *xmin, char *empty)
{
void *ptr[]= {(void*)xmax, (void*)xmin, (void*)empty};
int var[6];
int i;

i = -1;
while (++i < polygon->nb_vertices){
polygon_init_var(polygon, var, i);
xmax[var[1] - polygon->ymin] = var[0];
if (empty[var[1] - polygon->ymin]){
xmin[var[1] - polygon->ymin] = var[0];
empty[var[1] - polygon->ymin] = 0;
}
if (var[2] > var[3])
set_line_dx(polygon, ptr, var);
else
set_line_dy(polygon, ptr, var);
}
}

+ 92
- 0
lib/my_csfml/my_rectangle.c View File

@@ -0,0 +1,92 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include "../include/lib/s_sfml.h"
#include "../include/lib/my_graphics.h"
#include "../include/lib/my_stdlib.h"

static int check_position(sfml_t *sfml, int rectangle[])
{
if ((rectangle[0] < 0 && rectangle[2] < 0) ||
((rectangle[0] > sfml->width) && (rectangle[2] > sfml->width))
|| (rectangle[1] < 0 && rectangle[3] < 0)
|| ((rectangle[1] > sfml->height)
&& (rectangle[3] > sfml->height)))
return (1);
return (0);
}

void my_filled_rectangle(sfml_t *sfml, int rectangle[4], uint32_t color)
{
int h_line[3];
int var[4];
int i;

if (check_position(sfml, rectangle))
return;
i = -1;
var[0] = (rectangle[2] < rectangle[0]) ? rectangle[2] : rectangle[0];
var[0] = (var[0] < 0) ? 0 : var[0];
var[1] = (rectangle[3] < rectangle[1]) ? rectangle[3] : rectangle[1];
var[1] = (var[1] < 0) ? 0 : var[1];
var[2] = (rectangle[2] < rectangle[0]) ? rectangle[0] : rectangle[2];
var[2] = (var[2] > sfml->width) ? sfml->width : var[2];
var[3] = my_abs(rectangle[3] - rectangle[1]);
var[3] = (var[3] > sfml->height) ? sfml->height : var[3];
while (++i < var[3]){
h_line[0] = var[1] + i;
h_line[1] = var[0];
h_line[2] = var[2];
my_horizontal_line(sfml, h_line, color);
}
}

static void set_h_line(int h_line[3], int y, int x1, int x2)
{
h_line[0] = y;
h_line[1] = x1;
h_line[2] = x2;
}

static void draw_border(sfml_t *sfml, int rect[5], uint32_t border_color)
{
int h_line[3];
int i;

i = -1;
while (++i < rect[4] - 1){
set_h_line(h_line, rect[1] + i, rect[0], rect[2]);
my_horizontal_line(sfml, h_line, border_color);
set_h_line(h_line, rect[3] - i, rect[0], rect[2]);
my_horizontal_line(sfml, h_line, border_color);
}
i = rect[1] + rect[4] - 2;
while (++i <= rect[3] - rect[4] + 1){
set_h_line(h_line, i, rect[0], rect[0] + rect[4] - 1);
my_horizontal_line(sfml, h_line, border_color);
set_h_line(h_line, i, rect[2] - rect[4] + 1, rect[2]);
my_horizontal_line(sfml, h_line, border_color);
}
}

void my_rectangle(sfml_t *sfml, int rect[5],
uint32_t border_color, uint32_t fill_color)
{
int h_line[3];
int i;

if (check_position(sfml, rect))
return;
if (border_color & 0xff && rect[4] > 0)
draw_border(sfml, rect, border_color);
if (fill_color & 0xff){
i = rect[1] + rect[4] - 1;
while (++i <= rect[3] - rect[4]){
set_h_line(h_line, i, rect[0] + rect[4], rect[2] - rect[4]);
my_horizontal_line(sfml, h_line, fill_color);
}
}
}

+ 45
- 0
lib/my_csfml/my_vram_zoom.c View File

@@ -0,0 +1,45 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include <stdlib.h>
#include "../../include/lib/s_sfml.h"
#include "../../include/lib/my_graphics.h"

void copy_vram(sfml_t *sfml, uint32_t *src)
{
int i;
int end;

i = -1;
end = sfml->height * sfml->width;
while (++i < end)
sfml->vram[i] = src[i];
}

void my_vram_zoom(sfml_t *sfml, double zoom_width, double zoom_height)
{
uint32_t *new_vram;
int copy_x;
int copy_y;
int i = -1;
int j;

zoom_width = (zoom_width < 0) ? 0 : zoom_width;
zoom_height = (zoom_height < 0) ? 0 : zoom_height;
new_vram = (uint32_t*)malloc(sizeof(uint32_t) *
sfml->width * sfml->height);
while (++i < sfml->width){
j = -1;
copy_x = i / zoom_width + 0.5;
while (++j < sfml->height){
copy_y = j / zoom_height + 0.5;
new_vram[i + j * sfml->width] =
sfml->vram[copy_x + copy_y * sfml->width];
}
}
copy_vram(sfml, new_vram);
free(new_vram);
}

+ 17
- 0
lib/my_stdio/my_dprintf.c View File

@@ -0,0 +1,17 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include "lib/my_stdio.h"

void my_dprintf(int fd, const char *format, ...)
{
va_list ap;
int size;

va_start(ap, format);
my_vfprintf(fd, format, ap);
va_end(ap);
}

+ 12
- 0
lib/my_stdio/my_fprintf.c View File

@@ -0,0 +1,12 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include "lib/my_stdio.h"

void my_fprintf(FILE *stream, const char *format, ...)
{
return;
}

+ 16
- 0
lib/my_stdio/my_printf.c View File

@@ -0,0 +1,16 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include "lib/my_stdio.h"

void my_printf(char const *format, ...)
{
va_list ap;

va_start(ap, format);
my_vfprintf(1, format, ap);
va_end(ap);
}

+ 14
- 0
lib/my_stdio/my_putchar.c View File

@@ -0,0 +1,14 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include <unistd.h>
#include "lib/my_stdio.h"

int my_putchar(int c)
{
write(1, &c, 1);
return (c);
}

+ 12
- 0
lib/my_stdio/my_vdprintf.c View File

@@ -0,0 +1,12 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include "lib/my_stdio.h"

void my_vdprintf(int fd, const char *format, va_list ap)
{
my_vfprintf(fd, format, ap);
}

+ 69
- 0
lib/my_stdio/my_vfprintf.c View File

@@ -0,0 +1,69 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include <unistd.h>
#include "lib/my_stdio.h"

extern void vfprintf_get_arg(printf_t *print, char type);
extern void vfprintf_get_base(printf_t *print, char type);
extern void vfprintf_print_arg(printf_t *print, int size);
extern int vfprintf_get_size(printf_t *print, char type);
extern int vfprintf_get_ouput_type(printf_t *print, char type);
extern int vfprintf_get_type(printf_t *print, char const *format);
extern int vfprintf_get_flags(printf_t *print, char const *format);
extern int vfprintf_get_precision(printf_t *print, char const *format);

static void vfprintf_setup_print(printf_t *print)
{
print->type = 0;
print->base = 10;
print->value = 0;
print->cursor = 0;
print->sign = '\0';
print->str_width = 0;
print->nbr_width = 0;
print->precision = 0;
print->type = PRINT_TYPE_RESET;
print->mode_flags = PRINT_MODE_RESET;
}

static int vfprintf_action(printf_t *print, char const *format)
{
int read_size;
int error;

if (*format != '%')
return (0);
vfprintf_setup_print(print);
read_size = vfprintf_get_flags(print, format);
read_size += vfprintf_get_precision(print, format + read_size);
read_size += vfprintf_get_type(print, format + read_size);
vfprintf_get_base(print, *(format + read_size));
error = vfprintf_get_ouput_type(print, *(format + read_size));
if (error < 0)
return (read_size + 1);
if (error == 0)
return (0);
vfprintf_get_arg(print, *(format + read_size));
vfprintf_get_size(print, *(format + read_size));
vfprintf_print_arg(print, print->str_width);
return (read_size + 1);
}

void my_vfprintf(int fd, char const *format, va_list ap)
{
int read_flags;
printf_t print;

print.stream = fd;
va_copy(print.ap, ap);
while (*format != '\0'){
read_flags = vfprintf_action(&print, format);
if (!read_flags)
write(fd, format++, 1);
format += read_flags;
}
}

+ 13
- 0
lib/my_stdio/my_vprintf.c View File

@@ -0,0 +1,13 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include <stdarg.h>
#include "lib/my_stdio.h"

void my_vprintf(const char *format, va_list ap)
{
my_vfprintf(1, format, ap);
}

+ 55
- 0
lib/my_stdio/vfprintf_get_arg.c View File

@@ -0,0 +1,55 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include "lib/my_stdio.h"

/* */
/* it's a bit ugly but it's the best */
/* maniere to get exacly what we want */
/* */
static void get_signed_arg(printf_t *print)
{
if (print->type & PRINT_TYPE_CHAR)
print->value = (uintmax_t)(char)print->value;
if (!print->type)
print->value = (uintmax_t)(int)print->value;
if (print->type & PRINT_TYPE_INTM)
print->value = (uintmax_t)(intmax_t)print->value;
if (print->type & PRINT_TYPE_SINT || print->type & PRINT_TYPE_SIZE)
print->value = (uintmax_t)(short int)print->value;
if (print->type & PRINT_TYPE_LLONG)
print->value = (uintmax_t)(long long int)print->value;
if (print->type & PRINT_TYPE_LONG)
print->value = (uintmax_t)(long int)print->value;
if (print->type & PRINT_TYPE_PTRD)
print->value = (uintmax_t)(ptrdiff_t)print->value;
}

static void get_unsigned_arg(printf_t *print)
{
if (print->type & PRINT_TYPE_CHAR)
print->value = (uintmax_t)(unsigned char)print->value;
if (!print->type)
print->value = (uintmax_t)(unsigned int)print->value;
if (print->type & PRINT_TYPE_SINT || print->type & PRINT_TYPE_SIZE)
print->value = (uintmax_t)(unsigned short int)print->value;
if (print->type & PRINT_TYPE_LLONG)
print->value = (uintmax_t)(unsigned long long int)print->value;
if (print->type & PRINT_TYPE_LONG)
print->value = (intmax_t)(unsigned long int)print->value;
if (print->type & PRINT_TYPE_PTRD)
print->value = (uintmax_t)(ptrdiff_t)print->value;
}

void vfprintf_get_arg(printf_t *print, char type)
{
print->value = va_arg(print->ap, uintmax_t);
if (type == 'o' || type == 'x' || type == 'X'
|| type == 'p' || type == 'b' || type == 'u')
get_unsigned_arg(print);
else
get_signed_arg(print);
}

+ 97
- 0
lib/my_stdio/vfprintf_get_option.c View File

@@ -0,0 +1,97 @@
/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include <unistd.h>
#include "lib/my_stdio.h"

int vfprintf_get_flags(printf_t *print, char const *format)
{
int read_size;

read_size = 0;
while (format[++read_size] == '+' || format[read_size] == '#'