Skip to content

Commit

Permalink
added currency
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmasB committed Dec 31, 2021
1 parent 0384ca2 commit f16f091
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.almasb.fxglgames.td;

import com.almasb.fxgl.core.EngineService;
import com.almasb.fxgl.core.collection.PropertyMap;
import javafx.beans.property.IntegerProperty;

/**
* @author Almas Baimagambetov (almaslvl@gmail.com)
*/
public class CurrencyService extends EngineService {

private PropertyMap map = new PropertyMap();

public CurrencyService() {
map.setValue("currency", 0);
}

public int getCurrency() {
return map.getInt("currency");
}

public void setCurrency(int value) {
map.setValue("currency", value);
}

public IntegerProperty currencyProperty() {
return map.intProperty("currency");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ protected void initSettings(GameSettings settings) {
settings.setIntroEnabled(false);
settings.setMainMenuEnabled(true);
settings.setGameMenuEnabled(true);
settings.addEngineService(CurrencyService.class);
settings.setSceneFactory(new SceneFactory() {
@Override
public FXGLMenu newMainMenu() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.almasb.fxglgames.td.ui;

import javafx.scene.Parent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;

/**
* @author Almas Baimagambetov (almaslvl@gmail.com)
*/
public class CurrencyIcon extends Parent {

public CurrencyIcon() {
var circleOuter = new Circle(20, Color.YELLOW);
circleOuter.setStroke(Color.BLACK);
circleOuter.setStrokeWidth(4.0);

var circleInner = new Circle(11, Color.YELLOW.brighter());
circleInner.setStroke(Color.BLACK);
circleInner.setStrokeWidth(2.0);
circleInner.setTranslateY(-4);

getChildren().addAll(circleOuter, circleInner);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.almasb.fxglgames.td.ui;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxglgames.td.CurrencyService;
import javafx.scene.Parent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

/**
* @author Almas Baimagambetov (almaslvl@gmail.com)
*/
public class CurrencyView extends Parent {

public CurrencyView() {
var bg = new Rectangle(100, 34, Color.color(0.5, 0.5, 0.5, 0.75));
bg.setStroke(Color.color(0, 0, 0, 0.9));
bg.setStrokeWidth(2.5);
bg.setArcWidth(10);
bg.setArcHeight(10);

var icon = new CurrencyIcon();
icon.setTranslateX(15);
icon.setTranslateY(bg.getHeight() / 2.0);

var text = FXGL.getUIFactoryService().newText("", Color.WHITE, 22.0);
text.setTranslateX(55);
text.setTranslateY(25);

text.textProperty().bind(FXGL.getService(CurrencyService.class).currencyProperty().asString());

getChildren().addAll(bg, icon, text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.almasb.fxglgames.td.TowerDefenseApp;
import com.almasb.fxglgames.td.TowerDefenseFactory;
import com.almasb.fxglgames.td.data.LevelData;
import com.almasb.fxglgames.td.ui.CurrencyView;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Parent;
Expand Down Expand Up @@ -155,14 +156,19 @@ public TowerDefenseMainMenu() {
contentBox.setTranslateX(bgInnerRight.getTranslateX() + 25);
contentBox.setTranslateY(220);

var currencyView = new CurrencyView();
currencyView.setTranslateX(getAppWidth() - 300);
currencyView.setTranslateY(15);

getContentRoot().getChildren().addAll(
bg,
bgInnerLeft,
bgInnerRight,
menuBox,
contentBox,
title,
version
version,
currencyView
);
}

Expand Down

0 comments on commit f16f091

Please sign in to comment.