Skip to content

Commit

Permalink
Added features to Bossbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Pegacraffft committed Jul 10, 2020
1 parent 035e369 commit 5124d16
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
6 changes: 6 additions & 0 deletions src/main/java/engine/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ public abstract class Scene {
* The display, where this scene is attached to.
*/
public Display display;
/**
* The key listener, where this scene is attached to.
*/
public Keyboard keyListener;
/**
* The mouse listener, where this scene is attached to.
*/
public Mouse mouseListener;

/**
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/engine/editor/EditScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import engine.editor.menu.Sprite;
import engine.listeners.MouseButtons;
import engine.mechanics.*;
import engine.rendering.Graphics;
import game.TestObject;

import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
Expand Down Expand Up @@ -58,16 +56,10 @@ public void init() {
SettingsScene scene = (SettingsScene) (Game.getScene("Settings"));
grid.setWidth(scene.gridWidth);
grid.setHeight(scene.gridHeight);
addObject(env);
addObject(grid);
for (int i = 0; i < 10; i++)
addObject(new Tile(1100 + (i / 5) * 90, (i % 5) * 90));

Bossbar test = new Bossbar(20, 20, 100, 30)
.setBarColor(Color.pink)
.setBackgroundColor(Color.red)
.setCurrentValue(34)
.setMaxValue(120);
addObject(test);
addObject(env);
addObject(backPanel);
addObject(scaleBox);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/engine/editor/menu/Sprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Sprite implements Entity {
private final String spritePath;
private final double scale;
public boolean delete = false;
private final Scene scene;

/**
* create a sprite at a given location using a position, a scale,a path to an image, and a scene to be bound to.
Expand All @@ -37,6 +38,7 @@ public Sprite(int x, int y, double scale, String spritePath, Scene scene) {
this.y = y;
this.spritePath = spritePath;
this.scale = scale;
this.scene = scene;
BufferedImage sprite = Image.load(spritePath);
spriteScaled = sprite.getScaledInstance((int) (sprite.getWidth() * scale),
(int) (sprite.getHeight() * scale), 3);
Expand All @@ -60,7 +62,9 @@ public void init() {

@Override
public void logicLoop() {
// TBD
if (scene.mouseListener.isHeld(3))
if (h.isInside(scene.mouseListener.getMousePos()))
delete = true;
}

@Override
Expand Down
28 changes: 24 additions & 4 deletions src/main/java/engine/mechanics/Bossbar.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package engine.mechanics;

import engine.Entity;
import engine.rendering.Image;

import java.awt.*;
import java.awt.image.BufferedImage;
Expand Down Expand Up @@ -31,10 +32,19 @@ public void logicLoop() {

@Override
public void renderLoop() {
g.setColor(backgroundColor);
g.fillRect(x, y, width, height);
g.setColor(barColor);
g.fillRect(x, y, (int) (width * ((double) currentValue / (double) maxValue)), height);
if (backgroundImage == null) {
g.setColor(backgroundColor);
g.fillRect(x, y, width, height);
g.setColor(barColor);
} else {
g.drawImage(backgroundImage, x, y, width, height, null);
}
if (barImage == null)
g.fillRect(x, y, (int) (width * ((double) currentValue / (double) maxValue)), height);
else {
BufferedImage croped = barImage.getSubimage(0, 0, (int) (barImage.getWidth() * ((double) currentValue / (double) maxValue)), barImage.getHeight());
g.drawImage(croped, x, y, (int) (width * ((double) currentValue / (double) maxValue)), height, null);
}
}

public Bossbar setX(int x) {
Expand Down Expand Up @@ -77,4 +87,14 @@ public Bossbar setBarColor(Color barColor) {
this.barColor = barColor;
return this;
}

public Bossbar setBackgroundImage(String path) {
backgroundImage = Image.load(path);
return this;
}

public Bossbar setBarImage(String path) {
barImage = Image.load(path);
return this;
}
}
4 changes: 2 additions & 2 deletions src/main/java/engine/rendering/Graphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public static void graphicsLoop() {
* @param y The y offset
*/
public static void moveCam(int x, int y) {
xOffset = x;
yOffset = -y;
xOffset = -x + 640;
yOffset = -y + 360;
}

/**
Expand Down

0 comments on commit 5124d16

Please sign in to comment.