Newer
Older
JumpingGame / src / main / java / models / PlayerModel.java
package models;

import entities.*;

//---------------------------------------------------------------
//
public class PlayerModel implements IModel {
    //---------------------------------------------------------------
    private Acceleration acceleration;
    private Force force;
    private Mass mass;
    private Move move;
    private Position position;
    private Velocity velocity;
    private Onground onground;

    //---------------------------------------------------------------
    private double jumpPower = 32;

    //---------------------------------------------------------------
    //
    public PlayerModel(IModel model) {
        GroundModel groundModel = (GroundModel)model;

        position = new Position(new Pair<>(640d, 480d), groundModel.getGround());
        onground = new Onground(groundModel.getGround(), position);
        velocity = new Velocity(position, onground);
        acceleration = new Acceleration(velocity, onground);
        force = new Force(acceleration);
        mass = new Mass(acceleration);
        move = new Move(velocity);
    }

    //---------------------------------------------------------------
    //---------------------------------------------------------------
    // getter
    public Position getPosition() {
        return position;
    }

    //---------------------------------------------------------------
    //
    public void jump() {
        this.move.moveY(jumpPower);
    }

    //---------------------------------------------------------------
    //
    public void updateGravity(double gravity) {
        this.force.gravity(gravity);
    }
}