mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
Add timer, fix CCD
This commit is contained in:
parent
f88433ea26
commit
354bb52ea9
4 changed files with 118 additions and 10 deletions
11
src/Main.hx
11
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,
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
55
src/gui/PlayGui.hx
Normal file
55
src/gui/PlayGui.hx
Normal file
|
|
@ -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<Anim> = [];
|
||||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue