コード:
#include "Player.h"
#include <math.h>
#define RAD(k) ((k)*3.141592653589790/180.0)
Player::Player(void)
{
//player絵初期化**********
kuti_w = 32;
head_w = 32;
for(int i = UP;i <= LEFTUP;i++){//上から右回りに
kuti[i].naka_x = cos( RAD(i*45-90) ) * kuti_w;
kuti[i].naka_y = sin( RAD(i*45-90) ) * kuti_w;
kuti[i].tp_x = cos( RAD(i*45-90) ) * (kuti_w * 1.7);
kuti[i].tp_y = sin( RAD(i*45-90) ) * (kuti_w * 1.7);
kuti[i].up_x = cos( RAD(i*45-90-kuti_w) ) * kuti_w;
kuti[i].up_y = sin( RAD(i*45-90-kuti_w) ) * kuti_w;
kuti[i].down_x = cos( RAD(i*45-90+kuti_w) ) * kuti_w;
kuti[i].down_y = sin( RAD(i*45-90+kuti_w) ) * kuti_w;
}
//**********************
y = 3;
x = 5;
h = 64;
w = 64;
//デバッグ用
file = fopen("sokudo.txt","w");
if(file==NULL){
x=100;
}
fprintf(file,"sokudo:%02d,vv:%02d\n",sokudo,vv);
return;
}
Player::~Player(void)
{
//デバッグ用
fclose(file);
return;
}
void Player::draw(void){
(this->*draw_p[cmuki])();//プレイヤー表示
}
void Player::act(void)
{
(this->*cflg_act_p[cflg])();//状態にあわせた処理
return;
}
void Player::atack_start(void)
{
cflg = ATACK;
sokudo = 0;
vv = SYOKASOKU;
return;
}
void Player::damaged_start(void)
{
cflg = DAMAGED;
sokudo = 0;
vv = -SYOKASOKU;
return;
}
//方向にあわせたdraw関数*************************************************************
void Player::up_draw(void)
{
//player表示
dg_circle(bb,DRAW_PX+w/2,DRAW_PY+h/2-sokudo,h/2,RGB(255,255,0));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].naka_x, DRAW_PY+h/2 + kuti[cmuki].naka_y - sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x, DRAW_PY+h/2 + kuti[cmuki].tp_y - sokudo, RGB(255,255,255));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].up_x, DRAW_PY+h/2 + kuti[cmuki].up_y - sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x, DRAW_PY+h/2 + kuti[cmuki].tp_y - sokudo, RGB(255,255,255));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].down_x, DRAW_PY+h/2 + kuti[cmuki].down_y - sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x, DRAW_PY+h/2 + kuti[cmuki].tp_y - sokudo, RGB(255,255,255));
return;
}
void Player::rightup_draw(void)
{
//player表示
dg_circle(bb,DRAW_PX+w/2+sokudo, DRAW_PY+h/2-sokudo, h/2, RGB(255,255,0));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].naka_x + sokudo, DRAW_PY+h/2 + kuti[cmuki].naka_y - sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x+sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y - sokudo, RGB(255,255,255));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].up_x + sokudo, DRAW_PY+h/2 + kuti[cmuki].up_y - sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x+sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y - sokudo, RGB(255,255,255));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].down_x + sokudo, DRAW_PY+h/2 + kuti[cmuki].down_y - sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x+sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y - sokudo, RGB(255,255,255));
return;
}
void Player::right_draw(void)
{
//player表示
dg_circle(bb,DRAW_PX+w/2+sokudo,DRAW_PY+h/2,h/2,RGB(255,255,0));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].naka_x + sokudo, DRAW_PY+h/2 + kuti[cmuki].naka_y, DRAW_PX+w/2 + kuti[cmuki].tp_x+sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y, RGB(255,255,255));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].up_x + sokudo, DRAW_PY+h/2 + kuti[cmuki].up_y, DRAW_PX+w/2 + kuti[cmuki].tp_x+sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y, RGB(255,255,255));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].down_x + sokudo, DRAW_PY+h/2 + kuti[cmuki].down_y, DRAW_PX+w/2 + kuti[cmuki].tp_x+sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y, RGB(255,255,255));
return;
}
void Player::rightdown_draw(void)
{
//player表示
dg_circle(bb,DRAW_PX+w/2+sokudo,DRAW_PY+h/2+sokudo,h/2,RGB(255,255,0));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].naka_x + sokudo, DRAW_PY+h/2 + kuti[cmuki].naka_y + sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x+sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y + sokudo, RGB(255,255,255));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].up_x + sokudo, DRAW_PY+h/2 + kuti[cmuki].up_y + sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x+sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y + sokudo, RGB(255,255,255));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].down_x + sokudo, DRAW_PY+h/2 + kuti[cmuki].down_y + sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x+sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y + sokudo, RGB(255,255,255));
return;
}
void Player::down_draw(void)
{
//player表示
dg_circle(bb,DRAW_PX+w/2,DRAW_PY+h/2+sokudo,h/2,RGB(255,255,0));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].naka_x, DRAW_PY+h/2 + kuti[cmuki].naka_y + sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x, DRAW_PY+h/2 + kuti[cmuki].tp_y + sokudo, RGB(255,255,255));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].up_x, DRAW_PY+h/2 + kuti[cmuki].up_y + sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x, DRAW_PY+h/2 + kuti[cmuki].tp_y + sokudo, RGB(255,255,255));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].down_x , DRAW_PY+h/2 + kuti[cmuki].down_y + sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x, DRAW_PY+h/2 + kuti[cmuki].tp_y + sokudo, RGB(255,255,255));
return;
}
void Player::leftdown_draw(void)
{
//player表示
dg_circle(bb,DRAW_PX+w/2-sokudo,DRAW_PY+h/2+sokudo,h/2,RGB(255,255,0));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].naka_x - sokudo, DRAW_PY+h/2 + kuti[cmuki].naka_y + sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x-sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y + sokudo, RGB(255,255,255));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].up_x - sokudo, DRAW_PY+h/2 + kuti[cmuki].up_y + sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x-sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y + sokudo, RGB(255,255,255));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].down_x - sokudo, DRAW_PY+h/2 + kuti[cmuki].down_y + sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x-sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y + sokudo, RGB(255,255,255));
return;
}
void Player::left_draw(void)
{
//player表示
dg_circle(bb,DRAW_PX+w/2-sokudo,DRAW_PY+h/2,h/2,RGB(255,255,0));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].naka_x - sokudo, DRAW_PY+h/2 + kuti[cmuki].naka_y, DRAW_PX+w/2 + kuti[cmuki].tp_x-sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y, RGB(255,255,255));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].up_x - sokudo, DRAW_PY+h/2 + kuti[cmuki].up_y, DRAW_PX+w/2 + kuti[cmuki].tp_x-sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y, RGB(255,255,255));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].down_x - sokudo, DRAW_PY+h/2 + kuti[cmuki].down_y, DRAW_PX+w/2 + kuti[cmuki].tp_x-sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y, RGB(255,255,255));
return;
}
void Player::leftup_draw(void)
{
//player表示
dg_circle(bb,DRAW_PX+w/2-sokudo,DRAW_PY+h/2-sokudo,h/2,RGB(255,255,0));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].naka_x - sokudo, DRAW_PY+h/2 + kuti[cmuki].naka_y - sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x-sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y - sokudo, RGB(255,255,255));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].up_x - sokudo, DRAW_PY+h/2 + kuti[cmuki].up_y - sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x-sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y - sokudo, RGB(255,255,255));
dg_line(bb,DRAW_PX+w/2 + kuti[cmuki].down_x - sokudo, DRAW_PY+h/2 + kuti[cmuki].down_y - sokudo, DRAW_PX+w/2 + kuti[cmuki].tp_x-sokudo, DRAW_PY+h/2 + kuti[cmuki].tp_y - sokudo, RGB(255,255,255));
return;
}
/*************************************************************************************/
//各状態にあわせたcflg_関数**********************************************************
void Player::cflg_stop(void)
{
if( can_moved && cflg == STOP){//プレイヤーが入力を受け付けているかどうか
if( A_KEY ){
if( RIGHT_KEY && UP_KEY ){
cmuki = RIGHTUP;
if( Chara::pmap->can_move(x + 1,y - 1 )){//移動先の座標のフィールドが移動可能な場所かどうか
Chara::pmap->scr_rightup();
move_rightup();
}
}else if( RIGHT_KEY && DOWN_KEY){
cmuki = RIGHTDOWN;
if( Chara::pmap->can_move(x + 1,y + 1 )){//移動先の座標のフィールドが移動可能な場所かどうか
Chara::pmap->scr_rightdown();
move_rightdown();
}
}else if( LEFT_KEY && UP_KEY ){
cmuki = LEFTUP;
if( Chara::pmap->can_move(x - 1,y - 1 )){//移動先の座標のフィールドが移動可能な場所かどうか
Chara::pmap->scr_leftup();
move_leftup();
}
}else if( LEFT_KEY && DOWN_KEY ){
cmuki = LEFTDOWN;
if( Chara::pmap->can_move(x - 1,y + 1 )){//移動先の座標のフィールドが移動可能な場所かどうか
Chara::pmap->scr_leftdown();
move_leftdown();
}
}
}
else{
if( S_KEY ){//攻撃コマンド
atack_start();
}else if( UP_KEY ){
cmuki = UP;
if( Chara::pmap->can_move(x,y - 1 )){//移動先の座標のフィールドが移動可能な場所かどうか
Chara::pmap->scr_up();//マップをスクロール
move_up();
}
}else if( DOWN_KEY ){
cmuki = DOWN;
if( Chara::pmap->can_move(get_x(),get_y() + 1) ){
Chara::pmap->scr_down();
move_down();
}
}else if( LEFT_KEY ){
cmuki = LEFT;
if( Chara::pmap->can_move(get_x() - 1,get_y()) ){
Chara::pmap->scr_left();
move_left();
}
}else if( RIGHT_KEY ){
cmuki = RIGHT;
if( Chara::pmap->can_move(get_x() + 1,get_y()) ){
Chara::pmap->scr_right();
move_right();
}
}
}
}
return;
}
void Player::cflg_move(void)
{
//カメラ移動****************************************
switch(cmuki){
case UP:
camera_y += 2;
break;
case RIGHTUP:
camera_y += 2;
camera_x -= 2;
break;
case RIGHT:
camera_x -= 2;
break;
case RIGHTDOWN:
camera_y -= 2;
camera_x -= 2;
break;
case DOWN:
camera_y -= 2;
break;
case LEFTDOWN:
camera_y -= 2;
camera_x += 2;
break;
case LEFT:
camera_x += 2;
break;
case LEFTUP:
camera_y += 2;
camera_x += 2;
break;
}
//******************************************
if( (camera_x)%64==0 && camera_y%64==0 && cflg==MOVE){
cflg = STOP;
can_moved = false;//行動終了
}
return;
}
void Player::cflg_damaged(void)
{
return;
}
void Player::cflg_atack(void)
{
fprintf(file,"sokudo:%02d,vv:%02d\n",sokudo,vv);
//攻撃モーション******************
sokudo -= vv;
vv++;
if(sokudo<0){
sokudo=0;
vv = 1;
cflg = STOP;
can_moved = false;//行動終了
}
//********************************
return;
}
//***********************************************************************************