Subversion Repositories battle

[/] [trunk/] [Battle/] [Player.cpp] - Diff between revs 171 and 173

Show entire file | Details | Blame | View Log

Rev 171 Rev 173
Line 88... Line 88...
#define SPEED_VERT 2
#define SPEED_VERT 2
 
 
// Freeze time
// Freeze time
#define PLAYER_FREEZE_FRAMES 30
#define PLAYER_FREEZE_FRAMES 30
 
 
 
// Shield time
 
#define PLAYER_SHIELD_FRAMES 180
 
 
Player::Player(int character, int number) {
Player::Player(int character, int number) {
        name = CHARACTERS[character].name;
        name = CHARACTERS[character].name;
        this->character = character;
        this->character = character;
        this->number = number;
        this->number = number;
 
 
Line 163... Line 166...
        is_frozen = false;
        is_frozen = false;
        freeze_start = 0;
        freeze_start = 0;
 
 
        is_shielded = false;
        is_shielded = false;
        shield_start = 0;
        shield_start = 0;
        shield_time = 0;
 
        shield_frame = 0;
        shield_frame = 0;
 
 
        bounce_direction_x = 0;
        bounce_direction_x = 0;
        bounce_direction_y = 0;
        bounce_direction_y = 0;
 
 
Line 194... Line 196...
        cycle_direction = CYCLE_UP;
        cycle_direction = CYCLE_UP;
}
}
 
 
void Player::draw(SDL_Surface * screen, bool marker) {
void Player::draw(SDL_Surface * screen, bool marker) {
        SDL_Rect rect;
        SDL_Rect rect;
        SDL_Rect shield_s, shield_d;
        SDL_Surface * sprites;
 
 
        rect.x = position->x;
        rect.x = position->x;
        rect.y = position->y;
        rect.y = position->y;
 
 
 
        sprites = this->sprites;
 
 
        // Dead players are not visible
        // Dead players are not visible
        if(is_dead && Gameplay::frame - dead_start > 120) {
        if(is_dead && Gameplay::frame - dead_start > 120) {
                return;
                return;
        }
        }
 
 
        if(is_shielded) {
 
                shield_s.x = 0; shield_s.y = 0;
 
                shield_s.w = 40; shield_s.h = 58;
 
 
 
                shield_d.x = rect.x - 9;
 
                shield_d.y = rect.y - 7;
 
 
 
                shield_frame = (shield_frame + 1) % 20;
 
                if(shield_frame > 10) shield_s.x += shield_s.w;
 
        }
 
 
 
        // Check if player is hit and cycle between a show and a hide of the player to create
        // Check if player is hit and cycle between a show and a hide of the player to create
        // a flicker effect
        // a flicker effect
        if(is_hit) {
        if(is_hit) {
                hit_flicker_frame = (hit_flicker_frame + 1) % 10;
                hit_flicker_frame = (hit_flicker_frame + 1) % 10;
                if(hit_flicker_frame < 5)
                if(hit_flicker_frame < 5)
                        return;
                        return;
        }
        }
 
 
        if(is_shielded)
        if(is_shielded) {
                SDL_BlitSurface(Main::graphics->shield, &shield_s, screen, &shield_d);
                if((shield_start + PLAYER_SHIELD_FRAMES) - Gameplay::frame > 60) {
 
                        sprites = Main::graphics->shield;
 
                } else {
 
                        shield_frame = (shield_frame + 1) % 10;
 
                        if(shield_frame >= 5)
 
                                sprites = Main::graphics->shield;
 
                }
 
        }
 
 
        SDL_BlitSurface(sprites, Main::graphics->player_clip[current_sprite], screen, &rect);
        SDL_BlitSurface(sprites, Main::graphics->player_clip[current_sprite], screen, &rect);
 
 
        // If the player is going out the side of the screen, we want it to
        // If the player is going out the side of the screen, we want it to
        // appear on the other side.
        // appear on the other side.
        if(position->x >= WINDOW_WIDTH - PLAYER_W) {
        if(position->x >= WINDOW_WIDTH - PLAYER_W) {
                rect.x = position->x - WINDOW_WIDTH;
                rect.x = position->x - WINDOW_WIDTH;
                rect.y = position->y;
                rect.y = position->y;
 
 
                if(is_shielded) {
 
                        shield_d.x = rect.x - 9;
 
                        shield_d.y = rect.y - 7;
 
                        SDL_BlitSurface(Main::graphics->shield, &shield_s, screen, &rect);
 
                }
 
 
 
                SDL_BlitSurface(sprites, Main::graphics->player_clip[current_sprite], screen, &rect);
                SDL_BlitSurface(sprites, Main::graphics->player_clip[current_sprite], screen, &rect);
        }
        }
        if(position->x <= 0) {
        if(position->x <= 0) {
                rect.x = position->x + WINDOW_WIDTH;
                rect.x = position->x + WINDOW_WIDTH;
                rect.y = position->y;
                rect.y = position->y;
 
 
                if(is_shielded) {
 
                        shield_d.x = rect.x - 9;
 
                        shield_d.y = rect.y - 7;
 
                        SDL_BlitSurface(Main::graphics->shield, &shield_s, screen, &rect);
 
                }
 
 
 
                SDL_BlitSurface(sprites, Main::graphics->player_clip[current_sprite], screen, &rect);
                SDL_BlitSurface(sprites, Main::graphics->player_clip[current_sprite], screen, &rect);
        }
        }
 
 
        // Show marker if the player is above the screen
        // Show marker if the player is above the screen
        if(position->y + position->h <= 0) {
        if(position->y + position->h <= 0) {
Line 319... Line 307...
                        is_frozen = false;
                        is_frozen = false;
                }
                }
        }
        }
 
 
        if(is_shielded) {
        if(is_shielded) {
                if(Gameplay::frame > shield_start + shield_time) {
                if(Gameplay::frame > shield_start + PLAYER_SHIELD_FRAMES) {
                        is_shielded = false;
                        is_shielded = false;
                }
                }
 
                if(Gameplay::frame == (shield_start + PLAYER_SHIELD_FRAMES - 60)) {
 
                        Main::audio->play(SND_SHIELD, position->x + (position->w / 2));
 
                }
        }
        }
 
 
        speedx = SPEED_HORIZ;
        speedx = SPEED_HORIZ;
 
 
        momentumx_old = momentumx;
        momentumx_old = momentumx;