Java tutorial
/* * This file is part of the lunar-fever package. * * Copyright (c) 2014 Eric Fritz * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software * and associated documentation files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package com.kauridev.lunarfever.particle; import com.kauridev.lunarfever.camera.Camera; import com.kauridev.lunarfever.graphics.TextureLoader; import com.kauridev.lunarfever.util.Vector; import org.lwjgl.opengl.GL11; /** * @author Eric Fritz */ public class ExplosionParticleEmitter extends ParticleEmitter { public ExplosionParticleEmitter(int maxParticles) { super(TextureLoader.loadTexture("assets/textures/explosion.png"), maxParticles); this.minNumParticles = 20; this.maxNumParticles = 25; this.minInitialSpeed = .04f; this.maxInitialSpeed = .50f; this.minAcceleration = 0.0f; this.maxAcceleration = 0.0f; this.minRotationSpeed = -(float) (Math.PI / 4) / 500; this.maxRotationSpeed = +(float) (Math.PI / 4) / 500; this.minLifetime = 500.0f; this.maxLifetime = 1000.0f; this.minScale = 0.3f; this.maxScale = 1.0f; } @Override protected void init(Particle p, float x, float y) { super.init(p, x, y); p.acceleration = new Vector((float) (p.velocity.x / p.lifetime), (float) (p.velocity.y / p.lifetime)) .muli(-1); } @Override public void render(double elapsed, Camera camera) { // // TODO - configure this somehow? GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); super.render(elapsed, camera); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); } }