Add HitStarControl and StarPointControl,
Fixes Collision
This commit is contained in:
parent
c60601f63e
commit
488078f532
49
ShootingTest/src/mygame/HitStarControl.java
Normal file
49
ShootingTest/src/mygame/HitStarControl.java
Normal file
@ -0,0 +1,49 @@
|
||||
package mygame;
|
||||
|
||||
import com.jme3.renderer.RenderManager;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
import com.jme3.scene.control.Control;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Snowsun
|
||||
*/
|
||||
public class HitStarControl extends AbstractControl {
|
||||
|
||||
private boolean isHited = false;
|
||||
private Node starNode;
|
||||
|
||||
public HitStarControl(Node starNode) {
|
||||
this.starNode = starNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
if (isHited) {
|
||||
//Do some stuff for example spawn particels
|
||||
System.out.println(spatial.getName() + " is hited");
|
||||
starNode.detachChild(spatial);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||
}
|
||||
|
||||
public Control cloneForSpatial(Spatial spatial) {
|
||||
HitStarControl control = new HitStarControl(starNode);
|
||||
spatial.addControl(control);
|
||||
return control;
|
||||
}
|
||||
|
||||
public void setIsHited(boolean isHited) {
|
||||
this.isHited = isHited;
|
||||
}
|
||||
|
||||
public boolean getIsHited() {
|
||||
return isHited;
|
||||
}
|
||||
}
|
||||
@ -21,6 +21,7 @@ public class Main extends SimpleApplication {
|
||||
private Spatial projectile;
|
||||
private Spatial star;
|
||||
private Spatial star2;
|
||||
private Spatial star3;
|
||||
private PlayerMouseControl playerMouseControl;
|
||||
private PlayerShootControl playerShootControl;
|
||||
private WeaponProjectileControl weaponProjectileControl;
|
||||
@ -53,16 +54,33 @@ public class Main extends SimpleApplication {
|
||||
Material mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
mat3.setColor("Color", ColorRGBA.Orange);
|
||||
star.setMaterial(mat3);
|
||||
star.addControl(new HitStarControl(starNode));
|
||||
star.addControl(new StarPointControl());
|
||||
starNode.attachChild(star);
|
||||
|
||||
|
||||
Box b3 = new Box(Vector3f.ZERO, 1, 1, 1);
|
||||
star2 = new Geometry("Star2",b3);
|
||||
star2.move(-4f, 2f, 0);
|
||||
Material mat4 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
mat4.setColor("Color", ColorRGBA.Green);
|
||||
star2.setMaterial(mat4);
|
||||
star2.addControl(new HitStarControl(starNode));
|
||||
star2.addControl(new StarPointControl());
|
||||
starNode.attachChild(star2);
|
||||
|
||||
|
||||
Box b4 = new Box(Vector3f.ZERO, 1, 1, 1);
|
||||
star3 = new Geometry("Star3",b4);
|
||||
star3.move(0f, -5f, 0);
|
||||
Material mat5 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
mat5.setColor("Color", ColorRGBA.White);
|
||||
star3.setMaterial(mat5);
|
||||
star3.addControl(new HitStarControl(starNode));
|
||||
star3.addControl(new StarPointControl());
|
||||
starNode.attachChild(star3);
|
||||
|
||||
|
||||
Box box = new Box(Vector3f.ZERO, 1, 1, 2);
|
||||
projectile = new Geometry("Projectile", box);
|
||||
projectile.setLocalTranslation(player.getLocalTranslation());
|
||||
|
||||
50
ShootingTest/src/mygame/StarPointControl.java
Normal file
50
ShootingTest/src/mygame/StarPointControl.java
Normal file
@ -0,0 +1,50 @@
|
||||
package mygame;
|
||||
|
||||
import com.jme3.renderer.RenderManager;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
import com.jme3.scene.control.Control;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Snowsun
|
||||
*/
|
||||
public class StarPointControl extends AbstractControl {
|
||||
|
||||
private int points = 100; //Todo Change StartPoint at Spawn
|
||||
private boolean isHited = false;
|
||||
|
||||
public StarPointControl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
if(isIsHited()) {
|
||||
//Todo Check life time and set points
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||
|
||||
}
|
||||
|
||||
public Control cloneForSpatial(Spatial spatial) {
|
||||
StarPointControl control = new StarPointControl();
|
||||
spatial.addControl(control);
|
||||
return control;
|
||||
}
|
||||
|
||||
public void setIsHited(boolean isHited) {
|
||||
this.isHited = isHited;
|
||||
}
|
||||
|
||||
public boolean isIsHited() {
|
||||
return isHited;
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return this.points;
|
||||
}
|
||||
}
|
||||
@ -34,10 +34,11 @@ public class WeaponProjectileCollisionControl extends AbstractControl {
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
for (Spatial s : starNode.getChildren()) {
|
||||
results.clear();
|
||||
s.collideWith(boundingVolume, results);
|
||||
if (results.size() > 0) {
|
||||
starNode.detachChild(s);
|
||||
System.out.println("What was hit? " + s.getName());
|
||||
s.getControl(HitStarControl.class).setIsHited(true);
|
||||
s.getControl(StarPointControl.class).setIsHited(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user