commit c5cb8373ab1a1a8817b39a5ee93823726d8fa9ea Author: Edward Peterson Date: Thu Nov 3 19:26:43 2016 -0400 initial commit diff --git a/core/assets/badlogic.jpg b/core/assets/badlogic.jpg new file mode 100644 index 0000000..4390da6 Binary files /dev/null and b/core/assets/badlogic.jpg differ diff --git a/core/assets/crate.png b/core/assets/crate.png new file mode 100644 index 0000000..d47601b Binary files /dev/null and b/core/assets/crate.png differ diff --git a/core/assets/env.png b/core/assets/env.png new file mode 100644 index 0000000..f606856 Binary files /dev/null and b/core/assets/env.png differ diff --git a/core/assets/player.png b/core/assets/player.png new file mode 100644 index 0000000..572a21c Binary files /dev/null and b/core/assets/player.png differ diff --git a/core/assets/shadow.png b/core/assets/shadow.png new file mode 100644 index 0000000..6a96222 Binary files /dev/null and b/core/assets/shadow.png differ diff --git a/core/assets/testmap.tmx b/core/assets/testmap.tmx new file mode 100644 index 0000000..3609896 --- /dev/null +++ b/core/assets/testmap.tmx @@ -0,0 +1,115 @@ + + + + + + + +0,0,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,0,0,20,20,20,20,20,20,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,20,4,16,6,8,6,8,6,15,8,6,8,6,8,16,4,20,0,4,16,4,4,4,16,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,0,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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,20,1,1,1,1,1,1,1,0,20,20,20,20,20,20,20,20,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,4,1,1,1,1,1,1,1,0,4,5,12,13,13,14,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,1,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1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1, +20,20,20,20,20,20,20,20,12,13,14,20,20,20,20,20,20,20,20,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1, +3,4,16,4,16,4,16,6,7,15,7,8,16,4,16,4,16,4,5,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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,1,1,1,1,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,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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/src/com/toasted/chuck/ChuckGame.java b/core/src/com/toasted/chuck/ChuckGame.java new file mode 100644 index 0000000..65e63a1 --- /dev/null +++ b/core/src/com/toasted/chuck/ChuckGame.java @@ -0,0 +1,143 @@ +package com.toasted.chuck; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; + +import com.badlogic.gdx.ApplicationAdapter; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.InputProcessor; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.maps.MapLayer; +import com.badlogic.gdx.maps.MapObject; +import com.badlogic.gdx.maps.objects.RectangleMapObject; +import com.badlogic.gdx.maps.tiled.TiledMap; +import com.badlogic.gdx.maps.tiled.TiledMapRenderer; +import com.badlogic.gdx.maps.tiled.TmxMapLoader; +import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer; +import com.badlogic.gdx.math.Rectangle; + +public class ChuckGame extends ApplicationAdapter implements InputProcessor{ + Graphics graphics; + EntityPlayer player; + ArrayList entities = new ArrayList(); + Comparator zSorter; + TiledMap tiledMap; + TiledMapRenderer tmRenderer; + ArrayList collisions = new ArrayList(); + @Override + public void create () { + Gdx.input.setInputProcessor(this); + graphics = new Graphics(); + player = new EntityPlayer(); + entities.add(new EntityBox(20, 20)); + entities.add(new EntityBox(100, 100)); + entities.add(player); + zSorter = new Comparator(){ + + public int compare(Entity arg0, Entity arg1) { + return (int) Math.signum(arg1.position.y - arg0.position.y); + + } + + }; + tiledMap = new TmxMapLoader().load("testmap.tmx"); + tmRenderer = new OrthogonalTiledMapRenderer(tiledMap); + + MapLayer ml = tiledMap.getLayers().get("collisions"); + for(MapObject o: ml.getObjects()){ + RectangleMapObject rmo = (RectangleMapObject) o; + Rectangle r = new Rectangle(rmo.getRectangle()); + collisions.add(r); + + } + + + } + + @Override + public void render () { + +// player.update(Gdx.graphics.getDeltaTime(), entities); + for(Entity e: entities){ + e.update(Gdx.graphics.getDeltaTime(), entities, collisions); + } + Collections.sort(entities, zSorter); + +// graphics.cam.lookAt(player.position.x, player.position.y, 0); + graphics.cam.position.x = player.position.x + 8; + graphics.cam.position.y = player.position.y + 8; + + graphics.cam.update(); + + + graphics.prepare(); + Gdx.gl.glClearColor(0, 0, 0, 1); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + + tmRenderer.setView(graphics.cam); + tmRenderer.render(); + graphics.startSprite(); + + +// player.draw(graphics); + for(Entity e: entities){ + if(e.shouldDrawSelf) + e.draw(graphics); + } + graphics.endSprite(); +// graphics.endShapes(); + } + + @Override + public void dispose () { + } + + @Override + public boolean keyDown(int keycode) { + player.controller.acceptEvent(keycode, true, player, entities); + return false; + } + + @Override + public boolean keyUp(int keycode) { + player.controller.acceptEvent(keycode, false, player, entities); + return false; + } + + @Override + public boolean keyTyped(char character) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean touchDown(int screenX, int screenY, int pointer, int button) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean touchUp(int screenX, int screenY, int pointer, int button) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean touchDragged(int screenX, int screenY, int pointer) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean mouseMoved(int screenX, int screenY) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean scrolled(int amount) { + // TODO Auto-generated method stub + return false; + } +} diff --git a/core/src/com/toasted/chuck/Entity.java b/core/src/com/toasted/chuck/Entity.java new file mode 100644 index 0000000..abd15ed --- /dev/null +++ b/core/src/com/toasted/chuck/Entity.java @@ -0,0 +1,64 @@ +package com.toasted.chuck; + +import java.util.ArrayList; + +import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.math.Vector2; + +public abstract class Entity { + public Vector2 position = new Vector2(); + public Vector2 velocity = new Vector2(); + public EntityController controller; + public Rectangle collision; + float flyLength; + public boolean isChuckable = true; + boolean shouldDrawSelf = true; + public Entity(){ + + } + public abstract void update(float delta, ArrayList entities, ArrayList collisions); + protected void doCollisions(float delta, ArrayList collisions){ + position.x += velocity.x * delta; + + collision.x = position.x; + + for(Rectangle r: collisions){ + if(r.overlaps(collision)){ + if(velocity.x > 0){ + float overlap = collision.x + collision.width - r.x; + position.x -= overlap; + velocity.x = 0; + } else if(velocity.x < 0){ + float overlap = r.x + r.width - collision.x; + position.x += overlap; + velocity.x = 0; + } + } + } + collision.x = position.x; + + + position.y += velocity.y * delta; + + collision.y = position.y; + + for(Rectangle r: collisions){ + if(r.overlaps(collision)){ + if(velocity.y > 0){ + float overlap = collision.y + collision.height - r.y; + position.y -= overlap; + velocity.y = 0; + } else if(velocity.y < 0){ + float overlap = r.y + r.height - collision.y; + position.y += overlap; + velocity.y = 0; + } + } + } + collision.y = position.y; + } + public abstract void draw(Graphics g); + public void draw(Graphics g, float dx, float dy){ + draw(g); + } +} diff --git a/core/src/com/toasted/chuck/EntityBox.java b/core/src/com/toasted/chuck/EntityBox.java new file mode 100644 index 0000000..5bcf20e --- /dev/null +++ b/core/src/com/toasted/chuck/EntityBox.java @@ -0,0 +1,43 @@ +package com.toasted.chuck; + +import java.util.ArrayList; + +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.math.Rectangle; + +public class EntityBox extends Entity{ + float decel = 25; + Texture crate = new Texture("crate.png"); + Texture shadow = new Texture("shadow.png"); + + public EntityBox(float x, float y){ + super(); + position.x = x; + position.y = y; + collision = new Rectangle(x, y, 16, 16); + } + public void update(float delta, ArrayList entities, ArrayList collisions) { + flyLength -= delta; + if(flyLength <= 0) + velocity.mulAdd(velocity, -delta * decel); + doCollisions(delta, collisions); + } + + public void draw(Graphics g) { +// g.getShapes().setColor(Color.BLUE); +// g.getShapes().rect(position.x, position.y + (float)Math.sin((1 - Math.max(flyLength, 0) / .5f) * Math.PI) * 8, 16, 16); + draw(g, 0, 0); + + } + public void draw(Graphics g, float dx, float dy){ + if(flyLength >= 0){ + g.getBatch().draw(shadow, position.x, position.y-1); + } + float flyPerc = (Math.max(flyLength, 0) / .5f); + if(flyPerc > 0) + g.getBatch().draw(crate, position.x +dx, position.y + (float)Math.abs(Math.cos((1 - flyPerc) * (Math.PI * 3f / 4f) - (Math.PI / 4f))) * 15 + dy); + else g.getBatch().draw(crate, position.x + dx, position.y + dy); + } + +} diff --git a/core/src/com/toasted/chuck/EntityController.java b/core/src/com/toasted/chuck/EntityController.java new file mode 100644 index 0000000..f5b7776 --- /dev/null +++ b/core/src/com/toasted/chuck/EntityController.java @@ -0,0 +1,7 @@ +package com.toasted.chuck; + +import java.util.ArrayList; + +public interface EntityController { + public void acceptEvent(int keycode, boolean newState, Entity owner, ArrayList entities); +} diff --git a/core/src/com/toasted/chuck/EntityPlayer.java b/core/src/com/toasted/chuck/EntityPlayer.java new file mode 100644 index 0000000..a76f96f --- /dev/null +++ b/core/src/com/toasted/chuck/EntityPlayer.java @@ -0,0 +1,185 @@ +package com.toasted.chuck; + +import java.util.ArrayList; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input.Keys; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.math.Vector2; + +public class EntityPlayer extends Entity{ + Texture playerArt = new Texture("player.png"); + TextureRegion[] sprites = new TextureRegion[8]; + float moveSpeed = 100; + float throwSpeed = 100; + Entity holding; + Vector2 lastVelocity; + int lastDirectionalUsed; + int lastXDirectional, lastYDirectional; + private ArrayList directionals = new ArrayList();//Don't think I'll use this + private boolean[] arrowKeys = new boolean[4]; //UDLR + public EntityPlayer(){ + isChuckable = false; + for(int i = 0;i < 4;i++){ + sprites[i] = new TextureRegion(playerArt, i * 16, 0, 16, 16); + sprites[i + 4] = new TextureRegion(playerArt, i * 16, 16, 16,16); + } + lastVelocity = new Vector2(); + collision = new Rectangle(0, 0, 16, 16); + controller = new EntityController(){ + + public void acceptEvent(int keycode, boolean newState, Entity owner, ArrayList entities) { + + + if(newState){ + switch(keycode){ + case Keys.SPACE: + if(holding == null) + for(Entity e: entities){ + if(e.collision.overlaps(collision) && e.isChuckable){ + holding = e; + holding.shouldDrawSelf = false; + break; + } + } + else { + holding.velocity.add(velocity).mulAdd(getDirectionalVector(), throwSpeed); + holding.flyLength = .5f; + holding.shouldDrawSelf = true; + + holding = null; + } + } + if(keycode == Keys.UP || keycode == Keys.DOWN || keycode == Keys.LEFT || keycode == Keys.RIGHT){ + lastDirectionalUsed = keycode; + directionals.add(keycode - Keys.UP); + arrowKeys[keycode - Keys.UP] = newState; + } + if(Math.abs(velocity.x) > 0) + lastVelocity.x = velocity.x; + if(Math.abs(velocity.y) > 0) + lastVelocity.y = velocity.y; + + } else { + if(keycode == Keys.UP || keycode == Keys.DOWN || keycode == Keys.LEFT || keycode == Keys.RIGHT){ + directionals.remove(new Integer(keycode - Keys.UP)); + arrowKeys[keycode - Keys.UP] = newState; + } + + switch(keycode){ + case Keys.LEFT: + case Keys.RIGHT: + case Keys.UP: + case Keys.DOWN: + int t = getNewerPressEvent(getNewerPressEvent(0, 1), getNewerPressEvent(2, 3)); + if (t < 0){ + lastDirectionalUsed = keycode; + } else + lastDirectionalUsed = Keys.UP + t; + + + } + + + } + + } + + }; + } + private int getNewerPressEvent(int i, int j){ + for(int k = directionals.size() - 1;k >= 0;k--){ + if(directionals.get(k).equals(i)) return i; + if(directionals.get(k).equals(j)) return j; + } + + return -1; + } + private void doControls(ArrayList entities){ + for(int i = 0;i < 4;i++){ + switch(i){ + case 0: //UP + if(getNewerPressEvent(0, 1) == 0) + velocity.y = moveSpeed; + break; + case 1: //DOWN + if(!arrowKeys[0] && !arrowKeys[1]){ + //no up/down directions are pressed + velocity.y = 0; + break; + } + if(getNewerPressEvent(0, 1) == 1) + velocity.y = -moveSpeed; + break; + case 2: //LEFT + if(getNewerPressEvent(2, 3) == 2) + velocity.x = -moveSpeed; + break; + case 3: //RIGHT + if(!arrowKeys[2] && !arrowKeys[3]){ + velocity.x = 0; + } + if(getNewerPressEvent(2,3) == 3) + velocity.x = moveSpeed; + break; + } + if(Math.abs(velocity.x) > 0 && Math.abs(velocity.y) > 0){ + velocity.x = Math.signum(velocity.x) * ((float)Math.sqrt(2) / 2f) * moveSpeed; + velocity.y = Math.signum(velocity.y) * ((float)Math.sqrt(2) / 2f) * moveSpeed; + } + } + } + public void update(float delta, ArrayList entities, ArrayList collisions){ + + //test array based controls + + doControls(entities); + + + + doCollisions(delta, collisions); + + + if(holding != null){ + holding.position.x = position.x; + holding.position.y = position.y; + } + } + + @Override + public void draw(Graphics g) { + g.getBatch().draw(pickSprite(), position.x, position.y); + if(holding != null){ + holding.draw(g, 0, 12); + } + } + private TextureRegion pickSprite(){ + switch(lastDirectionalUsed){ + case Keys.UP: + return sprites[2 + (holding != null ? 4 : 0)]; + case Keys.LEFT: + return sprites[1 + (holding != null ? 4 : 0)]; + case Keys.DOWN: + return sprites[0 + (holding != null ? 4 : 0)]; + case Keys.RIGHT: + return sprites[3 + (holding != null ? 4 : 0)]; + } + return sprites[0]; + + } + private Vector2 getDirectionalVector(){ + switch(lastDirectionalUsed){ + case Keys.UP: + return new Vector2(0, 1); + case Keys.LEFT: + return new Vector2(-1, 0); + case Keys.DOWN: + return new Vector2(0, -1); + case Keys.RIGHT: + return new Vector2(1, 0); + } + return new Vector2(0, -1); + } +} diff --git a/core/src/com/toasted/chuck/Graphics.java b/core/src/com/toasted/chuck/Graphics.java new file mode 100644 index 0000000..e53d39f --- /dev/null +++ b/core/src/com/toasted/chuck/Graphics.java @@ -0,0 +1,49 @@ +package com.toasted.chuck; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; + +public class Graphics { + private SpriteBatch spriteBatch; + private ShapeRenderer shapeRenderer; + OrthographicCamera cam; + public Graphics(){ + cam = new OrthographicCamera(); + spriteBatch = new SpriteBatch(); + shapeRenderer = new ShapeRenderer(); + + cam.setToOrtho(false, 16 * 32, 9 * 32); + + } + public int getWidth(){ + return Gdx.graphics.getWidth(); + } + public int getHeight(){ + return Gdx.graphics.getHeight(); + } + public void startShapes(ShapeType shapeType){ + shapeRenderer.begin(shapeType); + } + public void endShapes(){ + shapeRenderer.end(); + } + public void startSprite(){ + spriteBatch.begin(); + } + public void endSprite(){ + spriteBatch.end(); + } + public SpriteBatch getBatch(){ + return spriteBatch; + } + public ShapeRenderer getShapes(){ + return shapeRenderer; + } + public void prepare(){ + shapeRenderer.setProjectionMatrix(cam.combined); + spriteBatch.setProjectionMatrix(cam.combined); + } +} diff --git a/desktop/src/com/toasted/chuck/desktop/DesktopLauncher.java b/desktop/src/com/toasted/chuck/desktop/DesktopLauncher.java new file mode 100644 index 0000000..3a83349 --- /dev/null +++ b/desktop/src/com/toasted/chuck/desktop/DesktopLauncher.java @@ -0,0 +1,14 @@ +package com.toasted.chuck.desktop; + +import com.badlogic.gdx.backends.lwjgl.LwjglApplication; +import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; +import com.toasted.chuck.ChuckGame; + +public class DesktopLauncher { + public static void main (String[] arg) { + LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); + config.width = 1280; + config.height = 720; + new LwjglApplication(new ChuckGame(), config); + } +}