summaryrefslogtreecommitdiff
path: root/main.c
blob: 82c28e642a065135c4f143d70890b733f5bbe95e (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.c                                             :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: kdx    <kdx   @student.42angouleme.fr      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2022/10/07 01:51:52 by kdx               #+#    #+#             */
/*   Updated: 2022/10/14 14:45:59 by kdx              ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "badeline.h"
#include "libft/libft.h"
#include "game.h"
#include "sily.h"
#include "sprite.h"
#include "player.h"
#include <stdlib.h>

static void	update(t_sily *sily)
{
	sily_input_update(sily);
	player_update(sily, &sily->game->player);
	badeline_update(&sily->game->badeline);
	if (sily->game->victory)
	{
		ft_putendl_fd("Victory!", 1);
		game_destroy(sily->game);
		exit(0);
	}
}

static void	draw(t_sily *sily)
{
	game_draw(sily->game);
}

int	main(int argc, char **argv)
{
	t_game	*game;

	if (argc != 2)
		return (ft_printf("Error\nusage: so_long <map.ber>\n"));
	game = game_new(argv[1]);
	if (game == NULL)
		return (1);
	game->redraw = 1;
	sily_loop(game->sily, update, draw);
	return (0);
}