mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
norm: normed code (except sprites)
This commit is contained in:
parent
258372bf09
commit
9a113374a6
6 changed files with 113 additions and 23 deletions
1
Makefile
1
Makefile
|
|
@ -28,6 +28,7 @@ SOURCEFILES = \
|
|||
src/raycast/ray.c \
|
||||
src/raycast/walls.c \
|
||||
src/renderer/render.c \
|
||||
src/sprites/sort_sprites.c \
|
||||
src/sprites/sprite_caster.c \
|
||||
|
||||
OBJECTS = $(SOURCEFILES:.c=.o)
|
||||
|
|
|
|||
38
src/consts.h
38
src/consts.h
|
|
@ -6,31 +6,31 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/17 14:54:36 by kcolin #+# #+# */
|
||||
/* Updated: 2025/08/06 13:44:29 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/08/06 14:23:35 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CONSTS_H
|
||||
#define CONSTS_H
|
||||
# define CONSTS_H
|
||||
|
||||
#define HEIGHT 800
|
||||
#define WIDTH 800
|
||||
# define HEIGHT 800
|
||||
# define WIDTH 800
|
||||
|
||||
#define SIZE 64
|
||||
#define MAP_SIZE 10
|
||||
#define PLAYER_SIZE 6
|
||||
#define RESSOURCE_DIR "ressources"
|
||||
#define MOVEMENT_SPEED 0.000005
|
||||
#define ROTATION_SPEED 0.000002
|
||||
#define PLANE_VALUE 0.6
|
||||
#define TEXTURE_SIZE 64
|
||||
# define SIZE 64
|
||||
# define MAP_SIZE 10
|
||||
# define PLAYER_SIZE 6
|
||||
# define RESSOURCE_DIR "ressources"
|
||||
# define MOVEMENT_SPEED 0.000005
|
||||
# define ROTATION_SPEED 0.000002
|
||||
# define PLANE_VALUE 0.6
|
||||
# define TEXTURE_SIZE 64
|
||||
# define SPRITE_TRANPARENCY_COLOR 0xff00dc
|
||||
// 4 static ones, 3 perks, the box and 25 zombies at max
|
||||
#define SPRITE_TRANPARENCY_COLOR 0xff00dc
|
||||
#define MAX_SPRITES 1 // FIXME: Change to 30
|
||||
#ifdef BONUS
|
||||
#define COMPILED_TEXT "Compiled with bonuses"
|
||||
#else
|
||||
#define COMPILED_TEXT " "
|
||||
#endif
|
||||
# define MAX_SPRITES 1 // FIXME: Change to 30
|
||||
# ifdef BONUS
|
||||
# define COMPILED_TEXT "Compiled with bonuses"
|
||||
# else
|
||||
# define COMPILED_TEXT " "
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/31 13:17:39 by kcolin #+# #+# */
|
||||
/* Updated: 2025/08/06 12:08:33 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/08/06 14:15:08 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -34,7 +34,6 @@ t_cardinal_dir get_cardinal(t_ray *ray)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static int get_color(t_cub3d_data *data, t_ray *ray, int tex_y)
|
||||
{
|
||||
t_cardinal_dir dir;
|
||||
|
|
|
|||
70
src/sprites/sort_sprites.c
Normal file
70
src/sprites/sort_sprites.c
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* sort_sprites.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/06 14:17:58 by tchampio #+# #+# */
|
||||
/* Updated: 2025/08/06 14:21:16 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../cub3d_data.h"
|
||||
|
||||
static void swap(int i, int j, int *spriteorder, double *spritedist)
|
||||
{
|
||||
double tmp_dist;
|
||||
int tmp_order;
|
||||
|
||||
tmp_order = spriteorder[i];
|
||||
tmp_dist = spritedist[i];
|
||||
spriteorder[i] = spriteorder[j];
|
||||
spritedist[i] = spritedist[j];
|
||||
spriteorder[j] = tmp_order;
|
||||
spritedist[j] = tmp_dist;
|
||||
}
|
||||
|
||||
static void bubble_sort(double *dist, int *order)
|
||||
{
|
||||
int j;
|
||||
int k;
|
||||
|
||||
j = 0;
|
||||
while (j < MAX_SPRITES)
|
||||
{
|
||||
k = 0;
|
||||
while (j < MAX_SPRITES - j - 1)
|
||||
{
|
||||
if (dist[k] < dist[k + 1] && dist[k] != -1)
|
||||
swap(k, k + 1, order, dist);
|
||||
k++;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
// the sorting part is a readaptation of the std::sort function from c++
|
||||
// more info on here: https://stackoverflow.com/questions/23816797/how-does-stdsort-work-for-list-of-pairs
|
||||
void sort_sprites(int *spriteorder, double *spritedist, t_cub3d_data *data)
|
||||
{
|
||||
int i;
|
||||
int order[MAX_SPRITES];
|
||||
double dist[MAX_SPRITES];
|
||||
|
||||
i = 0;
|
||||
while (i < MAX_SPRITES)
|
||||
{
|
||||
order[i] = i;
|
||||
dist[i] = ((data->player.x - data->static_sprite[i].x) * (data->player.x - data->static_sprite[i].x) + (data->player.y - data->static_sprite[i].y) * (data->player.y - data->static_sprite[i].y));
|
||||
i++;
|
||||
}
|
||||
bubble_sort(dist, order);
|
||||
i = 0;
|
||||
while (i < MAX_SPRITES)
|
||||
{
|
||||
spritedist[i] = dist[MAX_SPRITES - i - 1];
|
||||
spriteorder[i] = order[MAX_SPRITES - i - 1];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
20
src/sprites/sort_sprites.h
Normal file
20
src/sprites/sort_sprites.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* sort_sprites.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/06 14:18:47 by tchampio #+# #+# */
|
||||
/* Updated: 2025/08/06 14:19:23 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef SORT_SPRITES_H
|
||||
# define SORT_SPRITES_H
|
||||
|
||||
# include "../cub3d_data.h"
|
||||
|
||||
void sort_sprites(int *spriteorder, double *spritedist, t_cub3d_data *data);
|
||||
|
||||
#endif // SORT_SPRITES_H
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/31 13:28:47 by tchampio #+# #+# */
|
||||
/* Updated: 2025/08/05 15:05:10 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/08/06 14:14:11 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue