@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -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*/ |
@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -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*/ |
@ -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 |
@ -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 */ |
@ -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 |
@ -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 |
@ -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); | |||
} | |||
} |
@ -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); | |||
} |
@ -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); | |||
} |
@ -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) | |||
{ | |||