Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added .properties file #31

Merged
merged 19 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions core/src/com/po/fuck/model/.properties
MAKMED1337 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#Mon Jun 10 13:43:11 CEST 2024
BACKGROUND_LAYER=0
BASIC_ENEMY_HEALTH=5.0
BASIC_ENEMY_REWARD=1
BASIC_ENEMY_SPEED=250.0
BOOST_COOLDOWN=1.0
BOOST_DISTANCE=700
BOOST_DURATION=0.3
CAMERA_SPEED=10.0
COLLISION_ITERATIONS=20
COSMIC_BULLET_DAMAGE=1.0
COSMIC_BULLET_LIFE_TIME=10.0
COSMIC_BULLET_SPEED=600.0
DEFAULT_BULLET_LIFE_TIME=60.0
DEFAULT_DISTANCE_FACTOR=2.0
DEFAULT_MAX_DISTANCE_FROM_BODY=100.0
DEFAULT_SPEED=500.0
ENEMY_TEAM_TAG=0
ENTITY_LAYER=1
GAME_BORDER=20000
GLOCK_COOLDOWN=0.5
GUI_LAYER=19
LASERGUN_COOLDOWN=1.0
LASER_BEAM_DAMAGE=3.0
LASER_BEAM_LIFE_TIME=1.0
PLAYERS_HEALTH=10.0
PLAYER_TEAM_TAG=1
SCREEN_HEIGHT=720
SCREEN_WIDTH=1280
WEAPON_LAYER=2
144 changes: 114 additions & 30 deletions core/src/com/po/fuck/model/Constants.java
MAKMED1337 marked this conversation as resolved.
Show resolved Hide resolved
MAKMED1337 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,51 +1,135 @@
package com.po.fuck.model;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;

