diff --git a/core/src/com/po/fuck/model/Coins.java b/core/src/com/po/fuck/model/Coins.java index ac796ea..ad72ce1 100644 --- a/core/src/com/po/fuck/model/Coins.java +++ b/core/src/com/po/fuck/model/Coins.java @@ -1,22 +1,15 @@ package com.po.fuck.model; -import static com.po.fuck.model.Constants.GUI_LAYER; - import com.po.fuck.model.drawables.Drawable; public class Coins implements Drawable { private int coins = 0; - public int getCoins(){ + public int getCoins() { return coins; } public void addCoins(int cnt) { coins += cnt; } - - @Override - public int getZ(){ - return GUI_LAYER; - } } diff --git a/core/src/com/po/fuck/model/Constants.java b/core/src/com/po/fuck/model/Constants.java deleted file mode 100644 index 9eb09f7..0000000 --- a/core/src/com/po/fuck/model/Constants.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.po.fuck.model; - -public final class Constants { - public static final int SCREEN_WIDTH = 1280; - public static final int SCREEN_HEIGHT = 720; - - /* 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; - - /* physics */ - public static final int COLLISION_ITERATIONS = 3; - - /* team tags */ - public static final int ENEMY_TEAM_TAG = 0; - public static final int PLAYER_TEAM_TAG = 1; - - /* camera */ - public static final float CAMERA_SPEED = 10; - - /* 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; - - /* borders */ - public static final int GAME_BORDER = 20000; - - /* 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 GLOCK_COOLDOWN = 0.5f; - public static final float LASERGUN_COOLDOWN = 1f; - - public static final float PLAYERS_HEALTH = 10; - - public static final float DEFAULT_DISTANCE_FACTOR = 2; - public static final float DEFAULT_MAX_DISTANCE_FROM_BODY = 100; - - public static final float BASIC_ENEMY_SPEED = 250; - public static final float BASIC_ENEMY_HEALTH = 5; - public static final int BASIC_ENEMY_REWARD = 1; -} diff --git a/core/src/com/po/fuck/model/Core.java b/core/src/com/po/fuck/model/Core.java index 57c4cd1..0588ab0 100644 --- a/core/src/com/po/fuck/model/Core.java +++ b/core/src/com/po/fuck/model/Core.java @@ -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; @@ -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 diff --git a/core/src/com/po/fuck/model/Entity.java b/core/src/com/po/fuck/model/Entity.java index c1457bd..e3f05be 100644 --- a/core/src/com/po/fuck/model/Entity.java +++ b/core/src/com/po/fuck/model/Entity.java @@ -1,7 +1,5 @@ package com.po.fuck.model; -import static com.po.fuck.model.Constants.ENTITY_LAYER; - import com.po.fuck.model.lifetime.Managed; import com.po.fuck.model.lifetime.Manager; import com.po.fuck.model.movement.Movement; @@ -28,11 +26,6 @@ public int getTeamTag() { return teamTag; } - @Override - public int getZ() { - return ENTITY_LAYER; - } - public boolean isAlive() { return immortal || healthPoints > 0; } @@ -50,15 +43,15 @@ public boolean takeDamage(float damage) { return true; } - public float getHP(){ + public float getHP() { return healthPoints; } - public Managed getMovement(){ + public Managed getMovement() { return movement; } - public Managed getWeapon(){ + public Managed getWeapon() { return weapon; } diff --git a/core/src/com/po/fuck/model/ObjectFollower.java b/core/src/com/po/fuck/model/ObjectFollower.java index b541c6e..fd8e279 100644 --- a/core/src/com/po/fuck/model/ObjectFollower.java +++ b/core/src/com/po/fuck/model/ObjectFollower.java @@ -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(); @@ -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)); } diff --git a/core/src/com/po/fuck/model/Player.java b/core/src/com/po/fuck/model/Player.java index 9f297d5..00240ae 100644 --- a/core/src/com/po/fuck/model/Player.java +++ b/core/src/com/po/fuck/model/Player.java @@ -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; @@ -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 diff --git a/core/src/com/po/fuck/model/Room.java b/core/src/com/po/fuck/model/Room.java index 51469dd..68ba8c2 100644 --- a/core/src/com/po/fuck/model/Room.java +++ b/core/src/com/po/fuck/model/Room.java @@ -1,7 +1,6 @@ package com.po.fuck.model; -import static com.po.fuck.model.Constants.BACKGROUND_LAYER; -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; @@ -15,8 +14,6 @@ import com.po.fuck.model.lifetime.Managed; import com.po.fuck.model.lifetime.Manager; import com.po.fuck.model.position.GeometryData; -import com.po.fuck.view.CenterDrawer; -import com.po.fuck.model.Updatable; public class Room implements PositionDrawable, Updatable { public Vector2 tillingPosition; @@ -40,11 +37,6 @@ private enum State { geometryData.setWidth(width); } - @Override - public int getZ() { - return BACKGROUND_LAYER; - } - protected void spawnEnemies() { Vector2 center = getPosition(); @@ -53,13 +45,13 @@ protected void spawnEnemies() { // top left Manager.create(new BasicEnemy(new GeometryData(center.cpy().mulAdd(offset, -0.5f), - new Sprite(new Texture("player2.png")).getWidth(), - new Sprite(new Texture("player2.png")).getHeight(),0))); + new Sprite(new Texture("player2.png")).getWidth(), + new Sprite(new Texture("player2.png")).getHeight(), 0))); // bottom right Manager.create(new BasicEnemy(new GeometryData(center.cpy().mulAdd(offset, 0.5f), - new Sprite(new Texture("player2.png")).getWidth(), - new Sprite(new Texture("player2.png")).getHeight(),0))); + new Sprite(new Texture("player2.png")).getWidth(), + new Sprite(new Texture("player2.png")).getHeight(), 0))); } public Vector2 getPosition() { @@ -105,7 +97,7 @@ public void update(float delta) { // List of all the entities inside this room. List inside = All.collidableCollection .collides(GeometryMisc.createRectangle( - new GeometryData(getPosition(), geometryData.getWidth(), geometryData.getHeight(), 0))); + new GeometryData(getPosition(), geometryData.getWidth(), geometryData.getHeight(), 0))); if (state == State.NOT_ENTERED) { // If the player has not entered before this time, we need to check if he has diff --git a/core/src/com/po/fuck/model/collections/DrawableCollection.java b/core/src/com/po/fuck/model/collections/DrawableCollection.java index f41b30f..e17d860 100644 --- a/core/src/com/po/fuck/model/collections/DrawableCollection.java +++ b/core/src/com/po/fuck/model/collections/DrawableCollection.java @@ -1,65 +1,13 @@ package com.po.fuck.model.collections; import java.util.ArrayList; -import java.util.Iterator; -import java.util.NoSuchElementException; import com.po.fuck.model.drawables.Drawable; -public class DrawableCollection extends SimpleCollection implements Iterable { - public static final int MAX_Z = 20; - @SuppressWarnings("unchecked") - private final ArrayList[] objects = new ArrayList[MAX_Z]; - - { - for (int i = 0; i < MAX_Z; ++i) - objects[i] = new ArrayList<>(); - } +public class DrawableCollection extends SimpleCollection { + private final ArrayList objects = new ArrayList(); DrawableCollection() { super(Drawable.class); } - - @Override - public void add(Drawable drawable) { - objects[drawable.getZ()].add(drawable); - } - - @Override - public void remove(Drawable drawable) { - objects[drawable.getZ()].remove(drawable); - } - - @Override - public Iterator iterator() { - return new DrawableCollectionIterator(); - } - - private class DrawableCollectionIterator implements Iterator { - private int currentZ = 0; - private Iterator currentIterator = objects[currentZ].iterator(); - - private void moveToNextNonEmptyList() { - while (currentZ < MAX_Z && !currentIterator.hasNext()) { - currentZ++; - if (currentZ < MAX_Z) { - currentIterator = objects[currentZ].iterator(); - } - } - } - - @Override - public boolean hasNext() { - moveToNextNonEmptyList(); - return currentZ < MAX_Z && currentIterator.hasNext(); - } - - @Override - public Drawable next() { - if (!hasNext()) { - throw new NoSuchElementException(); - } - return currentIterator.next(); - } - } } diff --git a/core/src/com/po/fuck/model/collections/SimpleCollection.java b/core/src/com/po/fuck/model/collections/SimpleCollection.java index ba30649..25cc3cd 100644 --- a/core/src/com/po/fuck/model/collections/SimpleCollection.java +++ b/core/src/com/po/fuck/model/collections/SimpleCollection.java @@ -2,10 +2,11 @@ import java.util.ArrayList; +import java.util.Iterator; import com.po.fuck.model.lifetime.ClassData; import com.po.fuck.model.lifetime.Manager; -public abstract class SimpleCollection { +public abstract class SimpleCollection implements Iterable { protected SimpleCollection(Class cls) { Manager.registerClass(new ClassData( cls, @@ -22,4 +23,9 @@ public void add(T object) { public void remove(T object) { objects.remove(object); } + + @Override + public Iterator iterator() { + return objects.iterator(); + } } diff --git a/core/src/com/po/fuck/model/constants/BalanceConstants.java b/core/src/com/po/fuck/model/constants/BalanceConstants.java new file mode 100644 index 0000000..766d28d --- /dev/null +++ b/core/src/com/po/fuck/model/constants/BalanceConstants.java @@ -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"); +} \ No newline at end of file diff --git a/core/src/com/po/fuck/model/constants/BaseConstants.java b/core/src/com/po/fuck/model/constants/BaseConstants.java new file mode 100644 index 0000000..14a2939 --- /dev/null +++ b/core/src/com/po/fuck/model/constants/BaseConstants.java @@ -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 void addProperty(Properties properties, String name, T value) { + properties.setProperty(name, value.toString()); + } +} diff --git a/core/src/com/po/fuck/model/constants/CameraConstants.java b/core/src/com/po/fuck/model/constants/CameraConstants.java new file mode 100644 index 0000000..594c816 --- /dev/null +++ b/core/src/com/po/fuck/model/constants/CameraConstants.java @@ -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"); +} \ No newline at end of file diff --git a/core/src/com/po/fuck/model/constants/ConstantsLoader.java b/core/src/com/po/fuck/model/constants/ConstantsLoader.java new file mode 100644 index 0000000..d842cea --- /dev/null +++ b/core/src/com/po/fuck/model/constants/ConstantsLoader.java @@ -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)); + } +} diff --git a/core/src/com/po/fuck/model/constants/GameScreen.java b/core/src/com/po/fuck/model/constants/GameScreen.java new file mode 100644 index 0000000..63cc929 --- /dev/null +++ b/core/src/com/po/fuck/model/constants/GameScreen.java @@ -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"); +} diff --git a/core/src/com/po/fuck/model/constants/LayeringConstants.java b/core/src/com/po/fuck/model/constants/LayeringConstants.java new file mode 100644 index 0000000..5b5e2c6 --- /dev/null +++ b/core/src/com/po/fuck/model/constants/LayeringConstants.java @@ -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"); +} \ No newline at end of file diff --git a/core/src/com/po/fuck/model/constants/PhysicsConstants.java b/core/src/com/po/fuck/model/constants/PhysicsConstants.java new file mode 100644 index 0000000..53953f2 --- /dev/null +++ b/core/src/com/po/fuck/model/constants/PhysicsConstants.java @@ -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"); +} diff --git a/core/src/com/po/fuck/model/constants/PositionConstants.java b/core/src/com/po/fuck/model/constants/PositionConstants.java new file mode 100644 index 0000000..2e13a42 --- /dev/null +++ b/core/src/com/po/fuck/model/constants/PositionConstants.java @@ -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"); +} \ No newline at end of file diff --git a/core/src/com/po/fuck/model/constants/TagsConstants.java b/core/src/com/po/fuck/model/constants/TagsConstants.java new file mode 100644 index 0000000..a23f97f --- /dev/null +++ b/core/src/com/po/fuck/model/constants/TagsConstants.java @@ -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"); +} \ No newline at end of file diff --git a/core/src/com/po/fuck/model/drawables/Drawable.java b/core/src/com/po/fuck/model/drawables/Drawable.java index 8db0137..22af3fd 100644 --- a/core/src/com/po/fuck/model/drawables/Drawable.java +++ b/core/src/com/po/fuck/model/drawables/Drawable.java @@ -1,7 +1,3 @@ package com.po.fuck.model.drawables; -public interface Drawable { - default int getZ() { - return 0; - } -} +public interface Drawable {} diff --git a/core/src/com/po/fuck/model/drawables/PositionDrawable.java b/core/src/com/po/fuck/model/drawables/PositionDrawable.java index 4e29150..c663cc2 100644 --- a/core/src/com/po/fuck/model/drawables/PositionDrawable.java +++ b/core/src/com/po/fuck/model/drawables/PositionDrawable.java @@ -5,10 +5,9 @@ public interface PositionDrawable extends Drawable { - default public Vector2 getPosition(){ + default public Vector2 getPosition() { return getGeometryData().getPosition(); } public GeometryData getGeometryData(); } - diff --git a/core/src/com/po/fuck/model/enemies/BasicEnemy.java b/core/src/com/po/fuck/model/enemies/BasicEnemy.java index c3e8a16..02fbfbd 100644 --- a/core/src/com/po/fuck/model/enemies/BasicEnemy.java +++ b/core/src/com/po/fuck/model/enemies/BasicEnemy.java @@ -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; @@ -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; /** diff --git a/core/src/com/po/fuck/model/movement/Movement.java b/core/src/com/po/fuck/model/movement/Movement.java index 60f66d0..a8eb6ff 100644 --- a/core/src/com/po/fuck/model/movement/Movement.java +++ b/core/src/com/po/fuck/model/movement/Movement.java @@ -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; diff --git a/core/src/com/po/fuck/model/weapons/Bullet.java b/core/src/com/po/fuck/model/weapons/Bullet.java index 6d4e8c7..6bf9f32 100644 --- a/core/src/com/po/fuck/model/weapons/Bullet.java +++ b/core/src/com/po/fuck/model/weapons/Bullet.java @@ -11,8 +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.WEAPON_LAYER; +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; @@ -24,17 +24,12 @@ public abstract class Bullet implements PositionDrawable, Updatable { protected float lifeTime = DEFAULT_BULLET_LIFE_TIME; protected float elapsedTime = 0; - @Override - public int getZ() { - return WEAPON_LAYER; - } - @Override public Vector2 getPosition() { return geometryData.getPosition(); } - public Vector2 getVelocity(){ + public Vector2 getVelocity() { return velocity.cpy(); } @@ -51,7 +46,7 @@ public void update(float delta) { elapsedTime += delta; - if(elapsedTime > lifeTime){ + if (elapsedTime > lifeTime) { Manager.destroyRaw(this); return; } diff --git a/core/src/com/po/fuck/model/weapons/CosmicBullet.java b/core/src/com/po/fuck/model/weapons/CosmicBullet.java index bf8358b..0a66a15 100644 --- a/core/src/com/po/fuck/model/weapons/CosmicBullet.java +++ b/core/src/com/po/fuck/model/weapons/CosmicBullet.java @@ -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; diff --git a/core/src/com/po/fuck/model/weapons/Glock.java b/core/src/com/po/fuck/model/weapons/Glock.java index 65ae0b8..255873b 100644 --- a/core/src/com/po/fuck/model/weapons/Glock.java +++ b/core/src/com/po/fuck/model/weapons/Glock.java @@ -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 { { diff --git a/core/src/com/po/fuck/model/weapons/HandedWeapon.java b/core/src/com/po/fuck/model/weapons/HandedWeapon.java index 4cabe74..d9fe5ef 100644 --- a/core/src/com/po/fuck/model/weapons/HandedWeapon.java +++ b/core/src/com/po/fuck/model/weapons/HandedWeapon.java @@ -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; diff --git a/core/src/com/po/fuck/model/weapons/LaserBeam.java b/core/src/com/po/fuck/model/weapons/LaserBeam.java index dea79eb..3ca16f8 100644 --- a/core/src/com/po/fuck/model/weapons/LaserBeam.java +++ b/core/src/com/po/fuck/model/weapons/LaserBeam.java @@ -1,5 +1,8 @@ package com.po.fuck.model.weapons; +import static com.po.fuck.model.constants.BalanceConstants.LASER_BEAM_DAMAGE; +import static com.po.fuck.model.constants.BalanceConstants.LASER_BEAM_LIFE_TIME; + import java.util.List; import com.badlogic.gdx.Gdx; @@ -15,9 +18,6 @@ import com.po.fuck.view.GifDecoder; import com.po.fuck.model.collections.All; -import static com.po.fuck.model.Constants.LASER_BEAM_DAMAGE; -import static com.po.fuck.model.Constants.LASER_BEAM_LIFE_TIME; - public final class LaserBeam extends Bullet { { diff --git a/core/src/com/po/fuck/model/weapons/LaserGun.java b/core/src/com/po/fuck/model/weapons/LaserGun.java index 56515ce..232eec9 100644 --- a/core/src/com/po/fuck/model/weapons/LaserGun.java +++ b/core/src/com/po/fuck/model/weapons/LaserGun.java @@ -1,6 +1,6 @@ package com.po.fuck.model.weapons; -import static com.po.fuck.model.Constants.LASERGUN_COOLDOWN; +import static com.po.fuck.model.constants.BalanceConstants.LASERGUN_COOLDOWN; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Sprite; diff --git a/core/src/com/po/fuck/model/weapons/Weapon.java b/core/src/com/po/fuck/model/weapons/Weapon.java index e57aa43..cb1bd9d 100644 --- a/core/src/com/po/fuck/model/weapons/Weapon.java +++ b/core/src/com/po/fuck/model/weapons/Weapon.java @@ -1,7 +1,5 @@ package com.po.fuck.model.weapons; -import static com.po.fuck.model.Constants.WEAPON_LAYER; - import com.badlogic.gdx.math.Vector2; import com.po.fuck.model.Entity; import com.po.fuck.model.drawables.PositionDrawable; @@ -12,11 +10,6 @@ public abstract class Weapon implements PositionDrawable { protected Vector2 aiming = new Vector2(); protected GeometryData geometryData = new GeometryData(); - @Override - public int getZ() { - return WEAPON_LAYER; - } - Weapon(Entity owner) { this.owner = owner; } diff --git a/core/src/com/po/fuck/properties/balance.properties b/core/src/com/po/fuck/properties/balance.properties new file mode 100644 index 0000000..7ed1deb --- /dev/null +++ b/core/src/com/po/fuck/properties/balance.properties @@ -0,0 +1,16 @@ +BASIC_ENEMY_SPEED=250.0 +BASIC_ENEMY_HEALTH=5.0 +BASIC_ENEMY_REWARD=1 +PLAYERS_HEALTH=10 +DEFAULT_SPEED=500.0 +BOOST_DISTANCE=700 +BOOST_DURATION=0.3 +BOOST_COOLDOWN=1.0 +COSMIC_BULLET_LIFE_TIME=10.0 +COSMIC_BULLET_DAMAGE=1.0 +COSMIC_BULLET_SPEED=600.0 +LASER_BEAM_DAMAGE=3.0 +LASER_BEAM_LIFE_TIME=1.0 +DEFAULT_BULLET_LIFE_TIME=60.0 +GLOCK_COOLDOWN=0.5 +LASERGUN_COOLDOWN=1.0 diff --git a/core/src/com/po/fuck/properties/camera.properties b/core/src/com/po/fuck/properties/camera.properties new file mode 100644 index 0000000..fa0932b --- /dev/null +++ b/core/src/com/po/fuck/properties/camera.properties @@ -0,0 +1 @@ +SPEED=10.0 diff --git a/core/src/com/po/fuck/properties/gamescreen.properties b/core/src/com/po/fuck/properties/gamescreen.properties new file mode 100644 index 0000000..4bfc134 --- /dev/null +++ b/core/src/com/po/fuck/properties/gamescreen.properties @@ -0,0 +1,2 @@ +WIDTH=1280 +HEIGHT=720 diff --git a/core/src/com/po/fuck/properties/layering.properties b/core/src/com/po/fuck/properties/layering.properties new file mode 100644 index 0000000..3e94d79 --- /dev/null +++ b/core/src/com/po/fuck/properties/layering.properties @@ -0,0 +1,4 @@ +BACKGROUND=0 +ENTITY=1 +WEAPON=2 +GUI=19 diff --git a/core/src/com/po/fuck/properties/physics.properties b/core/src/com/po/fuck/properties/physics.properties new file mode 100644 index 0000000..3ff1a49 --- /dev/null +++ b/core/src/com/po/fuck/properties/physics.properties @@ -0,0 +1 @@ +COLLISION_ITERATIONS=20 diff --git a/core/src/com/po/fuck/properties/position.properties b/core/src/com/po/fuck/properties/position.properties new file mode 100644 index 0000000..b571cce --- /dev/null +++ b/core/src/com/po/fuck/properties/position.properties @@ -0,0 +1,2 @@ +DEFAULT_DISTANCE_FACTOR=2.0 +DEFAULT_MAX_DISTANCE_FROM_BODY=100.0 diff --git a/core/src/com/po/fuck/properties/tags.properties b/core/src/com/po/fuck/properties/tags.properties new file mode 100644 index 0000000..b5a5dd0 --- /dev/null +++ b/core/src/com/po/fuck/properties/tags.properties @@ -0,0 +1,2 @@ +ENEMY_TEAM_TAG=0 +PLAYER_TEAM_TAG=1 diff --git a/core/src/com/po/fuck/view/Renderer.java b/core/src/com/po/fuck/view/Renderer.java index bc05a83..873af3f 100644 --- a/core/src/com/po/fuck/view/Renderer.java +++ b/core/src/com/po/fuck/view/Renderer.java @@ -1,12 +1,15 @@ package com.po.fuck.view; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.utils.ScreenUtils; import com.po.fuck.model.ObjectFollower; +import com.po.fuck.model.drawables.Drawable; import com.po.fuck.model.collections.DrawableCollection; import com.po.fuck.view.classdrawers.ObjectDrawer; import com.po.fuck.view.classdrawers.factories.BulletDrawerFactory; @@ -24,8 +27,8 @@ * Class responsible for rendering game objects. */ public class Renderer { - static private Map, ObjectDrawer > drawers = new HashMap<>(); - + static private Map, ObjectDrawer> drawers = new HashMap<>(); + static { // TODO: remove this forceInit(BulletDrawerFactory.class); forceInit(EntityDrawerFactory.class); @@ -38,41 +41,58 @@ public class Renderer { private OrthographicCamera camera; private FollowingDrawer followingDrawer; - public Renderer(ObjectFollower objectFollower){ + public Renderer(ObjectFollower objectFollower) { camera = new OrthographicCamera(); camera.setToOrtho(false, GAME_WIDTH, GAME_HEIGHT); followingDrawer = new FollowingDrawer(new SpriteBatch(), objectFollower); } + /** + * Splits drawables into their respective layers + */ + protected TreeMap> getLayers(DrawableCollection drawableCollection) { + TreeMap> layers = new TreeMap<>(); + + for (Drawable drawable : drawableCollection) { + @SuppressWarnings("unchecked") + ObjectDrawer classDrawer = (ObjectDrawer) getDrawer(drawable.getClass()); + if (classDrawer == null) { + throw new RuntimeException("No ClassDrawer found for " + drawable.getClass().toString()); + } + + layers.computeIfAbsent(classDrawer.getZ(), x -> new ArrayList<>()).add(drawable); + } + return layers; + } /** * Renders the provided DrawableCollection. * * @param drawableCollection the collection of drawable objects to render */ - public void render(DrawableCollection drawableCollection){ - + public void render(DrawableCollection drawableCollection) { ScreenUtils.clear(0, 0, 0, 1); camera.update(); followingDrawer.batch.setProjectionMatrix(camera.combined); followingDrawer.batch.begin(); - for(Object object : drawableCollection){ - - @SuppressWarnings("unchecked") - ObjectDrawer classDrawer = (ObjectDrawer) getDrawer(object.getClass()); - if(classDrawer == null){ - throw new RuntimeException("No ClassDrawer found for " + object.getClass().toString()); + + for (ArrayList layer : getLayers(drawableCollection).values()) { + for (Drawable drawable : layer) { + @SuppressWarnings("unchecked") + ObjectDrawer classDrawer = (ObjectDrawer) getDrawer(drawable.getClass()); + classDrawer.draw(followingDrawer, drawable); } - - classDrawer.draw(followingDrawer, object.getClass().cast(object)); } + followingDrawer.batch.end(); } /** - * Retrieves the ClassDrawer instance for a specific class type. If there is no ClassDrawer instance for the provided - * class type, the method will attempt to find a ClassDrawer instance for a superclass of the provided class type. + * Retrieves the ClassDrawer instance for a specific class type. If there is no + * ClassDrawer instance for the provided + * class type, the method will attempt to find a ClassDrawer instance for a + * superclass of the provided class type. * * @param clazz the class type * @param the type of the class @@ -91,11 +111,11 @@ public static ObjectDrawer getDrawer(Class clazz) { return null; } - public static void addDrawer(Class cls, ObjectDrawer classDrawer){ - if(drawers.containsKey(cls)){ + public static void addDrawer(Class cls, ObjectDrawer classDrawer) { + if (drawers.containsKey(cls)) { throw new RuntimeException("ClassDrawer was added twice for " + cls.toString()); } - drawers.put(cls,classDrawer); + drawers.put(cls, classDrawer); } } diff --git a/core/src/com/po/fuck/view/classdrawers/ObjectDrawer.java b/core/src/com/po/fuck/view/classdrawers/ObjectDrawer.java index 2f9382b..aefe9b0 100644 --- a/core/src/com/po/fuck/view/classdrawers/ObjectDrawer.java +++ b/core/src/com/po/fuck/view/classdrawers/ObjectDrawer.java @@ -1,8 +1,14 @@ package com.po.fuck.view.classdrawers; +import static com.po.fuck.model.constants.LayeringConstants.BACKGROUND; + import com.po.fuck.view.CenterDrawer; public abstract class ObjectDrawer { public abstract void draw(CenterDrawer drawer, T object); + + public int getZ() { + return BACKGROUND; + } } diff --git a/core/src/com/po/fuck/view/classdrawers/factories/BulletDrawerFactory.java b/core/src/com/po/fuck/view/classdrawers/factories/BulletDrawerFactory.java index 89490f6..b9a3d1c 100644 --- a/core/src/com/po/fuck/view/classdrawers/factories/BulletDrawerFactory.java +++ b/core/src/com/po/fuck/view/classdrawers/factories/BulletDrawerFactory.java @@ -13,19 +13,23 @@ import com.po.fuck.view.Renderer; import com.po.fuck.view.classdrawers.ObjectDrawer; +import static com.po.fuck.model.constants.LayeringConstants.WEAPON; import static com.po.fuck.view.classdrawers.Misc.getAnimation; public class BulletDrawerFactory { - static { - Renderer.addDrawer(CosmicBullet.class, BulletDrawerFactory.get(CosmicBullet.class, getAnimation("bullet2.png"))); + Renderer.addDrawer(CosmicBullet.class, + BulletDrawerFactory.get(CosmicBullet.class, getAnimation("bullet2.png"))); Renderer.addDrawer(LaserBeam.class, BulletDrawerFactory.get(LaserBeam.class, - GifDecoder.loadGIFAnimation(Animation.PlayMode.LOOP, Gdx.files.internal("laser3.gif").read() - ))); + GifDecoder.loadGIFAnimation(Animation.PlayMode.LOOP, Gdx.files.internal("laser3.gif").read()))); } - public static ObjectDrawer get(Class clz, Animation animation){ + public static ObjectDrawer get(Class clz, Animation animation) { return new ObjectDrawer() { + @Override + public int getZ() { + return WEAPON; + } @Override public void draw(CenterDrawer drawer, T object) { @@ -36,5 +40,4 @@ public void draw(CenterDrawer drawer, T object) { } }; } - } diff --git a/core/src/com/po/fuck/view/classdrawers/factories/CoinDrawerFactory.java b/core/src/com/po/fuck/view/classdrawers/factories/CoinDrawerFactory.java index ba3adf9..a51b952 100644 --- a/core/src/com/po/fuck/view/classdrawers/factories/CoinDrawerFactory.java +++ b/core/src/com/po/fuck/view/classdrawers/factories/CoinDrawerFactory.java @@ -1,6 +1,7 @@ package com.po.fuck.view.classdrawers.factories; import static com.po.fuck.view.Constants.WIDTH_OF_THE_COIN_COUNTER_DIGIT; +import static com.po.fuck.model.constants.LayeringConstants.GUI; import static com.po.fuck.view.Constants.COINS_COUNTER_POSITION; import static com.po.fuck.view.Constants.COINS_COUNTER_TEXT_SCALE; import static com.po.fuck.view.Constants.COIN_SPRITE_POSITION; @@ -19,14 +20,17 @@ import static com.po.fuck.view.classdrawers.Misc.getAnimation; public class CoinDrawerFactory { - static { Renderer.addDrawer(Coins.class, CoinDrawerFactory.get(Coins.class, getAnimation("coin3.png"))); } - public static ObjectDrawer get(Class clz, Animation animation){ + public static ObjectDrawer get(Class clz, Animation animation) { return new ObjectDrawer() { - + @Override + public int getZ() { + return GUI; + } + @Override public void draw(CenterDrawer drawer, T object) { BitmapFont font = new BitmapFont(); @@ -34,7 +38,7 @@ public void draw(CenterDrawer drawer, T object) { font.setColor(Color.YELLOW); font.getData().scale(COINS_COUNTER_TEXT_SCALE); - + String text = Integer.toString(object.getCoins()); Vector2 counterPosition = new Vector2(COINS_COUNTER_POSITION.x, COINS_COUNTER_POSITION.y); @@ -42,11 +46,10 @@ public void draw(CenterDrawer drawer, T object) { drawer.drawText(text, font, counterPosition); Vector2 position = new Vector2(COIN_SPRITE_POSITION.x, COIN_SPRITE_POSITION.y); - + float len = text.length(); drawer.drawGlobal(coinSprite, position.add(WIDTH_OF_THE_COIN_COUNTER_DIGIT * len, 0)); } }; } - } diff --git a/core/src/com/po/fuck/view/classdrawers/factories/EntityDrawerFactory.java b/core/src/com/po/fuck/view/classdrawers/factories/EntityDrawerFactory.java index 619b08f..5fc7946 100644 --- a/core/src/com/po/fuck/view/classdrawers/factories/EntityDrawerFactory.java +++ b/core/src/com/po/fuck/view/classdrawers/factories/EntityDrawerFactory.java @@ -1,5 +1,6 @@ package com.po.fuck.view.classdrawers.factories; +import static com.po.fuck.model.constants.LayeringConstants.ENTITY; import static com.po.fuck.view.classdrawers.Misc.getAnimation; import com.badlogic.gdx.graphics.g2d.Animation; @@ -15,25 +16,29 @@ import com.po.fuck.view.classdrawers.ObjectDrawer; public class EntityDrawerFactory { - static { - Renderer.addDrawer(Player.class, EntityDrawerFactory.get(Player.class, getAnimation("FUCKerWithoutHands2.png"))); + Renderer.addDrawer(Player.class, + EntityDrawerFactory.get(Player.class, getAnimation("FUCKerWithoutHands2.png"))); Renderer.addDrawer(BasicEnemy.class, EntityDrawerFactory.get(BasicEnemy.class, getAnimation("player2.png"))); } - public static ObjectDrawer get(Class clz, Animation animation){ + public static ObjectDrawer get(Class clz, Animation animation) { return new ObjectDrawer() { + @Override + public int getZ() { + return ENTITY; + } + @Override public void draw(CenterDrawer drawer, T object) { Vector2 position = object.getPosition(); Sprite entitySprite = new Sprite(animation.getKeyFrame(0)); - + drawer.draw(entitySprite, position); - + HealthBar healthBar = new HealthBar(object); healthBar.draw(drawer); } }; } - } diff --git a/core/src/com/po/fuck/view/classdrawers/factories/GameObjectDrawerFactory.java b/core/src/com/po/fuck/view/classdrawers/factories/GameObjectDrawerFactory.java index 3068fd4..0181aab 100644 --- a/core/src/com/po/fuck/view/classdrawers/factories/GameObjectDrawerFactory.java +++ b/core/src/com/po/fuck/view/classdrawers/factories/GameObjectDrawerFactory.java @@ -9,10 +9,8 @@ import com.po.fuck.view.classdrawers.ObjectDrawer; public class GameObjectDrawerFactory { - - public static ObjectDrawer get(Class clz, Animation animation){ + public static ObjectDrawer get(Class clz, Animation animation) { return new ObjectDrawer() { - @Override public void draw(CenterDrawer drawer, T object) { Sprite gameObjectSprite = new Sprite(animation.getKeyFrame(0)); @@ -21,5 +19,4 @@ public void draw(CenterDrawer drawer, T object) { } }; } - } diff --git a/core/src/com/po/fuck/view/classdrawers/factories/HandedWeaponDrawerFactory.java b/core/src/com/po/fuck/view/classdrawers/factories/HandedWeaponDrawerFactory.java index cceeca4..a79c6b7 100644 --- a/core/src/com/po/fuck/view/classdrawers/factories/HandedWeaponDrawerFactory.java +++ b/core/src/com/po/fuck/view/classdrawers/factories/HandedWeaponDrawerFactory.java @@ -11,24 +11,28 @@ import com.po.fuck.view.Renderer; import com.po.fuck.view.classdrawers.ObjectDrawer; +import static com.po.fuck.model.constants.LayeringConstants.WEAPON; import static com.po.fuck.view.classdrawers.Misc.getAnimation; public class HandedWeaponDrawerFactory { - static { Renderer.addDrawer(Glock.class, HandedWeaponDrawerFactory.get(Glock.class, getAnimation("glock3.png"))); - Renderer.addDrawer(LaserGun.class, HandedWeaponDrawerFactory.get(LaserGun.class, getAnimation("laser_gun2.png"))); + Renderer.addDrawer(LaserGun.class, + HandedWeaponDrawerFactory.get(LaserGun.class, getAnimation("laser_gun2.png"))); } - public static ObjectDrawer get(Class clz, Animation animation){ - + public static ObjectDrawer get(Class clz, Animation animation) { return new ObjectDrawer() { - + @Override + public int getZ() { + return WEAPON; + } + @Override public void draw(CenterDrawer drawer, T weapon) { Sprite handedWeaponSprite = new Sprite(animation.getKeyFrame(0)); Vector2 position = weapon.getPosition(); - if (weapon.getAimPosition() != null){ + if (weapon.getAimPosition() != null) { Vector2 direction = weapon.getDirection(); float angle = direction.angleDeg(); handedWeaponSprite.setRotation(-angle); @@ -38,5 +42,4 @@ public void draw(CenterDrawer drawer, T weapon) { } }; } - } diff --git a/core/src/com/po/fuck/view/classdrawers/factories/RoomDrawerFactory.java b/core/src/com/po/fuck/view/classdrawers/factories/RoomDrawerFactory.java index de2dd3c..585a9f2 100644 --- a/core/src/com/po/fuck/view/classdrawers/factories/RoomDrawerFactory.java +++ b/core/src/com/po/fuck/view/classdrawers/factories/RoomDrawerFactory.java @@ -10,13 +10,12 @@ import com.po.fuck.model.Room; public class RoomDrawerFactory { - static { - Renderer.addDrawer(Room.class, - RoomDrawerFactory.get(Room.class, Misc.getAnimation("island2.png"))); + Renderer.addDrawer(Room.class, + RoomDrawerFactory.get(Room.class, Misc.getAnimation("island2.png"))); } - public static ObjectDrawer get(Class clz, Animation animation){ + public static ObjectDrawer get(Class clz, Animation animation) { return new ObjectDrawer() { @Override public void draw(CenterDrawer drawer, T object) { @@ -24,5 +23,4 @@ public void draw(CenterDrawer drawer, T object) { } }; } - } diff --git a/desktop/src/com/po/fuck/DesktopLauncher.java b/desktop/src/com/po/fuck/DesktopLauncher.java index e90c249..8dbfa72 100644 --- a/desktop/src/com/po/fuck/DesktopLauncher.java +++ b/desktop/src/com/po/fuck/DesktopLauncher.java @@ -2,7 +2,7 @@ import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application; import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration; -import com.po.fuck.model.Constants; +import com.po.fuck.model.constants.GameScreen; // Please note that on macOS your application needs to be started with the -XstartOnFirstThread JVM argument public class DesktopLauncher { @@ -10,7 +10,7 @@ public static void main(String[] arg) { Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration(); config.setForegroundFPS(60); config.setTitle("FUCK"); - config.setWindowedMode(Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT); + config.setWindowedMode(GameScreen.WIDTH, GameScreen.HEIGHT); new Lwjgl3Application(new FUCK(), config); } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a441313..b82aa23 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index b740cf1..1aa94a4 100755 --- a/gradlew +++ b/gradlew @@ -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/.