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

add my sprite sheets #372

Merged
merged 13 commits into from
Nov 13, 2022
Binary file added core/assets/dedault_spritesheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/default_spritesheet2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0008.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0009.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0011.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0012.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0013.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0014.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0015.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0016.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0017.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0018.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0019.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0020.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0021.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0022.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/punch/punch_0023.png
Binary file added core/assets/punch/punch_0024.png
Binary file added core/assets/punch/punch_0025.png
Binary file added core/assets/punch/punch_0026.png
Binary file added core/assets/walking_spritesheet.png
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public enum AnimationState {
WALKING_LEFT,
JUMPING,
FALLING,
ATTACKING,
PUNCH_LEFT,
PUNCH_RIGHT,
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class GameAnimationFactory {

GameAnimation createEntityAnimation() {
GameAnimation createEntityAnimation2() {
final int FRAME_COLS = 6, FRAME_ROWS = 5;
Texture walkSheet = new Texture(Gdx.files.internal("sprite-animation4.png"));
TextureRegion[][] tmp =
Expand Down Expand Up @@ -45,6 +45,98 @@ GameAnimation createEntityAnimation() {
.build();
}

GameAnimation createEntityAnimation() {
final int DEFAULT_FRAMES_NUM = 23;
final int DEFAULT_FRAME_COLS = 6, DEFAULT_FRAME_ROWS = 4;
final String DEFAULT_FILE_NAME = "default_spritesheet2.png";
Texture walkSheet = new Texture(Gdx.files.internal(DEFAULT_FILE_NAME));
TextureRegion[][] tmp =
TextureRegion.split(
walkSheet,
walkSheet.getWidth() / DEFAULT_FRAME_COLS,
walkSheet.getHeight() / DEFAULT_FRAME_ROWS);

TextureRegion[] defaultFrames = new TextureRegion[DEFAULT_FRAMES_NUM];
int index = 0;
for (int i = 0; i < DEFAULT_FRAME_ROWS; i++) {
for (int j = 0; j < DEFAULT_FRAME_COLS; j++) {
if (index >= DEFAULT_FRAMES_NUM) break;
defaultFrames[index++] = tmp[i][j];
}
}

final int WALKING_FRAMES_NUM = 26;
final int WALKING_FRAME_COLS = 6, WALKING_FRAME_ROWS = 5;
final String WALKING_FILE_NAME = "walking_spritesheet.png";

walkSheet = new Texture(Gdx.files.internal(WALKING_FILE_NAME));
tmp =
TextureRegion.split(
walkSheet,
walkSheet.getWidth() / WALKING_FRAME_COLS,
walkSheet.getHeight() / WALKING_FRAME_ROWS);

TextureRegion[] walkLeftFrames = new TextureRegion[WALKING_FRAMES_NUM];
index = 0;
for (int i = 0; i < WALKING_FRAME_ROWS; i++) {
for (int j = 0; j < WALKING_FRAME_COLS; j++) {
// tmp[i][j].flip(true, false);
if (index >= WALKING_FRAMES_NUM) break;

walkLeftFrames[index++] = tmp[i][j];
}
}

TextureRegion[] walkRightFrames = new TextureRegion[WALKING_FRAMES_NUM];
tmp =
TextureRegion.split(
walkSheet,
walkSheet.getWidth() / WALKING_FRAME_COLS,
walkSheet.getHeight() / WALKING_FRAME_ROWS);
index = 0;
for (int i = 0; i < WALKING_FRAME_ROWS; i++) {
for (int j = 0; j < WALKING_FRAME_COLS; j++) {
if (index >= WALKING_FRAMES_NUM) break;
tmp[i][j].flip(true, false);
walkRightFrames[index++] = tmp[i][j];
}
}

TextureRegion[] punchFramesLeft = new TextureRegion[27];
for (int i = 0; i < 27; i++) {
if (i < 10)
punchFramesLeft[i] =
new TextureRegion(new Texture(Gdx.files.internal("punch/punch_000" + i + ".png")));
else
punchFramesLeft[i] =
new TextureRegion(new Texture(Gdx.files.internal("punch/punch_00" + i + ".png")));
}

TextureRegion[] punchFramesRight = new TextureRegion[27];
for (int i = 0; i < 27; i++) {
if (i < 10)
punchFramesRight[i] =
new TextureRegion(new Texture(Gdx.files.internal("punch/punch_000" + i + ".png")));
else
punchFramesRight[i] =
new TextureRegion(new Texture(Gdx.files.internal("punch/punch_00" + i + ".png")));

punchFramesRight[i].flip(true, false);
}

return new GameAnimationBuilder()
.addAnimation(AnimationState.DEFAULT, new Animation<TextureRegion>(0.25f, defaultFrames))
.addAnimation(
AnimationState.WALKING_LEFT, new Animation<TextureRegion>(0.05f, walkLeftFrames))
.addAnimation(
AnimationState.WALKING_RIGHT, new Animation<TextureRegion>(0.05f, walkRightFrames))
.addAnimation(
AnimationState.PUNCH_LEFT, new Animation<TextureRegion>(0.05f, punchFramesLeft))
.addAnimation(
AnimationState.PUNCH_RIGHT, new Animation<TextureRegion>(0.05f, punchFramesRight))
.build();
}

GameAnimation createOrbAnimation() {
TextureRegion[] orbFrames = new TextureRegion[6];

Expand Down
4 changes: 2 additions & 2 deletions core/src/core/common/GameSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.Properties;

public class GameSettings {
public static final boolean RENDER_DEBUG = true;
public static final boolean RENDER_DEBUG = false;

public static final int AI_LIMIT = 10;

Expand All @@ -17,7 +17,7 @@ public class GameSettings {
public static final int WORLD_VELOCITY_ITERATIONS = 6;
public static final int WORLD_POSITION_ITERATIONS = 2;
public static final int CHUNK_SIZE = 5;
public static final int PIXEL_SCALE = 30;
public static final int PIXEL_SCALE = 70;
public static final int PHYSICS_SCALE = 25;
public static final float GRAVITY = 1f;
public static final int GENERATION_THREADS = 5;
Expand Down
13 changes: 13 additions & 0 deletions core/src/core/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
import core.entity.controllers.EntityController;
import core.entity.controllers.events.types.AbstractEntityEventType;
import core.entity.controllers.events.types.EntityEventTypeFactory;
import core.entity.statemachine.EntityStateMachine;
import core.networking.events.interfaces.SerializeNetworkData;
import core.networking.translation.NetworkDataSerializer;
import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Consumer;
Expand All @@ -53,6 +55,8 @@ public class Entity implements SerializeNetworkData {
public Health health;
protected BaseAssetManager baseAssetManager;
float stateTime;
private EntityStateMachine entityStateMachine =
new EntityStateMachine(this, new HashMap<>(), new HashMap<>());
private DirectionWrapper directionWrapper = new DirectionWrapper(Direction.RIGHT);
private CoordinatesWrapper coordinatesWrapper;
private UUID uuid;
Expand Down Expand Up @@ -81,6 +85,14 @@ public Entity(
stateTime = (float) ThreadLocalRandom.current().nextDouble(0, 20);
}

public EntityStateMachine getEntityStateMachine() {
return entityStateMachine;
}

public void setEntityStateMachine(EntityStateMachine entityStateMachine) {
this.entityStateMachine = entityStateMachine;
}

public AnimationStateWrapper getAnimationStateWrapper() {
return animationStateWrapper;
}
Expand Down Expand Up @@ -180,6 +192,7 @@ protected Pair<UUID, Body> addWorld(World world) {
}

public void render(AnimationManager animationManager, SpriteBatch batch) {
entityStateMachine.callAnimation();
stateTime += Gdx.graphics.getDeltaTime();

Vector2 v2 = this.getCoordinatesWrapper().getCoordinates().toRenderVector2();
Expand Down
3 changes: 3 additions & 0 deletions core/src/core/entity/EntityFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@
import core.entity.misc.Turret;
import core.entity.misc.water.Water;
import core.entity.misc.water.WaterPosition;
import core.entity.statemachine.EntityStateMachineFactory;

public class EntityFactory {

@Inject Clock clock;
@Inject BaseAssetManager baseAssetManager;
@Inject EntityBodyBuilder entityBodyBuilder;
@Inject EntityStateMachineFactory entityStateMachineFactory;

@Inject
EntityFactory() {}

public Entity createEntity(Coordinates coordinates) {
Entity entity = new Entity(clock, baseAssetManager, entityBodyBuilder, coordinates);
entity.setEntityStateMachine(entityStateMachineFactory.createEntityStateMachine(entity));
return entity;
}

Expand Down
10 changes: 6 additions & 4 deletions core/src/core/entity/controllers/EntityController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import core.app.game.GameController;
import core.app.screen.assets.animations.AnimationState;
import core.chunk.world.exceptions.BodyNotFound;
import core.common.CommonFactory;
import core.common.Coordinates;
Expand Down Expand Up @@ -61,10 +62,7 @@ public EntityController registerEntityEventConsumer(String type, EntityEventCons
}

public void applyAction(String type, Entity entity) throws ChunkNotFound, BodyNotFound {
entity.applyBody(
(Body body) -> {
this.actionMap.get(type).apply(body);
});
this.actionMap.get(type).apply(entity);
}

public EntityAction getAction(String type) {
Expand All @@ -82,12 +80,16 @@ public Set<Map.Entry<String, EntityAction>> getEntityActionEntrySet() {
public void beforeWorldUpdate() throws Exception {}

public void afterWorldUpdate() throws Exception {
entity.getEntityStateMachine().callAction();
Coordinates moveTo =
CommonFactory.createCoordinates(
this.entity.getBodyPosition().x / GameSettings.PHYSICS_SCALE,
this.entity.getBodyPosition().y / GameSettings.PHYSICS_SCALE);
if (!this.entity.getCoordinatesWrapper().getCoordinates().equals(moveTo))
gameController.moveEntity(this.entity.getUuid(), moveTo);
else {
entity.getEntityStateMachine().attemptTransition(AnimationState.DEFAULT);
}

if (this.getAction("climbUp").isValid(entity)) {
this.entity.setBodyVelocity(new Vector2(0, 0));
Expand Down
18 changes: 5 additions & 13 deletions core/src/core/entity/controllers/EntityUserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import core.entity.Entity;
import core.entity.attributes.inventory.Equipped;
import core.entity.attributes.inventory.InventoryBag;
import core.entity.attributes.msc.AnimationStateWrapper;
import core.entity.attributes.msc.DirectionWrapper;
import core.entity.block.DirtBlock;
import core.entity.controllers.actions.EntityActionFactory;
import core.networking.events.EventTypeFactory;
Expand Down Expand Up @@ -77,7 +75,11 @@ public void beforeWorldUpdate() throws EntityNotFound, ChunkNotFound, BodyNotFou
}
}
if (Gdx.input.isKeyJustPressed(Input.Keys.R)) {
gameController.useItem(this.entity);
if (entity.getDirectionWrapper().getDirection() == Direction.LEFT)
entity.getEntityStateMachine().attemptTransition(AnimationState.PUNCH_LEFT);
else if (entity.getDirectionWrapper().getDirection() == Direction.RIGHT) {
entity.getEntityStateMachine().attemptTransition(AnimationState.PUNCH_RIGHT);
}
}

if (Gdx.input.isKeyJustPressed(Keys.NUM_1)) {
Expand Down Expand Up @@ -131,21 +133,11 @@ public void beforeWorldUpdate() throws EntityNotFound, ChunkNotFound, BodyNotFou
if (Gdx.input.isKeyPressed(Input.Keys.A)) {
if (this.getAction("left").isValid(entity)) {
this.applyAction("left", entity);
this.gameController.updateEntityAttribute(
this.entity.getUuid(), new AnimationStateWrapper(AnimationState.WALKING_LEFT));

this.gameController.updateEntityAttribute(
this.entity.getUuid(), new DirectionWrapper(Direction.LEFT));
}
}
if (Gdx.input.isKeyPressed(Input.Keys.D)) {
if (this.getAction("right").isValid(entity)) {
this.applyAction("right", entity);
this.gameController.updateEntityAttribute(
this.entity.getUuid(), new AnimationStateWrapper(AnimationState.WALKING_RIGHT));

this.gameController.updateEntityAttribute(
this.entity.getUuid(), new DirectionWrapper(Direction.RIGHT));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package core.entity.controllers.actions;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import core.chunk.world.exceptions.BodyNotFound;
import core.common.exceptions.ChunkNotFound;
import core.entity.Entity;
import core.entity.collision.ladder.EntityLadderContact;

public class ClimbDownMovementAction extends ClimbUpMovementAction {
Expand All @@ -10,9 +12,12 @@ public ClimbDownMovementAction(EntityLadderContact entityLadderContact) {
}

@Override
public void apply(Body body) {
body.setGravityScale(0);
float x = body.getLinearVelocity().x;
body.setLinearVelocity(new Vector2(x, -5));
public void apply(Entity entity) throws ChunkNotFound, BodyNotFound {
entity.applyBody(
(body -> {
body.setGravityScale(0);
float x = body.getLinearVelocity().x;
body.setLinearVelocity(new Vector2(x, -5));
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import core.chunk.world.exceptions.BodyNotFound;
import core.common.exceptions.ChunkNotFound;
import core.entity.Entity;
import core.entity.collision.ladder.EntityLadderContact;
import java.util.function.Consumer;

public class ClimbUpMovementAction implements EntityAction {
EntityLadderContact entityLadderContact;
Expand All @@ -14,9 +16,16 @@ public ClimbUpMovementAction(EntityLadderContact entityLadderContact) {
}

@Override
public void apply(Body body) {
float x = body.getLinearVelocity().x;
body.setLinearVelocity(new Vector2(x, 5));
public void apply(Entity entity) throws ChunkNotFound, BodyNotFound {
entity.applyBody(this.applyBodyConsumer());
}

@Override
public Consumer<Body> applyBodyConsumer() {
return (body) -> {
float x = body.getLinearVelocity().x;
body.setLinearVelocity(new Vector2(x, 5));
};
}

@Override
Expand Down
6 changes: 5 additions & 1 deletion core/src/core/entity/controllers/actions/EntityAction.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package core.entity.controllers.actions;

import com.badlogic.gdx.physics.box2d.Body;
import core.chunk.world.exceptions.BodyNotFound;
import core.common.exceptions.ChunkNotFound;
import core.entity.Entity;
import java.util.function.Consumer;

public interface EntityAction {

void apply(Body body);
void apply(Entity entity) throws ChunkNotFound, BodyNotFound;

Consumer<Body> applyBodyConsumer();

Boolean isValid(Entity entity) throws ChunkNotFound;
}
Loading