summaryrefslogtreecommitdiff
path: root/map_spawn.c
blob: 521eeef9efbf80e1e6282b872a516f509a76f1c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   map_spawn.c                                        :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: kdx    <kdx   @student.42angouleme.fr      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2022/10/10 21:42:00 by kdx               #+#    #+#             */
/*   Updated: 2022/10/11 00:27:03 by kdx              ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "map.h"
#include "game.h"

void	map_spawn(t_game *game, t_map *map)
{
	size_t	x;
	size_t	y;
	int		tile;

	y = -1;
	while (++y < map->height)
	{
		x = -1;
		while (++x < map->width)
		{
			tile = map_get(map, x * TSIZE, y * TSIZE);
			if (tile == TILE_PLAYER)
			{
				game->player.pos[0] = x * TSIZE;
				game->player.pos[1] = y * TSIZE;
				map_set(map, x * TSIZE, y * TSIZE, '0');
			}
		}
	}
}