Fixed player rotation

This commit is contained in:
Ash Reynolds 2016-02-16 15:02:24 +00:00
parent 71d9c3afba
commit ec583e75be
13 changed files with 90 additions and 39 deletions

View file

@ -8,7 +8,7 @@
</tileset>
<layer name="PLATFORM" width="50" height="8">
<data encoding="base64" compression="zlib">
eJxjYBgFo2AUDARgIoAHC2AmgKkB0P2Oyy5GApge4YnL7pEIALMwAF8=
eJxjYBgFxAImJDyUABMDfrczY8HEAHL1kQIoDXNCbqK2mxmRMK3SC7XDnREHHowAl1tp4V58dlGK6e0uWgEAX2sAgg==
</data>
</layer>
<objectgroup name="PLAYER">

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

View file

@ -1,7 +1,9 @@
package com.game.actor;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.*;
import com.game.App;
@ -17,7 +19,7 @@ public class Player extends Base {
Vector2 curVel;
private Texture texture;
private Sprite sprite;
private Action curAction;
public enum Action
@ -38,7 +40,7 @@ public class Player extends Base {
);
Box2dUtils.makeCircle(body, size.x, "PLAYER", false, Vars.BIT_PLAYER, (short)(Vars.BIT_RED | Vars.BIT_MISC));
texture = App.assets.get("textures/player_red.png");
sprite = new Sprite(App.assets.get("textures/player_red.png", Texture.class));
}
public void update(float dt)
@ -53,15 +55,14 @@ public class Player extends Base {
curVel.x = Vars.SCROLLSPEED.x * dt;
body.setLinearVelocity(curVel);
pos = body.getPosition();
sprite.setPosition((pos.x * PPM) - size.x / 2, (pos.y * PPM) - size.y / 2);
sprite.setRotation(body.getAngle() * MathUtils.radiansToDegrees);
}
public void render(SpriteBatch sb)
{
sb.draw(texture,
(pos.x * PPM) - size.x / 2,
(pos.y * PPM) - size.y / 2,
size.x,
size.y);
sprite.draw(sb);
}
public void jump()
@ -90,26 +91,30 @@ public class Player extends Base {
case RED:
bits &= ~Vars.BIT_GREEN;
bits &= ~Vars.BIT_BLUE;
bits &= ~Vars.BIT_YELLOW;
bits |= Vars.BIT_RED;
texture = App.assets.get("textures/player_red.png", Texture.class);
sprite.setTexture(App.assets.get("textures/player_red.png", Texture.class));
break;
case GREEN:
bits &= ~Vars.BIT_RED;
bits &= ~Vars.BIT_BLUE;
bits &= ~Vars.BIT_YELLOW;
bits |= Vars.BIT_GREEN;
texture = App.assets.get("textures/player_green.png", Texture.class);
sprite.setTexture(App.assets.get("textures/player_green.png", Texture.class));
break;
case BLUE:
bits &= ~Vars.BIT_RED;
bits &= ~Vars.BIT_GREEN;
bits &= ~Vars.BIT_YELLOW;
bits |= Vars.BIT_BLUE;
texture = App.assets.get("textures/player_blue.png", Texture.class);
sprite.setTexture(App.assets.get("textures/player_blue.png", Texture.class));
break;
case YELLOW:
bits &= ~Vars.BIT_RED;
bits &= ~Vars.BIT_GREEN;
bits |= Vars.BIT_BLUE;
texture = App.assets.get("textures/player_yellow.png", Texture.class);
bits &= ~Vars.BIT_BLUE;
bits |= Vars.BIT_YELLOW;
sprite.setTexture(App.assets.get("textures/player_yellow.png", Texture.class));
break;
}

View file

@ -25,6 +25,7 @@ public class Vars {
public static final short BIT_RED = 2;
public static final short BIT_GREEN = 4;
public static final short BIT_BLUE = 8;
public static final short BIT_PLAYER = 16;
public static final short BIT_MISC = 32;
public static final short BIT_YELLOW = 16;
public static final short BIT_PLAYER = 32;
public static final short BIT_MISC = 64;
}

View file

