#include "wou.h"

void player_init(player *p) {
	p->name = "Rikas";
	p->avatar_num = 0;
	p->stance = S_STAND;
	p->attr = (attr*)malloc(sizeof(struct attr));
	backpack = new ObjectList();

	// creates the BMP with avatar
	p->BMP = create_bitmap(TILE_W, TILE_H);
	clear_bitmap(p->BMP);
	p->x = 12;
	p->y = 12;
}

void player_draw(player *p) {
	int line = p->avatar_num/TILE_W;  // line on tiles PCX
	int col = p->stance%TILE_W;       // column on tiles PCX
	int x = (TILE_W*col)+col+1;       // x of up left corner
	int y = (TILE_H*line)+line+1;     // y of up left corner

	masked_blit(charsBMP, p->BMP, x, y, 0, 0, TILE_W, TILE_H);
	masked_blit(p->BMP, gamearea, 0, 0, TILE_W*12, TILE_W*12, TILE_W, TILE_H);
	/*
	rectfill(vbuffer, 395,75,530,240,4);
	textprintf_ex(vbuffer, smallFONT, 399, 79, makecol(200,200,100), -1,"px:%i py:%i",
	PLAYER_X, PLAYER_Y);
	textprintf_ex(vbuffer, smallFONT, 398, 89, makecol(100,200,200), -1,"cx:%i cy:%i",
	CORNER_X, CORNER_Y);*/
}

int player_move(player *p, int x, int y) {
	if (x<0) x = 0;
	if (y<0) y = 0;

	// the destination tile is bloqued
	if (tiledb[map.tile[x][y].num].passable%10 == 2) {
		x = p->x;
		y = p->y;
		return FALSE;
	}
	else {
	  p->x = x;
	  p->y = y;
	}
	return TRUE;
}
