Android Open Source - SpaceRagdoll Space






From Project

Back to project page SpaceRagdoll.

License

The source code is released under:

GNU General Public License

If you think the Android project SpaceRagdoll listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*******************************************************************************
 * Copyright (C) 2015 Tuukka Ruhanen/*  ww w  .java2 s  .c o m*/
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *******************************************************************************/
package fi.karu.spaceragdoll;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Filter;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.Joint;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.physics.box2d.joints.RopeJointDef;

import fi.karu.spaceragdoll.Ragdoll.State;

/**
 * This class governs the physical events of the game,
 * e.g. force application, by responding to the changes
 * set by the Controller class. The events are directed
 * to their respective objects.
 */
public class Space {

    World world;
    Planet planet;
    Ragdoll doll;
    Joint catapultJoint;

    public Space() {
        world = new World(new Vector2(0, 0), true);
        doll = Ragdoll.create(world);
        planet = Planet.create(world);

        // catapult joint
        RopeJointDef ropeJointDef = new RopeJointDef();
        ropeJointDef.bodyA = planet.getBody();
        ropeJointDef.bodyB = doll.getLegBody();
        ropeJointDef.localAnchorA.set(0, Planet.R + 3f);
        ropeJointDef.localAnchorB.set(-Ragdoll.legLength / 2f, 0);
        ropeJointDef.maxLength = 6f;
        catapultJoint = world.createJoint(ropeJointDef);
    }

    public World getWorld() {
        return world;
    }

    public void setBirdState(State state) {
        doll.setState(state);
    }

    public State getBirdState() {
        return doll.getState();
    }

    public void setBirdSwing(int swingX, int swingY) {
        doll.setSwing(swingX, swingY);
    }

    public void releaseBird() {
        if (doll.getState() == Ragdoll.State.GROUND) {
            doll.setState(Ragdoll.State.OFF);
            // release catapult joint
            world.destroyJoint(catapultJoint);
            // make planet collidable
            Fixture planetFixture = planet.getBody().getFixtureList().get(0);
            Filter planetFilter = planetFixture.getFilterData();
            planetFilter.groupIndex = 1;
            planetFixture.setFilterData(planetFilter);
        }
    }

    public boolean isReleased() {
        return doll.state != Ragdoll.State.GROUND;
    }

    public float getBirdAngle() {
        return doll.getAngle();
    }

    public Vector2 getBirdPosition() {
        return doll.getPosition();
    }

    public void update(float delta) {
        doll.applyForces();
        world.step(1 / 300f, 6, 2);
        // world.step(delta, 6, 2);
    }
}




Java Source Code List

fi.karu.spacebird_android.SpaceRagdollActivity.java
fi.karu.spaceragdoll.GameScreen.java
fi.karu.spaceragdoll.Planet.java
fi.karu.spaceragdoll.Ragdoll.java
fi.karu.spaceragdoll.SpaceRagdoll.java
fi.karu.spaceragdoll.SpaceRenderer.java
fi.karu.spaceragdoll.Space.java
fi.karu.spaceragdoll.controller.Controller.java
fi.karu.spaceragdoll_desktop.SpaceRagdollDesktop.java