@ -52,6 +52,7 @@ public class Loading extends AbstractScreen {
@Override
public void update(float dt) {
percent = Interpolation.linear.apply(percent, app.assets.getProgress(), 0.3f);
System.out.println("Loading... " + app.assets.getProgress() * 100 + "%");
loadingRect.width = 0 + 853.3333f * percent;
@ -91,11 +92,12 @@ public class Loading extends AbstractScreen {
private void assetsToLoad()
{
// Fonts
loadFont("fonts/badaboom.TTF", 25, Color.BLACK);
loadFont("fonts/badaboom.TTF", 30, Color.BLACK);
loadFont("fonts/badaboom.TTF", 45, Color.BLACK);
// Textures
app.assets.load("textures/badlogic.jpg", Texture.class);
app.assets.load("textures/menuBackground.jpg", Texture.class);
app.assets.load("textures/leaderboardBackground.jpg", Texture.class);
@ -103,21 +105,27 @@ public class Loading extends AbstractScreen {
app.assets.load("textures/pauseBackground.png", Texture.class);
app.assets.load("textures/failureBackground.png", Texture.class);
app.assets.load("textures/successBackground.png", Texture.class);
app.assets.load("textures/level1Intro.png", Texture.class);
app.assets.load("textures/level2Intro.png", Texture.class);
app.assets.load("textures/pauseGlow.png", Texture.class);
app.assets.load("textures/position0.png", Texture.class);
app.assets.load("textures/position1.png", Texture.class);
app.assets.load("textures/position2.png", Texture.class);
for(int i = 1; i <= 10; i++)
{
app.assets.load("textures/level" + i + "Intro.png", Texture.class);
}
app.assets.load("textures/player_green.png", Texture.class);
app.assets.load("textures/player_blue.png", Texture.class);
app.assets.load("textures/player_yellow.png", Texture.class);
// Spritesheets
app.assets.load("spritesheets/platformSet.png", Texture.class);
// Music
app.assets.load("music/TheComplex.mp3", Music.class);
// Sound
app.assets.load("sounds/jumping.mp3", Sound.class);
app.assets.load("sounds/colourchange.mp3", Sound.class);
app.assets.load("music/TheComplex.mp3", Music.class);
}
private void loadFont(String fontFileName, int size, Color borderColour)

View file

@ -6,6 +6,7 @@ import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.maps.MapLayer;
import com.badlogic.gdx.maps.MapProperties;
import com.badlogic.gdx.maps.objects.PolylineMapObject;
@ -14,7 +15,9 @@ import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.math.Polyline;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.*;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
@ -64,27 +67,27 @@ public class Play extends AbstractScreen {
private ArrayList<Platform> platforms = new ArrayList<Platform>();
// Intro window
private boolean hasPlayedOnce = false;
private boolean isIntro;
private Window introWindow;
private Image introBackground;
private TextButton butProceed;
// Pause window
private boolean isPaused;
private Window pauseWindow;
private Image pauseBackground;
private Image pauseGlow;
private TextButton butContinue, butReset, butExit;
private Vector2 buttonSize;
// Endgame window
private boolean isEnd;
private boolean isSuccess;
private Window endgameWindow;
private TextButton butNext;
private Image failureBackground, successBackground;
// Progress bar
private float percent;
private Rectangle progressRect;
private int levelNumber;
private Sound jumpSound = Gdx.audio.newSound(Gdx.files.internal("sounds/jumping.mp3"));
@ -122,6 +125,8 @@ public class Play extends AbstractScreen {
skin.add("default-font", app.assets.get("badaboom60.ttf", BitmapFont.class));
skin.load(Gdx.files.internal("spritesheets/uiskin.json"));
progressRect = new Rectangle(stage.getWidth() - 550, (stage.getHeight() - 50), 0, 25);
initLevel();
initIntroWindow();
initPauseWindow();
@ -141,6 +146,11 @@ public class Play extends AbstractScreen {
Vector2 start = new Vector2(cam.viewportWidth / 2, cam.viewportHeight / 2);
CameraUtils.setBoundary(cam, start, new Vector2(mapWidth * tileSize.x - start.x * 2, mapHeight * tileSize.y - start.y * 2));
percent = Interpolation.linear.apply(percent, 500, 0.3f );
System.out.println(mapWidth - player.getPos().x);
progressRect.width = 0 + 500 * percent;
if (progressRect.width >= 499) { progressRect.width = 500; }
player.update(dt);
}
@ -153,9 +163,8 @@ public class Play extends AbstractScreen {
if(endgameWindow.isVisible() != isEnd)
{
initEndgameWindow(isSuccess);
endgameWindow.setVisible(isEnd);
endgameWindow.setVisible(isEnd);
pauseGlow.setVisible(isEnd);
}
stage.act(dt);
@ -178,6 +187,20 @@ public class Play extends AbstractScreen {
tmr.setView(cam);
tmr.render();
// HUD related
app.sb.setProjectionMatrix(hudCam.combined);
app.sr.begin(ShapeRenderer.ShapeType.Filled);
app.sr.setColor(1, 0, 0, 1);
app.sr.rect(progressRect.x, progressRect.y, progressRect.width, progressRect.height); // Red loading bar
app.sr.set(ShapeRenderer.ShapeType.Line);
app.sr.rect(progressRect.x, progressRect.y, 500f, progressRect.height); // Outline
app.sr.end();
app.sb.begin();
app.sb.draw(app.assets.get("spritesheets/platformSet.png", Texture.class), 100, 100);
app.sb.end();
}
else
{
@ -318,7 +341,7 @@ public class Play extends AbstractScreen {
introWindow.setPosition(280, 50);
introWindow.setVisible(true);
butProceed = new TextButton("PROCEED", skin, "default");
TextButton butProceed = new TextButton("PROCEED", skin, "default");
butProceed.setPosition((introWindow.getWidth() / 4) * 3, buttonSize.y + 360);
butProceed.setSize(buttonSize.x, buttonSize.y);
butProceed.addListener(new ClickListener() {
@ -332,11 +355,7 @@ public class Play extends AbstractScreen {
introWindow.addActor(butProceed);
if(!hasPlayedOnce){
stage.addActor(introWindow);
hasPlayedOnce = true;
}
stage.addActor(introWindow);
}
private void initPauseWindow()
@ -349,7 +368,7 @@ public class Play extends AbstractScreen {
pauseWindow.setPosition(280, 50);
pauseWindow.setVisible(false);
butContinue = new TextButton("Continue", skin, "default");
TextButton butContinue = new TextButton("Continue", skin, "default");
butContinue.setPosition((pauseWindow.getWidth() / 2) - buttonSize.x / 2, buttonSize.y + 240);
butContinue.setSize(buttonSize.x, buttonSize.y);
butContinue.addListener(new ClickListener() {
@ -359,7 +378,7 @@ public class Play extends AbstractScreen {
}
});
butReset = new TextButton("Reset", skin, "default");
TextButton butReset = new TextButton("Reset", skin, "default");
butReset.setPosition((pauseWindow.getWidth() / 2) - buttonSize.x / 2, buttonSize.y + 140);
butReset.setSize(buttonSize.x, buttonSize.y);
butReset.addListener(new ClickListener() {
@ -369,7 +388,7 @@ public class Play extends AbstractScreen {
}
});
butExit = new TextButton("Exit", skin, "default");
TextButton butExit = new TextButton("Exit", skin, "default");
butExit.setPosition((pauseWindow.getWidth() / 2) - buttonSize.x / 2, buttonSize.y + 40);
butExit.setSize(buttonSize.x, buttonSize.y);
butExit.addListener(new ClickListener() {
@ -397,7 +416,7 @@ public class Play extends AbstractScreen {
successBackground = new Image(app.assets.get("textures/successBackground.png", Texture.class));
endgameWindow.setBackground(successBackground.getDrawable());
butNext = new TextButton("Next", skin, "default");
TextButton butNext = new TextButton("Next", skin, "default");
butNext.setPosition((pauseWindow.getWidth() / 2) - buttonSize.x / 2, buttonSize.y + 240);
butNext.setSize(buttonSize.x, buttonSize.y);
butNext.addListener(new ClickListener() {
@ -417,10 +436,29 @@ public class Play extends AbstractScreen {
endgameWindow.setPosition(280, 50);
endgameWindow.setVisible(false);
TextButton butReset = new TextButton("Reset", skin, "default");
butReset.setPosition((pauseWindow.getWidth() / 2) - buttonSize.x / 2, buttonSize.y + 140);
butReset.setSize(buttonSize.x, buttonSize.y);
butReset.addListener(new ClickListener() {
@Override
public void clicked (com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
app.sm.setPlayScreen(levelNumber);
}
});
TextButton butExit = new TextButton("Exit", skin, "default");
butExit.setPosition((pauseWindow.getWidth() / 2) - buttonSize.x / 2, buttonSize.y + 40);
butExit.setSize(buttonSize.x, buttonSize.y);
butExit.addListener(new ClickListener() {
@Override
public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
app.sm.setScreen(ScreenManager.Screen.MENU);
}
});
endgameWindow.addActor(butReset);
endgameWindow.addActor(butExit);
stage.addActor(pauseGlow);
stage.addActor(endgameWindow);
}
@ -452,7 +490,6 @@ public class Play extends AbstractScreen {
{
isEnd = true;
isSuccess = true;
return;
}