Skip to content

Commit

Permalink
我整个人都是懵逼的
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Oct 7, 2016
1 parent cab2b1e commit b641338
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 90 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/org/frice/android/Game.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

/**
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -128,66 +132,59 @@ class CurveResource(color: ColorResource, val f: (Double) -> List<Double>, 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
})
}
}
}

0 comments on commit b641338

Please sign in to comment.