summaryrefslogtreecommitdiff
path: root/src/input.c
blob: fe1f21937ec9aa2ca39fb59a18a675e7c49c05dd (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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   input.c                                            :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2024/05/09 15:37:40 by dkaiser           #+#    #+#             */
/*   Updated: 2024/05/09 19:32:18 by dkaiser          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "so_long.h"

int	on_key_down(int keycode, t_game *game)
{
	if (keycode == 13 || keycode == 126)
		game->input_direction |= UP;
	else if (keycode == 0 || keycode == 123)
		game->input_direction |= LEFT;
	else if (keycode == 1 || keycode == 125)
		game->input_direction |= DOWN;
	else if (keycode == 2 || keycode == 124)
		game->input_direction |= RIGHT;
	return (0);
}

int	on_key_up(int keycode, t_game *game)
{
	if (keycode == 13 || keycode == 126)
		game->input_direction &= ~UP;
	else if (keycode == 0 || keycode == 123)
		game->input_direction &= ~LEFT;
	else if (keycode == 1 || keycode == 125)
		game->input_direction &= ~DOWN;
	else if (keycode == 2 || keycode == 124)
		game->input_direction &= ~RIGHT;
	return (0);
}