mirror of
https://github.com/GoodStartLabs/AI_Diplomacy.git
synced 2026-04-19 12:58:09 +00:00
Finished Shield + Quality of Life Changes
This commit is contained in:
parent
1b0a768603
commit
6e136d9c4e
3 changed files with 36 additions and 69 deletions
6
.vscode/launch.json
vendored
6
.vscode/launch.json
vendored
|
|
@ -4,11 +4,11 @@
|
||||||
{
|
{
|
||||||
"type": "pwa-chrome",
|
"type": "pwa-chrome",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "Chrome Debug 5179",
|
"name": "Chrome Debug 5173",
|
||||||
"url": "http://localhost:5179",
|
"url": "http://localhost:5173",
|
||||||
"webRoot": "${workspaceFolder}/ai_animation/",
|
"webRoot": "${workspaceFolder}/ai_animation/",
|
||||||
"sourceMapPathOverrides": {
|
"sourceMapPathOverrides": {
|
||||||
"http://localhost:5179/*": "${webRoot}/*"
|
"http://localhost:5173/*": "${webRoot}/*"
|
||||||
},
|
},
|
||||||
"runtimeArgs": [
|
"runtimeArgs": [
|
||||||
"--remote-debugging-port=9223"
|
"--remote-debugging-port=9223"
|
||||||
|
|
|
||||||
14
.vscode/tasks.json
vendored
Normal file
14
.vscode/tasks.json
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "Run Game",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "npm start",
|
||||||
|
"presentation": {
|
||||||
|
"panel": "shared"
|
||||||
|
},
|
||||||
|
"problemMatcher": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -70,50 +70,6 @@ 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();
|
|
||||||
const endPos = getProvincePosition(destination)!;
|
|
||||||
|
|
||||||
// compute direction & length
|
|
||||||
const dir = new THREE.Vector3()
|
|
||||||
.subVectors(endPos, startPos)
|
|
||||||
const length = startPos.distanceTo(endPos) - 2; //subtracted a bit so the arrow tip doesn't overlap the unit
|
|
||||||
|
|
||||||
const color = 0x00FF00
|
|
||||||
|
|
||||||
const arrow = new THREE.ArrowHelper(dir, startPos, length, color, 1, 0.5);
|
|
||||||
scene.add(arrow);
|
|
||||||
|
|
||||||
unitMesh.userData.moveArrow = arrow;
|
|
||||||
return arrow;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Different color arrow for bounce to differentate moves (red=bounce, green=regular move)
|
|
||||||
function createBounceArrow(
|
|
||||||
scene: THREE.Scene,
|
|
||||||
unitMesh: THREE.Group,
|
|
||||||
destination: ProvinceENUM)
|
|
||||||
: THREE.ArrowHelper {
|
|
||||||
const startPos = unitMesh.position.clone();
|
|
||||||
const endPos= getProvincePosition(destination)!;
|
|
||||||
|
|
||||||
// compute direction & length
|
|
||||||
const dir = new THREE.Vector3()
|
|
||||||
.subVectors(endPos, startPos)
|
|
||||||
const length = startPos.distanceTo(endPos) - 2; //subtracted a bit so arrow tip doesn't overlap the unit
|
|
||||||
|
|
||||||
const color = 0xFF0000
|
|
||||||
|
|
||||||
const arrow = new THREE.ArrowHelper(dir, startPos, length, color, 1, 0.5);
|
|
||||||
scene.add(arrow);
|
|
||||||
|
|
||||||
unitMesh.userData.moveArrow = arrow;
|
|
||||||
return arrow;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function getUnit(unitOrder: UnitOrder, power: string) {
|
function getUnit(unitOrder: UnitOrder, power: string) {
|
||||||
if (power === undefined) throw new Error("Must pass the power argument, cannot be undefined")
|
if (power === undefined) throw new Error("Must pass the power argument, cannot be undefined")
|
||||||
let posUnits = gameState.unitMeshes.filter((unit) => {
|
let posUnits = gameState.unitMeshes.filter((unit) => {
|
||||||
|
|
@ -276,43 +232,40 @@ function createBounceAnimation(unitMesh: THREE.Group, attemptedDestination: Prov
|
||||||
|
|
||||||
|
|
||||||
function createHoldAnimation(unitMesh: THREE.Group): Tween {
|
function createHoldAnimation(unitMesh: THREE.Group): Tween {
|
||||||
|
// 1) Build the shield mesh
|
||||||
|
const shield = createShield();
|
||||||
|
|
||||||
const newshield= createShield()
|
// 2) Figure out where the unit’s feet are
|
||||||
|
|
||||||
const worldPos = new THREE.Vector3();
|
const worldPos = new THREE.Vector3();
|
||||||
unitMesh.getWorldPosition(worldPos);
|
unitMesh.getWorldPosition(worldPos);
|
||||||
newshield.position.set(worldPos.x, -20, worldPos.z+8);
|
|
||||||
gameState.scene.add(newshield);
|
|
||||||
unitMesh.userData.newshield = newshield;
|
|
||||||
|
|
||||||
unitMesh.userData.isAnimating = true
|
shield.position.set(worldPos.x, 16, worldPos.z+8);
|
||||||
const RiserS= new Tween (newshield.position)
|
shield.scale.set(1, 0, 1); // collapse height
|
||||||
.to({ x: worldPos.x, y: 20, z: worldPos.z+8}, 2000)
|
|
||||||
|
gameState.scene.add(shield);
|
||||||
|
unitMesh.userData.newshield = shield;
|
||||||
|
unitMesh.userData.isAnimating = true;
|
||||||
|
|
||||||
|
const growTween = new Tween(shield.scale)
|
||||||
|
.to({ x: 1, y: 1, z: 1 }, 2000)
|
||||||
.easing(Easing.Quadratic.Out)
|
.easing(Easing.Quadratic.Out)
|
||||||
.onComplete(() => {
|
.onComplete(() => {
|
||||||
// parent under the unit so it moves with them
|
gameState.scene.remove(shield);
|
||||||
gameState.scene.remove(newshield);
|
unitMesh.userData.isAnimating = false;
|
||||||
delete unitMesh.userData.newshield;
|
|
||||||
unitMesh.userData.isAnimating = false
|
|
||||||
})
|
})
|
||||||
.start();
|
.start();
|
||||||
|
|
||||||
// 5) make sure it's updated each frame
|
gameState.unitAnimations.push(growTween);
|
||||||
gameState.unitAnimations.push(RiserS);
|
|
||||||
|
|
||||||
|
return growTween;
|
||||||
|
|
||||||
return RiserS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates animations for unit movements based on orders from the previous phase
|
* Creates animations for unit movements based on orders from the previous phase
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
export function createAnimationsForNextPhase() {
|
export function createAnimationsForNextPhase() {
|
||||||
let previousPhase = gameState.gameData?.phases[gameState.phaseIndex == 0 ? 0 : gameState.phaseIndex - 1]
|
let previousPhase = gameState.gameData?.phases[gameState.phaseIndex == 0 ? 0 : gameState.phaseIndex - 1]
|
||||||
|
// const sequence = ["build", "disband", "hold", "move", "bounce", "retreat"]
|
||||||
// Safety check - if no previous phase or no orders, return
|
// Safety check - if no previous phase or no orders, return
|
||||||
if (!previousPhase) {
|
if (!previousPhase) {
|
||||||
logger.log("No previous phase to animate");
|
logger.log("No previous phase to animate");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue