Skip to content

Commit

Permalink
sort of camera haha shut up >:
Browse files Browse the repository at this point in the history
  • Loading branch information
nac0n committed Feb 11, 2018
1 parent a88bfaf commit e2a7e53
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 28 deletions.
14 changes: 7 additions & 7 deletions core/assets/matrix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 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 -10,6 +10,9 @@
public class Character {
private int x;
private int y;
private int prevX;
private int prevY;

private Body body;

private TextureRegion[][] animations;
Expand Down Expand Up @@ -126,6 +129,14 @@ public int getY() {
return y;
}

public int getPrevX() {
return prevX;
}

public int getPrevY() {
return prevY;
}

public void setX(int sx) {
x = sx;

Expand All @@ -135,6 +146,13 @@ public void setY(int sy) {
y = sy;

}
public void setPrevX(int spx) {
prevX = spx;
}

public void setPrevY(int spy) {
prevY = spy;
}

public boolean goingRight() {
return right;
Expand Down
55 changes: 34 additions & 21 deletions core/src/com/mygdx/game/MyGdxGame.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.mygdx.game;

import java.io.Console;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
Expand Down Expand Up @@ -51,7 +53,7 @@ public class MyGdxGame extends ApplicationAdapter {

private Matrix4 cameraBox2D;
private Box2DDebugRenderer debugRender;
public OrthographicCamera camera, lightCamera;
public OrthographicCamera worldCamera, lightCamera;

private Sound testSound;
private Music testMusic;
Expand Down Expand Up @@ -91,14 +93,24 @@ private void update() {
world.step(1/60f, 3, 3);

//Render camera update after stepping is done in physics
camera.update();

//Rendering stuff updates according to camera.... l doesn't do that though...
//worldCamera.position.set(loli.getBoxX()*WORLD_TO_RENDER, loli.getBoxY()*WORLD_TO_RENDER, 0);
worldCamera.position.set((loli.getBoxX()*WORLD_TO_RENDER)+(loli.getWidth()/2), (loli.getBoxY()*WORLD_TO_RENDER)+(loli.getHeight()/2), 0);

worldCamera.update();

//Change light position to follow player to give sight
pl.setPosition((loli.getBoxX()+loli.getWidth()),
(loli.getBoxY()+loli.getHeight()*1.5f));
//pl.setPosition((loli.getBoxX()+loli.getWidth()),(loli.getBoxY()+loli.getHeight()*1.5f));
//pl.setPosition((loli.getBoxX()*WORLD_TO_RENDER)+(loli.getWidth()/2), (loli.getBoxY()*WORLD_TO_RENDER) +(loli.getHeight()/2));
pl.setPosition(loli.getBoxX()*WORLD_TO_RENDER, loli.getBoxY()*WORLD_TO_RENDER);
pl.update();
lightCamera.update();

System.out.println(loli.getBoxX()*WORLD_TO_RENDER);
//lightCamera.position.set((loli.getBoxX()*WORLD_TO_RENDER)+(loli.getWidth()/2), (loli.getBoxY()*WORLD_TO_RENDER)+(loli.getHeight()/2), 0);
lightCamera.position.set(loli.getBoxX()*WORLD_TO_RENDER, loli.getBoxY()*WORLD_TO_RENDER, 0);
//lightCamera.position.set(loli.getBoxX()*WORLD_TO_RENDER, loli.getBoxY()*WORLD_TO_RENDER, 0);
lightCamera.update();
loli.update();

}
Expand All @@ -109,32 +121,35 @@ public void create() {
Box2D.init();
world = new World(new Vector2(0,-10f),true);


rayhandler = new RayHandler(world);
rayhandler.setShadows(true);
rayhandler.setAmbientLight(0, 0, 0, 0.0f);
rayhandler.setBlurNum(1);
rayhandler.setBlurNum(2);

map = new Map("../core/assets/matrix.txt", world, RENDER_TO_WORLD);

float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();

camera = new OrthographicCamera(w, h);
camera.position.set(camera.viewportWidth / 2f, camera.viewportHeight / 2f, 0);
camera.update();
batch = new SpriteBatch();
font = new BitmapFont();
loli = new Character(200,400, world, 123*RENDER_TO_WORLD, 192*RENDER_TO_WORLD);

worldCamera = new OrthographicCamera(w, h);

// worldCamera.position.set(loli.getBoxX()*WORLD_TO_RENDER, loli.getBoxY()*WORLD_TO_RENDER, 0);
//worldCamera.position.set((loli.getBoxX())*WORLD_TO_RENDER, loli.getBoxY()*WORLD_TO_RENDER, 0);
///worldCamera.position.set(worldCamera.viewportWidth / 2f, worldCamera.viewportHeight / 2f, 0);
//System.out.println(loli.getWidth() +" " + loli.getHeight());
worldCamera.update();

lightCamera = new OrthographicCamera(w*RENDER_TO_WORLD, h*RENDER_TO_WORLD);
lightCamera.position.set(lightCamera.viewportWidth / 2f, lightCamera.viewportHeight / 2f, 0);
//lightCamera.position.set(loli.getBoxX()*WORLD_TO_RENDER, loli.getBoxY()*WORLD_TO_RENDER, 0);
lightCamera.update();

batch = new SpriteBatch();
font = new BitmapFont();
loli = new Character(0,750, world, 123*RENDER_TO_WORLD, 192*RENDER_TO_WORLD);

pl = new PointLight(rayhandler, 256, new Color(1,1,1,0.8f), 600*RENDER_TO_WORLD, 0, 0);
pl.setSoft(true);
pl.setStaticLight(false);
pl.setStaticLight(true);

backImage = new Texture(Gdx.files.internal("../core/assets/generalconcept.png"));
//Block textures create:
Expand All @@ -148,17 +163,15 @@ public void create() {
//charTex = new Texture(Gdx.files.internal("../core/assets/protag.png"));



font.setColor(Color.RED);

debugRender = new Box2DDebugRenderer();


//audio
testSound = Gdx.audio.newSound(Gdx.files.internal("../core/assets/heartbeat.mp3"));
testMusic = Gdx.audio.newMusic(Gdx.files.internal("../core/assets/indoor_ambient.mp3"));
testMusic.setLooping(true);
testMusic.play();
//testMusic.play();
}


Expand All @@ -176,10 +189,10 @@ public void render() {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

update();
cameraBox2D = camera.combined.cpy();
cameraBox2D = worldCamera.combined.cpy();
cameraBox2D.scl(WORLD_TO_RENDER);

batch.setProjectionMatrix(camera.combined);
batch.setProjectionMatrix(worldCamera.combined);

batch.begin();
batch.draw(backImage,0,0);
Expand Down

0 comments on commit e2a7e53

Please sign in to comment.