Touch controls ready.
This commit is contained in:
@@ -440,9 +440,6 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
|
|||||||
font.dispose();
|
font.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(GameSettings.getEntityCreator() != null)
|
|
||||||
GameSettings.getEntityCreator().dispose();
|
|
||||||
|
|
||||||
// Dispose screens.
|
// Dispose screens.
|
||||||
for(int i = 0; i < states.length; i++){
|
for(int i = 0; i < states.length; i++){
|
||||||
states[i].dispose();
|
states[i].dispose();
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package ve.ucv.ciens.ccg.nxtar.components;
|
||||||
|
|
||||||
|
import com.artemis.Component;
|
||||||
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
|
||||||
|
public class AutomaticMovementComponent extends Component{
|
||||||
|
public boolean moving;
|
||||||
|
public boolean forward;
|
||||||
|
public float distance;
|
||||||
|
public Vector3 startPoint;
|
||||||
|
public Vector3 endPoint;
|
||||||
|
|
||||||
|
public AutomaticMovementComponent(Vector3 startPoint, Vector3 endPoint, boolean moving){
|
||||||
|
this.moving = moving;
|
||||||
|
this.forward = true;
|
||||||
|
this.distance = 0.0f;
|
||||||
|
this.startPoint = startPoint;
|
||||||
|
this.endPoint = endPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutomaticMovementComponent(Vector3 startPoint, Vector3 endPoint){
|
||||||
|
this(startPoint, endPoint, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutomaticMovementComponent(boolean moving){
|
||||||
|
this(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(), moving);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutomaticMovementComponent(Vector3 endPoint){
|
||||||
|
this(new Vector3(0.0f, 0.0f, 0.0f), endPoint, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutomaticMovementComponent(){
|
||||||
|
this(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
package ve.ucv.ciens.ccg.nxtar.entities;
|
package ve.ucv.ciens.ccg.nxtar.entities;
|
||||||
|
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.AutomaticMovementComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.BombComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.BombComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.BombComponent.bomb_type_t;
|
import ve.ucv.ciens.ccg.nxtar.components.BombComponent.bomb_type_t;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.BombGameObjectTypeComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.BombGameObjectTypeComponent;
|
||||||
@@ -232,12 +233,13 @@ public class BombGameEntityCreator extends EntityCreatorBase{
|
|||||||
private void addRobotArm(EntityParameters parameters){
|
private void addRobotArm(EntityParameters parameters){
|
||||||
Entity robotArm = world.createEntity();
|
Entity robotArm = world.createEntity();
|
||||||
|
|
||||||
robotArm.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, -0.5f), new Matrix3(), new Vector3(1, 1, 1)));
|
robotArm.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, -1.0f), new Matrix3(), new Vector3(1, 1, 1)));
|
||||||
robotArm.addComponent(new EnvironmentComponent(parameters.environment));
|
robotArm.addComponent(new EnvironmentComponent(parameters.environment));
|
||||||
robotArm.addComponent(new ShaderComponent(parameters.shader));
|
robotArm.addComponent(new ShaderComponent(parameters.shader));
|
||||||
robotArm.addComponent(new RenderModelComponent(robotArmModel));
|
robotArm.addComponent(new RenderModelComponent(robotArmModel));
|
||||||
robotArm.addComponent(new CollisionModelComponent(robotArmCollisionModel));
|
robotArm.addComponent(new CollisionModelComponent(robotArmCollisionModel));
|
||||||
robotArm.addComponent(new CollisionDetectionComponent());
|
robotArm.addComponent(new CollisionDetectionComponent());
|
||||||
|
robotArm.addComponent(new AutomaticMovementComponent());
|
||||||
robotArm.addToWorld();
|
robotArm.addToWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class TouchUserInput extends UserInput {
|
|||||||
public Vector3 userTouchEndPoint;
|
public Vector3 userTouchEndPoint;
|
||||||
|
|
||||||
public TouchUserInput(){
|
public TouchUserInput(){
|
||||||
this.userTouchEndPoint = null;
|
this.userTouchEndPoint = new Vector3();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TouchUserInput(Vector3 userTouchEndPoint){
|
public TouchUserInput(Vector3 userTouchEndPoint){
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package ve.ucv.ciens.ccg.nxtar.systems;
|
package ve.ucv.ciens.ccg.nxtar.systems;
|
||||||
|
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.AutomaticMovementComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
|
||||||
@@ -22,30 +23,33 @@ import ve.ucv.ciens.ccg.nxtar.input.GamepadUserInput;
|
|||||||
import ve.ucv.ciens.ccg.nxtar.input.KeyboardUserInput;
|
import ve.ucv.ciens.ccg.nxtar.input.KeyboardUserInput;
|
||||||
import ve.ucv.ciens.ccg.nxtar.input.TouchUserInput;
|
import ve.ucv.ciens.ccg.nxtar.input.TouchUserInput;
|
||||||
import ve.ucv.ciens.ccg.nxtar.input.UserInput;
|
import ve.ucv.ciens.ccg.nxtar.input.UserInput;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
|
||||||
|
|
||||||
import com.artemis.Aspect;
|
import com.artemis.Aspect;
|
||||||
import com.artemis.ComponentMapper;
|
import com.artemis.ComponentMapper;
|
||||||
import com.artemis.Entity;
|
import com.artemis.Entity;
|
||||||
import com.artemis.annotations.Mapper;
|
import com.artemis.annotations.Mapper;
|
||||||
import com.artemis.systems.EntityProcessingSystem;
|
import com.artemis.systems.EntityProcessingSystem;
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.math.Vector3;
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
|
||||||
public class RobotArmPositioningSystem extends EntityProcessingSystem {
|
public class RobotArmPositioningSystem extends EntityProcessingSystem {
|
||||||
private static final String TAG = "ROBOT_ARM_POSITIONING_SYSTEM";
|
private static final String TAG = "ROBOT_ARM_POSITIONING_SYSTEM";
|
||||||
private static final String CLASS_NAME = RobotArmPositioningSystem.class.getSimpleName();
|
private static final String CLASS_NAME = RobotArmPositioningSystem.class.getSimpleName();
|
||||||
|
private static final float INTERPOLATION_STEP = 0.05f;
|
||||||
private static final float STEP_SIZE = 0.05f;
|
private static final float STEP_SIZE = 0.05f;
|
||||||
private static final Vector3 END_POINT = new Vector3(-1.0f, 0.0f, 0.0f);
|
private static final Vector3 END_POINT = new Vector3(0.0f, 0.0f, -0.5f);
|
||||||
private static final float MAX_Z = -4.5f;
|
private static final float MAX_Z = -4.5f;
|
||||||
|
|
||||||
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
|
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
|
||||||
// @Mapper ComponentMapper<AutomaticMovementComponent> autoMapper;
|
@Mapper ComponentMapper<AutomaticMovementComponent> autoMapper;
|
||||||
@Mapper ComponentMapper<CollisionDetectionComponent> collisionMapper;
|
@Mapper ComponentMapper<CollisionDetectionComponent> collisionMapper;
|
||||||
|
|
||||||
private UserInput input;
|
private UserInput input;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public RobotArmPositioningSystem(){
|
public RobotArmPositioningSystem(){
|
||||||
super(Aspect.getAspectForAll(GeometryComponent.class, /*AutomaticMovementComponent.class,*/ CollisionDetectionComponent.class).exclude(MarkerCodeComponent.class));
|
super(Aspect.getAspectForAll(GeometryComponent.class, AutomaticMovementComponent.class, CollisionDetectionComponent.class).exclude(MarkerCodeComponent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserInput(UserInput input){
|
public void setUserInput(UserInput input){
|
||||||
@@ -58,61 +62,58 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
|
|||||||
GamepadUserInput tempGP;
|
GamepadUserInput tempGP;
|
||||||
KeyboardUserInput tempKey;
|
KeyboardUserInput tempKey;
|
||||||
GeometryComponent geometry = geometryMapper.get(e);
|
GeometryComponent geometry = geometryMapper.get(e);
|
||||||
// AutomaticMovementComponent auto = autoMapper.get(e);
|
AutomaticMovementComponent auto = autoMapper.get(e);
|
||||||
CollisionDetectionComponent collision = collisionMapper.get(e);
|
CollisionDetectionComponent collision = collisionMapper.get(e);
|
||||||
|
|
||||||
if(input == null){
|
if(input == null){
|
||||||
/*if(auto.moving) autoMove(geometry, auto, collision);
|
if(auto.moving) autoMove(geometry, auto, collision);
|
||||||
else */return;
|
else return;
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
if(input instanceof TouchUserInput){
|
if(input instanceof TouchUserInput){
|
||||||
// if(!auto.moving){
|
if(!auto.moving){
|
||||||
// endPoint = ((TouchUserInput) input).userTouchEndPoint;
|
endPoint = ((TouchUserInput) input).userTouchEndPoint;
|
||||||
// endPoint.set(endPoint.x, endPoint.y, MAX_Z);
|
endPoint.set(endPoint.x, endPoint.y, MAX_Z);
|
||||||
// auto.startPoint.set(geometry.position);
|
auto.startPoint.set(geometry.position);
|
||||||
// auto.endPoint.set(endPoint);
|
auto.endPoint.set(endPoint);
|
||||||
// auto.moving = true;
|
auto.moving = true;
|
||||||
// auto.forward = true;
|
auto.forward = true;
|
||||||
//
|
|
||||||
// auto.target.set(endPoint).sub(auto.startPoint);
|
Gdx.app.log(TAG, CLASS_NAME + ".process(): Started moving from " + Utils.vector2String(auto.startPoint) + " to " + Utils.vector2String(auto.endPoint));
|
||||||
// auto.epsilon = 0.05f;
|
}else autoMove(geometry, auto, collision);
|
||||||
//
|
|
||||||
// Gdx.app.log(TAG, CLASS_NAME + ".process(): Started moving from " + Utils.vector2String(auto.startPoint) + " to " + Utils.vector2String(auto.endPoint));
|
|
||||||
// }else autoMove(geometry, auto, collision);
|
|
||||||
|
|
||||||
}else if(input instanceof GamepadUserInput){
|
}else if(input instanceof GamepadUserInput){
|
||||||
// tempGP = (GamepadUserInput) input;
|
tempGP = (GamepadUserInput) input;
|
||||||
//
|
|
||||||
// if(!collision.colliding && !auto.moving){
|
if(!collision.colliding){
|
||||||
// geometry.position.x += tempGP.axisLeftY * STEP_SIZE;
|
geometry.position.x += tempGP.axisLeftY * STEP_SIZE;
|
||||||
// geometry.position.y += tempGP.axisLeftX * STEP_SIZE;
|
geometry.position.y += tempGP.axisLeftX * STEP_SIZE;
|
||||||
// geometry.position.z += tempGP.axisRightY * STEP_SIZE;
|
geometry.position.z += tempGP.axisRightY * STEP_SIZE;
|
||||||
//clampPosition(geometry);
|
//clampPosition(geometry);
|
||||||
// }else{
|
}else{
|
||||||
// auto.moving = true;
|
auto.moving = true;
|
||||||
// auto.forward = false;
|
auto.forward = false;
|
||||||
// auto.startPoint.set(geometry.position);
|
auto.startPoint.set(geometry.position);
|
||||||
// auto.endPoint.set(END_POINT);
|
auto.endPoint.set(END_POINT);
|
||||||
// }
|
}
|
||||||
|
|
||||||
}else if(input instanceof KeyboardUserInput){
|
}else if(input instanceof KeyboardUserInput){
|
||||||
// tempKey = (KeyboardUserInput) input;
|
tempKey = (KeyboardUserInput) input;
|
||||||
//
|
|
||||||
// if(!collision.colliding && !auto.moving){
|
if(!collision.colliding){
|
||||||
// geometry.position.x -= tempKey.keyUp ? STEP_SIZE : 0.0f;
|
geometry.position.x += tempKey.keyUp ? STEP_SIZE : 0.0f;
|
||||||
// geometry.position.x += tempKey.keyDown ? STEP_SIZE : 0.0f;
|
geometry.position.x -= tempKey.keyDown ? STEP_SIZE : 0.0f;
|
||||||
// geometry.position.y -= tempKey.keyLeft ? STEP_SIZE : 0.0f;
|
geometry.position.y -= tempKey.keyLeft ? STEP_SIZE : 0.0f;
|
||||||
// geometry.position.y += tempKey.keyRight ? STEP_SIZE : 0.0f;
|
geometry.position.y += tempKey.keyRight ? STEP_SIZE : 0.0f;
|
||||||
// geometry.position.z -= tempKey.keyZ ? STEP_SIZE : 0.0f;
|
geometry.position.z -= tempKey.keyZ ? STEP_SIZE : 0.0f;
|
||||||
// geometry.position.z += tempKey.keyA ? STEP_SIZE : 0.0f;
|
geometry.position.z += tempKey.keyA ? STEP_SIZE : 0.0f;
|
||||||
//clampPosition(geometry);
|
//clampPosition(geometry);
|
||||||
// }else{
|
}else{
|
||||||
// auto.moving = true;
|
auto.moving = true;
|
||||||
// auto.forward = false;
|
auto.forward = false;
|
||||||
// auto.startPoint.set(geometry.position);
|
auto.startPoint.set(geometry.position);
|
||||||
// auto.endPoint.set(END_POINT);
|
auto.endPoint.set(END_POINT);
|
||||||
// }
|
}
|
||||||
|
|
||||||
}else
|
}else
|
||||||
throw new ClassCastException("Input is not a valid UserInput instance.");
|
throw new ClassCastException("Input is not a valid UserInput instance.");
|
||||||
@@ -121,45 +122,45 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
|
|||||||
input = null;
|
input = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// private void autoMove(GeometryComponent geometry, AutomaticMovementComponent auto, CollisionDetectionComponent collision){
|
private void autoMove(GeometryComponent geometry, AutomaticMovementComponent auto, CollisionDetectionComponent collision){
|
||||||
// float step;
|
float step;
|
||||||
//
|
|
||||||
// if(auto.moving){
|
|
||||||
// if(auto.forward)
|
|
||||||
// step = STEP_SIZE;
|
|
||||||
// else
|
|
||||||
// step = -STEP_SIZE;
|
|
||||||
//
|
|
||||||
// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(step));
|
|
||||||
//
|
|
||||||
// auto.distance += step;
|
|
||||||
//
|
|
||||||
// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(auto.distance));
|
|
||||||
//
|
|
||||||
// geometry.position.x = (auto.startPoint.x * (1.0f - auto.distance)) + (auto.endPoint.x * auto.distance);
|
|
||||||
// geometry.position.y = (auto.startPoint.y * (1.0f - auto.distance)) + (auto.endPoint.y * auto.distance);
|
|
||||||
// geometry.position.z = (auto.startPoint.z * (1.0f - auto.distance)) + (auto.endPoint.z * auto.distance);
|
|
||||||
//
|
|
||||||
// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Current position: " + Utils.vector2String(geometry.position));
|
|
||||||
//
|
|
||||||
// if(auto.distance <= 0.0f){
|
|
||||||
// auto.forward = true;
|
|
||||||
// auto.moving = false;
|
|
||||||
// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going forward now.");
|
|
||||||
// }else if(auto.distance >= 1.0f || collision.colliding){
|
|
||||||
// auto.forward = false;
|
|
||||||
// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going backwards now.");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }else return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
private void clampPosition(GeometryComponent geometry){
|
if(auto.moving){
|
||||||
geometry.position.x = geometry.position.x >= -1.0f ? geometry.position.x : -1.0f;
|
if(auto.forward)
|
||||||
geometry.position.x = geometry.position.x <= 1.0f ? geometry.position.x : 1.0f;
|
step = INTERPOLATION_STEP;
|
||||||
geometry.position.y = geometry.position.y >= -1.0f ? geometry.position.y : -1.0f;
|
else
|
||||||
geometry.position.y = geometry.position.y <= 1.0f ? geometry.position.y : 1.0f;
|
step = -INTERPOLATION_STEP;
|
||||||
geometry.position.z = geometry.position.z >= 0.0f ? geometry.position.z : 0.0f;
|
|
||||||
geometry.position.z = geometry.position.z <= 6.0f ? geometry.position.z : 6.0f;
|
Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(step));
|
||||||
|
|
||||||
|
auto.distance += step;
|
||||||
|
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(auto.distance));
|
||||||
|
|
||||||
|
geometry.position.x = (auto.startPoint.x * (1.0f - auto.distance)) + (auto.endPoint.x * auto.distance);
|
||||||
|
geometry.position.y = (auto.startPoint.y * (1.0f - auto.distance)) + (auto.endPoint.y * auto.distance);
|
||||||
|
geometry.position.z = (auto.startPoint.z * (1.0f - auto.distance)) + (auto.endPoint.z * auto.distance);
|
||||||
|
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Current position: " + Utils.vector2String(geometry.position));
|
||||||
|
|
||||||
|
if(auto.distance <= 0.0f){
|
||||||
|
auto.forward = true;
|
||||||
|
auto.moving = false;
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going forward now.");
|
||||||
|
}else if(auto.distance >= 1.0f || collision.colliding){
|
||||||
|
auto.forward = false;
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going backwards now.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}else return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// private void clampPosition(GeometryComponent geometry){
|
||||||
|
// geometry.position.x = geometry.position.x >= -1.0f ? geometry.position.x : -1.0f;
|
||||||
|
// geometry.position.x = geometry.position.x <= 1.0f ? geometry.position.x : 1.0f;
|
||||||
|
// geometry.position.y = geometry.position.y >= -1.0f ? geometry.position.y : -1.0f;
|
||||||
|
// geometry.position.y = geometry.position.y <= 1.0f ? geometry.position.y : 1.0f;
|
||||||
|
// geometry.position.z = geometry.position.z >= 0.0f ? geometry.position.z : 0.0f;
|
||||||
|
// geometry.position.z = geometry.position.z <= 6.0f ? geometry.position.z : 6.0f;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,9 +49,11 @@ public abstract class GameSettings{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void clearGameSettings(){
|
public static void clearGameSettings(){
|
||||||
|
entityCreator.dispose();
|
||||||
entityCreator = null;
|
entityCreator = null;
|
||||||
gameLogicSystem = null;
|
gameLogicSystem = null;
|
||||||
gameWorld = null;
|
gameWorld = null;
|
||||||
|
System.gc();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user