This commit is contained in:
DBotThePony 2023-01-02 00:27:00 +07:00
parent 7eaccacc68
commit b21bd50e7b
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 14 additions and 3 deletions

View File

@ -13,6 +13,7 @@ import java.io.ByteArrayInputStream
import java.io.DataInputStream import java.io.DataInputStream
import java.io.File import java.io.File
import java.util.zip.Inflater import java.util.zip.Inflater
import kotlin.random.Random
private val LOGGER = LogManager.getLogger() private val LOGGER = LogManager.getLogger()
@ -162,11 +163,15 @@ fun main() {
//client.world!!.parallax = Starbound.parallaxAccess["garden"] //client.world!!.parallax = Starbound.parallaxAccess["garden"]
for (i in 0 .. 16) { val item = Starbound.ITEM.values.random()
val item = ItemEntity(client.world!!, Starbound.ITEM["money"]!!) val rand = java.util.Random()
for (i in 0 .. 240) {
val item = ItemEntity(client.world!!, item)
item.position = Vector2d(600.0 + 16.0 + i, 721.0 + 48.0) item.position = Vector2d(600.0 + 16.0 + i, 721.0 + 48.0)
item.spawn() item.spawn()
item.movement.applyVelocity(Vector2d(rand.nextDouble() * 1000.0 - 500.0, rand.nextDouble() * 1000.0 - 500.0))
} }
} }

View File

@ -33,7 +33,7 @@ class ItemEntity(world: World<*, *>, val def: IItemDefinition) : Entity(world) {
// все предметы в мире являются коробками // все предметы в мире являются коробками
val fixture = FixtureDef( val fixture = FixtureDef(
shape = PolygonShape().also { it.setAsBox(1.0, 1.0) }, shape = PolygonShape().also { it.setAsBox(0.75, 0.75) },
restitution = 0.0, restitution = 0.0,
friction = 1.0, friction = 1.0,
density = 0.3, density = 0.3,

View File

@ -63,6 +63,12 @@ abstract class MovementController<T : IEntity>(val entity: T) : IContactListener
open val velocity get() = body.linearVelocity open val velocity get() = body.linearVelocity
open fun applyVelocity(velocity: Vector2d) {
if (velocity != Vector2d.ZERO) {
body.applyLinearImpulseToCenter(velocity)
}
}
/** /**
* Проверяет, находится ли что-либо под нами * Проверяет, находится ли что-либо под нами
*/ */