/** * @param x1 #start * @param y1 #start * @param x2 #end * @param y2 #end * @param numParticles #density */ public void MakeFrontFire(int x1, int y1, int x2, int y2, int numParticles) { final Timeline fronttimeline = new Timeline(); y2 = (int) (y2 - ((y2 - y1) * .8)); for (int i = 0; i < numParticles; i++) { int size = CoreMath.rand(15, 20); int duration = (100 - size) * 10; int moveDistance = CoreMath.rand(1, 4 * size); double moveDirection = 180; // CoreMath.rand(0,5); int startX = x1 + i * (x2 - x1) / numParticles; int startY = y1 + i * (y2 - y1) / numParticles; int goalX = startX + (int) (moveDistance * Math.cos(moveDirection)); int goalY = startY + (int) (moveDistance * Math.sin(moveDirection)); CoreImage image = flame[CoreMath.rand(flame.length - 1)]; Sprite sprite = new ImageSprite(image, startX, startY); sprite.setAnchor(.5, .5); sprite.setSize(size * 6, size * 2); sprite.alpha.set(50); scene.add(sprite); fronttimeline.animate( sprite.height, sprite.height.get(), sprite.width.get(), duration, Easing.REGULAR_OUT); fronttimeline.animateTo(sprite.x, goalX, duration, Easing.REGULAR_OUT); fronttimeline.animateTo(sprite.y, goalY, duration, Easing.REGULAR_OUT); fronttimeline.at(100).animateTo(sprite.alpha, 0, duration - 100, Easing.REGULAR_OUT); fronttimeline.add(new RemoveSpriteEvent(scene.getMainLayer(), sprite, duration)); } scene.addTimeline(fronttimeline); }
public Centipede(Player p, Level l, int x, int y) { super(p, l, "enemy_centipede.png", x, y); speed = CoreMath.rand(0.8, 1.4) + (p.getLevelNumber() / 7); health = p.getLevelNumber() + CoreMath.rand(2.0, 5.0); points = (int) health; int size = CoreMath.rand(20, 30); setSize(size, size); }
public void load() { setCursor(Input.CURSOR_OFF); cursor = new ImageSprite("glow.png", 0, 0); cursor.setAnchor(0.5, 0.5); cursor.visible.set(false); // Create the mask maskLayer = new Group(); maskLayer.add(new FilledSprite(gray(18))); maskLayer.add(cursor); maskLayer.setBlendMode(BlendMode.Multiply()); maskLayer.createBackBuffer(); // Create the background image Timeline t = new Timeline(); Group imageLayer = new Group(); imageLayer.add(new FilledSprite(rgb(0xba9b65))); int size = 80; int spacing = 16; for (int i = -spacing / 2; i < Stage.getWidth(); i += spacing + size) { for (int j = -spacing / 2; j < Stage.getHeight(); j += spacing + size) { int color1 = colors[CoreMath.rand(colors.length - 1)]; int color2 = colors[CoreMath.rand(colors.length - 1)]; FilledSprite sprite = new FilledSprite(i, j, size, size, color1); imageLayer.add(sprite); int delay1 = CoreMath.rand(20000); int delay2 = delay1 + CoreMath.rand(20000); t.set(sprite.fillColor, color2, delay1); t.set(sprite.fillColor, color1, delay2); } } t.loopForever(); addTimeline(t); // Add the layers to the scene addLayer(imageLayer); addLayer(maskLayer); }
/** * @param x1 #start * @param y1 #start * @param x2 #end * @param y2 #end */ public void MakeFire(int x1, int y1, int x2, int y2) { final Timeline backtimeline = new Timeline(); for (int i = 0; i < 1; i++) { int size = CoreMath.rand(25, 50); int duration = (100 - size) * 10; if (duration < 0) { duration = 10; } int moveDistance = CoreMath.rand(70, 150 - size); double moveDirection = 180; // CoreMath.rand(0); int startX = x1 + i * (x2 - x1); int startY = y1 + i * (y2 - y1); int goalX = startX + (int) (moveDistance * Math.cos(moveDirection)); int goalY = startY + (int) (moveDistance * Math.sin(moveDirection)); CoreImage image = flame[CoreMath.rand(flame.length - 1)]; Sprite sprite = new ImageSprite(image, startX, startY); sprite.setAnchor(.5, .5); sprite.setSize(size, size); scene.add(sprite); scene.getMainLayer().moveToBottom(sprite); scene.getMainLayer().moveUp(sprite); backtimeline.animateTo(sprite.x, goalX, duration, Easing.REGULAR_OUT); backtimeline.animateTo(sprite.y, goalY, duration, Easing.REGULAR_OUT); backtimeline.at(100).animateTo(sprite.alpha, 0, duration - 100, Easing.REGULAR_OUT); backtimeline.add(new RemoveSpriteEvent(scene.getMainLayer(), sprite, duration)); } scene.addTimeline(backtimeline); MakeFrontFire(x1, y1, x2, y2, 1); }
void blend( int[] srcData, int srcScanSize, boolean srcOpaque, int edgeClamp, int srcX, int srcY, int srcWidth, int srcHeight, int u, int v, int du, int dv, boolean rotation, boolean renderBilinear, int renderAlpha, int[] destData, int destScanSize, int destOffset, int numPixels, int numRows) { if (renderAlpha <= 0) { return; } // // Pre-calc for bilinear scaling // int srcOffset = 0; int offsetTop = 0; int offsetBottom = 0; if (!rotation) { if (renderBilinear) { int imageY = v >> 16; if (srcOpaque) { if (imageY >= srcHeight - 1) { offsetTop = srcX + (srcY + srcHeight - 1) * srcScanSize; offsetBottom = offsetTop; } else if (imageY < 0) { offsetTop = srcX + srcY * srcScanSize; offsetBottom = offsetTop; } else if ((v & 0xffff) == 0) { offsetTop = srcX + (srcY + (v >> 16)) * srcScanSize; offsetBottom = offsetTop; } else { offsetTop = srcX + (srcY + (v >> 16)) * srcScanSize; offsetBottom = offsetTop + srcScanSize; } } else { if (imageY >= 0) { if (imageY < srcHeight - 1) { offsetTop = srcX + (srcY + (v >> 16)) * srcScanSize; offsetBottom = offsetTop + srcScanSize; } else if ((edgeClamp & CoreGraphics.EDGE_CLAMP_BOTTOM) != 0) { offsetTop = srcX + (srcY + srcHeight - 1) * srcScanSize; offsetBottom = offsetTop; } else if (v < (srcHeight << 16)) { offsetTop = srcX + (srcY + (v >> 16)) * srcScanSize; offsetBottom = -1; } else { offsetTop = -1; offsetBottom = -1; } } else if ((edgeClamp & CoreGraphics.EDGE_CLAMP_TOP) != 0) { offsetBottom = srcX + srcY * srcScanSize; offsetTop = offsetBottom; } else if (v > -(1 << 16)) { offsetBottom = srcX + srcY * srcScanSize; offsetTop = -1; } else { offsetTop = -1; offsetBottom = -1; } } } else { srcOffset = srcX; if ((u >> 16) >= srcWidth - 1) { srcOffset += srcWidth - 1; } else if (u > 0) { srcOffset += (u >> 16); } if ((v >> 16) >= srcHeight - 1) { srcOffset += (srcY + srcHeight - 1) * srcScanSize; } else if (v >= 0) { srcOffset += (srcY + (v >> 16)) * srcScanSize; } } } // // Opaque blending // if (renderAlpha == 255) { if (rotation) { // TODO: handle opaque images seperately? if (renderBilinear) { for (int i = 0; i < numPixels; i++) { int srcARGB = getPixelBilinearTranslucent( srcData, srcScanSize, srcX, srcY, srcWidth, srcHeight, edgeClamp, u, v); int srcAlpha = srcARGB >>> 24; if (srcAlpha == 0xff) { blendOpaquePixel(destData, destOffset, srcARGB); } else if (BLEND_TRANSPARENT_PIXELS || srcAlpha != 0) { blendPixel(destData, destOffset, srcARGB); } destOffset++; u += du; v += dv; } } else { srcOffset = srcX + srcY * srcScanSize; for (int i = 0; i < numPixels; i++) { int x = CoreMath.clamp(u >> 16, 0, srcWidth - 1); int y = CoreMath.clamp(v >> 16, 0, srcHeight - 1); int srcARGB = srcData[srcOffset + x + y * srcScanSize]; int srcAlpha = srcARGB >>> 24; if (srcAlpha == 0xff) { blendOpaquePixel(destData, destOffset, srcARGB); } else if (BLEND_TRANSPARENT_PIXELS || srcAlpha != 0) { blendPixel(destData, destOffset, srcARGB); } destOffset++; u += du; v += dv; } } } else if (renderBilinear) { if (srcOpaque) { for (int i = 0; i < numPixels; i++) { int srcARGB = getPixelBilinearOpaque(srcData, offsetTop, offsetBottom, u, v, srcWidth); blendOpaquePixel(destData, destOffset, srcARGB); destOffset++; u += du; } } else { for (int i = 0; i < numPixels; i++) { int srcARGB = getPixelBilinearTranslucent( srcData, edgeClamp, offsetTop, offsetBottom, u, v, srcWidth); int srcAlpha = srcARGB >>> 24; if (srcAlpha == 0xff) { blendOpaquePixel(destData, destOffset, srcARGB); } else if (BLEND_TRANSPARENT_PIXELS || srcAlpha != 0) { blendPixel(destData, destOffset, srcARGB); } destOffset++; u += du; } } } else { for (int y = 0; y < numRows; y++) { if (du != (1 << 16)) { int offset = u & 0xffff; if (srcOpaque) { for (int i = 0; i < numPixels; i++) { int srcARGB = srcData[srcOffset + (offset >> 16)]; blendOpaquePixel(destData, destOffset + i, srcARGB); offset += du; } } else { for (int i = 0; i < numPixels; i++) { int srcARGB = srcData[srcOffset + (offset >> 16)]; int srcAlpha = srcARGB >>> 24; if (srcAlpha == 0xff) { blendOpaquePixel(destData, destOffset + i, srcARGB); } else if (BLEND_TRANSPARENT_PIXELS || srcAlpha != 0) { blendPixel(destData, destOffset + i, srcARGB); } offset += du; } } } else { if (srcOpaque) { for (int i = 0; i < numPixels; i++) { int srcARGB = srcData[srcOffset + i]; blendOpaquePixel(destData, destOffset + i, srcARGB); } } else { for (int i = 0; i < numPixels; i++) { int srcARGB = srcData[srcOffset + i]; int srcAlpha = srcARGB >>> 24; if (srcAlpha == 0xff) { blendOpaquePixel(destData, destOffset + i, srcARGB); } else if (BLEND_TRANSPARENT_PIXELS || srcAlpha != 0) { blendPixel(destData, destOffset + i, srcARGB); } } } } destOffset += destScanSize; srcOffset += srcScanSize; } } } // // Translucent blending // else { if (rotation) { // TODO: handle opaque images seperately? if (renderBilinear) { for (int i = 0; i < numPixels; i++) { int srcARGB = getPixelBilinearTranslucent( srcData, srcScanSize, srcX, srcY, srcWidth, srcHeight, edgeClamp, u, v); if (BLEND_TRANSPARENT_PIXELS || srcARGB != 0) { blendPixel(destData, destOffset, srcARGB, renderAlpha); } destOffset++; u += du; v += dv; } } else { srcOffset = srcX + srcY * srcScanSize; for (int i = 0; i < numPixels; i++) { int x = CoreMath.clamp(u >> 16, 0, srcWidth - 1); int y = CoreMath.clamp(v >> 16, 0, srcHeight - 1); int srcARGB = srcData[srcOffset + x + y * srcScanSize]; if (BLEND_TRANSPARENT_PIXELS || srcARGB != 0) { blendPixel(destData, destOffset, srcARGB, renderAlpha); } destOffset++; u += du; v += dv; } } } else if (renderBilinear) { if (srcOpaque) { for (int i = 0; i < numPixels; i++) { int srcARGB = getPixelBilinearOpaque(srcData, offsetTop, offsetBottom, u, v, srcWidth); blendOpaquePixel(destData, destOffset, srcARGB, renderAlpha); destOffset++; u += du; } } else { for (int i = 0; i < numPixels; i++) { int srcARGB = getPixelBilinearTranslucent( srcData, edgeClamp, offsetTop, offsetBottom, u, v, srcWidth); if (BLEND_TRANSPARENT_PIXELS || srcARGB != 0) { blendPixel(destData, destOffset, srcARGB, renderAlpha); } destOffset++; u += du; } } } else { for (int y = 0; y < numRows; y++) { if (du != (1 << 16)) { int offset = u & 0xffff; if (srcOpaque) { for (int i = 0; i < numPixels; i++) { int srcARGB = srcData[srcOffset + (offset >> 16)]; blendOpaquePixel(destData, destOffset + i, srcARGB, renderAlpha); offset += du; } } else { for (int i = 0; i < numPixels; i++) { int srcARGB = srcData[srcOffset + (offset >> 16)]; if (BLEND_TRANSPARENT_PIXELS || srcARGB != 0) { blendPixel(destData, destOffset + i, srcARGB, renderAlpha); } offset += du; } } } else { if (srcOpaque) { for (int i = 0; i < numPixels; i++) { int srcARGB = srcData[srcOffset + i]; blendOpaquePixel(destData, destOffset + i, srcARGB, renderAlpha); } } else { for (int i = 0; i < numPixels; i++) { int srcARGB = srcData[srcOffset + i]; if (BLEND_TRANSPARENT_PIXELS || srcARGB != 0) { blendPixel(destData, destOffset + i, srcARGB, renderAlpha); } } } } destOffset += destScanSize; srcOffset += srcScanSize; } } } }