Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
019e1c7
First commit
paganaye Dec 10, 2021
8f8b7e9
Added base elements
DaveRubin Feb 2, 2023
220f425
Added material
DaveRubin Feb 2, 2023
2504513
Added vite
DaveRubin Feb 2, 2023
c5cc14b
cleanup
DaveRubin Feb 3, 2023
beb89e4
Added mask
DaveRubin Feb 3, 2023
6029d85
Added plant
DaveRubin Feb 3, 2023
5ee97a7
plant tweaks
DaveRubin Feb 3, 2023
49903b7
cleanup
DaveRubin Feb 3, 2023
ba50a45
Added camera movement
DaveRubin Feb 3, 2023
5fde912
texture style
DaveRubin Feb 3, 2023
4c51738
Added color sets
DaveRubin Feb 3, 2023
f6d4084
Adde particles
DaveRubin Feb 3, 2023
6140ff5
moved to particle burst
DaveRubin Feb 3, 2023
da8e2bb
added root class and shere
gavriel200 Feb 3, 2023
a1c170e
added single root
DaveRubin Feb 3, 2023
8c30d99
added move instead of position
gavriel200 Feb 3, 2023
06dde5f
Merge pull request #1 from DaveRubin/add-root-class
gavriel200 Feb 3, 2023
3d9a47d
added single toot
DaveRubin Feb 3, 2023
db64a74
Merge branch 'main' into generate
DaveRubin Feb 3, 2023
1157ae9
fix move with mousePosition
gavriel200 Feb 3, 2023
383e743
Merge pull request #2 from DaveRubin/add-root-class
gavriel200 Feb 3, 2023
d3b0d20
Merge branch 'main' into generate
DaveRubin Feb 3, 2023
2a1e4e4
aaa
DaveRubin Feb 3, 2023
901f4b2
XXXX
DaveRubin Feb 3, 2023
5320523
create arrayof poits add to roots
gavriel200 Feb 3, 2023
6b8eb51
Merge pull request #3 from DaveRubin/add-array-of-root-points
gavriel200 Feb 3, 2023
06c7426
Added camera follow
DaveRubin Feb 3, 2023
7db1c68
Added rules
DaveRubin Feb 3, 2023
3950e46
single roots to roots
gavriel200 Feb 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000/",
"webRoot": "${workspaceFolder}",
"trace": true
}
]
}
32 changes: 0 additions & 32 deletions README.md

This file was deleted.

16 changes: 16 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + TS</title>
</head>

<body>
<div id="app"></div>
<script type="module" src="/src/app.ts"></script>
</body>

</html>
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "global-game-jam-2023",
"version": "1.0.0",
"main": "index.js",
"repository": "[email protected]:DaveRubin/global-game-jam-2023.git",
"author": "David Rubin <[email protected]>",
"license": "MIT",
"scripts": {
"build": "webpack",
"start": "webpack-dev-server --port 8080",
"dev": "vite"
},
"devDependencies": {
"@babylonjs/core": "^5.44.0",
"@babylonjs/gui": "^5.44.0",
"@babylonjs/gui-editor": "^5.44.0",
"@babylonjs/inspector": "^5.44.0",
"@babylonjs/loaders": "^5.44.0",
"@babylonjs/materials": "^5.44.0",
"@babylonjs/serializers": "^5.44.0",
"@types/node": "^18.11.18",
"html-webpack-plugin": "^5.5.0",
"ts-loader": "^9.4.2",
"typescript": "^4.9.5",
"vite": "^4.1.1",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.11.1"
}
}
9 changes: 9 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of Your Project</title>
</head>
<body>
</body>
</html>
Binary file added public/textures/Flare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/textures/forest_ground_04_ao_1k.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/textures/forest_ground_04_diff_1k.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/textures/forest_ground_04_disp_1k.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/textures/forest_ground_04_nor_gl_1k.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions src/CameraController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Camera, Engine, Mesh, TransformNode, Vector3 } from "@babylonjs/core";
import { animateTo, animateToVector } from "./animations";

const REGULAR_ZOOM = -12;
const CLOSE_UP = -5;

export class CameraConrtoller {
cameraContainer: TransformNode;
target?: Mesh;
constructor(camera: Camera) {
this.cameraContainer = new TransformNode("cameraNode");

camera.parent = this.cameraContainer;
this.cameraContainer.position.set(0, 0.1, REGULAR_ZOOM);
Engine.LastCreatedScene?.onBeforeRenderObservable.add(() => {
if (this.target) {
const diff = this.target.position.subtract(this.cameraContainer.position);
diff.z = 0;

this.cameraContainer.position.x += diff.x / 4;
this.cameraContainer.position.y += diff.y / 4;
}
});
}
startFollow = (target: Mesh) => {
this.target = target;
animateTo(this.cameraContainer, "position.z", 1, [REGULAR_ZOOM, CLOSE_UP]);
};
stopFollow = () => {
this.target = undefined;
animateTo(this.cameraContainer, "position.z", 1, [CLOSE_UP, REGULAR_ZOOM]);
animateToVector(this.cameraContainer, "position", 1, [
this.cameraContainer.position,
new Vector3(0, 0.1, REGULAR_ZOOM),
]);
};
}
29 changes: 29 additions & 0 deletions src/MainGame.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const INITIAL_ENERGY = 1000;
const ENERGY_USAGE = 7;
const INITIAL_ENERGY_PER_TICK = 2;