public final class Constants {
public static final int SCREEN_WIDTH = 1280;
public static final int SCREEN_HEIGHT = 720;
static Properties properties = null;
MAKMED1337 marked this conversation as resolved.
Show resolved Hide resolved

static <T> T loadConstant(String name, Class<T> cls){
if(properties == null){
properties = new Properties();
try {
properties.load(new FileInputStream("../core/src/com/po/fuck/model/.properties"));
} catch(IOException io){
throw new RuntimeException(io.getMessage());
}
MAKMED1337 marked this conversation as resolved.
Show resolved Hide resolved
}
String value = properties.getProperty(name);
if(value == null){
throw new RuntimeException(cls.getName() + name + " is not found in .properties");
}
if (cls == Integer.class) {
return cls.cast(Integer.valueOf(value));
} else if (cls == Float.class) {
return cls.cast(Float.valueOf(value));
} else {
throw new IllegalArgumentException("Unsupported property type");
}
}

public static final int SCREEN_WIDTH = loadConstant("SCREEN_WIDTH", Integer.class);
public static final int SCREEN_HEIGHT = loadConstant("SCREEN_HEIGHT", Integer.class);

/* movement */
public static final float DEFAULT_SPEED = 500;
public static final int BOOST_DISTANCE = 700;
public static final float BOOST_DURATION = 0.3f;
public static final float BOOST_COOLDOWN = 1f;
public static final float DEFAULT_SPEED = loadConstant("DEFAULT_SPEED", Float.class);
public static final int BOOST_DISTANCE = loadConstant("BOOST_DISTANCE", Integer.class);
public static final float BOOST_DURATION = loadConstant("BOOST_DURATION", Float.class);
public static final float BOOST_COOLDOWN = loadConstant("BOOST_COOLDOWN", Float.class);

/* physics */
public static final int COLLISION_ITERATIONS = 3;
public static final int COLLISION_ITERATIONS = loadConstant("COLLISION_ITERATIONS", Integer.class);

/* team tags */
public static final int ENEMY_TEAM_TAG = 0;
public static final int PLAYER_TEAM_TAG = 1;
public static final int ENEMY_TEAM_TAG = loadConstant("ENEMY_TEAM_TAG", Integer.class);
public static final int PLAYER_TEAM_TAG = loadConstant("PLAYER_TEAM_TAG", Integer.class);

/* camera */
public static final float CAMERA_SPEED = 10;
public static final float CAMERA_SPEED = loadConstant("CAMERA_SPEED", Float.class);

/* layering */
public static final int BACKGROUND_LAYER = 0;
public static final int ENTITY_LAYER = 1;
public static final int WEAPON_LAYER = 2;
public static final int GUI_LAYER = 19;
public static final int BACKGROUND_LAYER = loadConstant("BACKGROUND_LAYER", Integer.class);
public static final int ENTITY_LAYER = loadConstant("ENTITY_LAYER", Integer.class);
public static final int WEAPON_LAYER = loadConstant("WEAPON_LAYER", Integer.class);
public static final int GUI_LAYER = loadConstant("GUI_LAYER", Integer.class);

/* borders */
public static final int GAME_BORDER = 20000;
public static final int GAME_BORDER = loadConstant("GAME_BORDER", Integer.class);

/* bullets */
public static final float COSMIC_BULLET_LIFE_TIME = loadConstant("COSMIC_BULLET_LIFE_TIME", Float.class);
public static final float COSMIC_BULLET_DAMAGE = loadConstant("COSMIC_BULLET_DAMAGE", Float.class);
public static final float COSMIC_BULLET_SPEED = loadConstant("COSMIC_BULLET_SPEED", Float.class);
public static final float LASER_BEAM_DAMAGE = loadConstant("LASER_BEAM_DAMAGE", Float.class);
public static final float LASER_BEAM_LIFE_TIME = loadConstant("LASER_BEAM_LIFE_TIME", Float.class);
public static final float DEFAULT_BULLET_LIFE_TIME = loadConstant("DEFAULT_BULLET_LIFE_TIME", Float.class);

public static final float GLOCK_COOLDOWN = loadConstant("GLOCK_COOLDOWN", Float.class);
public static final float LASERGUN_COOLDOWN = loadConstant("LASERGUN_COOLDOWN", Float.class);

public static final float PLAYERS_HEALTH = loadConstant("PLAYERS_HEALTH", Float.class);

public static final float DEFAULT_DISTANCE_FACTOR = loadConstant("DEFAULT_DISTANCE_FACTOR", Float.class);
public static final float DEFAULT_MAX_DISTANCE_FROM_BODY = loadConstant("DEFAULT_MAX_DISTANCE_FROM_BODY", Float.class);

/* bullets */ /* TODO: move to .properties */
public static final float COSMIC_BULLET_LIFE_TIME = 10f;
public static final float COSMIC_BULLET_DAMAGE = 1f;
public static final float COSMIC_BULLET_SPEED = 600f;
public static final float LASER_BEAM_DAMAGE = 3f;
public static final float LASER_BEAM_LIFE_TIME = 1f;
public static final float DEFAULT_BULLET_LIFE_TIME = 60f;
public static final float BASIC_ENEMY_SPEED = loadConstant("BASIC_ENEMY_SPEED", Float.class);
public static final float BASIC_ENEMY_HEALTH = loadConstant("BASIC_ENEMY_HEALTH", Float.class);
public static final int BASIC_ENEMY_REWARD = loadConstant("BASIC_ENEMY_REWARD", Integer.class);

public static final float GLOCK_COOLDOWN = 0.5f;
public static final float LASERGUN_COOLDOWN = 1f;
public static void saveToProperties() {
String propertiesFilePath = "../core/src/com/po/fuck/model/.properties";
MAKMED1337 marked this conversation as resolved.
Show resolved Hide resolved

// Ensure the file exists or create it if it doesn't
File propertiesFile = new File(propertiesFilePath);
if (!propertiesFile.exists()) {
try {
propertiesFile.getParentFile().mkdirs(); // Create parent directories if they don't exist
propertiesFile.createNewFile(); // Create the file
} catch (IOException e) {
throw new RuntimeException("Unable to create properties file: " + e.getMessage());
MAKMED1337 marked this conversation as resolved.
Show resolved Hide resolved
}
}

public static final float PLAYERS_HEALTH = 10;
try (OutputStream output = new FileOutputStream(propertiesFilePath)) {
Properties prop = new Properties();

public static final float DEFAULT_DISTANCE_FACTOR = 2;
public static final float DEFAULT_MAX_DISTANCE_FROM_BODY = 100;
prop.setProperty("SCREEN_WIDTH", Integer.toString(SCREEN_WIDTH));
MAKMED1337 marked this conversation as resolved.
Show resolved Hide resolved
prop.setProperty("SCREEN_HEIGHT", Integer.toString(SCREEN_HEIGHT));
prop.setProperty("DEFAULT_SPEED", Float.toString(DEFAULT_SPEED));
prop.setProperty("BOOST_DISTANCE", Integer.toString(BOOST_DISTANCE));
prop.setProperty("BOOST_DURATION", Float.toString(BOOST_DURATION));
prop.setProperty("BOOST_COOLDOWN", Float.toString(BOOST_COOLDOWN));
prop.setProperty("COLLISION_ITERATIONS", Integer.toString(COLLISION_ITERATIONS));
prop.setProperty("ENEMY_TEAM_TAG", Integer.toString(ENEMY_TEAM_TAG));
prop.setProperty("PLAYER_TEAM_TAG", Integer.toString(PLAYER_TEAM_TAG));
prop.setProperty("CAMERA_SPEED", Float.toString(CAMERA_SPEED));
prop.setProperty("BACKGROUND_LAYER", Integer.toString(BACKGROUND_LAYER));
prop.setProperty("ENTITY_LAYER", Integer.toString(ENTITY_LAYER));
prop.setProperty("WEAPON_LAYER", Integer.toString(WEAPON_LAYER));
prop.setProperty("GUI_LAYER", Integer.toString(GUI_LAYER));
prop.setProperty("GAME_BORDER", Integer.toString(GAME_BORDER));
prop.setProperty("COSMIC_BULLET_LIFE_TIME", Float.toString(COSMIC_BULLET_LIFE_TIME));
prop.setProperty("COSMIC_BULLET_DAMAGE", Float.toString(COSMIC_BULLET_DAMAGE));
prop.setProperty("COSMIC_BULLET_SPEED", Float.toString(COSMIC_BULLET_SPEED));
prop.setProperty("LASER_BEAM_DAMAGE", Float.toString(LASER_BEAM_DAMAGE));
prop.setProperty("LASER_BEAM_LIFE_TIME", Float.toString(LASER_BEAM_LIFE_TIME));
prop.setProperty("DEFAULT_BULLET_LIFE_TIME", Float.toString(DEFAULT_BULLET_LIFE_TIME));
prop.setProperty("GLOCK_COOLDOWN", Float.toString(GLOCK_COOLDOWN));
prop.setProperty("LASERGUN_COOLDOWN", Float.toString(LASERGUN_COOLDOWN));
prop.setProperty("PLAYERS_HEALTH", Float.toString(PLAYERS_HEALTH));
prop.setProperty("DEFAULT_DISTANCE_FACTOR", Float.toString(DEFAULT_DISTANCE_FACTOR));
prop.setProperty("DEFAULT_MAX_DISTANCE_FROM_BODY", Float.toString(DEFAULT_MAX_DISTANCE_FROM_BODY));
prop.setProperty("BASIC_ENEMY_SPEED", Float.toString(BASIC_ENEMY_SPEED));
prop.setProperty("BASIC_ENEMY_HEALTH", Float.toString(BASIC_ENEMY_HEALTH));
prop.setProperty("BASIC_ENEMY_REWARD", Integer.toString(BASIC_ENEMY_REWARD));

public static final float BASIC_ENEMY_SPEED = 250;
public static final float BASIC_ENEMY_HEALTH = 5;
public static final int BASIC_ENEMY_REWARD = 1;
prop.store(output, null);
} catch (IOException io) {
throw new RuntimeException(io.getMessage());
}
}
}
1 change: 1 addition & 0 deletions core/src/com/po/fuck/model/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Core implements Updatable {
static { // TODO: remove
forceInit(Destructable.class);
forceInit(All.class);
// Constants.saveToProperties();
MAKMED1337 marked this conversation as resolved.
Show resolved Hide resolved
}

public static Managed<Player> player;
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
MAKMED1337 marked this conversation as resolved.
Show resolved Hide resolved
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down