Repository navigation
Slide
private void slide(boolean pressed) {
if (pressed) {
sliding = true;
SlideTimer = 0;
textureRenderComponent.setTexture(SLIDE_TEXTURE);
slidingAction(walkDirection.cpy());
} else {
sliding = false;
textureRenderComponent.setTexture(NORMAL_TEXTURE);
}
}
It is used for slide feature for player. Pressed is used to make sure the key for slide (left shift) is pressed. Each time the key is pressed, the timer will be reset to 0. textureRenderComponent.setTexture is used to change the body of player.
private void slidingAction(Vector2 direction) { Body body = physicsComponent.getBody(); Vector2 impulse = direction.cpy().scl(slidespeed); body.applyLinearImpulse(impulse, body.getWorldCenter(), true); }
Impulse is used to give a player a impulse, it can make player looked faster. Slide should be worked when player walking, so it need not use something to record the last direction and only make player smaller.
In other way, slide is crouch + dash. It will be looked like slide.
private void timerforslide(){
if(sliding!=true)
return;
SlideTimer += Gdx.graphics.getDeltaTime();
if(SlideTimer >= SlideMaxTime){//finish slide
sliding = false;
textureRenderComponent.setTexture(NORMAL_TEXTURE);
}
}
It is a timer for slide. It can record the time of slide. When timer is over the max time of slide , slide should be finished. So, sliding will be marked as false and use textureRenderComponent.setTexture to change the body of player to be normal.