Pārlūkot izejas kodu

added energy system

Hudriwudri 5 gadi atpakaļ
vecāks
revīzija
5ae672fbce

+ 1 - 1
src/pathgame/PathGame.java

@@ -16,7 +16,7 @@ public class PathGame implements IGame
     private final TileMap map = TileMapGenerator.getMap(50, 50);
 
     private final PlayerRenderer playerRenderer = new PlayerRenderer();
-    private final Player player = new Player();
+    private final Player player = new Player(100);
     
     private float lastScale = 1.0f;
     private float scale = 1.0f;

+ 24 - 1
src/pathgame/gameplay/Player.java

@@ -15,9 +15,13 @@ public class Player
     private float velX = 0;
     private float velY = 0;
     private boolean isMoving = false;
+    
+    private final int energySupply;
+    private int energyUsed = 0;
 
-    public Player()
+    public Player(int energySupply)
     {
+        this.energySupply = energySupply;
     }
 
     public float getLastX()
@@ -51,6 +55,10 @@ public class Player
             velY = 0.0f;
             if(isMoving)
             {
+                //System.out.print(map.getTile((int)x,(int) y).getEnergyCost());
+                energyUsed += map.getTile((int)x,(int) y).getEnergyCost();
+                
+                System.out.print(energyUsed);
                 //TODO: +Energy
                 //Tile currTile = map.getTile((int)x,(int) y);
 
@@ -86,4 +94,19 @@ public class Player
     {
         return Math.abs(x - Math.round(x)) < 0.01f && Math.abs(y - Math.round(y)) < 0.01f;
     }
+    
+    public int getEnergySupply()
+    {
+        return energySupply;
+    }
+    
+    public int getEnergyLeft()
+    {
+        return energySupply - energyUsed;
+    }
+    
+    public int getEnergyUsed()
+    {
+        return energyUsed;
+    }
 }

+ 8 - 1
src/pathgame/tilemap/Tile.java

@@ -8,6 +8,7 @@ public class Tile
 {
     private static int idCounter = 0;
     private static Tile[] tiles = new Tile[8];
+    private final int energyCost;
     
     private static int addTile(Tile t)
     {
@@ -40,9 +41,10 @@ public class Tile
     /** Creates a new tile, which is automatically registered.
      *
      */
-    public Tile()
+    public Tile(int energyCost)
     {
         id = addTile(this);
+        this.energyCost = energyCost;
     }
 
     /** Returns the id of the tile.
@@ -53,4 +55,9 @@ public class Tile
     {
         return id;
     }
+    
+    public final int getEnergyCost()
+    {
+        return energyCost;
+    }
 }

+ 1 - 0
src/pathgame/tilemap/TileMap.java

@@ -81,5 +81,6 @@ public class TileMap
     {
         dirty = false;
     }
+    
 }
 

+ 12 - 12
src/pathgame/tilemap/Tiles.java

@@ -2,13 +2,13 @@ package pathgame.tilemap;
 
 public class Tiles
 {
-    public final static Tile GRASS = new Tile();
-    public final static Tile GRASS_WITH_STONE = new Tile();
-    public final static Tile GRASS_WITH_6_BUSHES = new Tile();
-    public final static Tile GRASS_WITH_3_BUSHES = new Tile();
-    public final static Tile GRASS_WITH_FLOWERS = new Tile();
-    public final static Tile GRASS_WITH_HILL = new Tile();
-    public final static Tile GRASS_WITH_EARTH = new Tile();
+    public final static Tile GRASS = new Tile(1);
+    public final static Tile GRASS_WITH_STONE = new Tile(1);
+    public final static Tile GRASS_WITH_6_BUSHES = new Tile(1);
+    public final static Tile GRASS_WITH_3_BUSHES = new Tile(1);
+    public final static Tile GRASS_WITH_FLOWERS = new Tile(1);
+    public final static Tile GRASS_WITH_HILL = new Tile(1);
+    public final static Tile GRASS_WITH_EARTH = new Tile(1);
     
     public final static Tile[] GRASS_VARIANTS = new Tile[]
     {
@@ -16,9 +16,9 @@ public class Tiles
         GRASS_WITH_FLOWERS, GRASS_WITH_HILL, GRASS_WITH_EARTH
     };
     
-    public final static Tile FOREST = new Tile();
-    public final static Tile SHALLOW_WATER = new Tile();
-    public final static Tile DEEP_WATER = new Tile();
-    public final static Tile HILL = new Tile();
-    public final static Tile MOUNTAIN = new Tile();
+    public final static Tile FOREST = new Tile(2);
+    public final static Tile SHALLOW_WATER = new Tile(3);
+    public final static Tile DEEP_WATER = new Tile(5);
+    public final static Tile HILL = new Tile(3);
+    public final static Tile MOUNTAIN = new Tile(5);
 }