From b21bd50e7ba77e161d7e314ef441227a02d52708 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 2 Jan 2023 00:27:00 +0700 Subject: [PATCH] =?UTF-8?q?=D1=85=D0=BC=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt | 9 +++++++-- .../dbotthepony/kstarbound/world/entities/ItemEntity.kt | 2 +- .../kstarbound/world/entities/MovementController.kt | 6 ++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt index ff7f0ecc..52136e2e 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt @@ -13,6 +13,7 @@ import java.io.ByteArrayInputStream import java.io.DataInputStream import java.io.File import java.util.zip.Inflater +import kotlin.random.Random private val LOGGER = LogManager.getLogger() @@ -162,11 +163,15 @@ fun main() { //client.world!!.parallax = Starbound.parallaxAccess["garden"] - for (i in 0 .. 16) { - val item = ItemEntity(client.world!!, Starbound.ITEM["money"]!!) + val item = Starbound.ITEM.values.random() + 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.spawn() + item.movement.applyVelocity(Vector2d(rand.nextDouble() * 1000.0 - 500.0, rand.nextDouble() * 1000.0 - 500.0)) } } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/ItemEntity.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/ItemEntity.kt index 021d4e15..2699e51a 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/ItemEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/ItemEntity.kt @@ -33,7 +33,7 @@ class ItemEntity(world: World<*, *>, val def: IItemDefinition) : Entity(world) { // все предметы в мире являются коробками val fixture = FixtureDef( - shape = PolygonShape().also { it.setAsBox(1.0, 1.0) }, + shape = PolygonShape().also { it.setAsBox(0.75, 0.75) }, restitution = 0.0, friction = 1.0, density = 0.3, diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/MovementController.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/MovementController.kt index 3a877417..46af42d7 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/MovementController.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/MovementController.kt @@ -63,6 +63,12 @@ abstract class MovementController(val entity: T) : IContactListener open val velocity get() = body.linearVelocity + open fun applyVelocity(velocity: Vector2d) { + if (velocity != Vector2d.ZERO) { + body.applyLinearImpulseToCenter(velocity) + } + } + /** * Проверяет, находится ли что-либо под нами */