added stars
This commit is contained in:
parent
b8fa020781
commit
b44e1c0849
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
|
||||
*
|
||||
* 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 org.wyrez.shootingstars.controls;
|
||||
|
||||
import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.control.Control;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Darth Affe
|
||||
*/
|
||||
public class StarFaceControl extends BaseControl {
|
||||
|
||||
private Spatial target;
|
||||
|
||||
public StarFaceControl(Spatial target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float tpf) {
|
||||
spatial.lookAt(target.getLocalTranslation(), Vector3f.UNIT_Y);
|
||||
spatial.rotate(FastMath.HALF_PI, 0f, 0f);
|
||||
}
|
||||
|
||||
public Control cloneForSpatial(Spatial spatial) {
|
||||
return new StarFaceControl(target);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
|
||||
*
|
||||
* 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 org.wyrez.shootingstars.game;
|
||||
|
||||
import com.jme3.light.AmbientLight;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import java.util.Random;
|
||||
import org.wyrez.shootingstars.controls.StarDeathControl;
|
||||
import org.wyrez.shootingstars.controls.StarFaceControl;
|
||||
import org.wyrez.shootingstars.controls.StarPointControl;
|
||||
import org.wyrez.shootingstars.data.AudioDataManager;
|
||||
import org.wyrez.shootingstars.factories.Materials;
|
||||
import org.wyrez.shootingstars.helper.MathHelper;
|
||||
import org.wyrez.shootingstars.mesh.Star;
|
||||
import org.wyrez.shootingstars.states.GameState;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Darth Affe
|
||||
*/
|
||||
public class StarManager extends Node {
|
||||
|
||||
private static final Random random;
|
||||
private static final float MAX_STAR_SIZE = 75f;
|
||||
|
||||
static {
|
||||
random = new Random();
|
||||
}
|
||||
/**/
|
||||
private AudioDataManager audioDataManager;
|
||||
private Spatial player;
|
||||
|
||||
public StarManager(AudioDataManager audioDataManager, Spatial player) {
|
||||
this.audioDataManager = audioDataManager;
|
||||
this.player = player;
|
||||
addLight();
|
||||
}
|
||||
|
||||
public void update(float tpf) {
|
||||
float[] data = audioDataManager.getSpawnData();
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
for (float d : data) {
|
||||
if (d > 0f) {
|
||||
spawn(calcPosition(), calcSize(d), d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3f calcPosition() {
|
||||
float radius = (GameState.FIELD_RADIUS - MAX_STAR_SIZE) * random.nextFloat();
|
||||
|
||||
return MathHelper.calcPointOnCircle(MathHelper.degreeToRadian(random.nextFloat() * 360f),
|
||||
radius, random.nextFloat() * GameState.FIELD_HEIGHT + GameState.FIELD_LOWER_POS);
|
||||
}
|
||||
|
||||
private float calcSize(float data) {
|
||||
return MAX_STAR_SIZE - 50f * data;
|
||||
}
|
||||
|
||||
private void spawn(Vector3f location, float size, float value) {
|
||||
Geometry star = new Geometry("Star", new Star(size, size * 0.2f, 0.5f));
|
||||
star.addControl(new StarFaceControl(player));
|
||||
star.addControl(new StarDeathControl(this));
|
||||
star.addControl(new StarPointControl(player, value));
|
||||
star.setLocalTranslation(location);
|
||||
Material mat = Materials.STAR.create();
|
||||
mat.setColor("Color", ColorRGBA.Yellow);
|
||||
star.setMaterial(mat);
|
||||
this.attachChild(star);
|
||||
}
|
||||
|
||||
private void addLight() {
|
||||
AmbientLight ambient = new AmbientLight();
|
||||
ambient.setColor(ColorRGBA.White);
|
||||
this.addLight(ambient);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
|
||||
*
|
||||
* 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 org.wyrez.shootingstars.helper;
|
||||
|
||||
import com.jme3.math.ColorRGBA;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Darth Affe
|
||||
*/
|
||||
public class ColorHelper {
|
||||
|
||||
public static ColorRGBA calcColor(float value) {
|
||||
int r, g, b;
|
||||
if (value < 0.25f) {
|
||||
r = 0;
|
||||
g = Math.round(255 * value / 0.25f);
|
||||
b = 255;
|
||||
} else if (value < 0.5f) {
|
||||
r = 0;
|
||||
g = 255;
|
||||
b = Math.round(255 * ((0.25f - (value - 0.25f)) / 0.25f));
|
||||
} else if (value < 0.75f) {
|
||||
g = 255;
|
||||
r = Math.round(255 * (value - 0.5f) / 0.25f);
|
||||
b = 0;
|
||||
} else {
|
||||
g = Math.round(255 * ((0.25f - (value - 0.75f)) / 0.25f));
|
||||
r = 255;
|
||||
b = 0;
|
||||
}
|
||||
return new ColorRGBA((float) r / 255f, (float) g / 255f, (float) b / 255f, 1f);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user