mirror of
https://github.com/GoodStartLabs/AI_Diplomacy.git
synced 2026-04-19 12:58:09 +00:00
Added Hold Animation + Implemented Arrow Grow for Bounce Animation + Fixed Event Queue/ Pause Button
This commit is contained in:
parent
17f2494026
commit
1b0a768603
2 changed files with 75 additions and 12 deletions
|
|
@ -61,12 +61,7 @@ export class EventQueue {
|
|||
* Remove resolved events from the queue
|
||||
*/
|
||||
cleanup(): void {
|
||||
let clearedQueue = this.events.filter(event => !event.resolved);
|
||||
if (clearedQueue.length <= 1) {
|
||||
console.log(this.events)
|
||||
throw new Error("We've cleared all the messages out of the queue")
|
||||
}
|
||||
this.events = clearedQueue
|
||||
this.events = this.events.filter(e => !e.resolved);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -9,10 +9,12 @@ import { config } from "../config"; // Assuming config is defined in a separate
|
|||
import { PowerENUM, ProvinceENUM } from "../types/map";
|
||||
import { UnitTypeENUM } from "../types/units";
|
||||
import { sineWave, getTimeInSeconds } from "../utils/timing";
|
||||
//import { color } from "chart.js/helpers";
|
||||
//import { depth } from "three/tsl";
|
||||
|
||||
|
||||
function buildFancyArrow(length: number, colorDeter: string): THREE.Mesh {
|
||||
|
||||
//Specs to change arrow size
|
||||
const tw = 3.5;
|
||||
const headLength = tw * 4;
|
||||
const hw = tw * 4;
|
||||
|
|
@ -36,9 +38,38 @@ function buildFancyArrow(length: number, colorDeter: string): THREE.Mesh {
|
|||
mat = new THREE.MeshStandardMaterial({color: 0xFF0000})
|
||||
}
|
||||
const mesh= new THREE.Mesh(extrude, mat)
|
||||
//(Potential Addition: Outline of arrow)
|
||||
return mesh;
|
||||
}
|
||||
|
||||
function createShield() {
|
||||
|
||||
//Shield Specs
|
||||
const BSH= 10
|
||||
const SW= 10
|
||||
const TSH= 10
|
||||
|
||||
|
||||
const outL= new THREE.Shape()
|
||||
.moveTo(0, TSH)
|
||||
.lineTo(SW, TSH)
|
||||
.lineTo(SW, 0)
|
||||
.quadraticCurveTo(SW, -BSH, 0, -BSH)
|
||||
.quadraticCurveTo(-SW, -BSH, -SW, 0)
|
||||
.lineTo(-SW,TSH)
|
||||
.lineTo(0, TSH)
|
||||
.closePath();
|
||||
|
||||
const SExtrude= new THREE.ExtrudeGeometry(outL, {depth: 5})
|
||||
|
||||
const SMat= new THREE.MeshStandardMaterial({color: 0x00FF00})
|
||||
|
||||
const SMesh= new THREE.Mesh(SExtrude, SMat )
|
||||
|
||||
return SMesh
|
||||
|
||||
}
|
||||
|
||||
//create an arrow from the unit’s current pos toward the target
|
||||
function createMoveArrow(scene: THREE.Scene, unitMesh: THREE.Group, destination: ProvinceENUM): THREE.ArrowHelper {
|
||||
const startPos = unitMesh.position.clone();
|
||||
|
|
@ -151,7 +182,7 @@ function createMoveAnimation(unitMesh: THREE.Group, orderDestination: ProvinceEN
|
|||
unitMesh.userData.moveArrow = arrowMesh;
|
||||
//Value beside x:1 controls the speed of the growth
|
||||
const ArrowGrow = new Tween(arrowMesh.scale)
|
||||
.to({ x: 1 }, 300)
|
||||
.to({ x: 1 }, 1000)
|
||||
.easing(Easing.Quadratic.Out)
|
||||
.onComplete(() => {
|
||||
const anim = new Tween(unitMesh.position)
|
||||
|
|
@ -213,11 +244,15 @@ function createBounceAnimation(unitMesh: THREE.Group, attemptedDestination: Prov
|
|||
);
|
||||
arrowMesh.setRotationFromQuaternion(q);
|
||||
|
||||
//arrowMesh.scale.set(0, 1, 1);
|
||||
arrowMesh.scale.set(0, 1, 1);
|
||||
|
||||
gameState.scene.add(arrowMesh);
|
||||
unitMesh.userData.moveArrow = arrowMesh;
|
||||
|
||||
const growBounce= new Tween (arrowMesh.scale)
|
||||
//Number beside x:1 controls speed in ms
|
||||
.to({ x: 1 }, 1000)
|
||||
.easing(Easing.Quadratic.Out)
|
||||
.onComplete(() => {
|
||||
const bounceOut = new Tween(unitMesh.position)
|
||||
.to({ x: end.x, y: 10, z: end.z }, config.effectiveAnimationDuration / 2)
|
||||
.easing(Easing.Quadratic.Out)
|
||||
|
|
@ -233,11 +268,43 @@ function createBounceAnimation(unitMesh: THREE.Group, attemptedDestination: Prov
|
|||
|
||||
bounceOut.start();
|
||||
|
||||
gameState.unitAnimations.push(bounceOut);
|
||||
return bounceOut;
|
||||
gameState.unitAnimations.push(bounceOut);})
|
||||
growBounce.start()
|
||||
gameState.unitAnimations.push(growBounce)
|
||||
return growBounce;
|
||||
}
|
||||
|
||||
|
||||
function createHoldAnimation(unitMesh: THREE.Group): Tween {
|
||||
|
||||
const newshield= createShield()
|
||||
|
||||
const worldPos = new THREE.Vector3();
|
||||
unitMesh.getWorldPosition(worldPos);
|
||||
newshield.position.set(worldPos.x, -20, worldPos.z+8);
|
||||
gameState.scene.add(newshield);
|
||||
unitMesh.userData.newshield = newshield;
|
||||
|
||||
unitMesh.userData.isAnimating = true
|
||||
const RiserS= new Tween (newshield.position)
|
||||
.to({ x: worldPos.x, y: 20, z: worldPos.z+8}, 2000)
|
||||
.easing(Easing.Quadratic.Out)
|
||||
.onComplete(() => {
|
||||
// parent under the unit so it moves with them
|
||||
gameState.scene.remove(newshield);
|
||||
delete unitMesh.userData.newshield;
|
||||
unitMesh.userData.isAnimating = false
|
||||
})
|
||||
.start();
|
||||
|
||||
// 5) make sure it's updated each frame
|
||||
gameState.unitAnimations.push(RiserS);
|
||||
|
||||
|
||||
|
||||
return RiserS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates animations for unit movements based on orders from the previous phase
|
||||
|
|
@ -315,6 +382,7 @@ export function createAnimationsForNextPhase() {
|
|||
|
||||
case "hold":
|
||||
//TODO: Hold animation, maybe a sheild or something?
|
||||
createHoldAnimation(gameState.unitMeshes[unitIndex])
|
||||
break;
|
||||
|
||||
case "convoy":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue