add player moves and test image
This commit is contained in:
@@ -1,15 +1,51 @@
|
||||
#include "cube3d.h"
|
||||
|
||||
static int pxl_out_limits(t_game *game, int x, int y)
|
||||
{
|
||||
int xmax;
|
||||
int ymax;
|
||||
|
||||
xmax = game->sizel / (game->bpp / 8);
|
||||
ymax = game->win_size_y;
|
||||
if (x < 0 || y < 0 || x > xmax || y > ymax)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void draw_pixel(t_game *game, int x, int y, int color)
|
||||
{
|
||||
unsigned int position;
|
||||
|
||||
if (pxl_out_limits(game, x, y))
|
||||
return ;
|
||||
position = y * game->sizel + x * (game->bpp / 8);
|
||||
*(unsigned int*)(game->img_data + position) = color;
|
||||
}
|
||||
|
||||
void draw(t_game *game)
|
||||
{
|
||||
draw_pixel(game, game->plr_x, game->plr_y, 0x00FF0000);
|
||||
// temp, draw a map of points
|
||||
int x;
|
||||
int y;
|
||||
int x_size;
|
||||
// unsigned int screen_size;
|
||||
|
||||
x_size = game->sizel / (game->bpp / 8);
|
||||
// screen_size = x_size * game->win_size_y / 5;
|
||||
x = 0;
|
||||
y = 0;
|
||||
while (y <= game->win_size_y)
|
||||
{
|
||||
// y = x % x_size * 5;
|
||||
draw_pixel(game, x, y, 0x00999999);
|
||||
x += 5;
|
||||
if (x > x_size)
|
||||
{
|
||||
x = 0;
|
||||
y += 5;
|
||||
}
|
||||
}
|
||||
// temp
|
||||
draw_pixel(game, game->plr_x, game->plr_y, 0x0000FF00);
|
||||
mlx_put_image_to_window(game->mlx_ptr, game->win_ptr, game->img_ptr, 0, 0);
|
||||
}
|
||||
|
||||
18
srcs/draw/player_limits.c
Normal file
18
srcs/draw/player_limits.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "cube3d.h"
|
||||
|
||||
void plr_limits(t_game *game, int x, int y)
|
||||
{
|
||||
int xmax;
|
||||
int ymax;
|
||||
|
||||
xmax = game->sizel / (game->bpp / 8);
|
||||
ymax = game->win_size_y;
|
||||
if (x < 0)
|
||||
plr_posx_increment(game);
|
||||
else if (y < 0)
|
||||
plr_posy_increment(game);
|
||||
else if (x > xmax)
|
||||
plr_posx_decrement(game);
|
||||
else if (y > ymax)
|
||||
plr_posy_decrement(game);
|
||||
}
|
||||
25
srcs/draw/player_moves.c
Normal file
25
srcs/draw/player_moves.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "cube3d.h"
|
||||
|
||||
void plr_posx_decrement(t_game *game)
|
||||
{
|
||||
(game->plr_x) -= 5;
|
||||
plr_limits(game, game->plr_x, game->plr_y);
|
||||
}
|
||||
|
||||
void plr_posy_decrement(t_game *game)
|
||||
{
|
||||
(game->plr_y) -= 5;
|
||||
plr_limits(game, game->plr_x, game->plr_y);
|
||||
}
|
||||
|
||||
void plr_posx_increment(t_game *game)
|
||||
{
|
||||
(game->plr_x) += 5;
|
||||
plr_limits(game, game->plr_x, game->plr_y);
|
||||
}
|
||||
|
||||
void plr_posy_increment(t_game *game)
|
||||
{
|
||||
(game->plr_y) += 5;
|
||||
plr_limits(game, game->plr_x, game->plr_y);
|
||||
}
|
||||
Reference in New Issue
Block a user