mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 04:24:05 +09:00
Finally fixed CIELabUtil's anomaly; apparently past me was dumb fucking perkeleen vittupää
Former-commit-id: 731df40639ccf1463238f70dd615bd1771eee259 Former-commit-id: fdf00fbe30f876731d9d952b2a65f448b90c7913
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import net.torvald.colourutil.CIELabUtil.brighterLab
|
||||
import net.torvald.spriteanimation.SpriteAnimation
|
||||
import org.dyn4j.geometry.Vector2
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
@@ -8,16 +9,20 @@ import org.newdawn.slick.Graphics
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Simplest projectile.
|
||||
*
|
||||
* Created by minjaesong on 16-08-29.
|
||||
*/
|
||||
open class ProjectileSimple(
|
||||
type: Int,
|
||||
position: Vector2,
|
||||
velocity: Vector2,
|
||||
fromPoint: Vector2, // projected coord
|
||||
toPoint: Vector2, // arriving coord
|
||||
override var luminosity: Int = 0) : ActorWithBody(), Luminous {
|
||||
|
||||
val damage: Int
|
||||
val displayColour: Color
|
||||
/** scalar part of velocity */
|
||||
val speed: Int
|
||||
|
||||
/**
|
||||
* Arguments:
|
||||
@@ -28,19 +33,35 @@ open class ProjectileSimple(
|
||||
override val lightBoxList = ArrayList<Hitbox>()
|
||||
|
||||
init {
|
||||
hitbox.set(position.x, position.y, 2.0, 2.0) // 2.0: size of the hitbox in pixels
|
||||
lightBoxList.add(Hitbox(0.0, 0.0, 2.0, 2.0))
|
||||
hitbox.set(fromPoint.x, fromPoint.y, 2.0, 2.0) // 2.0: size of the hitbox in pixels
|
||||
// lightbox sized 8x8 centered to the bullet
|
||||
lightBoxList.add(Hitbox(-4.0, -4.0, 8.0, 8.0))
|
||||
this.velocity.set(velocity)
|
||||
|
||||
damage = bulletDatabase[type][0] as Int
|
||||
displayColour = bulletDatabase[type][1] as Color
|
||||
damage = bulletDatabase[type][OFFSET_DAMAGE] as Int
|
||||
displayColour = bulletDatabase[type][OFFSET_COL] as Color
|
||||
isNoSubjectToGrav = bulletDatabase[type][OFFSET_NOGRAVITY] as Boolean
|
||||
speed = bulletDatabase[type][OFFSET_SPEED] as Int
|
||||
|
||||
if (displayColour == Color(254, 0, 0, 0)) {
|
||||
sprite = bulletDatabase[type][OFFSET_SPRITE] as SpriteAnimation
|
||||
}
|
||||
|
||||
|
||||
|
||||
val initVelo = Vector2(speed.toDouble(), 0.0)
|
||||
initVelo.setDirection((fromPoint to toPoint).direction)
|
||||
|
||||
velocity.set(initVelo)
|
||||
|
||||
|
||||
|
||||
collisionType = KINEMATIC
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
// hit something and despawn
|
||||
if (ccdCollided) flagDespawn()
|
||||
if (ccdCollided || grounded) flagDespawn()
|
||||
|
||||
super.update(gc, delta)
|
||||
}
|
||||
@@ -59,11 +80,15 @@ open class ProjectileSimple(
|
||||
}
|
||||
|
||||
companion object {
|
||||
val TYPE_BULLET_BASIC = 0
|
||||
|
||||
val OFFSET_DAMAGE = 0
|
||||
val OFFSET_COL = 1 // set it to Color(254, 0, 0, 0) to use sprite
|
||||
val OFFSET_NOGRAVITY = 2
|
||||
val OFFSET_SPEED = 3
|
||||
val OFFSET_SPRITE = 4
|
||||
val bulletDatabase = arrayOf(
|
||||
arrayOf(7, Color(0xFF5429)),
|
||||
arrayOf(8, Color(0xFF5429))
|
||||
// damage, display colour, no gravity, speed
|
||||
arrayOf(7, Color(0xFF5429), true, 50),
|
||||
arrayOf(8, Color(0xFF5429), true, 50)
|
||||
// ...
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user