/*
* Copyright (C) 2021 P. J. McDermott
*
* This file is part of Maze Fight
*
* Maze Fight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Maze Fight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Maze Fight. If not, see .
*/
#include
#include "../char.h"
#include "../defs.h"
#include "../maze.h"
#include "char.h"
struct mf_player {
struct mf_char parent;
};
static int
_mf_player_update(struct mf_char *c)
{
int dx;
int dy;
int x;
int y;
switch (c->cur_dir) {
case MF_CHAR_DIR_U_: dx = 0; dy = -1; break;
case MF_CHAR_DIR_D_: dx = 0; dy = 1; break;
case MF_CHAR_DIR_L_: dx = -1; dy = 0; break;
case MF_CHAR_DIR_R_: dx = 1; dy = 0; break;
default: dx = 0; dy = 0; break;
}
x = c->cur_x - dx, y = c->cur_y - dy;
do {
x += dx, y += dy;
mf_maze_reveal_wall(c->maze, x, y, -1, 0);
mf_maze_reveal_wall(c->maze, x, y, 1, 0);
mf_maze_reveal_wall(c->maze, x, y, 0, -1);
mf_maze_reveal_wall(c->maze, x, y, 0, 1);
} while (!mf_maze_is_wall(c->maze, x, y, dx, dy));
return 0;
}
static int
_mf_player_step(struct mf_char *c __attribute__((__unused__)))
{
return 0;
}
static int
_mf_player_turn(struct mf_char *c __attribute__((__unused__)))
{
return 0;
}
static int
_mf_player_render(struct mf_char *c __attribute__((__unused__)),
SDL_Renderer *renderer __attribute__((__unused__)))
{
return 0;
}
static void
_mf_player_collide(struct mf_char *c __attribute__((__unused__)))
{
}
static void
_mf_player_destroy(struct mf_char *c __attribute__((__unused__)))
{
}
struct mf_char *
mf_player_new(struct mf_maze *maze, int cell_width)
{
struct mf_char *c;
struct mf_player *p __attribute__((__unused__));
mf_char_init(c, p, player);
c->maze = maze;
c->cell_width = cell_width;
c->speed = MF_PLAYER_SPEED;
c->new_dir = MF_CHAR_DIR_N_;
c->turning = 0;
c->turn_time = MF_PLAYER_TURN_TIME;
c->cur_x = 0;
c->cur_y = 0;
c->travel = 0;
c->padding = MF_PLAYER_P;
c->smile_y = MF_PLAYER_SMILE_Y;
c->smile_r = MF_PLAYER_SMILE_R;
c->eye_x = MF_PLAYER_EYE_X;
c->eye_y = MF_PLAYER_EYE_Y;
c->eye_r = MF_PLAYER_EYE_R;
c->head_color.r = MF_COLOR_PLYR_R, c->head_color.g = MF_COLOR_PLYR_G;
c->head_color.b = MF_COLOR_PLYR_B, c->head_color.a = MF_COLOR_PLYR_A;
c->smil_color.r = MF_COLOR_PSML_R, c->smil_color.g = MF_COLOR_PSML_G;
c->smil_color.b = MF_COLOR_PSML_B, c->smil_color.a = MF_COLOR_PSML_A;
c->eyes_color.r = MF_COLOR_PEYE_R, c->eyes_color.g = MF_COLOR_PEYE_G;
c->eyes_color.b = MF_COLOR_PEYE_B, c->eyes_color.a = MF_COLOR_PEYE_A;
if (mf_maze_is_wall(maze, 0, 0, 1, 0)) {
c->old_dir = c->cur_dir = MF_CHAR_DIR_D_;
} else {
c->old_dir = c->cur_dir = MF_CHAR_DIR_R_;
}
return c;
}
void
mf_player_key_event(struct mf_char *c, SDL_Event *e)
{
switch (e->type) {
case SDL_KEYDOWN:
switch (e->key.keysym.sym) {
case SDLK_UP:
c->new_dir = MF_CHAR_DIR_U_;
break;
case SDLK_DOWN:
c->new_dir = MF_CHAR_DIR_D_;
break;
case SDLK_LEFT:
c->new_dir = MF_CHAR_DIR_L_;
break;
case SDLK_RIGHT:
c->new_dir = MF_CHAR_DIR_R_;
break;
default:
break;
}
default:
break;
}
}