export class MainGame {
maxEnergy = INITIAL_ENERGY;
currentEnergy = INITIAL_ENERGY;
energyPerTick = INITIAL_ENERGY_PER_TICK;

constructor() {}

get energyRatio() {
return this.currentEnergy / this.maxEnergy;
}

updateEnergy = () => {
this.currentEnergy += this.energyPerTick;
if (this.currentEnergy > this.maxEnergy) {
this.currentEnergy = this.maxEnergy;
}
};

useEnergy = () => {
this.currentEnergy -= ENERGY_USAGE;
if (this.currentEnergy < 0) {
this.currentEnergy = 0;
}
};
}
29 changes: 29 additions & 0 deletions src/animations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Animation, CubicEase, EasingFunction, Engine, Vector3 } from "@babylonjs/core";

let runner = 1;
const ease = new CubicEase()
ease.setEasingMode(EasingFunction.EASINGMODE_EASEINOUT)
export const animateTo = (target: any, key: string, duration: number, values: any[]) => new Promise((resolve) => {
const frameRate = 10;

const animation = new Animation("xSlide" + runner, key, frameRate, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CONSTANT);
animation.setEasingFunction(ease)
const keyDuration = duration / values.length;

animation.setKeys(values.map((value, index) => ({
frame: index * keyDuration * frameRate,
value
})));

Engine.LastCreatedScene?.beginDirectAnimation(target, [animation], 0, duration * frameRate, false, undefined, () => {
resolve(true);
});

})

export const animateToVector = (target: any, key: string, duration: number, values: Vector3[]) => new Promise((resolve) => {
animateTo(target, key + ".x", duration, values.map(val => val.x));
animateTo(target, key + ".y", duration, values.map(val => val.y));
animateTo(target, key + ".z", duration, values.map(val => val.z));

})
120 changes: 120 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { Engine, FreeCamera, HemisphericLight, Matrix, Scene, TransformNode, Vector3 } from "@babylonjs/core";
import "@babylonjs/core/Debug/debugLayer";
import "@babylonjs/inspector";
import "@babylonjs/loaders";
import "@babylonjs/loaders/glTF";
import { animateTo } from "./animations";
import { CameraConrtoller } from "./CameraController";
import { MainGUI } from "./gui";
import { MainGame } from "./MainGame";
import { createMainStage } from "./mainStage";
import { Roots } from "./roots";

class App {
constructor() {
// create the canvas html element and attach it to the webpage
var canvas = document.createElement("canvas");
canvas.style.width = "100%";
canvas.style.height = "100%";
canvas.id = "gameCanvas";
document.body.appendChild(canvas);

var engine = new Engine(canvas, true);
var scene = new Scene(engine);

const camera = new FreeCamera("camera1", Vector3.Zero(), scene);
const controller = new CameraConrtoller(camera);
var mainLight: HemisphericLight = new HemisphericLight("light1", new Vector3(0, 1, 1), scene);
mainLight.intensity = 0.2;
const game = new MainGame();
const mainGui = new MainGUI();
mainGui.progress = game.energyRatio;
// animateFloat(mainGui, "progress", 4, [0, 1]).then(() => console.log("DONE!"));
const dirt = createMainStage();
scene.registerBeforeRender(() => {
// leaf.addRotation(0, 0.05, 0);
});
// scene.onPointerDown = function castRay() {
// var ray = scene.createPickingRay(scene.pointerX, scene.pointerY, Matrix.Identity(), camera, false);

// var hit = scene.pickWithRay(ray);

// if (hit?.pickedMesh?.id === "plantBase") {
// const p = hit?.pickedMesh?.position;
// animateTo(CoT, "position.x", 1, [CoT.position.x, p.x]);
// animateTo(CoT, "position.y", 1, [CoT.position.y, p.y]);
// }
// };

// hide/show the Inspector
window.addEventListener("keydown", (ev) => {
// Shift+Ctrl+Alt+I
if (ev.key === "i") {
// if (ev.shiftKey && ev.ctrlKey && ev.altKey && ev.key === 'i') {
if (scene.debugLayer.isVisible()) {
scene.debugLayer.hide();
} else {
scene.debugLayer.show();
}
}
});

const roots = new Roots(scene);

canvas.addEventListener("pointerdown", (event) => {
const pickRoots = scene.pick(event.clientX, event.clientY, (mesh) => roots.isMeshInRoots(mesh));
if (pickRoots.hit) {
const pickDirt = scene.pick(event.clientX, event.clientY, (mesh) => mesh === dirt);

if (pickDirt.hit) {
const target = pickDirt.pickedPoint;
target!.z = 0;
const sph = roots.createSphere(target!);
controller.startFollow(sph);
roots.updateMousePosition(target!);
roots.addRoot();
roots.addTime();
}
}
});
const finishFollow = () => {
roots.deleteSphere();
controller.stopFollow();
};

canvas.addEventListener("pointermove", (event) => {
if (roots.getIsDragging() && game.currentEnergy > 0) {
let pickResult = scene.pick(event.clientX, event.clientY, (mesh) => {
return mesh === dirt;
});
let target = pickResult.pickedPoint;
target!.z = 0;
roots.updateMousePosition(target!);
game.useEnergy();
} else if (game.currentEnergy <= 0) {
finishFollow();
}
});

canvas.addEventListener("pointerup", () => {
if (roots.getIsDragging()) {
finishFollow();
}
});

scene.registerBeforeRender(() => {
roots.moveSphere();
});

// run the main render loop
engine.runRenderLoop(() => {
if (!roots.getIsDragging()) {
game.updateEnergy();
}

mainGui.progress = game.energyRatio;
scene.render();
});
}
}
new App();
1 change: 1 addition & 0 deletions src/consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DEGREE = Math.PI / 180;
Loading