Newer
Older
CarrotServer / src / game / Player.java
t-nakanishi on 18 Jul 2017 4 KB [add] project
package game;

import framework.gameMain.Movable;
import framework.gameMain.OvergroundActor;
import framework.model3D.BaseObject3D;
import framework.model3D.Object3D;
import framework.model3D.Position3D;
import framework.physics.Ground;
import framework.physics.Solid3D;
import framework.physics.Velocity3D;
import java3d.Appearance;
import java3d.Box;
import java3d.Material;
import java3d.TransformGroup;
import java3d.Vector3d;


public class Player implements Movable {

	OvergroundActor actor;

	private double angle;
	private String mode = "normal";
	private String hit = "no";

	private int hp = 100;
	
	public Player() {
		
		//プレイヤー生成
		Appearance ap1 = new Appearance();
		Material color = new Material();
		color.setDiffuseColor(0.0f, 1.0f, 0.0f);
		ap1.setMaterial(color);
		
		Box b_head = new Box(2.0f, 2.0f, 2.0f, ap1);
		Box b_body = new Box(3.5f, 4.5f, 2.0f, ap1);
		Box b_rightarm = new Box(2.5f, 1.0f, 1.0f, ap1);
		Box b_leftarm = new Box(2.5f, 1.0f, 1.0f, ap1);
		Box b_rightleg = new Box(1.0f, 3.0f, 1.0f, ap1);
		Box b_leftleg = new Box(1.0f, 3.0f, 1.0f, ap1);
				
		Object3D obj1 = new Object3D("head", b_head);
		obj1.apply(new Position3D(0.0, 19.5, 0.0), false);
//		Solid3D head = new Solid3D(obj1);
//		head.scale(2.0, 2.0, 2.0);
		
		Object3D obj2 = new Object3D("body", b_body);
		obj2.apply(new Position3D(0.0, 13.0, 0.0), false);
//		Solid3D body = new Solid3D(obj2);
//		body.scale(3.0, 5.0, 2.0);
		
		Object3D obj3 = new Object3D("rightarm", b_rightarm);
		obj3.apply(new Position3D(6.0, 15.0, 0.0), false);
//		Solid3D rightarm = new Solid3D(obj3);
//		rightarm.scale(2.0, 1.0, 1.0);
		
		Object3D obj4 = new Object3D("leftarm", b_leftarm);
		obj4.apply(new Position3D(-6.0, 15.0, 0.0), false);
//		Solid3D leftarm = new Solid3D(obj4);
//		leftarm.scale(2.0, 1.0, 1.0);
		
		Object3D obj5 = new Object3D("rightleg", b_rightleg);
		obj5.apply(new Position3D(2.0, 5.5, 0.0), false);
//		Solid3D rightleg = new Solid3D(obj5);
//		rightleg.scale(1.0, 3.0, 1.0);
		
		Object3D obj6 = new Object3D("leftleg", b_leftleg);
		obj6.apply(new Position3D(-2.0, 5.5, 0.0), false);
//		Solid3D leftleg = new Solid3D(obj6);
//		leftleg.scale(1.0, 3.0, 1.0);
		
		Object3D pl = new Object3D("player", new Object3D[] {
				obj1, obj2, obj3, obj4, obj5, obj6
		});
		pl.apply(new Position3D(0.0, 0.0, 0.0), false);
		Solid3D s_player = new Solid3D(pl);
		actor = new OvergroundActor(s_player,null);
		
		actor.setInitialDirection(new Vector3d(0.0, 0.0, -1.0));
		
	}
	
	//pointX
	public double getPointX() {
		return actor.getPosition().getX();
	}

	//pointY
	public double getPointY() {
		return actor.getPosition().getY();
	}
	
	//pointZ
	public double getPointZ() {
		return actor.getPosition().getZ();
	}

	//point
	public void setPoint(Position3D p) {
		actor.setPosition(p);
	}

	//angel
	public double getAngle() {
		return angle;
	}
	
	public void setAngle(double angle) {
		Vector3d initialDir = actor.getInitialDirection().clone();
		double x = initialDir.getZ()* Math.sin(angle) + initialDir.getX()*Math.cos(angle);
		double z = initialDir.getZ()* Math.cos(angle) - initialDir.getX()*Math.sin(angle);
		actor.setDirection(new Vector3d(x, 0.0, z));
		
		this.angle = angle;
	}

	//mode
	public String getMode() {
		return mode;
	}
	public void setMode(String mode) {
		this.mode = mode;
	}

	//hit
	public String getHit() {
		return hit;
	}
	public void setHit(String hit) {
		this.hit = hit;
	}

	//HP
	public int getHp() {
		return hp;
	}
	public void setHp(int hp) {
		this.hp = hp;
	}

	public void setDirection(Vector3d v){
		actor.setDirection(v);
	}
	
	@Override
	public void motion(long interval, Ground ground) {
		actor.motion(interval, ground);
		
	}
	
	@Override
	public BaseObject3D getBody() {
		return actor.getBody();
	}
	
	public void setVelocity(Velocity3D velocity3d) {
		actor.setVelocity(velocity3d);
	}

	@Override
	public TransformGroup getTransformGroupToPlace() {
		// TODO Auto-generated method stub
		return null;
	}

}