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

move camera only forward #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
13 changes: 10 additions & 3 deletions core/src/com/brentaureli/mariobros/Screens/PlayScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void update(float dt){
player.update(dt);
for(Enemy enemy : creator.getEnemies()) {
enemy.update(dt);
if(enemy.getX() < player.getX() + 224 / MarioBros.PPM) {
if(enemy.getX() < gamecam.position.x + 224 / MarioBros.PPM) {
enemy.b2body.setActive(true);
}
}
Expand All @@ -166,8 +166,15 @@ public void update(float dt){
hud.update(dt);

//attach our gamecam to our players.x coordinate
if(player.currentState != Mario.State.DEAD) {
gamecam.position.x = player.b2body.getPosition().x;
if (player.currentState != Mario.State.DEAD) {
// move camera only forward
if (gamecam.position.x < player.b2body.getPosition().x) {
gamecam.position.x = player.b2body.getPosition().x;
// stop mario when he is running out of the screen
} else if (player.b2body.getPosition().x - player.b2body.getFixtureList().get(0).getShape().getRadius() <= gamecam.position.x - gamecam.viewportWidth / 2) {
player.b2body.setLinearVelocity(0, player.b2body.getLinearVelocity().y);
player.b2body.applyLinearImpulse(new Vector2(0.1f, 0), player.b2body.getLocalCenter(), true);
}
}

//update our gamecam with correct coordinates after changes
Expand Down