Adds ParticleSystem to main menu & hud editor
This commit is contained in:
parent
67d05f8e67
commit
2ad02d3716
|
@ -0,0 +1,115 @@
|
|||
package me.rigamortis.seppuku.api.gui.hud.particle;
|
||||
|
||||
import me.rigamortis.seppuku.api.util.ColorUtil;
|
||||
import me.rigamortis.seppuku.api.util.RenderUtil;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import javax.vecmath.Vector2f;
|
||||
import java.awt.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class Particle {
|
||||
|
||||
private Vector2f pos;
|
||||
private Vector2f velocity;
|
||||
private Vector2f acceleration;
|
||||
|
||||
private int alpha;
|
||||
private int maxAlpha;
|
||||
|
||||
private float size;
|
||||
|
||||
public Particle(Vector2f pos) {
|
||||
this.pos = pos;
|
||||
int lowVel = -1;
|
||||
int highVel = 1;
|
||||
float resultXVel = lowVel + ThreadLocalRandom.current().nextFloat() * (highVel - lowVel);
|
||||
float resultYVel = lowVel + ThreadLocalRandom.current().nextFloat() * (highVel - lowVel);
|
||||
this.velocity = new Vector2f(resultXVel, resultYVel);
|
||||
this.acceleration = new Vector2f(0, 0.35f);
|
||||
this.alpha = 0;
|
||||
this.maxAlpha = ThreadLocalRandom.current().nextInt(32, 192);
|
||||
this.size = 0.5f + ThreadLocalRandom.current().nextFloat() * (2.0f - 0.5f);
|
||||
}
|
||||
|
||||
public void respawn(ScaledResolution scaledResolution) {
|
||||
this.pos = new Vector2f((float) (Math.random() * scaledResolution.getScaledWidth()), (float) (Math.random() * scaledResolution.getScaledHeight()));
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (this.alpha < this.maxAlpha) {
|
||||
this.alpha += 8;
|
||||
}
|
||||
|
||||
if (this.acceleration.getX() > 0.35f) {
|
||||
this.acceleration.setX(this.acceleration.getX() * 0.975f);
|
||||
} else if (this.acceleration.getX() < -0.35f) {
|
||||
this.acceleration.setX(this.acceleration.getX() * 0.975f);
|
||||
}
|
||||
|
||||
if (this.acceleration.getY() > 0.35f) {
|
||||
this.acceleration.setY(this.acceleration.getY() * 0.975f);
|
||||
} else if (this.acceleration.getY() < -0.35f) {
|
||||
this.acceleration.setY(this.acceleration.getY() * 0.975f);
|
||||
}
|
||||
|
||||
this.pos.add(acceleration);
|
||||
this.pos.add(velocity);
|
||||
|
||||
//this.lifeAlpha -= 1;
|
||||
}
|
||||
|
||||
public void render(int mouseX, int mouseY) {
|
||||
if (Mouse.isButtonDown(0)) {
|
||||
float deltaXToMouse = mouseX - this.pos.getX();
|
||||
float deltaYToMouse = mouseY - this.pos.getY();
|
||||
if (Math.abs(deltaXToMouse) < 50 && Math.abs(deltaYToMouse) < 50) {
|
||||
this.acceleration.setX(this.acceleration.getX() + (deltaXToMouse * 0.0025f));
|
||||
this.acceleration.setY(this.acceleration.getY() + (deltaYToMouse * 0.0025f));
|
||||
}
|
||||
}
|
||||
|
||||
RenderUtil.drawRect(this.pos.x, this.pos.y, this.pos.x + this.size, this.pos.y + this.size, ColorUtil.changeAlpha(0xFF9900EE, this.alpha));
|
||||
}
|
||||
|
||||
public Vector2f getPos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public void setPos(Vector2f pos) {
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
public Vector2f getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
public void setVelocity(Vector2f velocity) {
|
||||
this.velocity = velocity;
|
||||
}
|
||||
|
||||
public Vector2f getAcceleration() {
|
||||
return acceleration;
|
||||
}
|
||||
|
||||
public void setAcceleration(Vector2f acceleration) {
|
||||
this.acceleration = acceleration;
|
||||
}
|
||||
|
||||
public int getAlpha() {
|
||||
return alpha;
|
||||
}
|
||||
|
||||
public void setAlpha(int alpha) {
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
public float getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(float size) {
|
||||
this.size = size;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package me.rigamortis.seppuku.api.gui.hud.particle;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
|
||||
import javax.vecmath.Vector2f;
|
||||
import java.util.List;
|
||||
|
||||
public final class ParticleSystem {
|
||||
|
||||
private final int PARTS = 100;
|
||||
private final List<Particle> particles = Lists.newArrayListWithCapacity(PARTS);
|
||||
|
||||
private final ScaledResolution scaledResolution;
|
||||
|
||||
public ParticleSystem(ScaledResolution scaledResolution) {
|
||||
this.scaledResolution = scaledResolution;
|
||||
for (int i = 0; i < PARTS; i++) {
|
||||
this.particles.add(new Particle(new Vector2f((float) (Math.random() * scaledResolution.getScaledWidth()), (float) (Math.random() * scaledResolution.getScaledHeight()))));
|
||||
}
|
||||
}
|
||||
|
||||
public void update() {
|
||||
for (Particle particle : this.particles) {
|
||||
if (this.scaledResolution != null) {
|
||||
final boolean isOffScreenX = particle.getPos().x > this.scaledResolution.getScaledWidth() || particle.getPos().x < 0;
|
||||
final boolean isOffScreenY = particle.getPos().y > this.scaledResolution.getScaledHeight() || particle.getPos().y < 0;
|
||||
if (isOffScreenX || isOffScreenY) {
|
||||
particle.respawn(this.scaledResolution);
|
||||
}
|
||||
}
|
||||
particle.update();
|
||||
}
|
||||
}
|
||||
|
||||
public void render(int mouseX, int mouseY) {
|
||||
for (Particle particle : this.particles) {
|
||||
particle.render(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package me.rigamortis.seppuku.impl.gui.hud;
|
|||
import me.rigamortis.seppuku.Seppuku;
|
||||
import me.rigamortis.seppuku.api.gui.hud.component.DraggableHudComponent;
|
||||
import me.rigamortis.seppuku.api.gui.hud.component.HudComponent;
|
||||
import me.rigamortis.seppuku.api.gui.hud.particle.ParticleSystem;
|
||||
import me.rigamortis.seppuku.api.util.RenderUtil;
|
||||
import me.rigamortis.seppuku.impl.gui.hud.anchor.AnchorPoint;
|
||||
import me.rigamortis.seppuku.impl.module.ui.HudEditorModule;
|
||||
|
@ -20,6 +21,15 @@ import java.io.IOException;
|
|||
*/
|
||||
public final class GuiHudEditor extends GuiScreen {
|
||||
|
||||
private ParticleSystem particleSystem;
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
this.particleSystem = new ParticleSystem(new ScaledResolution(mc));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
|
@ -47,6 +57,8 @@ public final class GuiHudEditor extends GuiScreen {
|
|||
public void onResize(Minecraft mcIn, int w, int h) {
|
||||
super.onResize(mcIn, w, h);
|
||||
|
||||
this.particleSystem = new ParticleSystem(new ScaledResolution(mcIn));
|
||||
|
||||
final ScaledResolution sr = new ScaledResolution(mcIn);
|
||||
for (AnchorPoint anchorPoint : Seppuku.INSTANCE.getHudManager().getAnchorPoints()) {
|
||||
anchorPoint.updatePosition(sr);
|
||||
|
@ -60,6 +72,9 @@ public final class GuiHudEditor extends GuiScreen {
|
|||
|
||||
final ScaledResolution res = new ScaledResolution(Minecraft.getMinecraft());
|
||||
|
||||
if (this.particleSystem != null)
|
||||
this.particleSystem.render(mouseX, mouseY);
|
||||
|
||||
final float halfWidth = res.getScaledWidth() / 2.0f;
|
||||
final float halfHeight = res.getScaledHeight() / 2.0f;
|
||||
RenderUtil.drawLine(halfWidth, 0, halfWidth, res.getScaledHeight(), 1, 0x75909090);
|
||||
|
@ -189,6 +204,14 @@ public final class GuiHudEditor extends GuiScreen {
|
|||
super.onGuiClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
|
||||
if (this.particleSystem != null)
|
||||
this.particleSystem.update();
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
// empty
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package me.rigamortis.seppuku.impl.gui.menu;
|
|||
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||
import me.rigamortis.seppuku.Seppuku;
|
||||
import me.rigamortis.seppuku.api.event.minecraft.EventDisplayGui;
|
||||
import me.rigamortis.seppuku.api.gui.hud.particle.ParticleSystem;
|
||||
import me.rigamortis.seppuku.api.gui.menu.MainMenuButton;
|
||||
import me.rigamortis.seppuku.api.texture.Texture;
|
||||
import me.rigamortis.seppuku.impl.fml.SeppukuMod;
|
||||
|
@ -37,6 +38,8 @@ public final class GuiSeppukuMainMenu extends GuiScreen {
|
|||
|
||||
private Texture seppukuLogo;
|
||||
|
||||
private ParticleSystem particleSystem;
|
||||
|
||||
private boolean inactive = false;
|
||||
|
||||
public GuiSeppukuMainMenu() {
|
||||
|
@ -47,13 +50,15 @@ public final class GuiSeppukuMainMenu extends GuiScreen {
|
|||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
final GuiSeppukuMainMenu menu = this;
|
||||
final Minecraft mc = Minecraft.getMinecraft();
|
||||
final ScaledResolution res = new ScaledResolution(mc);
|
||||
|
||||
if (this.seppukuLogo == null)
|
||||
this.seppukuLogo = new Texture("seppuku-logo.png");
|
||||
|
||||
final GuiSeppukuMainMenu menu = this;
|
||||
|
||||
final Minecraft mc = Minecraft.getMinecraft();
|
||||
final ScaledResolution res = new ScaledResolution(mc);
|
||||
if (this.particleSystem == null)
|
||||
this.particleSystem = new ParticleSystem(res);
|
||||
|
||||
// resize the seppuku hud editor with the size of the main menu
|
||||
Seppuku.INSTANCE.getHudEditor().onResize(mc, res.getScaledWidth(), res.getScaledHeight());
|
||||
|
@ -178,6 +183,14 @@ public final class GuiSeppukuMainMenu extends GuiScreen {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
|
||||
if (this.particleSystem != null)
|
||||
this.particleSystem.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
|
@ -189,6 +202,10 @@ public final class GuiSeppukuMainMenu extends GuiScreen {
|
|||
GlStateManager.enableAlpha();
|
||||
GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1, 0);
|
||||
|
||||
// draw particle system
|
||||
if (this.particleSystem != null)
|
||||
this.particleSystem.render(mouseX, mouseY);
|
||||
|
||||
// draw logo
|
||||
this.seppukuLogo.bind();
|
||||
this.seppukuLogo.render((res.getScaledWidth() / 2.0f) - 120, (res.getScaledHeight() / 8.0f), 240, 38);
|
||||
|
@ -260,6 +277,8 @@ public final class GuiSeppukuMainMenu extends GuiScreen {
|
|||
public void onResize(Minecraft mcIn, int w, int h) {
|
||||
super.onResize(mcIn, w, h);
|
||||
|
||||
this.particleSystem = new ParticleSystem(new ScaledResolution(mcIn));
|
||||
|
||||
// resize the seppuku hud editor with the size of the main menu
|
||||
Seppuku.INSTANCE.getHudEditor().onResize(mcIn, w, h);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue