00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "player.h"
00030
00031 Player::Player(){
00032 num_frames_phase = 24;
00033 num_frames_action = 3;
00034 phase = 0;
00035 frame_dir = 1;
00036 }
00037
00038 Player::~Player(){
00039 }
00040
00041 void Player::set_screen(Screen &s){
00042 screen = s;
00043 }
00044
00045 void Player::set_paul_info(paul_info *p){
00046 pinfo = p;
00047 }
00048
00049 void Player::update(){
00050 if(PLAYER_DEBUG)printf("update player (%d %d)\n", box.x, box.y);
00051 onscreen = 1;
00052 current_box.x = pinfo->paul_ax;
00053 current_box.y = pinfo->paul_ay;
00054 }
00055
00056 void Player::move(int dir){
00057 int amount = MOVE_PER_FRAME;
00058 if(dir != pinfo->direction){
00059 current_frame = 0; pinfo->direction = dir;
00060 }else{
00061 undo_move_x = pinfo->paul_ax;
00062 undo_move_y = pinfo->paul_ay;
00063 switch(dir){
00064 case 0: if(pinfo->paul_ay - amount > 0) pinfo->paul_ay -= amount;
00065
00066 break;
00067 case 1: if(pinfo->paul_ax + amount + pinfo->tilesize < pinfo->map_width)
00068 pinfo->paul_ax += amount;
00069 if(pinfo->paul_ay - amount > 0) pinfo->paul_ay -= amount;
00070 break;
00071 case 2: if(pinfo->paul_ax + amount + pinfo->tilesize < pinfo->map_width)
00072 pinfo->paul_ax += amount;
00073 break;
00074 case 3: if(pinfo->paul_ax + amount + pinfo->tilesize < pinfo->map_width)
00075 pinfo->paul_ax += amount;
00076 if(pinfo->paul_ay + amount + pinfo->tilesize < pinfo->map_height)
00077 pinfo->paul_ay += amount;
00078 break;
00079 case 4: if(pinfo->paul_ay + amount + pinfo->tilesize < pinfo->map_height)
00080 pinfo->paul_ay += amount;
00081 break;
00082 case 5: if(pinfo->paul_ax - amount > 0) pinfo->paul_ax -= amount;
00083 if(pinfo->paul_ay + amount + pinfo->tilesize < pinfo->map_height)
00084 pinfo->paul_ay += amount;
00085 break;
00086 case 6: if(pinfo->paul_ax - amount > 0) pinfo->paul_ax -= amount;
00087 break;
00088 case 7: if(pinfo->paul_ax - amount > 0) pinfo->paul_ax -= amount;
00089 if(pinfo->paul_ay - amount > 0) pinfo->paul_ay -= amount;
00090 break;
00091 }
00092 }
00093 redraw();
00094
00095 pinfo->map_ax = pinfo->paul_ax + (pinfo->tilesize/2) - (pinfo->win_width/2);
00096 pinfo->map_ay = pinfo->paul_ay + (pinfo->tilesize/2) - (pinfo->win_height/2);
00097 }
00098
00099 void Player::unmove(int dir){
00100 pinfo->paul_ax = undo_move_x;
00101 pinfo->paul_ay = undo_move_y;
00102 redraw();
00103 pinfo->map_ax = pinfo->paul_ax + (pinfo->tilesize/2) - (pinfo->win_width/2);
00104 pinfo->map_ay = pinfo->paul_ay + (pinfo->tilesize/2) - (pinfo->win_height/2);
00105 }
00106
00107 void Player::redraw(){
00108 if(current_frame == (num_frames_action - 1)) frame_dir = -1;
00109 if(current_frame == 0) frame_dir = 1;
00110 screen.blit(tiledata.tile[pinfo->direction*num_frames_action+current_frame],
00111 makerect(pinfo->paul_x, pinfo->paul_y, pinfo->tilesize, pinfo->tilesize));
00112 current_frame += frame_dir;
00113 }
00114
00115 void Player::static_redraw(int dir){
00116 if(dir != pinfo->direction && dir != -1){
00117 current_frame = 0; pinfo->direction = dir;
00118 }
00119 screen.blit(tiledata.tile[pinfo->direction*num_frames_action+current_frame],
00120 makerect(pinfo->paul_x, pinfo->paul_y, pinfo->tilesize, pinfo->tilesize));
00121 }
00122
00123 void Player::static_redraw_cycle(int dir){
00124 if(dir != pinfo->direction && dir != -1){
00125 current_frame = 0; pinfo->direction = dir;
00126 }
00127 if(current_frame == (num_frames_action - 1)) frame_dir = -1;
00128 if(current_frame == 0) frame_dir = 1;
00129 screen.blit(tiledata.tile[pinfo->direction*num_frames_action+current_frame],
00130 makerect(pinfo->paul_x, pinfo->paul_y, pinfo->tilesize, pinfo->tilesize));
00131 current_frame += frame_dir;
00132 }
00133
00134 void Player::overlay(){
00135 screen.blit(tiledata.tile[pinfo->direction*num_frames_action+current_frame],
00136 makerect(pinfo->paul_x, pinfo->paul_y, pinfo->tilesize, pinfo->tilesize));
00137 }