Exemple #1
0
void Player::draw()
{
    SDL_Rect clip;

    clip.x = (PLAYER_WIDTH*3)*get_direction() + (PLAYER_WIDTH*(get_frame()/10));
    clip.y = 0;
    clip.h = PLAYER_HEIGTH;
    clip.w = PLAYER_WIDTH;

    //Apply the message to the screen
    ih_apply_surface( (get_x() - camera_x()), (get_y() - camera_y()), PLAYER, &clip);
}
Exemple #2
0
NE_API void update_camera(ortho_camera* camera) {
	if (camera->target) {
		transform3f* target = camera->target;
		const int delta_x = (int) ((target->position.x + target->scale.x / 2.0f) - camera_width(camera) / camera->target_chase_aspect.x);
		const int delta_y = (int) ((target->position.y + target->scale.y / 2.0f) - camera_height(camera) / camera->target_chase_aspect.y);
		camera->transform.position.x += (int) (((float) delta_x - camera_x(camera)) * camera->target_chase_speed.x);
		camera->transform.position.y += (int) (((float) delta_y - camera_y(camera)) * camera->target_chase_speed.y);
	}
	camera->transform.rotation.z = fmodf(camera->transform.rotation.z, 360.0f);
	if (camera->transform.rotation.z < 0.0f) {
		camera->transform.rotation.z += 360.0f;
	}
}
Exemple #3
0
void Player::center()
{

    if((get_x() - BORDER_X) < camera_x())
    {
        move_camera((get_x() - BORDER_X) - camera_x(), 0);
    }
    if((get_y() - BORDER_Y) < camera_y())
    {
        move_camera(0, (get_y() - BORDER_Y) - camera_y());
    }
    if((get_x() + PLAYER_WIDTH  + BORDER_X) > (camera_x() + SCREEN_WIDTH))
    {
        move_camera((get_x() + PLAYER_WIDTH  + BORDER_X) - (camera_x() + SCREEN_WIDTH), 0);
    }
    if((get_y() + PLAYER_HEIGTH + BORDER_Y) > (camera_y() + SCREEN_HEIGHT))
    {
        move_camera(0, (get_y() + PLAYER_HEIGTH + BORDER_Y) - (camera_y() + SCREEN_HEIGHT));
    }


}
Exemple #4
0
void Game::handle_events(Player *player)
{
    SDL_Rect    *tmp;
    Box         *tmpbox;

    //The mouse offsets
    int32_t x = 0;
    int32_t y = 0;

    //Handle events for player
    //If a key was pressed
    if( event.type == SDL_KEYDOWN )
    {
        //Adjust the velocity
        switch( event.key.keysym.sym )
        {
            case SDLK_UP:
                player->jump();
                break;
            case SDLK_LEFT:
                player->set_x_vel(player->get_x_vel() - PLAYER_VEL);
                break;
            case SDLK_RIGHT:
                player->set_x_vel(player->get_x_vel() + PLAYER_VEL);
                break;
            default:
                break;
        }
    }
    //If a key was released
    else if( event.type == SDL_KEYUP )
    {
        //Adjust the velocity
        switch( event.key.keysym.sym )
        {
            case SDLK_UP:
                //Nothing to do here really. Set some flags maybe.
                break;
            case SDLK_LEFT:
                player->set_x_vel(player->get_x_vel() + PLAYER_VEL);
                break;
            case SDLK_RIGHT:
                player->set_x_vel(player->get_x_vel() - PLAYER_VEL);
                break;
            default:
                break;
        }
    }
    //If a mouse button was pressed
    else if( event.type == SDL_MOUSEBUTTONDOWN )
    {
        //If the left mouse button was pressed
        if( event.button.button == SDL_BUTTON_LEFT )
        {
            mouseleft_flag = YES;
        }
        //If the right mouse button was pressed
        if( event.button.button == SDL_BUTTON_RIGHT )
        {
            mouseright_flag = YES;
        }
    }
    else if( event.type == SDL_MOUSEBUTTONUP )
    {
        //If the left mouse button was pressed
        if( event.button.button == SDL_BUTTON_LEFT )
        {
            mouseleft_flag = NO;
        }
        //If the right mouse button was pressed
        if( event.button.button == SDL_BUTTON_RIGHT )
        {
            mouseright_flag = NO;
        }
    }
    //If mouse moved
    else if( event.type == SDL_MOUSEMOTION )
    {
        set_cursor(event.button.x, event.button.y);
    }
    if(mouseleft_flag == YES)
    {
        //Get the mouse offsets
        x = get_cursor_x() + camera_x();
        y = get_cursor_y() + camera_y();

        add(new Box(x,y,DEF_BOX_SIZE,DEF_BOX_SIZE, YES));
    }
    if(mouseright_flag == YES)
    {
        SDL_Rect eraser;
        //Get the mouse offsets
        eraser.x = get_cursor_x() + camera_x();
        eraser.y = get_cursor_y() + camera_y();
        eraser.h = DEF_BOX_SIZE;
        eraser.w = DEF_BOX_SIZE;
        //If the mouse is over the box
        start_over();
        while(get_curr())
        {
            tmpbox = get_curr();
            if(tmpbox != NULL)
            {
                tmp = tmpbox->get_box();
            }

            if(check_collision(tmp, &eraser))
            {
                remove();
            }
            traverse();
        }

    }


}