Skip to content

Commit

Permalink
Merge pull request #31 from MAKMED1337/15-use-properties-instead-of-s…
Browse files Browse the repository at this point in the history
…ome-constants

Added .properties files
  • Loading branch information
welleyth authored Jun 16, 2024
2 parents 3ac0112 + c288704 commit 1da120b
Show file tree
Hide file tree
Showing 37 changed files with 237 additions and 104 deletions.
51 changes: 0 additions & 51 deletions core/src/com/po/fuck/model/Constants.java

This file was deleted.

13 changes: 0 additions & 13 deletions core/src/com/po/fuck/model/Core.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.po.fuck.model;

import static com.po.fuck.model.Constants.GAME_BORDER;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
Expand Down Expand Up @@ -35,17 +33,6 @@ public static void initialize() {
Manager.create(new Room(new Vector2(1, 0),
new Sprite(new Texture("island2.png")).getWidth(),
new Sprite(new Texture("island2.png")).getHeight()));

// Creating some game borders to destroy the bullets that went off the map.
// We can not use here VERTICAL/HORIZONTAL, because if something went off the
// map, then we want to catch with a thick wall, because it can be laggy or
// something else.
final int HUGE = 1000, HUGE2 = 2 * HUGE, SIZE = GAME_BORDER + HUGE2;
Manager.create(new InvisibleWall(new Vector2(-GAME_BORDER - HUGE, 0), new Vector2(HUGE2, SIZE)));
Manager.create(new InvisibleWall(new Vector2(-GAME_BORDER + HUGE, 0), new Vector2(HUGE2, SIZE)));

Manager.create(new InvisibleWall(new Vector2(0, -GAME_BORDER - HUGE), new Vector2(SIZE, HUGE2)));
Manager.create(new InvisibleWall(new Vector2(0, -GAME_BORDER + HUGE), new Vector2(SIZE, HUGE2)));
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions core/src/com/po/fuck/model/ObjectFollower.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.po.fuck.model;

import com.badlogic.gdx.math.Vector2;
import static com.po.fuck.model.constants.CameraConstants.SPEED;

import static com.po.fuck.model.Constants.CAMERA_SPEED;
import com.badlogic.gdx.math.Vector2;

public final class ObjectFollower implements Updatable {
private Vector2 position = new Vector2();
Expand All @@ -11,7 +11,7 @@ public final class ObjectFollower implements Updatable {
@Override
public void update(float delta) {
// https://lisyarus.github.io/blog/posts/exponential-smoothing.html
float factor = 1 - (float) Math.exp(-delta * CAMERA_SPEED);
float factor = 1 - (float) Math.exp(-delta * SPEED);
position.add(target.cpy().sub(position).scl(factor));
}

Expand Down
10 changes: 6 additions & 4 deletions core/src/com/po/fuck/model/Player.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.po.fuck.model;

import static com.po.fuck.model.Constants.DEFAULT_SPEED;
import static com.po.fuck.model.Constants.PLAYERS_HEALTH;
import static com.po.fuck.model.constants.BalanceConstants.DEFAULT_SPEED;
import static com.po.fuck.model.constants.BalanceConstants.PLAYERS_HEALTH;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.po.fuck.controller.KeyboardController;
import com.po.fuck.controller.MouseController;
import com.po.fuck.model.constants.BalanceConstants;
import com.po.fuck.model.constants.TagsConstants;
import com.po.fuck.model.lifetime.Managed;
import com.po.fuck.model.lifetime.Manager;
import com.po.fuck.model.movement.BasicMovement;
Expand All @@ -24,8 +26,8 @@ public class Player extends Entity {
movement = Manager.create(
new Boost(
new BasicMovement(this, DEFAULT_SPEED),
Constants.BOOST_DISTANCE, Constants.BOOST_DURATION, Constants.BOOST_COOLDOWN));
teamTag = Constants.PLAYER_TEAM_TAG;
BalanceConstants.BOOST_DISTANCE, BalanceConstants.BOOST_DURATION, BalanceConstants.BOOST_COOLDOWN));
teamTag = TagsConstants.PLAYER_TEAM_TAG;
}

// Controllers
Expand Down
2 changes: 1 addition & 1 deletion core/src/com/po/fuck/model/Room.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.po.fuck.model;

import static com.po.fuck.model.Constants.ENEMY_TEAM_TAG;
import static com.po.fuck.model.constants.TagsConstants.ENEMY_TEAM_TAG;

import java.util.List;

Expand Down
32 changes: 32 additions & 0 deletions core/src/com/po/fuck/model/constants/BalanceConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.po.fuck.model.constants;

import java.nio.file.Paths;
import java.util.Properties;

import static com.po.fuck.model.constants.ConstantsLoader.loadProperties;
import static com.po.fuck.model.constants.ConstantsLoader.loadFloat;
import static com.po.fuck.model.constants.ConstantsLoader.loadInt;

public final class BalanceConstants extends BaseConstants {
private static final String PATH = Paths.get(PROPERTIES_FOLDER, "/balance.properties").toString();
private static final Properties PROPERTIES = loadProperties(PATH);

public static final float BASIC_ENEMY_SPEED = loadFloat(PROPERTIES, "BASIC_ENEMY_SPEED");
public static final float BASIC_ENEMY_HEALTH = loadFloat(PROPERTIES, "BASIC_ENEMY_HEALTH");
public static final int BASIC_ENEMY_REWARD = loadInt(PROPERTIES, "BASIC_ENEMY_REWARD");
public static final float PLAYERS_HEALTH = loadFloat(PROPERTIES, "PLAYERS_HEALTH");

public static final float DEFAULT_SPEED = loadFloat(PROPERTIES, "DEFAULT_SPEED");
public static final int BOOST_DISTANCE = loadInt(PROPERTIES, "BOOST_DISTANCE");
public static final float BOOST_DURATION = loadFloat(PROPERTIES, "BOOST_DURATION");
public static final float BOOST_COOLDOWN = loadFloat(PROPERTIES, "BOOST_COOLDOWN");

public static final float COSMIC_BULLET_LIFE_TIME = loadFloat(PROPERTIES, "COSMIC_BULLET_LIFE_TIME");
public static final float COSMIC_BULLET_DAMAGE = loadFloat(PROPERTIES, "COSMIC_BULLET_DAMAGE");
public static final float COSMIC_BULLET_SPEED = loadFloat(PROPERTIES, "COSMIC_BULLET_SPEED");
public static final float LASER_BEAM_DAMAGE = loadFloat(PROPERTIES, "LASER_BEAM_DAMAGE");
public static final float LASER_BEAM_LIFE_TIME = loadFloat(PROPERTIES, "LASER_BEAM_LIFE_TIME");
public static final float DEFAULT_BULLET_LIFE_TIME = loadFloat(PROPERTIES, "DEFAULT_BULLET_LIFE_TIME");
public static final float GLOCK_COOLDOWN = loadFloat(PROPERTIES, "GLOCK_COOLDOWN");
public static final float LASERGUN_COOLDOWN = loadFloat(PROPERTIES, "LASERGUN_COOLDOWN");
}
10 changes: 10 additions & 0 deletions core/src/com/po/fuck/model/constants/BaseConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.po.fuck.model.constants;

import java.util.Properties;

public class BaseConstants {
protected static final String PROPERTIES_FOLDER = "../core/src/com/po/fuck/properties";
protected static <T> void addProperty(Properties properties, String name, T value) {
properties.setProperty(name, value.toString());
}
}
14 changes: 14 additions & 0 deletions core/src/com/po/fuck/model/constants/CameraConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.po.fuck.model.constants;

import java.nio.file.Paths;
import java.util.Properties;

import static com.po.fuck.model.constants.ConstantsLoader.loadProperties;
import static com.po.fuck.model.constants.ConstantsLoader.loadFloat;;

public final class CameraConstants extends BaseConstants {
private static final String PATH = Paths.get(PROPERTIES_FOLDER, "/camera.properties").toString();
private static final Properties PROPERTIES = loadProperties(PATH);

public static final float SPEED = loadFloat(PROPERTIES, "SPEED");
}
32 changes: 32 additions & 0 deletions core/src/com/po/fuck/model/constants/ConstantsLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.po.fuck.model.constants;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class ConstantsLoader {
protected static Properties loadProperties(String filePath) {
try {
Properties properties = new Properties();
properties.load(new FileInputStream(filePath));
return properties;
} catch (IOException io) {
throw new RuntimeException("Unable to load properties file: " + filePath + " - " + io.getMessage());
}
}

protected static String loadConstant(Properties properties, String name) {
String value = properties.getProperty(name);
if(value == null)
throw new RuntimeException(name + " is null");
return value;
}

protected static int loadInt(Properties properties, String name){
return Integer.valueOf(loadConstant(properties, name));
}

protected static float loadFloat(Properties properties, String name){
return Float.valueOf(loadConstant(properties, name));
}
}
15 changes: 15 additions & 0 deletions core/src/com/po/fuck/model/constants/GameScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.po.fuck.model.constants;

import java.nio.file.Paths;
import java.util.Properties;

import static com.po.fuck.model.constants.ConstantsLoader.loadProperties;
import static com.po.fuck.model.constants.ConstantsLoader.loadInt;

public final class GameScreen extends BaseConstants {
private static final String PATH = Paths.get(PROPERTIES_FOLDER, "/gamescreen.properties").toString();
private static final Properties PROPERTIES = loadProperties(PATH);

public static final int WIDTH = loadInt(PROPERTIES, "WIDTH");
public static final int HEIGHT = loadInt(PROPERTIES, "HEIGHT");
}
17 changes: 17 additions & 0 deletions core/src/com/po/fuck/model/constants/LayeringConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.po.fuck.model.constants;

import java.nio.file.Paths;
import java.util.Properties;

import static com.po.fuck.model.constants.ConstantsLoader.loadProperties;
import static com.po.fuck.model.constants.ConstantsLoader.loadInt;

public final class LayeringConstants extends BaseConstants {
private static final String PATH = Paths.get(PROPERTIES_FOLDER, "/layering.properties").toString();
private static final Properties PROPERTIES = loadProperties(PATH);

public static final int BACKGROUND = loadInt(PROPERTIES, "BACKGROUND");
public static final int ENTITY = loadInt(PROPERTIES, "ENTITY");
public static final int WEAPON = loadInt(PROPERTIES, "WEAPON");
public static final int GUI = loadInt(PROPERTIES, "GUI");
}
14 changes: 14 additions & 0 deletions core/src/com/po/fuck/model/constants/PhysicsConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.po.fuck.model.constants;

import java.nio.file.Paths;
import java.util.Properties;

import static com.po.fuck.model.constants.ConstantsLoader.loadProperties;
import static com.po.fuck.model.constants.ConstantsLoader.loadInt;

public final class PhysicsConstants extends BaseConstants {
private static final String PATH = Paths.get(PROPERTIES_FOLDER, "/physics.properties").toString();
private static final Properties PROPERTIES = loadProperties(PATH);

public static final int COLLISION_ITERATIONS = loadInt(PROPERTIES, "COLLISION_ITERATIONS");
}
15 changes: 15 additions & 0 deletions core/src/com/po/fuck/model/constants/PositionConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.po.fuck.model.constants;

import java.nio.file.Paths;
import java.util.Properties;

import static com.po.fuck.model.constants.ConstantsLoader.loadProperties;
import static com.po.fuck.model.constants.ConstantsLoader.loadFloat;

public final class PositionConstants extends BaseConstants {
private static final String PATH = Paths.get(PROPERTIES_FOLDER, "/position.properties").toString();
private static final Properties PROPERTIES = loadProperties(PATH);

public static final float DEFAULT_DISTANCE_FACTOR = loadFloat(PROPERTIES, "DEFAULT_DISTANCE_FACTOR");
public static final float DEFAULT_MAX_DISTANCE_FROM_BODY = loadFloat(PROPERTIES, "DEFAULT_MAX_DISTANCE_FROM_BODY");
}
15 changes: 15 additions & 0 deletions core/src/com/po/fuck/model/constants/TagsConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.po.fuck.model.constants;

import java.nio.file.Paths;
import java.util.Properties;

import static com.po.fuck.model.constants.ConstantsLoader.loadProperties;
import static com.po.fuck.model.constants.ConstantsLoader.loadInt;

public final class TagsConstants extends BaseConstants {
private static final String PATH = Paths.get(PROPERTIES_FOLDER, "/tags.properties").toString();
private static final Properties PROPERTIES = loadProperties(PATH);

public static final int ENEMY_TEAM_TAG = loadInt(PROPERTIES, "ENEMY_TEAM_TAG");
public static final int PLAYER_TEAM_TAG = loadInt(PROPERTIES, "PLAYER_TEAM_TAG");
}
11 changes: 6 additions & 5 deletions core/src/com/po/fuck/model/enemies/BasicEnemy.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package com.po.fuck.model.enemies;

import static com.po.fuck.model.Constants.BASIC_ENEMY_SPEED;
import static com.po.fuck.model.Constants.BASIC_ENEMY_HEALTH;
import static com.po.fuck.model.Constants.BASIC_ENEMY_REWARD;
import static com.po.fuck.model.Constants.ENEMY_TEAM_TAG;

import com.po.fuck.model.Entity;
import com.po.fuck.model.GeometryMisc;
import com.po.fuck.model.Updatable;
Expand All @@ -14,6 +9,12 @@
import com.po.fuck.model.position.GeometryData;
import com.po.fuck.model.weapons.Glock;
import com.po.fuck.model.weapons.Weapon;

import static com.po.fuck.model.constants.BalanceConstants.BASIC_ENEMY_HEALTH;
import static com.po.fuck.model.constants.BalanceConstants.BASIC_ENEMY_REWARD;
import static com.po.fuck.model.constants.BalanceConstants.BASIC_ENEMY_SPEED;
import static com.po.fuck.model.constants.TagsConstants.ENEMY_TEAM_TAG;

import com.badlogic.gdx.math.Vector2;

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/com/po/fuck/model/movement/Movement.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.po.fuck.model.movement;

import static com.po.fuck.model.Constants.COLLISION_ITERATIONS;
import static com.po.fuck.model.constants.PhysicsConstants.COLLISION_ITERATIONS;

import com.badlogic.gdx.math.Vector2;
import com.po.fuck.model.collision.Collidable;
Expand Down
3 changes: 2 additions & 1 deletion core/src/com/po/fuck/model/weapons/Bullet.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import com.po.fuck.model.position.GeometryData;
import com.po.fuck.model.collections.All;

import static com.po.fuck.model.Constants.DEFAULT_BULLET_LIFE_TIME;
import static com.po.fuck.model.constants.BalanceConstants.DEFAULT_BULLET_LIFE_TIME;
import static com.po.fuck.model.constants.LayeringConstants.WEAPON;

import java.util.List;

Expand Down
8 changes: 4 additions & 4 deletions core/src/com/po/fuck/model/weapons/CosmicBullet.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.po.fuck.model.weapons;

import static com.po.fuck.model.constants.BalanceConstants.COSMIC_BULLET_DAMAGE;
import static com.po.fuck.model.constants.BalanceConstants.COSMIC_BULLET_LIFE_TIME;
import static com.po.fuck.model.constants.BalanceConstants.COSMIC_BULLET_SPEED;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import com.po.fuck.model.position.GeometryData;

import static com.po.fuck.model.Constants.COSMIC_BULLET_DAMAGE;
import static com.po.fuck.model.Constants.COSMIC_BULLET_LIFE_TIME;
import static com.po.fuck.model.Constants.COSMIC_BULLET_SPEED;

public final class CosmicBullet extends Bullet {
{
damage = COSMIC_BULLET_DAMAGE;
Expand Down
3 changes: 2 additions & 1 deletion core/src/com/po/fuck/model/weapons/Glock.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.po.fuck.model.weapons;

import static com.po.fuck.model.constants.BalanceConstants.GLOCK_COOLDOWN;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import com.po.fuck.model.Entity;
import static com.po.fuck.model.Constants.GLOCK_COOLDOWN;

public final class Glock extends Gun {
{
Expand Down
4 changes: 2 additions & 2 deletions core/src/com/po/fuck/model/weapons/HandedWeapon.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.po.fuck.model.weapons;

import static com.po.fuck.model.Constants.DEFAULT_DISTANCE_FACTOR;
import static com.po.fuck.model.Constants.DEFAULT_MAX_DISTANCE_FROM_BODY;
import static com.po.fuck.model.constants.PositionConstants.DEFAULT_DISTANCE_FACTOR;
import static com.po.fuck.model.constants.PositionConstants.DEFAULT_MAX_DISTANCE_FROM_BODY;

import com.badlogic.gdx.math.Vector2;
import com.po.fuck.model.Entity;
Expand Down
Loading

0 comments on commit 1da120b

Please sign in to comment.