From 354bb52ea96dea578feb73e6251e52be6c6053ab Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Wed, 9 Jun 2021 13:34:27 +0530 Subject: [PATCH] Add timer, fix CCD --- src/Main.hx | 11 +++----- src/Marble.hx | 60 +++++++++++++++++++++++++++++++++++++++++-- src/ParticleSystem.hx | 2 +- src/gui/PlayGui.hx | 55 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 10 deletions(-) create mode 100644 src/gui/PlayGui.hx diff --git a/src/Main.hx b/src/Main.hx index 43abad4f..0738218c 100644 --- a/src/Main.hx +++ b/src/Main.hx @@ -1,12 +1,6 @@ package; -import h3d.mat.Data.Blend; -import src.ParticleSystem.ParticleEmitterOptions; -import src.ParticleSystem.ParticleEmitter; -import src.ParticleSystem.Particle; -import src.ParticleSystem.ParticleManager; -import src.ParticleSystem.ParticleData; -import src.ParticleSystem.ParticleData; +import gui.PlayGui; import shapes.Helicopter; import shapes.ShockAbsorber; import shapes.SuperBounce; @@ -123,7 +117,10 @@ class Main extends hxd.App { ag.y = 6; world.addDtsObject(ag); + var pg = new PlayGui(); + pg.init(s2d); // var le:ParticleEmitterOptions = { + // ejectionPeriod: 0.01, // ambientVelocity: new Vector(0, 0, 0), // ejectionVelocity: 0.5, diff --git a/src/Marble.hx b/src/Marble.hx index e0933644..570b0b26 100644 --- a/src/Marble.hx +++ b/src/Marble.hx @@ -1,5 +1,6 @@ package src; +import src.ParticleSystem.ParticleEmitter; import src.ParticleSystem.ParticleData; import src.ParticleSystem.ParticleEmitterOptions; import src.DtsObject; @@ -61,6 +62,29 @@ final bounceParticleOptions:ParticleEmitterOptions = { } }; +final trailParticleOptions:ParticleEmitterOptions = { + ejectionPeriod: 5, + ejectionVelocity: 0.0, + velocityVariance: 0.25, + emitterLifetime: 1e8, + inheritedVelFactor: 1, + ambientVelocity: new Vector(), + particleOptions: { + texture: 'particles/smoke.png', + blending: Alpha, + spinSpeed: 0, + spinRandomMin: 0, + spinRandomMax: 0, + dragCoefficient: 1, + lifetime: 100, + lifetimeVariance: 10, + acceleration: 0, + colors: [new Vector(1, 1, 0, 0), new Vector(1, 1, 0, 1), new Vector(1, 1, 1, 0)], + sizes: [0.7, 0.4, 0.1], + times: [0, 0.15, 1] + } +}; + class Marble extends GameObject { public var camera:CameraController; public var cameraObject:Object; @@ -84,7 +108,8 @@ class Marble extends GameObject { var _gravity = 20; var _airAccel:Float = 5; var _maxDotSlide = 0.5; - var _minBounceVel = 0.1; + var _minBounceVel = 3; + var _minTrailVel = 10; var _bounceKineticFriction = 0.2; public var _bounceRestitution = 0.5; @@ -111,7 +136,11 @@ class Marble extends GameObject { var shockAbsorberEnableTime:Float = -1e8; var helicopterEnableTime:Float = -1e8; + var bounceEmitDelay:Float = 0; + var bounceEmitterData:ParticleData; + var trailEmitterData:ParticleData; + var trailEmitterNode:ParticleEmitter; public function new() { super(); @@ -131,6 +160,10 @@ class Marble extends GameObject { this.bounceEmitterData = new ParticleData(); this.bounceEmitterData.identifier = "MarbleBounceParticle"; this.bounceEmitterData.texture = ResourceLoader.getTexture("data/particles/star.png"); + + this.trailEmitterData = new ParticleData(); + this.trailEmitterData.identifier = "MarbleTrailParticle"; + this.trailEmitterData.texture = ResourceLoader.getTexture("data/particles/smoke.png"); } public function init(level:MarbleWorld) { @@ -506,7 +539,24 @@ class Marble extends GameObject { } function bounceEmitter(speed:Float, normal:Vector) { - this.level.particleManager.createEmitter(bounceParticleOptions, this.bounceEmitterData, this.getAbsPos().getPosition()); + if (this.bounceEmitDelay == 0 && this._minBounceVel <= speed) { + this.level.particleManager.createEmitter(bounceParticleOptions, this.bounceEmitterData, this.getAbsPos().getPosition()); + this.bounceEmitDelay = 0.3; + } + } + + function trailEmitter() { + var speed = this.velocity.length(); + if (this._minTrailVel > speed) { + if (this.trailEmitterNode != null) { + this.level.particleManager.removeEmitter(this.trailEmitterNode); + this.trailEmitterNode = null; + } + return; + } + if (this.trailEmitterNode == null) + this.trailEmitterNode = this.level.particleManager.createEmitter(trailParticleOptions, trailEmitterData, null, + () -> this.getAbsPos().getPosition()); } function ReportBounce(pos:Vector, normal:Vector, speed:Float) { @@ -713,6 +763,12 @@ class Marble extends GameObject { updatePowerupStates(currentTime, dt); + this.trailEmitter(); + if (bounceEmitDelay > 0) + bounceEmitDelay -= dt; + if (bounceEmitDelay < 0) + bounceEmitDelay = 0; + // this.camera.target.load(this.getAbsPos().getPosition().toPoint()); } diff --git a/src/ParticleSystem.hx b/src/ParticleSystem.hx index 4e2658b7..9360d033 100644 --- a/src/ParticleSystem.hx +++ b/src/ParticleSystem.hx @@ -255,12 +255,12 @@ class ParticleManager { } public function update(currentTime:Float, dt:Float) { - this.tick(); this.currentTime = currentTime; for (obj => batch in particlebatches) { for (instance in batch.instances) instance.update(currentTime, dt); } + this.tick(); for (obj => batch in particlebatches) { batch.meshBatch.begin(batch.instances.length); for (instance in batch.instances) { diff --git a/src/gui/PlayGui.hx b/src/gui/PlayGui.hx new file mode 100644 index 00000000..2541f897 --- /dev/null +++ b/src/gui/PlayGui.hx @@ -0,0 +1,55 @@ +package gui; + +import h2d.Anim; +import h2d.Bitmap; +import src.ResourceLoader; + +class PlayGui { + var scene2d:h2d.Scene; + + public function new() {} + + var numbers:Array = []; + var timerPoint:Bitmap; + var timerColon:Bitmap; + + public function init(scene2d:h2d.Scene) { + this.scene2d = scene2d; + + var numberTiles = []; + for (i in 0...10) { + var tile = ResourceLoader.getImage('data/ui/game/numbers/${i}.png').toTile(); + numberTiles.push(tile); + } + + for (i in 0...7) { + numbers.push(new Anim(numberTiles, 0, scene2d)); + } + + timerPoint = new Bitmap(ResourceLoader.getImage('data/ui/game/numbers/point.png').toTile(), scene2d); + timerColon = new Bitmap(ResourceLoader.getImage('data/ui/game/numbers/colon.png').toTile(), scene2d); + initTimer(); + } + + public function initTimer() { + var screenWidth = scene2d.width; + var screenHeight = scene2d.height; + + function toScreenSpaceX(x:Float) { + return screenWidth / 2 - (234 / 2) + x; + } + function toScreenSpaceY(y:Float) { + return (y / 480) * screenHeight; + } + + numbers[0].x = toScreenSpaceX(23); + numbers[1].x = toScreenSpaceX(47); + timerColon.x = toScreenSpaceX(67); + numbers[2].x = toScreenSpaceX(83); + numbers[3].x = toScreenSpaceX(107); + timerPoint.x = toScreenSpaceX(127); + numbers[4].x = toScreenSpaceX(143); + numbers[5].x = toScreenSpaceX(167); + numbers[6].x = toScreenSpaceX(191); + } +}