Skip to content

Commit

Permalink
Second release
Browse files Browse the repository at this point in the history
  • Loading branch information
malmers committed Sep 30, 2013
2 parents 274d3c7 + 616fc1f commit f66f2cc
Show file tree
Hide file tree
Showing 27 changed files with 691 additions and 288 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,10 @@ Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/

#Gradle
build.gradle
gradle/
gradlew
gradlew.bat


8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
SegwaySimulator
===============
##Changelog:
###v0.2
+ Added gyro support
+ Added golden cookie
+ More levels
+ New music
+ New death screen! (Dark Souls inspired??)
+ Tip
Binary file modified assets/gfx/game/curvyPlatform1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/gfx/game/curvyPlatform2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/gfx/game/goldcookie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/gfx/game/segwayBackwards.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/gfx/game/youdied2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/level/3.lvl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<level width="3000" height="780">
<entity x="260" y="100" type="curvyPlatform1"/>
<entity x="50" y="300" type="player"/>
</level>
50 changes: 50 additions & 0 deletions assets/level/4.lvl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<level width="14000" height="5500">
<entity x="100" y="5000" type="platform1"/>
<entity x="400" y="4900" type="platform2"/>
<entity x="700" y="4800" type="platform2"/>
<entity x="1000" y="4700" type="platform2"/>
<entity x="1300" y="4600" type="platform2"/>
<entity x="1600" y="4500" type="platform2"/>
<entity x="1900" y="4400" type="platform2"/>
<entity x="2200" y="4300" type="platform2"/>
<entity x="2500" y="4200" type="platform2"/>
<entity x="2800" y="4100" type="platform2"/>
<entity x="3100" y="4000" type="platform2"/>
<entity x="3400" y="3900" type="platform2"/>
<entity x="3700" y="3800" type="platform2"/>
<entity x="4000" y="3700" type="platform2"/>
<entity x="4300" y="3600" type="platform2"/>
<entity x="4600" y="3500" type="platform2"/>
<entity x="4900" y="3400" type="platform2"/>
<entity x="5200" y="3300" type="platform2"/>
<entity x="5500" y="3200" type="platform2"/>
<entity x="5800" y="3100" type="platform2"/>
<entity x="6100" y="3000" type="platform2"/>
<entity x="6400" y="2900" type="platform2"/>
<entity x="6700" y="2800" type="platform2"/>
<entity x="7000" y="2700" type="platform2"/>
<entity x="7300" y="2600" type="platform2"/>
<entity x="7600" y="2500" type="platform2"/>
<entity x="7900" y="2400" type="platform2"/>
<entity x="8200" y="2300" type="platform2"/>
<entity x="8500" y="2200" type="platform2"/>
<entity x="8800" y="2100" type="platform2"/>
<entity x="9100" y="2000" type="platform2"/>
<entity x="9400" y="1900" type="platform2"/>
<entity x="9700" y="1800" type="platform2"/>
<entity x="10000" y="1700" type="platform2"/>
<entity x="10300" y="1600" type="platform2"/>
<entity x="10600" y="1500" type="platform2"/>
<entity x="10900" y="1400" type="platform2"/>
<entity x="11200" y="1300" type="platform2"/>
<entity x="11500" y="1200" type="platform2"/>
<entity x="11800" y="1100" type="platform2"/>
<entity x="12100" y="1000" type="platform2"/>
<entity x="12400" y="900" type="platform2"/>
<entity x="12700" y="800" type="platform2"/>
<entity x="13000" y="700" type="platform2"/>
<entity x="13300" y="600" type="platform2"/>
<entity x="13600" y="700" type="golden_cookie"/>
<entity x="50" y="5200" type="player"/>
</level>
Binary file added assets/sfx/shepard_tone.ogg
Binary file not shown.
135 changes: 69 additions & 66 deletions src/se/chalmers/segway/entities/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,83 @@
import org.andengine.extension.physics.box2d.PhysicsWorld;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

import se.chalmers.segway.resources.ResourcesManager;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;

import se.chalmers.segway.managers.ResourcesManager;

