Skip to content

Commit

Permalink
#12 added healthbar
Browse files Browse the repository at this point in the history
  • Loading branch information
KOTerra committed Jul 20, 2023
1 parent 6d7826e commit bd02ebd
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Disposable;
import com.strafergame.Strafer;
import com.strafergame.game.ecs.component.AnimationComponent;
import com.strafergame.game.ecs.component.Box2dComponent;
import com.strafergame.game.ecs.component.EntityTypeComponent;
import com.strafergame.game.ecs.component.MovementComponent;
import com.strafergame.game.ecs.component.PlayerComponent;
import com.strafergame.game.ecs.component.PositionComponent;
import com.strafergame.game.ecs.component.SpriteComponent;
import com.strafergame.game.ecs.component.*;
import com.strafergame.game.ecs.system.AnimationSystem;
import com.strafergame.game.ecs.system.CameraSystem;
import com.strafergame.game.ecs.system.MovementSystem;
Expand Down Expand Up @@ -74,6 +68,10 @@ public Entity createPlayer(final Vector2 playerSpawnLocation) {

Box2dComponent b2dCmp = this.createComponent(Box2dComponent.class);
player.add(b2dCmp);

HealthComponent hlthComponent = this.createComponent(HealthComponent.class);
player.add(hlthComponent);

this.addEntity(player);
return player;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.strafergame.game.ecs.component;

import com.badlogic.ashley.core.Component;
import com.badlogic.gdx.utils.Pool.Poolable;

public class HealthComponent implements Component, Poolable {
int hitPoints=0;

@Override
public void reset() {
hitPoints=0;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package com.strafergame.game.ecs.component;

import com.badlogic.ashley.core.Component;
import com.strafergame.game.entities.EntityDirection;
import com.badlogic.gdx.utils.Pool.Poolable;

public class MovementComponent implements Component {
public EntityDirection direction = EntityDirection.s;
public class MovementComponent implements Component, Poolable {
public float dirX = 0f;
public float dirY = 0f;
public float speed = 0f;
public float dashForce = 0f;

@Override
public void reset() {
dirX=0f;
dirY=0f;
speed=0f;
dashForce=0f;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.badlogic.ashley.core.Component;
import com.badlogic.gdx.graphics.g2d.Sprite;

public class SpriteComponent implements Component {
public class SpriteComponent implements Component{
public Sprite sprite;
public float width;
public float height;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.strafergame.graphics;

import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.math.Vector3;
Expand Down Expand Up @@ -190,11 +191,11 @@ public void update() {
default:
break;
}

Strafer.worldCamera.position
.set(Math.round(Strafer.worldCamera.position.x / Strafer.SCALE_FACTOR) * Strafer.SCALE_FACTOR,
Math.round(Strafer.worldCamera.position.y / Strafer.SCALE_FACTOR) * Strafer.SCALE_FACTOR, 0)
.interpolate(cameraSnapPosition, alpha, interpolation);
.interpolate(cameraSnapPosition, alpha , interpolation);

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ public boolean buttonUp(Controller controller, int buttonIndex) {
@Override
public boolean axisMoved(Controller controller, int axisIndex, float value) {

float axis = controller.getAxis(axisIndex);
return value > 0 ? axis >= value : axis <= value;
//float axis = controller.getAxis(axisIndex);
//return value > 0 ? axis >= value : axis <= value;
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void render(float delta) {
public void resize(int width, int height) {
Strafer.extendViewport.update(width, height);
Strafer.uiScreenViewport.update(width, height, true);
hud.resize();
}

@Override
Expand Down
39 changes: 31 additions & 8 deletions StrafeOverdead/core/src/com/strafergame/ui/HUD.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
package com.strafergame.ui;

import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Event;
import com.badlogic.gdx.scenes.scene2d.EventListener;
import com.badlogic.gdx.scenes.scene2d.ui.ProgressBar;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Align;
import com.kotcrab.vis.ui.VisUI;
import com.kotcrab.vis.ui.widget.VisProgressBar;
import com.strafergame.Strafer;
import com.strafergame.input.PlayerControl;

public class HUD extends Table {

private VisProgressBar healthBar;
public HUD() {
setFillParent(true);
pad(40);

align(Align.center);
Strafer.uiManager.addActor(this);
this.healthBar= makeHealthBar();

mockUI();

}

private void mockUI() {
private VisProgressBar makeHealthBar(){
VisProgressBar healthbar=new VisProgressBar(0,100,1,false);

setFillParent(true);
pad(150);
defaults().space(20);
align(Align.bottomLeft);
Strafer.uiManager.getRoot().addActor(this);

add(healthbar).expandX().top().left();
row();
add(new Table()).fillY().expandY();
row();
return healthbar;
}
private void mockUI() {
align(Align.bottomLeft);
/*
* VisTextButton mockButton = new VisTextButton(Strafer.i18n.get("hud")); row();
* add(mockButton); mockButton.addListener(new ChangeListener() {
Expand All @@ -32,7 +50,7 @@ private void mockUI() {
*/
final float deadzone = 5f;
final Touchpad touchpad = new Touchpad(deadzone, VisUI.getSkin());
touchpad.setScale(15);
touchpad.setScale(20);
touchpad.setOrigin(Align.center);
touchpad.addListener(new ChangeListener() {

Expand All @@ -45,7 +63,12 @@ public void changed(ChangeEvent event, Actor actor) {

}
});
add(touchpad);
add(touchpad).bottom().left().pad(60);
//row();
}
public void resize() {
setBounds(0, 0, Strafer.uiManager.getWidth(), Strafer.uiManager.getHeight());

}

public void hide() {
Expand Down

0 comments on commit bd02ebd

Please sign in to comment.