Skip to content

Commit

Permalink
huh
Browse files Browse the repository at this point in the history
  • Loading branch information
Nintendoboi22 authored Jan 27, 2025
1 parent 335f5de commit 3f7a0f7
Show file tree
Hide file tree
Showing 9 changed files with 54,912 additions and 0 deletions.
114 changes: 114 additions & 0 deletions burger-and-frights/js/game/app.class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/**
* @file app.class.js
* @version 1.0.0
*/

import AudioSystem from '../framework/audiosystem.class.js';
import ImageManager from '../framework/imagemanager.class.js';
import Input from '../framework/input.class.js';
import ModelManager from '../framework/modelmanager.class.js';
import Time from '../framework/time.class.js';

import Context from './context.class.js';

import * as THREE from '../lib/three.js/three.module.js';

import Ingame from '../scenes/ingame.class.js';

import config from '../resources/config.js';

export default class App {
static _init() {
App.version = '1.0.0';

THREE.Object3D.DefaultMatrixAutoUpdate = false;

window.addEventListener('load', () => {
App._elementLoading = document.querySelector('.loading');
App._elementCredits = document.querySelector('.credits');
App._elementShowCredits = document.querySelector('.show-credits');

App._creditsVisible = false;
App._showCreditsVisible = false;

App._elementShowCredits.addEventListener('click', () => {
App.setCreditsVisibility(!App._creditsVisible);
});

AudioSystem.createAudioContext(THREE.AudioContext.getContext());

AudioSystem.asyncLoadSounds()
.then(() => ImageManager.asyncLoadImages())
.then(() => ModelManager.asyncLoadModels())
.then(() => {
App._elementLoading.style.visibility = 'hidden';

App.setCreditsVisibility(false);

new App();
});
});
}

static setCreditsVisibility(creditsVisible = true, showCreditsVisible = true) {
App._creditsVisible = creditsVisible;
App._showCreditsVisible = showCreditsVisible;

App._elementCredits.style.visibility = creditsVisible ? 'visible' : 'hidden';
App._elementShowCredits.style.visibility = showCreditsVisible ? 'visible' : 'hidden';
}

constructor() {
this._time = new Time();

this._clock = new THREE.Clock(false);

this._canvas = document.querySelector('canvas');

this._renderer = new THREE.WebGLRenderer({
antialias: config.renderer.antialias,
canvas: this._canvas,
precision: THREE.mediump,
stencil: false,
});

this._renderer.autoClearColor = false;

Input.setContextMenuEnabled(false);
Input.setKeyScrollEnabled(false);

this._context = new Context(this, this._time, this._renderer);

this._scene = new Ingame(this._context);

window.addEventListener('resize', this._handleResize.bind(this));

this._clock.start();
this._renderer.setAnimationLoop(this._update.bind(this));

this._handleResize();
}

_handleResize() {
const height = Math.min(window.innerHeight, config.renderer.height);
const width = Math.round(window.innerWidth / window.innerHeight * height);

this._renderer.setSize(width, height);

this._canvas.style.width = `${window.innerWidth}px`;
this._canvas.style.height = `${window.innerHeight}px`;

this._scene.handleResize(this._context);
}

_update(time) {
this._context.time.addElapsedSeconds(
Math.min(this._clock.getDelta(), config.simulation.maxTimestep));

this._scene.update(this._context);

Input.resetState();
}
}

App._init();
12 changes: 12 additions & 0 deletions burger-and-frights/js/game/context.class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @file context.class.js
* @version 1.0.0
*/

export default class Context {
constructor(app, time, renderer) {
this.app = app;
this.time = time;
this.renderer = renderer;
}
}
58 changes: 58 additions & 0 deletions burger-and-frights/js/game/utility.class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @file utility.class.js
* @version 1.0.0
*/

import * as THREE from '../lib/three.js/three.module.js';

export default class Utility {
static getClosestAngle(a, b) {
const tau = Math.PI * 2;
const x = b - a + Math.PI;
return x - Math.floor(x / tau) * tau - Math.PI;
}

static replaceMaterial(material, isToon = true) {
if (material === undefined) {
return undefined;
}

const newMaterial = new (material.transparent ? THREE.MeshBasicMaterial :
isToon ? THREE.MeshToonMaterial : THREE.MeshPhongMaterial)({
map: material.map,
color: material.color,
side: material.side,
transparent: material.transparent,
opacity: material.opacity,
alphaTest: material.alphaTest,
depthWrite: !material.transparent,
});

if (!material.transparent) {
newMaterial.emissive = material.emissive;
newMaterial.emissiveMap = material.emissiveMap;
newMaterial.emissiveIntensity = material.emissiveIntensity;

if (!isToon) {
newMaterial.shininess = 0;
newMaterial.specular.setHex(0);
}
}

if (newMaterial.map) {
newMaterial.map.magFilter = THREE.NearestFilter;
newMaterial.map.minFilter = THREE.NearestFilter;
}

if (newMaterial.emissiveMap) {
newMaterial.emissiveMap.magFilter = THREE.NearestFilter;
newMaterial.emissiveMap.minFilter = THREE.NearestFilter;
}

return newMaterial;
}

static easeInOutCubic(x) {
return x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;
}
}
Loading

0 comments on commit 3f7a0f7

Please sign in to comment.