public abstract class Player extends AnimatedSprite {

private Body body;
private int footContacts = 0;
private boolean canRun = false;
private boolean hasContact = false;
final long[] PLAYER_SLOW_ANIMATE = new long[] { 100, 100, 100 };
final long[] PLAYER_FAST_ANIMATE = new long[] { 50, 50, 50 };
private Vector2 speed;

public Player(float pX, float pY, VertexBufferObjectManager vbo,
Camera camera, PhysicsWorld physicsWorld) {
super(pX, pY, ResourcesManager.getInstance().player_region, vbo);
createPhysics(camera, physicsWorld);
camera.setChaseEntity(this);
}

private void createPhysics(final Camera camera, PhysicsWorld physicsWorld) {
body = PhysicsFactory.createBoxBody(physicsWorld, this,
BodyType.DynamicBody, PhysicsFactory.createFixtureDef(0, 0, 0));

body.setUserData("player");
body.setFixedRotation(true);

physicsWorld.registerPhysicsConnector(new PhysicsConnector(this, body,
true, false) {
@Override
public void onUpdate(float pSecondsElapsed) {
super.onUpdate(pSecondsElapsed);
camera.onUpdate(0.1f);

if (getY() <= 0) {
onDie();
}

movePlayer(pSecondsElapsed);

if (Math.abs(body.getLinearVelocity().x) < 0.5) {
animate(PLAYER_FAST_ANIMATE, 0, 2, true);
}
}
});
}

public void movePlayer(float pSecondsElapsed){
if (speed != null) {
body.applyForce(speed.mul(50*pSecondsElapsed),
body.getPosition());
if (Math.abs(body.getLinearVelocity().x) >= 15) {
body.setLinearVelocity(
Math.signum(body.getLinearVelocity().x) * 15,
body.getLinearVelocity().y);
}
}
}

public Player(float pX, float pY, VertexBufferObjectManager vbo, Camera camera, PhysicsWorld physicsWorld)
{
super(pX, pY, ResourcesManager.getInstance().player_region, vbo);
createPhysics(camera, physicsWorld);
camera.setChaseEntity(this);
}

private void createPhysics(final Camera camera, PhysicsWorld physicsWorld)
{
body = PhysicsFactory.createBoxBody(physicsWorld, this, BodyType.DynamicBody, PhysicsFactory.createFixtureDef(0, 0, 0));

body.setUserData("player");
body.setFixedRotation(true);

physicsWorld.registerPhysicsConnector(new PhysicsConnector(this, body, true, false)
{
@Override
public void onUpdate(float pSecondsElapsed)
{
super.onUpdate(pSecondsElapsed);
camera.onUpdate(0.1f);

if (getY() <= 0)
{
onDie();
}

if (canRun)
{
//The actual speed of the segway
body.setLinearVelocity(new Vector2(5, body.getLinearVelocity().y));
}
}
});
}

public void increaseFootContacts() {
footContacts++;
public void setContact(boolean b) {
hasContact = b;
}

public void decreaseFootContacts() {
footContacts--;
public void setSpeed(Vector2 v) {
speed = v;
}

public void jump()
{
if (footContacts < 1)
{
return;
}
body.setLinearVelocity(new Vector2(body.getLinearVelocity().x/10, 6));
}

public void setRunning()
{
canRun = true;

final long[] PLAYER_ANIMATE = new long[] { 100, 100, 100 };

animate(PLAYER_ANIMATE, 0, 2, true);
}

public abstract void onDie();


public void jump() {
if (hasContact == false) {
return;
}
hasContact = false;
body.setLinearVelocity(new Vector2(body.getLinearVelocity().x, 6));

}

public abstract void onDie();

}
8 changes: 2 additions & 6 deletions src/se/chalmers/segway/entities/TestSprite.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package se.chalmers.segway.entities;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.handler.physics.PhysicsHandler;
import org.andengine.entity.sprite.AnimatedSprite;
import org.andengine.entity.sprite.Sprite;
import org.andengine.extension.physics.box2d.PhysicsConnector;
import org.andengine.extension.physics.box2d.PhysicsFactory;
import org.andengine.extension.physics.box2d.PhysicsWorld;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

import se.chalmers.segway.resources.ResourcesManager;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;

import se.chalmers.segway.managers.ResourcesManager;

/**
* Sprite for prototype of the game.
* @author Trivoc
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package se.chalmers.segway.managers;
package se.chalmers.segway.game;


/**
Expand Down
109 changes: 109 additions & 0 deletions src/se/chalmers/segway/game/PlayerContact.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package se.chalmers.segway.game;

import org.andengine.engine.Engine;
import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;

import se.chalmers.segway.entities.Player;

import com.badlogic.gdx.physics.box2d.Contact;
import com.badlogic.gdx.physics.box2d.ContactImpulse;
import com.badlogic.gdx.physics.box2d.ContactListener;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.Manifold;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;

public class PlayerContact implements ContactListener {

private Player player;
private Engine engine;


/**
* @return the player
*/
public Player getPlayer() {
return player;
}

/**
* @param player the player to set
*/
public void setPlayer(Player player) {
this.player = player;
}

/**
* @return the engine
*/
public Engine getEngine() {
return engine;
}

/**
* @param engine the engine to set
*/
public void setEngine(Engine engine) {
this.engine = engine;
}

@Override
public void beginContact(Contact contact) {
final Fixture x1 = contact.getFixtureA();
final Fixture x2 = contact.getFixtureB();

if (x1.getBody().getUserData() != null
&& x2.getBody().getUserData() != null) {
if (x2.getBody().getUserData().equals("platform1")
|| x2.getBody().getUserData().equals("platform2")
|| x2.getBody().getUserData().equals("platform3")) {
player.setContact(true);
}
}

if (x1.getBody().getUserData().equals("player")
&& x2.getBody().getUserData().equals("platform3")) {
x2.getBody().setType(BodyType.DynamicBody);
}

if (x1.getBody().getUserData().equals("player")
&& x2.getBody().getUserData().equals("platform2")) {
engine.registerUpdateHandler(new TimerHandler(0.2f,
new ITimerCallback() {
public void onTimePassed(
final TimerHandler pTimerHandler) {
pTimerHandler.reset();
engine.unregisterUpdateHandler(pTimerHandler);
x2.getBody().setType(BodyType.DynamicBody);
}
}));
}

}

@Override
public void endContact(Contact contact) {
final Fixture x1 = contact.getFixtureA();
final Fixture x2 = contact.getFixtureB();

if (x1.getBody().getUserData() != null
&& x2.getBody().getUserData() != null) {
if (!x2.getBody().getUserData().equals("player")) {
player.setContact(false);
System.out.println("End contact");
}
}

}

@Override
public void preSolve(Contact contact, Manifold oldManifold) {

}

@Override
public void postSolve(Contact contact, ContactImpulse impulse) {

}

}
27 changes: 27 additions & 0 deletions src/se/chalmers/segway/game/Upgrade.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package se.chalmers.segway.game;
/**
* Model for an basic upgrade.
* @author Wiixtor!
*
*/
public class Upgrade {
private int cost;
private boolean enabled;

/**
*
* @param cost The amount of cookies it will cost to purchase this upgrade.
*/
public Upgrade(int cost) {
this.cost = cost;
this.enabled = false;
}

public void enable() {
this.enabled = true;
}

public void disable() {
this.enabled = false;
}
}
Loading

0 comments on commit f66f2cc

Please sign in to comment.