@@ -1,3 +1,4 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Random;
import java.util.Vector;
@@ -8,6 +9,7 @@
import ch.hevs.gdx2d.components.physics.primitives.PhysicsBox;
import ch.hevs.gdx2d.components.physics.primitives.PhysicsStaticBox;
import ch.hevs.gdx2d.lib.GdxGraphics;
import ch.hevs.gdx2d.lib.ScreenManager;
import ch.hevs.gdx2d.lib.interfaces.DrawableObject;
import ch.hevs.gdx2d.lib.physics.AbstractPhysicsObject;
import ch.hevs.gdx2d.lib.utils.Logger;
@@ -21,13 +23,19 @@ public class Cube extends PhysicsBox implements DrawableObject {
Vector2 pos;

boolean jump = false;
boolean fly = false;
boolean jumpMode = true;
boolean flyMode = false;
boolean specialJump = false;
boolean isTouching = false;
boolean isHurt = false;
boolean cubeDead = false;
boolean stopInc = false;
boolean checkInAirRotation = false;
boolean cubeDead = false;
boolean itsTheEnd = false;

private boolean checkInAirRotation = false;
private boolean firstTouchdown = false;
private boolean gameMode = true;

private int particleAmount = Gsing.get().cParticleAmount;
private int drawAngle;
@@ -36,10 +44,14 @@ public class Cube extends PhysicsBox implements DrawableObject {
private int nFrames = 9;
private int dir = 1;
private int i = 0;
private int angleIndex;

public int CREATION_RATE = 1;
public final int MAX_AGE = 20;

int cubeDamageCnt = 0;

float dt = 0;
float jumpCountDown = 0.2f;
float frameTime = 0.02f;

double angle = Math.PI/4;
@@ -52,14 +64,18 @@ public class Cube extends PhysicsBox implements DrawableObject {
SoundSample impact = new SoundSample("data/sounds/impact.mp3");

LinkedList<Particle> particles;

Random random;

public Cube(Vector2 position){
public Cube(Vector2 position, Random rand){

super("Cube", position, Gsing.get().cSize, Gsing.get().cSize, 3f, 0, 0);
this.setCollisionGroup(-1);
this.drawAngle = 0;
this.getBody().setFixedRotation(true);
Gsing.get().cImpulse = this.getBodyMass() * 15;
this.getBody().setFixedRotation(true);
this.random = rand;
Gsing.get().cImpulse = this.getBodyMass() * 15;
Gsing.get().cForce = this.getBodyMass() * 500;
particles = new LinkedList<Particle>();
impact.setVolume(0.15f);
death.setVolume(0.15f);
@@ -70,75 +86,137 @@ public void collision(AbstractPhysicsObject theOtherObject, float energy) {

super.collision(theOtherObject, energy);

if(theOtherObject.getClass() == Platform.class || theOtherObject.getClass() == PhysicsStaticBox.class){
if(theOtherObject.getClass() == PhysicsStaticBox.class || theOtherObject.getClass() == Platform.class){
impact.play();
isTouching = true;
firstTouchdown = true;

}
if (theOtherObject instanceof Sensor) {
Sensor sensor = (Sensor) theOtherObject;

if (theOtherObject instanceof DamageSensor) {
DamageSensor sensor = (DamageSensor) theOtherObject;
if(!sensor.alreadyCollided)
cubeDamageCnt++;
impact.play();
isHurt = true;
sensor.alreadyCollided = true;
}

if(theOtherObject.getClass() == HoleOfTheDamned.class){
if(theOtherObject.getClass() == HoleOfTheDamned.class || theOtherObject.getClass() == AirTimeObstacle.class){
death.play();
cubeDead = true;
Gsing.get().totalDistance = (int)(this.getBodyWorldCenter().x);
}

// System.out.println("Collided with " + theOtherObject);
if(theOtherObject.getClass() == ModeSelector.class){
jumpMode = !jumpMode;
flyMode = !flyMode;
isTouching = true;
checkInAirRotation = true;
}

if(theOtherObject.getClass() == HorizontalCollisionSensor.class){
Vector2 pos = this.getBodyWorldCenter();
// this.setBodyLinearVelocity(this.getBodyLinearVelocity().x * 2, 17);
System.out.println(this.getBodyLinearVelocity().y);

if(this.getBodyLinearVelocity().y < 8){
this.applyBodyLinearImpulse(new Vector2(0, Gsing.get().cImpulse), pos, true);
}
//
else{
this.applyBodyLinearImpulse(new Vector2(0, Gsing.get().cImpulse/3), pos, true);
}
System.out.println("Collided with " + theOtherObject);
}

if(theOtherObject.getClass() == WinSensor.class){
gameMode = false;
this.setBodyLinearDamping(.7f);
}
}

public void updateLogic(){

/*
* Still have to ajust this so that the cube is not able to jump anymore exactly when is
* is at the edge of the box
*/

/*
* Have to cleanup all this logic mess!! ######################################
*/

System.out.println(drawAngle);
if(firstTouchdown){
//linear x movement of the cube
this.applyBodyForceToCenter(Gsing.get().cSpeed, 0, true);
this.setBodyLinearDamping(0.3f);
}

if(!stopInc){
this.applyBodyForceToCenter(0, 50*this.getBodyMass(), true);
}

if(jump && isTouching){
jump = false;
isTouching = false;
checkInAirRotation = true;
pos = this.getBodyWorldCenter();
this.applyBodyLinearImpulse(new Vector2(0, Gsing.get().cImpulse), pos, true);
if(gameMode){
if(firstTouchdown){
//linear x movement of the cube
this.applyBodyForceToCenter(Gsing.get().cSpeed, 0, true);
this.setBodyLinearDamping(0.3f);
}

if(!stopInc){
this.applyBodyForceToCenter(0, 50*this.getBodyMass(), true);
}

if(jump && isTouching){
jump = false;
isTouching = false;
checkInAirRotation = true;
pos = this.getBodyWorldCenter();
// this.setBodyLinearVelocity(this.getBodyLinearVelocity().x, 17);
this.applyBodyLinearImpulse(new Vector2(0, Gsing.get().cImpulse), pos, true);
}

if(flyMode){
pos = this.getBodyWorldCenter();
this.applyBodyForceToCenter(0, 35*this.getBodyMass(), true);

if(fly){
fly = false;
this.applyBodyForceToCenter(0, Gsing.get().cForce, true);
}
}

if(specialJump && isTouching){
angle = Math.random()*Math.PI*2;
specialJump = false;
isTouching = false;
pos = this.getBodyWorldCenter();
this.applyBodyLinearImpulse(specialImpulse, pos, true);
Logger.log("jumped in a special way");
}

if(checkInAirRotation){
setDrawAngle();
}

if(cubeDamageCnt == 6){
cubeDead = true;
}

//check if the cube has encountered an obstacle
if(isHurt)
{
emitParticle();
}

if(cubeDead){
ScreenHub.s.transitionTo(2, ScreenManager.TransactionType.SLICE);
}

}

if(specialJump && isTouching){
angle = Math.random()*Math.PI*2;
specialJump = false;
isTouching = false;
pos = this.getBodyWorldCenter();
this.applyBodyLinearImpulse(specialImpulse, pos, true);
Logger.log("jumped in a special way");
else{

if(this.getBodyLinearVelocity().x < .1 && !itsTheEnd){
if(this.getBodyWorldCenter().y <= Gdx.graphics.getHeight()*.75){
this.applyBodyForceToCenter(0, 700f, true);
// this.getBody().setTransform(this.getBodyPosition(), 0);
}
else{
emitParticle();
itsTheEnd = true;
}
}
}

if(checkInAirRotation){
setDrawAngle();
}
checkParticles4Destruction();
}


public void updateGraphics(GdxGraphics g){

dt += Gdx.graphics.getDeltaTime();
@@ -170,7 +248,11 @@ public void draw(GdxGraphics g) {
updateLogic();
updateGraphics(g);
Vector2 pos = this.getBodyWorldCenter();
g.draw(cubeBirth.sprites[currentRow][currentFrame],pos.x - 85, pos.y - 85, 85, 85, 170, 170, 1, 1, drawAngle);

if(!itsTheEnd){
g.draw(cubeBirth.sprites[currentRow][currentFrame],pos.x - 85, pos.y - 85, 85, 85, 170, 170, 1, 1, drawAngle);
}

for (Particle particle : particles) {
particle.draw(g);
}
@@ -179,27 +261,27 @@ public void draw(GdxGraphics g) {
public void emitParticle(){

int angle = 0;
long seed = (long)(Math.random() * 10000);

Vector2 impulse = new Vector2(0, 0);
Random r = new Random(seed);

isHurt = false;
creationTime = System.nanoTime();

for(int i = 0; i < particleAmount; i++){
int size = (int)(r.nextDouble()*20) + 5;
Particle aParticle = new Particle("Particle" , Cube.this.getBodyWorldCenter(), size, (long)(Math.random()*10000));
aParticle.setCollisionGroup(-1);
int size = (int)(random.nextDouble()*20) + 5;
Particle aParticle = new Particle(this.getBodyWorldCenter(), size, angle, random);
particles.add(aParticle);
Vector2 pos = this.getBodyWorldCenter();
impulse.x = (float) Math.sin(angle)*Gsing.get().pImpulse;
impulse.y = (float) Math.cos(angle)*Gsing.get().pImpulse;
aParticle.applyBodyLinearImpulse(impulse, pos, true);
angle += 180/Gsing.get().cParticleAmount;
}
}

public void createTrailParticles() {
for (int i = 0; i < CREATION_RATE; i++) {
Vector2 position = this.getBodyWorldCenter();
position.x -= 40;
position.y -= 40;
TrailParticle c = new TrailParticle(position, 10, MAX_AGE + random.nextInt(MAX_AGE / 2), random);
}
}


public void checkParticles4Destruction(){

//destroys the particles after a while
@@ -213,10 +295,24 @@ public void checkParticles4Destruction(){
}

public void setDrawAngle(){
int chance = (int)(Math.random()*2);

switch (chance) {
case 0:
angleIndex = 90;
break;

case 1:
angleIndex = 180;
break;

default:
break;
}

drawAngle -= 9;

if(drawAngle % 180 == 0){
if(drawAngle % angleIndex == 0){
checkInAirRotation = false;
}
}
@@ -5,13 +5,13 @@
import ch.hevs.gdx2d.lib.interfaces.DrawableObject;
import ch.hevs.gdx2d.lib.physics.AbstractPhysicsObject;

public class Sensor extends PhysicsStaticBox implements DrawableObject {
public class DamageSensor extends PhysicsStaticBox implements DrawableObject {

int height;
int width;
boolean alreadyCollided = false;

public Sensor(Vector2 position, int width, int height) {
public DamageSensor(Vector2 position, int width, int height) {
super(null, position, width, height);
this.width = width;
this.height = height;
@@ -0,0 +1,26 @@
import ch.hevs.gdx2d.lib.GdxGraphics;
import ch.hevs.gdx2d.lib.interfaces.DrawableObject;

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


public class EndPlatform implements DrawableObject{

Platform platform;
WinSensor sensorOfTheWin;
Vector2 tempPos;

public EndPlatform(Vector2 position, int width, int height){
tempPos = position;
platform = new Platform(tempPos, width, height);
tempPos.x -= width/4;
tempPos.y = Gdx.graphics.getHeight()/2;
sensorOfTheWin = new WinSensor(tempPos, 20, Gdx.graphics.getHeight());
}

public void draw(GdxGraphics g) {
sensorOfTheWin.draw(g);
platform.draw(g);
}
}
@@ -1,3 +1,4 @@
import ch.hevs.gdx2d.components.bitmaps.BitmapImage;
import ch.hevs.gdx2d.components.screen_management.RenderingScreen;
import ch.hevs.gdx2d.desktop.PortableApplication;
import ch.hevs.gdx2d.lib.GdxGraphics;
@@ -20,10 +21,11 @@
public class GameOverWindow extends RenderingScreen{
Skin skin;
Stage stage;
TextButton newGameButton, quitGameButton;
TextButton newGameButton, quitGameButton, retryButton;
TextField textArea;
int stateCounter = 0;
String state;
BitmapImage bckgrnd;

public static void main(String[] args) {
new GameOverWindow();
@@ -34,7 +36,7 @@ public void onInit(){

int buttonWidth = 180;
int buttonHeight = 30;

bckgrnd = new BitmapImage("data/images/CrownNebula.bmp/");
// setTitle("Jumping Cube");

stage = new Stage();
@@ -53,30 +55,22 @@ public void onInit(){
quitGameButton = new TextButton("Quit", skin); // Use the initialized skin
quitGameButton.setWidth(buttonWidth);
quitGameButton.setHeight(buttonHeight);

retryButton = new TextButton("Retry the same map", skin);
retryButton.setWidth(buttonWidth);
retryButton.setHeight(buttonHeight);

newGameButton.setPosition(Gdx.graphics.getWidth() / 2 - buttonWidth / 2, (int) (Gdx.graphics.getHeight() * .6));
quitGameButton.setPosition(Gdx.graphics.getWidth() / 2 - buttonWidth / 2, (int) (Gdx.graphics.getHeight() * .7));

textArea = new TextField("Enter your name...", skin);
textArea.setWidth(buttonWidth);
textArea.setPosition(Gdx.graphics.getWidth() / 2 - buttonWidth / 2, (int) (Gdx.graphics.getHeight() * .4));

textArea.setTextFieldListener(new TextFieldListener() {
public void keyTyped(TextField textField, char key) {
textArea.setSelection(0, 0);

// When you press 'enter', do something
if (key == 13)
Logger.log("You have typed " + textArea.getText());
}
});
retryButton.setPosition(Gdx.graphics.getWidth() / 2 - buttonWidth/2, (int) (Gdx.graphics.getHeight() * .8));


/**
* Adds the buttons to the stage
*/
stage.addActor(newGameButton);
stage.addActor(quitGameButton);
stage.addActor(textArea);
stage.addActor(retryButton);

/**
* Register listener
@@ -96,24 +90,29 @@ public void clicked(InputEvent event, float x, float y) {
System.exit(0);
}
});

retryButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
Gsing.get().retryMap = true;
ScreenHub.s.transitionTo(1, ScreenManager.TransactionType.SMOOTH);
}
});
}

public void onGraphicRender(GdxGraphics g) {
g.clear();
g.clear(Color.BLACK);
g.drawBackground(bckgrnd, 0, 0);

// This is required for having the GUI work properly

// stage.act();
// stage.draw();
// g.setColor(Color.GREEN);
// g.drawStringCentered(Gdx.graphics.getHeight()/2, "Congratulation! Your journey was " + Gsing.get().totalDistance + "Long!");
// System.out.println("HIHI" + Gsing.get().totalDistance/10);
// g.drawStringCentered(700, "Seed : " + Gsing.get().mapGenSeed);
stage.act();
stage.draw();
g.setColor(Color.GREEN);
g.drawStringCentered(Gdx.graphics.getHeight()/2, "Congratulation! Your journey was " + Gsing.get().totalDistance + "Long!");
g.drawStringCentered(700, "Seed : " + Gsing.get().mapGenSeed);
// g.drawStringCentered(getWindowHeight() / 4, "Colin Cina & Martin Juon");
g.drawSchoolLogo();
g.drawFilledRectangle(100,100,100,100,0,Color.BLACK);
g.drawFilledCircle(100,100,100,Color.CYAN);
g.drawFilledRectangle(100,100,100,100,0,Color.GREEN);
g.drawFPS();
}

@@ -4,10 +4,10 @@

import ch.hevs.gdx2d.components.audio.SoundSample;
import ch.hevs.gdx2d.components.bitmaps.Spritesheet;
import ch.hevs.gdx2d.components.physics.primitives.PhysicsBox;
import ch.hevs.gdx2d.components.screen_management.RenderingScreen;
import ch.hevs.gdx2d.desktop.physics.DebugRenderer;
import ch.hevs.gdx2d.lib.GdxGraphics;
import ch.hevs.gdx2d.lib.ScreenManager;
import ch.hevs.gdx2d.lib.interfaces.DrawableObject;
import ch.hevs.gdx2d.lib.physics.PhysicsWorld;
import ch.hevs.gdx2d.lib.utils.Logger;
@@ -30,21 +30,19 @@ public class GameWindow extends RenderingScreen{

Vector<DrawableObject> toDraw = new Vector<DrawableObject>();
Vector<TrailParticle> trailParticles = new Vector<TrailParticle>();
Vector<HoleOfTheDamned> holes = new Vector<HoleOfTheDamned>();

Vector2 globalPosition = new Vector2(1000, 50);
Vector2 globalPosition = new Vector2(0, 50);

Cube cube1;
Platform startPlatform;
DoubleJumpBox d;
DebugRenderer debugRenderer;

public int CREATION_RATE = 1;
public final int MAX_AGE = 10;
private int platformLength = 0;

private float xPos = 0;
private float zoom = 0.5f;

private int platformLength = 0;

long seed;

private boolean debugDraw;
@@ -66,147 +64,80 @@ public void onInit() {
seed = Gsing.get().enteredSeed;
}

else if(Gsing.get().retryMap){
seed = Gsing.get().mapGenSeed;
Vector2 position = new Vector2(Gsing.get().totalDistance, 400);
VarObstacle beacon = new VarObstacle(position);
toDraw.add(beacon);
Gsing.get().retryMap = false;
}

else{
Gsing.get().mapGenSeed = (long)(Math.random()*10000);
seed = Gsing.get().mapGenSeed;
}

random = new Random(seed);

sLowPulse = new SoundSample("data/sounds/lowpulse.wav");
sGameMusic = new SoundSample("data/sounds/Space Travel.mp3");



world.setGravity(new Vector2(0, -25f));

//add the background
// toDraw.add(new Background());

//add the cube
cube1 = new Cube(new Vector2(100, 600));
toDraw.add(cube1);
Logger.log("Cube has been created");

//start platform added
toDraw.add(new StartPlatform(2000));
globalPosition.x += 1000;

for(int i = 0; i < 50; i++){
int rand = random.nextInt(4);
switch (rand) {
case 0:
createMapEntity1();
break;

case 1:
System.out.println(rand);
if(noMore2){
break;
}
createMapEntity2();
break;

case 2:
if(noMore3){
break;
}
createMapEntity3(random.nextBoolean());
break;

case 3:
if(noMore4){
break;
}
createMapEntity4();
break;
default:
System.out.println("Numbers are shit");
break;
}
}

generateWorld();
debugRenderer = new DebugRenderer();
sGameMusic.loop();
// sGameMusic.loop();
}

public void onGraphicRender(GdxGraphics g) {

g.clear();
g.setBackgroundColor(Color.WHITE);

/*
* particle trail MAKE A SEPARATE VECTOR FOR THE PARTICLES
*/
//display some text to see if the cube is grounded
if(cube1.isTouching && !cube1.itsTheEnd)
{
g.setColor(Color.BLACK);
g.drawString(cube1.getBodyPosition().x, cube1.getBodyPosition().y + 100, "Cube grounded");
cube1.createTrailParticles();
}

else if (!cube1.isTouching){
g.drawString(cube1.getBodyPosition().x, cube1.getBodyPosition().y + 100, "Cube not grounded");
}

PhysicsWorld.updatePhysics(Gdx.graphics.getDeltaTime());
moveCamera(g, cube1);

debugRenderer.render(world, g.getCamera().combined);

Array<Body> bodies = new Array<Body>();
world.getBodies(bodies);

Iterator<Body> it = bodies.iterator();


while (it.hasNext()) {
Body p = it.next();

if (p.getUserData() instanceof TrailParticle) {
TrailParticle particle = (TrailParticle) p.getUserData();
particle.step();
trailParticles.add(particle);
particle.draw(g);

if (particle.shouldbeDestroyed()) {
trailParticles.remove(trailParticles.indexOf(particle));
particle.destroy();
}

else{
particle.draw(g);
if(!cube1.itsTheEnd){
if (particle.shouldbeDestroyed()) {
particle.destroy();
}
}
}
}

PhysicsWorld.updatePhysics(Gdx.graphics.getDeltaTime());

holeCollisionNotifier(holes);

//display some text to see if the cube is grounded
if(cube1.isTouching)
{
g.setColor(Color.BLACK);
g.drawString(cube1.getBodyPosition().x, cube1.getBodyPosition().y + 100, "Cube grounded");
createParticles();
}

else if (!cube1.isTouching)
{
g.setColor(Color.BLACK);
g.drawString(cube1.getBodyPosition().x, cube1.getBodyPosition().y + 100, "Cube not grounded");
}

if(cube1.isBodyFixedRotation()){
g.setColor(Color.BLACK);
g.drawString(cube1.getBodyPosition().x, cube1.getBodyPosition().y + 125, "Fix Rot");
}

moveCamera(g, cube1);
debugRenderer.render(world, g.getCamera().combined);

//Draw the objects
if (!debugDraw){
for (DrawableObject obj : toDraw) {
obj.draw(g);
}
// for (TrailParticle part : trailParticles) {
// part.draw(g);
// }
}


//check if the cube has encountered an obstacle
if(cube1.isHurt)
{
cube1.emitParticle();
}

if(cube1.cubeDead){
ScreenHub.s.transitionTo(2, ScreenManager.TransactionType.SLICE);
}

g.drawFPS(Color.WHITE);
}

@@ -219,10 +150,15 @@ public void dispose() {
@Override
public void onKeyDown(int keycode) {

if(keycode == Keys.SPACE && cube1.isTouching){
if(keycode == Keys.SPACE && cube1.isTouching && cube1.jumpMode){
cube1.jump = true;
}

if(keycode == Keys.SPACE && cube1.isTouching && cube1.flyMode){
cube1.fly = true;
System.out.println("the cube can fly !!!!!");
}

if (keycode == Keys.D){
debugDraw = !debugDraw;
}
@@ -235,29 +171,8 @@ public void onKeyDown(int keycode) {
}
}

public boolean holeCollisionNotifier(Vector<HoleOfTheDamned> holes){
for (HoleOfTheDamned holeOfTheDamned : holes) {
if(holeOfTheDamned.playerDiedInMe){
Logger.log("Cube is dead in " + holeOfTheDamned.name);
return true;
}
}
return false;
}

public void moveCamera(GdxGraphics g, Cube cube)
{
// if(birthAnim){
// g.getCamera().zoom = zoom;
// Vector2 pos = cube.getBodyWorldCenter();
// g.moveCamera(pos.x + g.getScreenWidth()/2, pos.y + g.getScreenHeight()/2);
// if(zoom >= 1){
// birthAnim = false;
// g.getCamera().zoom = 1f;
// }
// zoom += 0.005;
// }

float h = 3*(g.getScreenHeight()/4);
float y = cube.getBodyWorldCenter().y ;

@@ -269,7 +184,6 @@ public void moveCamera(GdxGraphics g, Cube cube)
y = y - h;
// g.getCamera().zoom = 2f;
}

g.moveCamera(cube.getBodyWorldCenter().x - 1000, y);
}

@@ -280,7 +194,6 @@ protected void createMapEntity1(){
MapEntity1 mapPart = new MapEntity1(platformLength, globalPosition, sDeath);
globalPosition.x += (Gsing.get().holeWidthme1/2 + platformLength);
toDraw.add(mapPart);
holes.add(mapPart.hole);
noMore3 = false;
noMore2 = false;
}
@@ -328,19 +241,96 @@ protected void createMapEntity4(){
noMore3 = false;
}

void createParticles() {
for (int i = 0; i < CREATION_RATE; i++) {
Vector2 position = cube1.getBodyWorldCenter();
position.x -= 40;
position.y -= 40;
TrailParticle c = new TrailParticle(position, 10, MAX_AGE + random.nextInt(MAX_AGE / 2));

// Apply a vertical force with some random horizontal component
Vector2 force = new Vector2();
force.x = random.nextFloat() * -0.00095f;
force.y = random.nextFloat() * 0.0004f * (random.nextBoolean() == true ? -1 : 1);
c.applyBodyLinearImpulse(force, position, true);
}
protected void generateWorld(){
//add the background
// toDraw.add(new Background());

//add the cube
cube1 = new Cube(new Vector2(-500, 600), random);
toDraw.add(cube1);
Logger.log("Cube has been created");

//start platform added
startPlatform = new Platform(globalPosition, 2000, 100);
startPlatform.enableCollisionListener();
toDraw.add(startPlatform);
globalPosition.x += 1000;

for(int i = 0; i < 5; i++){
int rand = random.nextInt(4);
switch (rand) {
case 0:
createMapEntity1();
break;

case 1:
System.out.println(rand);
if(noMore2){
break;
}
createMapEntity2();
break;

case 2:
if(noMore3){
break;
}
createMapEntity3(random.nextBoolean());
break;

case 3:
if(noMore4){
break;
}
createMapEntity4();
break;
default:
System.out.println("Numbers are shit");
break;
}
}

globalPosition.x += 9500;
AirTime yolo = new AirTime(15000, 200, globalPosition, random);
toDraw.add(yolo);

for(int i = 0; i < 5; i++){
int rand = random.nextInt(4);
switch (rand) {
case 0:
createMapEntity1();
break;

case 1:
System.out.println(rand);
if(noMore2){
break;
}
createMapEntity2();
break;

case 2:
if(noMore3){
break;
}
createMapEntity3(random.nextBoolean());
break;

case 3:
if(noMore4){
break;
}
createMapEntity4();
break;
default:
System.out.println("Numbers are shit");
break;
}
}
globalPosition.x += 1000;
globalPosition.y = 50;
EndPlatform theEnd = new EndPlatform(globalPosition, 2000, 100);
toDraw.add(theEnd);
}

public static void main(String args[]){
@@ -1,3 +1,8 @@
import java.util.Vector;

import ch.hevs.gdx2d.components.physics.primitives.PhysicsBox;
import ch.hevs.gdx2d.lib.interfaces.DrawableObject;


public class Gsing {

@@ -8,7 +13,8 @@ public class Gsing {
int cParticleAmount = 30;
int pImpulse = 20;
float cSpeed = 55f;
float cImpulse;
float cImpulse;
float cForce;

//Platform parameters
int platformHeight = 100;
@@ -33,6 +39,7 @@ public class Gsing {

//Seed Management Logic
boolean seedBeingUsed = false;
boolean retryMap = false;
long enteredSeed;

//Jump Detector dimensions
@@ -52,9 +59,12 @@ public class Gsing {
int VarObsW1 = 40;
int VarObsH1 = 200;

//AirTime dimensions
int AirPlatformWidth = 2000;

int totalDistance;

// Vector<PhysicsBox> todestroy = new Vector<PhysicsBox>();
/*
* Superdupermega private constructor of Henry Death
*/
@@ -1,41 +1,59 @@
import ch.hevs.gdx2d.components.audio.SoundSample;
import ch.hevs.gdx2d.components.bitmaps.Spritesheet;
import ch.hevs.gdx2d.components.physics.primitives.PhysicsStaticBox;
import ch.hevs.gdx2d.lib.GdxGraphics;
import ch.hevs.gdx2d.lib.interfaces.DrawableObject;
import ch.hevs.gdx2d.lib.physics.AbstractPhysicsObject;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;


public class HoleOfTheDamned extends PhysicsStaticBox implements DrawableObject {

int width;
float dt;
float frameTime = 0.1f;
int currentFrame = 0;
int currentRow = 0;
int nFrames = 4;
boolean playerDiedInMe = false;
JumpDetector detector;
Spritesheet laser;

public HoleOfTheDamned(int width, Vector2 position) {
super(null, position, width, Gsing.get().holeHeight, 0);
detector = new JumpDetector(new Vector2(position.x - width/2 + Gsing.get().detectorW/2 + Gsing.get().cSize, position.y + Gsing.get().detectorH/2));
detector.enableCollisionListener();
detector.setSensor(true);
this.width = width;
laser = new Spritesheet("data/Spritesheets/LaserWaveColorsSpritesheet.png", 465, 60);
currentRow = (int)(Math.random()*3);
}

@Override
public void collision(AbstractPhysicsObject theOtherObject, float energy) {
super.collision(theOtherObject, energy);
public void updateGraphics(GdxGraphics g){

dt += Gdx.graphics.getDeltaTime();

//Selects the right field of the SpriteSheet

if (theOtherObject instanceof Cube) {
Cube cube1 = (Cube) theOtherObject;
cube1.cubeDead = true;
playerDiedInMe = true;
System.out.println(theOtherObject.name + " Collided with " + this.name);
}
if (dt > frameTime) {
dt = 0;
currentFrame = (currentFrame + 1) % nFrames;
if(currentFrame == 4){
// currentRow++;
currentFrame = 0;
}

// if(currentRow == 3){
// currentRow = 0;
// }
}
}

public void draw(GdxGraphics g) {

updateGraphics(g);
Vector2 pos = this.getBodyWorldCenter();
g.drawFilledRectangle(pos.x, pos.y, width, Gsing.get().holeHeight, 0, Color.RED);
// g.drawFilledRectangle(pos.x, pos.y, width, Gsing.get().holeHeight, 0, Color.RED);
g.draw(laser.sprites[currentRow][currentFrame], pos.x - 232.5f , pos.y - 30);

}
}
@@ -0,0 +1,27 @@
import ch.hevs.gdx2d.components.physics.primitives.PhysicsStaticBox;
import ch.hevs.gdx2d.lib.GdxGraphics;
import ch.hevs.gdx2d.lib.interfaces.DrawableObject;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;

public class HorizontalCollisionSensor extends PhysicsStaticBox implements DrawableObject{

int width;
int height;

public HorizontalCollisionSensor(Vector2 position, int width, int height) {
super(null, position, width, height, 0);
this.setSensor(true);
this.width = width;
this.height = height;
}


public void draw(GdxGraphics g) {
Vector2 pos = this.getBodyWorldCenter();
g.drawFilledRectangle(pos.x, pos.y, width, height, 0, Color.GREEN);
}
}


@@ -12,6 +12,8 @@ public class JumpDetector extends PhysicsStaticBox implements DrawableObject{

public JumpDetector(Vector2 position) {
super(null, position, Gsing.get().detectorW, Gsing.get().detectorH, 0);
this.enableCollisionListener();
this.setSensor(true);
}
@Override
public void collision(AbstractPhysicsObject theOtherObject, float energy) {
@@ -5,18 +5,22 @@

public class ME4HighObstacle extends ME4Obstacle{

Sensor sensor;
Platform platform;
DamageSensor sensor;
Platform platform;
HorizontalCollisionSensor hzSensor;

public ME4HighObstacle(Vector2 position){
sensor = new Sensor(position, Gsing.get().obsW1, Gsing.get().obsH);
sensor = new DamageSensor(position, width1, height);
pos = position;
pos.y -= height;
platform = new Platform(position, width1, height);
pos.x -= width1/2;
hzSensor = new HorizontalCollisionSensor(pos, 10, height - 10);
}

public void draw(GdxGraphics g) {
sensor.draw(g);
hzSensor.draw(g);
platform.draw(g);
}

@@ -2,10 +2,10 @@
import com.badlogic.gdx.math.Vector2;

public class ME4LowObstacle extends ME4Obstacle{
Sensor sensor;
DamageSensor sensor;

public ME4LowObstacle(Vector2 position){
sensor = new Sensor(position, Gsing.get().obsW2, Gsing.get().obsH);
sensor = new DamageSensor(position, Gsing.get().obsW2, Gsing.get().obsH);
}

public void draw(GdxGraphics g) {
@@ -4,20 +4,28 @@

public class ME4LowPlatformObstacle extends ME4Obstacle{

Sensor highSensor, LowSensor;
DamageSensor highSensor, LowSensor;
Platform platform;
HorizontalCollisionSensor hzSensor;
JumpDetector jumpSensor;

public ME4LowPlatformObstacle(Vector2 position){

platform = new Platform(position, width1, height);
pos = position;
platform = new Platform(position, width1, height);
pos.x -= width1/2;
hzSensor = new HorizontalCollisionSensor(pos, 10, height - 10);
pos.x += width1;
jumpSensor = new JumpDetector(position);
pos.x -= width1/2;
pos.y = 125;
LowSensor = new Sensor(position, Gsing.get().obsW1, Gsing.get().obsH);
LowSensor = new DamageSensor(position, width1, height);
}

public void draw(GdxGraphics g) {

LowSensor.draw(g);
hzSensor.draw(g);
platform.draw(g);
}

@@ -6,13 +6,20 @@
public class MapEntity2 implements DrawableObject {

Platform stepBox;
HorizontalCollisionSensor hzSensor;
int height = Gsing.get().me2H;
Vector2 tempPos;

public MapEntity2(int length, Vector2 position) {
stepBox = new Platform(position, length, height);
tempPos = position;
stepBox = new Platform(tempPos, length, height);
tempPos.x -= length/2;
hzSensor = new HorizontalCollisionSensor(tempPos, 10, height - 10);
tempPos.x += length/2;
}

public void draw(GdxGraphics g) {
stepBox.draw(g);
hzSensor.draw(g);
}
}
@@ -12,7 +12,7 @@ public class MapEntity4 implements DrawableObject {
SoundSample loveHurts;
int height = Gsing.get().platformHeight;
int width;
Random r = new Random();
Random r;
Vector2 obsPos = new Vector2(0,0);

//Same sound sample as if the cube had touched a VarObstacle
@@ -100,7 +100,7 @@ public void clicked(InputEvent event, float x, float y) {
ScreenHub.s.transitionTo(1, ScreenManager.TransactionType.SMOOTH);
}
});
loop.loop();
// loop.loop();
}

public void onGraphicRender(GdxGraphics g) {
@@ -0,0 +1,28 @@
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;

import ch.hevs.gdx2d.components.physics.primitives.PhysicsStaticBox;
import ch.hevs.gdx2d.lib.GdxGraphics;
import ch.hevs.gdx2d.lib.interfaces.DrawableObject;


public class ModeSelector extends PhysicsStaticBox implements DrawableObject{

int width;
int height;

public ModeSelector(Vector2 position, int width, int height) {
super(null, position, width, height, 0);
this.setSensor(true);
this.width = width;
this.height = height;
}


public void draw(GdxGraphics g) {
Vector2 pos = this.getBodyWorldCenter();
g.drawFilledRectangle(pos.x, pos.y, width, height, 0, Color.YELLOW);
}


}
@@ -11,28 +11,26 @@
public class Particle extends PhysicsBox implements DrawableObject{

int size;
Random r;
long seed;

public Particle(String name, Vector2 position, int size, long seed){
super(name, position, size, size, 50f, 0.5f, 0.5f, 0);
Random random;
int angle;
Vector2 impulse = new Vector2(0, 0);

public Particle(Vector2 position, int size, int angle, Random rand){
super(null, position, size, size, 50f, 0.5f, 0.5f, 0);
this.size = size;
this.seed = seed;
r = new Random(seed);
random = rand;
this.setCollisionGroup(-1);
impulse.x = (float) Math.sin(angle)*Gsing.get().pImpulse;
impulse.y = (float) Math.cos(angle)*Gsing.get().pImpulse;
this.applyBodyLinearImpulse(impulse, position, true);
}

public Particle(String name, Vector2 position){
super(name, position, 0, 0);
public Particle(Vector2 position){
super(null, position, 0, 0);
}

public void draw(GdxGraphics g) {

// r.setSeed(seed);
// int red = (int)(r.nextInt()*255);
// int green = (int)(r.nextInt()* 255);
// int blue = (int)(r.nextInt()* 255);
Vector2 pos = this.getBodyWorldCenter();
// g.drawFilledRectangle(pos.x, pos.y, size, size, this.getBodyAngle(), new Color(red, green, blue, 0));
g.drawFilledRectangle(pos.x, pos.y, size, size, this.getBodyAngle() * MathUtils.radiansToDegrees, Color.BLACK);

}
@@ -23,7 +23,7 @@ public void onInit() {
}

public void onGraphicRender(GdxGraphics g) {
s.render(g);
s.render(g);
}

public void onClick(int x, int y, int button) {
@@ -5,7 +5,7 @@
import ch.hevs.gdx2d.lib.interfaces.DrawableObject;


public class StartPlatform implements DrawableObject{
public class StartPlatform implements DrawableObject {

int width;
PhysicsStaticBox startPlatform;
@@ -1,3 +1,5 @@
import java.util.Random;

import ch.hevs.gdx2d.components.bitmaps.BitmapImage;
import ch.hevs.gdx2d.components.physics.primitives.PhysicsBox;
import ch.hevs.gdx2d.lib.GdxGraphics;
@@ -15,16 +17,25 @@ public class TrailParticle extends PhysicsBox implements DrawableObject{
// Resources MUST not be static
protected BitmapImage img = new BitmapImage("data/images/cubetrailTexture.png");
protected int age = 0;
private boolean init = false;
private boolean init = false;
Random random;

public TrailParticle(Vector2 position, int radius, int maxAge) {
public TrailParticle(Vector2 position, int radius, int maxAge, Random rand) {
super(null, position, radius, radius, 0.005f, 0, 1f);
this.maxAge = maxAge;
this.random = rand;

// Particles should not collide together
Filter filter = new Filter();
filter.groupIndex = -1;
f.setFilterData(filter);

// Apply a vertical force with some random horizontal component
Vector2 force = new Vector2();
force.x = random.nextFloat() * -0.00095f;
force.y = random.nextFloat() * 0.0002f * (random.nextBoolean() == true ? -1 : 1);
this.applyBodyLinearImpulse(force, position, true);
this.getBody().setGravityScale(0);
}

@Override
@@ -45,16 +56,6 @@ public void draw(GdxGraphics g) {

final Color col = g.sbGetColor();
final Vector2 pos = getBodyPosition();

/*
* Have to understand this! ##################################
*/

// if (!init) {
// g.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
// init = true;
// }


// Make the particle disappear with time
g.sbSetColor(col.r, col.g, col.b, 1.0f - age / (float) (maxAge + 5));
@@ -10,11 +10,11 @@ public class VarObstacle implements DrawableObject {

int width;
int height;
Sensor sensor;
DamageSensor sensor;
// boolean iKilledTheCube = false;

public VarObstacle(Vector2 position) {
sensor = new Sensor(position, Gsing.get().VarObsW1, Gsing.get().VarObsH1);
sensor = new DamageSensor(position, Gsing.get().VarObsW1, Gsing.get().VarObsH1);
}

public void draw(GdxGraphics g) {
@@ -0,0 +1,24 @@
import ch.hevs.gdx2d.components.physics.primitives.PhysicsStaticBox;
import ch.hevs.gdx2d.lib.GdxGraphics;
import ch.hevs.gdx2d.lib.interfaces.DrawableObject;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;

public class WinSensor extends PhysicsStaticBox implements DrawableObject{

int width;
int height;

public WinSensor(Vector2 position, int width, int height) {
super(null, position, width, height, 0);
this.setSensor(true);
this.width = width;
this.height = height;
}


public void draw(GdxGraphics g) {
Vector2 pos = this.getBodyWorldCenter();
g.drawFilledRectangle(pos.x, pos.y, width, height, 0, Color.GREEN);
}
}