-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
38 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: yzaim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/08 15:26:51 by yzaim #+# #+# */ | ||
/* Updated: 2024/01/25 16:01:28 by jboeve ######## odam.nl */ | ||
/* Updated: 2024/01/29 12:51:57 by yesimzaim ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -112,4 +112,5 @@ void game_loop(void* param) | |
timer_start(&meta->update_timer); | ||
render_minimap(&meta->minimap, &meta->map, &meta->player); | ||
render_viewport(meta->image, &meta->player); | ||
sprite_calculate(&meta->player); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,13 @@ | |
/* By: jboeve <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/25 16:01:20 by jboeve #+# #+# */ | ||
/* Updated: 2024/01/26 17:22:12 by yzaim ######## odam.nl */ | ||
/* Updated: 2024/01/29 13:00:59 by yesimzaim ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "meta.h" | ||
#include "vector.h" | ||
//#include <algorithm> | ||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
@@ -39,16 +40,20 @@ void init_sprites(t_sprite *sprites) | |
UNIMPLEMENTED("mlx_load_png failed"); | ||
} | ||
|
||
// static void sprite_sort(int32_t *order, double *dist, uint32_t count) | ||
// { | ||
// size_t i = 0; | ||
// while (i < count) | ||
// { | ||
// s[i] = | ||
// i++; | ||
// } | ||
|
||
// } | ||
bool if_black(uint32_t color) | ||
{ | ||
// Extract individual color channels | ||
uint8_t r = (color >> 24) & 0xFF; | ||
uint8_t g = (color >> 16) & 0xFF; | ||
uint8_t b = (color >> 8) & 0xFF; | ||
|
||
// Check if all color channels are 0 (black) | ||
if (r == 0 && g == 0 && b == 0) { | ||
return true; // Black | ||
} else { | ||
return false; // Not black | ||
} | ||
} | ||
|
||
void sprite_calculate(t_player *p) | ||
{ | ||
|
@@ -101,14 +106,30 @@ void sprite_calculate(t_player *p) | |
if (draw_end.x >= (int32_t) p->meta->image->width) | ||
draw_end.x = p->meta->image->width - 1; | ||
|
||
|
||
// loop through every vertical stripe of the sprite on the screen | ||
int stripe = draw_start.x; | ||
while (stripe < draw_end.x) | ||
{ | ||
|
||
int tex_x; | ||
tex_x = (int)(256 * (stripe - (-sprite_width / 2 + sprite_screen_x)) * p->meta->attributes.sprites[i].tex->width / sprite_width) / 256; | ||
if (transform.y > 0 && stripe > 0 && stripe < p->meta->image->width && transform.y < p->z_buffer[stripe]) | ||
{ | ||
int y; | ||
y = draw_start.y; | ||
while (y < draw_end.y) | ||
{ | ||
int d = (y) * 256 - p->meta->image->height * 128 + sprite_height * 128; //256 and 128 factors to avoid floats | ||
int tex_y = ((d * p->meta->attributes.sprites[i].tex->height) / sprite_height) / 256; | ||
uint32_t color = pixel_picker(p->meta->attributes.sprites[i].tex, tex_x, tex_y); | ||
if (!if_black(color)) | ||
{ | ||
mlx_put_pixel(p->meta->image, stripe, y, color); | ||
} | ||
y++; | ||
} | ||
} | ||
stripe++; | ||
} | ||
|
||
i++; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: jboeve <[email protected]> +#+ */ | ||
/* +#+ */ | ||
/* Created: 2024/01/25 16:01:20 by jboeve #+# #+# */ | ||
/* Updated: 2024/01/26 17:24:54 by yzaim ######## odam.nl */ | ||
/* Updated: 2024/01/29 12:50:12 by yesimzaim ######## odam.nl */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -68,10 +68,5 @@ void quick_sort(double *sprite_dist, int32_t *sprite_order, int32_t low, int32_t | |
|
||
void sprite_sort(double *sprite_dist, int32_t *sprite_order) | ||
{ | ||
print_double_array("SPRITE_DIST", sprite_dist, SPRITE_COUNT); | ||
print_ints_array("SPRITE_ORDER", sprite_order, SPRITE_COUNT); | ||
printf("SPRITECOUNT: %u\n", SPRITE_COUNT); | ||
quick_sort(sprite_dist, sprite_order, 0, SPRITE_COUNT - 1); | ||
print_double_array("SPRITE_DIST", sprite_dist, SPRITE_COUNT); | ||
print_ints_array("SPRITE_ORDER", sprite_order, SPRITE_COUNT); | ||
} |