diff --git a/app/src/main/java/org/frice/android/Game.kt b/app/src/main/java/org/frice/android/Game.kt index 3be94d0..c21062c 100644 --- a/app/src/main/java/org/frice/android/Game.kt +++ b/app/src/main/java/org/frice/android/Game.kt @@ -19,7 +19,7 @@ import org.frice.android.utils.graphics.shape.FOval import org.frice.android.utils.graphics.shape.FRectangle import org.frice.android.utils.message.error.FatalError import org.frice.android.utils.message.log.FLog -import org.frice.game.obj.effects.LineEffect +import org.frice.android.obj.effects.LineEffect import org.frice.game.obj.sub.ShapeObject import org.frice.game.resource.FResource import org.frice.game.utils.misc.forceRun diff --git a/app/src/main/java/org/frice/game/obj/effects/Effects.kt b/app/src/main/java/org/frice/android/obj/effects/Effects.kt similarity index 73% rename from app/src/main/java/org/frice/game/obj/effects/Effects.kt rename to app/src/main/java/org/frice/android/obj/effects/Effects.kt index 716b664..37d68c0 100644 --- a/app/src/main/java/org/frice/game/obj/effects/Effects.kt +++ b/app/src/main/java/org/frice/android/obj/effects/Effects.kt @@ -1,11 +1,14 @@ -package org.frice.game.obj.effects +package org.frice.android.obj.effects import android.graphics.Bitmap import org.frice.android.obj.AbstractObject +import org.frice.android.obj.CollideBox import org.frice.android.resource.graphics.ColorResource import org.frice.android.resource.graphics.CurveResource import org.frice.android.resource.graphics.FunctionResource +import org.frice.android.resource.graphics.ParticleResource import org.frice.android.resource.image.ImageResource +import org.frice.android.utils.graphics.shape.FRectangle import org.frice.game.obj.sub.ImageObject /** @@ -22,33 +25,33 @@ class LineEffect(var colorResource: ColorResource, override var x: Double, overr constructor(x: Double, y: Double, x2: Double, y2: Double) : this(ColorResource.BLACK, x, y, x2, y2) } -///** -// * Created by ice1000 on 2016/8/17. -// * @author ice1000 -// * @since 0.3.2 -// */ +/** + * Created by ice1000 on 2016/8/17. + * @author ice1000 + * @since 0.3.2 + */ // FIXME!!! -//class ParticleEffect(private var resource: ParticleResource, override var x: Double, override var y: Double) : -// ImageObject(resource.getResource(), x, y) { -// override val image: Bitmap -// get() = resource.getResource() -// -// override val collideBox = FRectangle(x.toInt(), y.toInt()) -// -// override val width: Double -// get() = resource.width.toDouble() -// override val height: Double -// get() = resource.height.toDouble() -// -// override fun getResource() = ImageResource.create(image) -// -// override fun scale(x: Double, y: Double) { -// resource.width = (resource.width * x / 1000.0).toInt() -// resource.height = (resource.height * y / 1000.0).toInt() -// } -// -// // override fun isCollide(other: CollideBox): Boolean = false -//} +class ParticleEffect(private var resource: ParticleResource, override var x: Double, override var y: Double) : + ImageObject(resource.getResource(), x, y) { + override val image: Bitmap + get() = resource.getResource() + + override val collideBox = FRectangle(x.toInt(), y.toInt()) + + override val width: Double + get() = resource.width.toDouble() + override val height: Double + get() = resource.height.toDouble() + + override fun getResource() = ImageResource.create(image) + + override fun scale(x: Double, y: Double) { + resource.width = (resource.width * x / 1000.0).toInt() + resource.height = (resource.height * y / 1000.0).toInt() + } + + override fun isCollide(other: CollideBox): Boolean = false +} /** * Tested, Work stably. diff --git a/app/src/main/java/org/frice/android/resource/graphics/GraphicsResource.kt b/app/src/main/java/org/frice/android/resource/graphics/GraphicsResource.kt index 0a18ee4..92455ed 100644 --- a/app/src/main/java/org/frice/android/resource/graphics/GraphicsResource.kt +++ b/app/src/main/java/org/frice/android/resource/graphics/GraphicsResource.kt @@ -2,8 +2,12 @@ package org.frice.android.resource.graphics import android.graphics.Bitmap import android.graphics.Color +import org.frice.android.Game +import org.frice.android.resource.image.ImageResource import org.frice.game.resource.FResource import org.frice.game.utils.misc.forceRun +import org.frice.game.utils.misc.loop +import java.util.* /** * Created by ice1000 on 2016/8/14. @@ -128,66 +132,59 @@ class CurveResource(color: ColorResource, val f: (Double) -> List, width override fun getResource() = image } -// -///** -// * Particle effects -// * Created by ice1000 on 2016/8/17. -// * -// * @author ice1000 -// * @since v0.3.2 -// */ + +/** + * Particle effects + * Created by ice1000 on 2016/8/17. + * + * @author ice1000 + * @since v0.3.2 + */ // FIXME!!! -//class ParticleResource(val game: Game, -// var width: Int, -// var height: Int, -// val back: FResource, -// var fore: ColorResource, -// var percentage: Double) : FResource { -// constructor(game: Game, x: Int, y: Int, back: ColorResource, fore: ColorResource) : -// this(game, x, y, back, fore, 0.5) -// -// constructor(game: Game, x: Int, y: Int, percentage: Double) : -// this(game, x, y, ColorResource.WHITE, ColorResource.BLACK, percentage) -// -// constructor(game: Game, x: Int, y: Int) : this(game, x, y, 0.5) -// -// /** -// * particle effects as an bitmap -// */ -// private val image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) -// private val random = Random(Random().nextLong()) -// -// private fun drawBackground() { -// val g = image.graphics -// when (back) { -// is ColorResource -> { -// g.fillRect(0, 0, width, height) -// g.color = back.color -// } -// is ImageResource -> g.drawImage(back.bitmap, 0, 0, width, height, game) -// } -// } -// -// init { -// drawBackground() -// loop((image.width * image.height * percentage).toInt()) { -// image.setPixel(random.nextInt(width), random.nextInt(height), fore.color) -// } -// } -// -// override fun getResource() = image.apply { -// // FLog.debug("Ah!? Ah!") -// var cache1: Int -// var cache2: Int -// loop((image.width * image.height * percentage).toInt()) { -// cache1 = random.nextInt(width) -// cache2 = random.nextInt(height) -// image.setPixel(random.nextInt(width), random.nextInt(height), fore.color) -// image.setPixel(cache1, cache2, when (back) { -// is ColorResource -> back.color.rgb -// is ImageResource -> back.bitmap.getRGB(cache1, cache2) -// else -> ColorResource.COLORLESS.color -// }) -// } -// } -//} +class ParticleResource(val game: Game, + var width: Int, + var height: Int, + val back: FResource, + var fore: ColorResource, + var percentage: Double) : FResource { + constructor(game: Game, x: Int, y: Int, back: ColorResource, fore: ColorResource) : + this(game, x, y, back, fore, 0.5) + + constructor(game: Game, x: Int, y: Int, percentage: Double) : + this(game, x, y, ColorResource.WHITE, ColorResource.BLACK, percentage) + + constructor(game: Game, x: Int, y: Int) : this(game, x, y, 0.5) + + /** + * particle effects as an bitmap + */ + private val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) + private val random = Random(Random().nextLong()) + + private fun drawBackground() { + // unknown how 2 deal with + // FIXME + } + + init { + drawBackground() + loop((bitmap.width * bitmap.height * percentage).toInt()) { + bitmap.setPixel(random.nextInt(width), random.nextInt(height), fore.color) + } + } + + override fun getResource() = bitmap.apply { + var cache1: Int + var cache2: Int + loop((bitmap.width * bitmap.height * percentage).toInt()) { + cache1 = random.nextInt(width) + cache2 = random.nextInt(height) + bitmap.setPixel(random.nextInt(width), random.nextInt(height), fore.color) + bitmap.setPixel(cache1, cache2, when (back) { + is ColorResource -> back.color + is ImageResource -> back.bitmap.getPixel(cache1, cache2) + else -> ColorResource.COLORLESS.color + }) + } + } +}