Skip to content

Commit

Permalink
use hex image
Browse files Browse the repository at this point in the history
  • Loading branch information
hundun000 committed Sep 10, 2023
1 parent ced3512 commit de7423e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
Binary file added IdleDemo-game/core/assets/CellIcons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ protected RootSaveData genereateStarterRootSaveData() {
.prototypeId(ConstructionPrototypeId.COOKIE_CLICK_PROVIDER)
.level(0)
.workingLevel(0)
.position( new GridPosition(1, 1))
.position( new GridPosition(0, 0))
.build(),
ConstructionPrototypeId.COOKIE_AUTO_PROVIDER,
ConstructionSaveData.builder()
.prototypeId(ConstructionPrototypeId.COOKIE_AUTO_PROVIDER)
.level(1)
.workingLevel(1)
.position( new GridPosition(1, -1))
.position( new GridPosition(0, -1))
.build(),
ConstructionPrototypeId.COOKIE_AUTO_SELLER,
ConstructionSaveData.builder()
.prototypeId(ConstructionPrototypeId.COOKIE_AUTO_SELLER)
.level(1)
.workingLevel(0)
.position( new GridPosition(-1, 1))
.position( new GridPosition(-1, 0))
.build()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ public void lazyInitOnGameCreateStage2() {
gameAreaBackMap.put(GameArea.AREA_FOREST, regions[0][2]);
//gameAreaBackMap.put(GameArea.AREA_WIN, regions[0][3]);
}

{
Texture texture = new Texture(Gdx.files.internal("CellIcons.png"));
TextureRegion[][] regions = TextureRegion.split(texture, 675, 733);
defaultAreaBack = regions[0][0];
constructionHexImageMap.put(ConstructionPrototypeId.COOKIE_CLICK_PROVIDER, regions[0][1]);
constructionHexImageMap.put(ConstructionPrototypeId.COOKIE_AUTO_PROVIDER, regions[0][2]);
constructionHexImageMap.put(ConstructionPrototypeId.COOKIE_AUTO_SELLER, regions[0][3]);
//gameAreaBackMap.put(GameArea.AREA_WIN, regions[0][3]);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import hundun.gdxgame.corelib.base.util.DrawableFactory;
import hundun.gdxgame.idledemo.DemoIdleGame;
import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction;
Expand Down Expand Up @@ -54,7 +55,7 @@ public ChessVM(DeskAreaVM deskAreaVM, BaseConstruction deskData) {
public void updateUI(){

this.mainLabel.setText(deskData.getId());
image.setDrawable(DrawableFactory.createAlphaBoard(1, 1, Color.GRAY, 0.8f));
image.setDrawable(new TextureRegionDrawable(game.getTextureManager().getConstructionHexImage(deskData.getPrototypeId())));
Vector2 uiPosition = calculatePosition(deskData.getSaveData().getPosition().getX(), deskData.getSaveData().getPosition().getY());
this.setBounds(
uiPosition.x,
Expand All @@ -66,9 +67,10 @@ public void updateUI(){

private static Vector2 calculatePosition(int gridX, int gridY)
{
float hexBaseSize = 100;
Vector2 newposition = new Vector2(0, 0);
newposition.y += 0.75f * gridY;
newposition.x += Math.sqrt(3) / 2 * (gridX - (Math.abs(gridY) % 2) / 2.0f);
newposition.y += hexBaseSize * 0.75f * gridY;
newposition.x += hexBaseSize * Math.sqrt(3.0f) / 2 * (gridX - (Math.abs(gridY) % 2) / 2.0f);
return newposition;
}

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

A self-made framework for idle game, using engine Libgdx. And some games using the idle-framework with various themes. Maybe someday these sub-games can combine to a big-game which allows player change areas between themes.

use [libgdx-hundun-lib](https://github.com/hundun000/libgdx-hundun-lib) [![](https://jitpack.io/v/hundun000/libgdx-hundun-lib.svg)](https://jitpack.io/#hundun000/libgdx-hundun-lib)

### subprojects

- [idle-framework](/share): the framework for idle game [![](https://jitpack.io/v/hundun000/hundun-idle-all.svg)](https://jitpack.io/#hundun000/hundun-idle-all)
- [idle-framework](/idleshare): the framework for idle game [![](https://jitpack.io/v/hundun000/hundun-idle-all.svg)](https://jitpack.io/#hundun000/hundun-idle-all)
- [IdleDemo-game](/IdleDemo-game): a demo game using the idle-framework, can run in desktop & html.

Other game using this idle-framework:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import lombok.Getter;

public abstract class AbstractTextureManager {
Expand All @@ -32,7 +33,7 @@ public abstract class AbstractTextureManager {
protected Map<String, TextureRegion> gameAreaLeftPartRegionMap = new HashMap<>();
protected Map<String, TextureRegion> gameAreaRightPartRegionMap = new HashMap<>();
protected Map<String, TextureRegion> gameAreaBackMap = new HashMap<>();

protected Map<String, TextureRegion> constructionHexImageMap = new HashMap<>();
protected TextureRegion defaultIcon;
protected TextureRegion defaultAreaBack;

Expand Down Expand Up @@ -64,4 +65,8 @@ public TextureRegion getGameAreaTexture(String key, boolean longVersion) {
}

public abstract void lazyInitOnGameCreateStage2();

public TextureRegion getConstructionHexImage(String constructionId) {
return constructionHexImageMap.getOrDefault(constructionId, defaultIcon);
}
}

0 comments on commit de7423e

Please sign in to comment.