-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Camera following entities but within specified bounds.
- Loading branch information
Showing
11 changed files
with
208 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
core/src/main/java/jgd/platformer/logic/PlatformerTimeEntityProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package jgd.platformer.logic; | ||
|
||
import com.gempukku.gaming.time.TimeEntityProvider; | ||
import com.gempukku.secsy.context.annotation.Inject; | ||
import com.gempukku.secsy.context.annotation.RegisterSystem; | ||
import com.gempukku.secsy.context.system.LifeCycleSystem; | ||
import com.gempukku.secsy.entity.EntityManager; | ||
import com.gempukku.secsy.entity.EntityRef; | ||
|
||
@RegisterSystem( | ||
shared = TimeEntityProvider.class | ||
) | ||
public class PlatformerTimeEntityProvider implements TimeEntityProvider, LifeCycleSystem { | ||
@Inject | ||
private EntityManager entityManager; | ||
|
||
private EntityRef timeEntity; | ||
|
||
@Override | ||
public void initialize() { | ||
timeEntity = entityManager.createEntity(); | ||
} | ||
|
||
@Override | ||
public EntityRef getTimeEntity() { | ||
return timeEntity; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
core/src/main/java/jgd/platformer/logic/controls/KeyboardSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package jgd.platformer.logic.controls; | ||
|
||
import com.badlogic.gdx.Gdx; | ||
import com.badlogic.gdx.Input; | ||
import com.gempukku.gaming.time.TimeManager; | ||
import com.gempukku.secsy.context.annotation.Inject; | ||
import com.gempukku.secsy.context.annotation.RegisterSystem; | ||
import com.gempukku.secsy.context.system.LifeCycleSystem; | ||
import com.gempukku.secsy.entity.EntityRef; | ||
import com.gempukku.secsy.entity.game.GameLoop; | ||
import com.gempukku.secsy.entity.game.GameLoopListener; | ||
import com.gempukku.secsy.entity.index.EntityIndex; | ||
import com.gempukku.secsy.entity.index.EntityIndexManager; | ||
import jgd.platformer.component.LocationComponent; | ||
|
||
@RegisterSystem( | ||
profiles = "keyboard" | ||
) | ||
public class KeyboardSystem implements LifeCycleSystem, GameLoopListener { | ||
private static final float BLOCKS_PER_MILLISECOND = (4f / 1000); | ||
@Inject | ||
private GameLoop gameLoop; | ||
@Inject | ||
private TimeManager timeManager; | ||
@Inject | ||
private EntityIndexManager entityIndexManager; | ||
|
||
private int[] leftKeys = {Input.Keys.LEFT, Input.Keys.A}; | ||
private int[] rightKeys = {Input.Keys.RIGHT, Input.Keys.D}; | ||
private EntityIndex controlledEntities; | ||
|
||
@Override | ||
public void initialize() { | ||
gameLoop.addGameLoopListener(this); | ||
|
||
controlledEntities = entityIndexManager.addIndexOnComponents(PlayerControlledComponent.class, LocationComponent.class); | ||
} | ||
|
||
@Override | ||
public void update() { | ||
boolean leftPressed = isLeftPressed(); | ||
boolean rightPressed = isRightPressed(); | ||
|
||
long timeSinceLastUpdate = timeManager.getTimeSinceLastUpdate(); | ||
|
||
float xDiff = 0; | ||
|
||
if (leftPressed && !rightPressed) { | ||
xDiff -= timeSinceLastUpdate * BLOCKS_PER_MILLISECOND; | ||
} else if (rightPressed && !leftPressed) { | ||
xDiff += timeSinceLastUpdate * BLOCKS_PER_MILLISECOND; | ||
} | ||
|
||
if (xDiff != 0) { | ||
for (EntityRef entityRef : controlledEntities.getEntities()) { | ||
LocationComponent location = entityRef.getComponent(LocationComponent.class); | ||
location.setX(location.getX() + xDiff); | ||
entityRef.saveChanges(); | ||
} | ||
} | ||
} | ||
|
||
private boolean isLeftPressed() { | ||
return isAnyPressed(leftKeys); | ||
} | ||
|
||
private boolean isRightPressed() { | ||
return isAnyPressed(rightKeys); | ||
} | ||
|
||
private boolean isAnyPressed(int[] keys) { | ||
for (int key : keys) { | ||
if (Gdx.input.isKeyPressed(key)) | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
core/src/main/java/jgd/platformer/logic/controls/PlayerControlledComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package jgd.platformer.logic.controls; | ||
|
||
import com.gempukku.secsy.entity.Component; | ||
|
||
public interface PlayerControlledComponent extends Component { | ||
} |
13 changes: 13 additions & 0 deletions
13
core/src/main/java/jgd/platformer/rendering/CameraBoundsComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package jgd.platformer.rendering; | ||
|
||
import com.gempukku.secsy.entity.Component; | ||
|
||
public interface CameraBoundsComponent extends Component { | ||
float getMinX(); | ||
|
||
float getMaxX(); | ||
|
||
float getMinY(); | ||
|
||
float getMaxY(); | ||
} |
9 changes: 9 additions & 0 deletions
9
core/src/main/java/jgd/platformer/rendering/CameraFocusComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package jgd.platformer.rendering; | ||
|
||
import com.gempukku.secsy.entity.Component; | ||
|
||
public interface CameraFocusComponent extends Component { | ||
float getFocusWeight(); | ||
|
||
void setFocusWeight(float focusWeight); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters