Skip to content

Commit

Permalink
less fail
Browse files Browse the repository at this point in the history
  • Loading branch information
cantrem committed Dec 18, 2011
2 parents 0d97ffc + 1a35ff8 commit 12be532
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 5 deletions.
Binary file modified fanta-is-awesome/bin/com/siegedog/hava/derpygame/LRR.class
Binary file not shown.
Binary file modified fanta-is-awesome/bin/com/siegedog/hava/engine/GameCam2D.class
Binary file not shown.
Binary file modified fanta-is-awesome/bin/com/siegedog/hava/engine/MU.class
Binary file not shown.
Binary file modified fanta-is-awesome/bin/com/siegedog/hava/engine/RenderNode2D.class
Binary file not shown.
Expand Up @@ -60,7 +60,6 @@ public class GameplayScreen implements Screen {

public void initPlayer(Unit player) {
dude1 = player;
cam.follow(player.getPhysics(), false);
root.addNode(player);
}

Expand All @@ -71,8 +70,6 @@ public GameplayScreen(FancyGame game) {

font = new BitmapFont();
font.setColor(new Color(0.5f, 0.5f, 0.8f, 0.94f));
cam = new GameCam2D(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
UICam = new OrthographicCamera();

spriteBatch = new SpriteBatch();

Expand All @@ -82,6 +79,12 @@ public GameplayScreen(FancyGame game) {
map = new TileMap("level", PIXELS_PER_METER, this);
map.loadCollisions("data/tiledmap/collisions.txt", world);
boxDebugRenderer = new Box2DDebugRenderer(true, true, true);

cam = new GameCam2D(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),
new Vector2(map.getWidth() * PIXELS_PER_METER, map.getHeight() * PIXELS_PER_METER));

cam.follow(dude1.getPhysics(), false);

root.addNode(new UberJumpNode(15,40,3,3));
root.addNode(new UberSpeedNode(17,43,3,3));

Expand Down
4 changes: 3 additions & 1 deletion fanta-is-awesome/src/com/siegedog/hava/derpygame/LRR.java
Expand Up @@ -20,6 +20,7 @@ public LRR(float x, float y, InputNode _inputNode) {

renderNode.setOffset(16f, 26f);
renderNode.addAnimationByFrameCount("basic", 8, 0.05f);
renderNode.addAnimationByFrameCount("idle", 1, 0.1f);
renderNode.play("basic");
}

Expand All @@ -34,7 +35,8 @@ public void update(float delta) {
renderNode.flip(true);
renderNode.play("basic");
} else
renderNode.stop();
renderNode.play("idle");


super.update(delta);
}
Expand Down
16 changes: 15 additions & 1 deletion fanta-is-awesome/src/com/siegedog/hava/engine/GameCam2D.java
@@ -1,6 +1,7 @@
package com.siegedog.hava.engine;

import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
Expand All @@ -24,6 +25,8 @@ public class GameCam2D {
float targetZoom = 1f;
float zoomStep = 0.01f;

Vector2 maxPos;

OrthographicCamera gameCam;
OrthographicCamera UICam;

Expand All @@ -40,10 +43,12 @@ public class GameCam2D {

Interpolator interpolator;

public GameCam2D(int width, int height) {
public GameCam2D(int width, int height, Vector2 maxPos) {
gameCam = new OrthographicCamera(width, height);
UICam = new OrthographicCamera(width, height);

this.maxPos = maxPos;

UICam.zoom = 1f;
gameCam.zoom = 0.5f;

Expand Down Expand Up @@ -183,6 +188,15 @@ else if (gameCam.zoom > targetZoom)
Vector3 pan = new Vector3(diff.nor().mul( /*(dist/ 30f) **/ realStep ));
gameCam.position.add(pan);
}

Vector2 cPos = new Vector2(gameCam.position.x, gameCam.position.y);
Vector2 min = new Vector2(0f, 0f);
Vector2 max = new Vector2(maxPos);
min.add(width /2 * gameCam.zoom, height /2 * gameCam.zoom);
max.sub(width /2 * gameCam.zoom, height /2 *gameCam.zoom);

MU.clamp(cPos, min, max);
gameCam.position.set(cPos.x, cPos.y, gameCam.position.z);

gameCam.update();
UICam.update();
Expand Down
6 changes: 6 additions & 0 deletions fanta-is-awesome/src/com/siegedog/hava/engine/MU.java
@@ -1,6 +1,7 @@
package com.siegedog.hava.engine;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;

public class MU extends MathUtils {

Expand All @@ -17,5 +18,10 @@ public static float clamp(float value, float min, float max) {
public static float lerp(float start, float end, float alpha) {
return start + (end - start) * alpha;
}

public static void clamp(Vector2 value, Vector2 min, Vector2 max) {
value.x = clamp(value.x, min.x, max.x);
value.y = clamp(value.y, min.y, max.y);
}

}
Expand Up @@ -70,6 +70,7 @@ public void stop() {
activeAnimation = null;
}


public boolean flipped = false;
public void flip(boolean flip) {
if(flip && !flipped) {
Expand Down

0 comments on commit 12be532

Please sign in to comment.