Compare commits

...

14 Commits

Author SHA1 Message Date
e6daabf16d Removed Stuff 2025-10-29 16:48:03 -05:00
ab79e95734 Changed Rarity 2025-10-29 16:47:37 -05:00
ffe9bc6156 More Settings 2025-10-29 16:46:54 -05:00
24d0a07be9 Black Hole Function 2025-10-29 16:46:36 -05:00
2e9320f9ac If Entity is shown draw it 2025-10-29 16:46:22 -05:00
7ad1dcc44b Removed World Scale 2025-10-29 16:45:39 -05:00
5084d969ba Updated Rarity 2025-10-29 16:45:02 -05:00
dd29fb8571 Updated count 2025-10-29 16:43:42 -05:00
da186279b6 More Settings 2025-10-29 16:43:32 -05:00
9ff7d3d284 Froze Enum 2025-10-29 16:40:01 -05:00
c5730952f9 Created More Settings 2025-10-29 16:39:48 -05:00
210e190f11 Changed Mass to grab from Settings Object 2025-10-29 16:39:24 -05:00
1202cd0221 Made new entities created use the old locations 2025-10-29 16:39:04 -05:00
0b1a622b99 Fixed Member post width 2025-10-29 16:35:20 -05:00
3 changed files with 158 additions and 72 deletions

View File

@ -159,4 +159,3 @@
<script src="/javascript/remeber.js"></script> <script src="/javascript/remeber.js"></script>
</body> </body>
</html> </html>
<!--Gitea Discord Test 2-->

View File

@ -2,30 +2,72 @@ let images = {};
let simulator = []; let simulator = [];
let maxSpeed = 1; let maxSpeed = 1;
let backgroundImage; let backgroundImage;
let worldScale;
let LEFT = [-1,0]; let LEFT = [-1,0];
const entityTypes = { const entityTypes = Object.freeze({
METERORITE_SMALL: "meteorite_small", METERORITE_SMALL: "meteorite_small",
METERORITE_LARGE: "meteorite_large", METERORITE_LARGE: "meteorite_large",
COMET: "comet", COMET: "comet",
}; });
let Settings = { var Settings = {
windowWrap: true, windowWrap: true,
physics: true, physics: true,
respawn: true,
devMode: false,
maxSpeed: 1,
backgroundImage: "/media/Art/EmptySpace.png",
entityCount: 200,
emptyEntries: [],
rarity: {
"comet": .99,
"meteorite_small": 500.0,
"meteorite_large": 1000.0,
},
mass: {
"comet": 1400.0,
"meteorite_small": 500.0,
"meteorite_large": 1000.0,
},
}
function distance(entity1, entity2){
return Math.sqrt(
((entity2.x-entity1.x)*(entity2.x-entity1.x)) +
((entity2.y-entity1.y)*(entity2.y-entity1.y))
);
} }
function getMass(type){ function getMass(type){
switch (type){ switch (type){
case entityTypes.COMET: return 1400.0; case entityTypes.COMET: return Settings.mass[entityTypes.COMET]
case entityTypes.METERORITE_SMALL: return 500.0; case entityTypes.METERORITE_SMALL: return Settings.mass[entityTypes.METERORITE_SMALL];
case entityTypes.METERORITE_LARGE: return 1000.0; case entityTypes.METERORITE_LARGE: return Settings.mass[entityTypes.METERORITE_LARGE];
} }
} }
function createEntity(x, y, vx, vy, ax, ay, rot, rotv, type){ function createEntity(x, y, vx, vy, ax, ay, rot, rotv, type, id=0, iframes=Math.floor(Math.random()*100)){
let entity = { if (Settings.emptyEntries.length > 1){
var entryID = Settings.emptyEntries.pop();
if (Settings.devMode) console.warn("Creating new enity from old", entryID);
if (entryID <= simulator.length && entryID >= 0){
entity = simulator[entryID];
entity.x = x;
entity.y = y;
entity.vx = vx;
entity.vy = vy;
entity.ax = ax;
entity.ay = ay;
entity.rot = rot;
entity.rotv = rotv;
entity.iframes = 1000;
entity.show = true;
entity.type = type
}else{
if (Settings.devMode) console.error("Entry ID out of bounds", Settings.emptyEntries.length, id, entryID);
}
}else{
simulator.push({
x: x, x: x,
y: y, y: y,
ax: ax, ax: ax,
@ -38,17 +80,20 @@ function createEntity(x, y, vx, vy, ax, ay, rot, rotv, type){
forcex: 0.0, forcex: 0.0,
forcey: 0.0, forcey: 0.0,
type: type, type: type,
show: true,
ueid: id,
iframes: iframes
});
} }
simulator.push(entity);
} }
function getRandomType(){ function getRandomType(){
let rand = Math.random(); let rand = Math.random();
if (rand > 0.955){ if (rand > 0.99){
console.log("Comet made"); if(Settings.devMode) console.log("Comet made");
return entityTypes.COMET; return entityTypes.COMET;
}if(rand > 0.4){ }if(rand > 0.5){
return entityTypes.METERORITE_SMALL; return entityTypes.METERORITE_SMALL;
}else{ }else{
return entityTypes.METERORITE_LARGE; return entityTypes.METERORITE_LARGE;
@ -56,34 +101,52 @@ function getRandomType(){
} }
function physicsUpdate(entity){ function physicsUpdate(entity){
if (entity.show){
entity.vx += entity.ax; entity.vx += entity.ax;
entity.vy += entity.ay; entity.vy += entity.ay;
entity.x += entity.vx; entity.x += entity.vx;
entity.y += entity.vy; entity.y += entity.vy;
entity.rot += entity.rotv; entity.rot += entity.rotv;
if (entity.iframes > 0) entity.iframes -= 1;
if (entity.iframes == 0) simulator.forEach((other_entity) =>{
checkCollision(entity, other_entity);
});
}
} }
function onHit(entity1, entity2){ function checkCollision(entity1, entity2){
if(entity1.type == entityTypes.METERORITE_LARGE){ if (entity1.type == entityTypes.COMET && entity2.type == entityTypes.COMET){
createEntity(entity1.x, entity1.y, entity2.vx-entity1.vx, entity2.vy-entity1.vy, 0.0,0.0,entity2.rot-entity1.rot, entity2.rotv-entity1.rotv, entityTypes.METERORITE_SMALL);
}if(entity1.type == entityTypes.COMET){
}else{ }else if (entity1.ueid != entity2.ueid
&& entity1.show
&& entity2.show){
var dist = distance(entity1, entity2);
if(dist < 15){
if (Settings.devMode) {
stroke('magenta');
strokeWeight(5);
line(entity1.x,entity1.y, entity2.x, entity2.y);
console.log("Collision at", entity1.x, entity1.y, entity1.iframes, entity2.x, entity2.y, dist);
}
Explode(entity1); Explode(entity1);
}
if(entity2.type == entityTypes.METERORITE_LARGE){
createEntity(entity2.x, entity2.y, entity1.vx-entity2.vx, entity1.vy-entity2.vy, 0.0,0.0,entity2.rot-entity1.rot, entity2.rotv-entity1.rotv, entityTypes.METERORITE_SMALL);
}if(entity1.type == entityTypes.COMET){
}else{
Explode(entity2); Explode(entity2);
} }
}
} }
function Explode(entity){ function Explode(entity){
if(entity.type == entityTypes.METERORITE_SMALL){
entity.show = false;
Settings.emptyEntries.push(entity.ueid);
}if(entity.type == entityTypes.METERORITE_LARGE){
entity.type = entityTypes.METERORITE_SMALL
entity.iframes = 1000;
createEntity(entity.x, entity.y, entity.vx + Math.random(), entity.vy + Math.random(), 0.0,0.0,0.0,0.0, entityTypes.METERORITE_SMALL, id=entity.ueid, iframes=1000);
}
}
function BlackHole(x,y,m,entity){
} }
@ -98,18 +161,19 @@ function drawBackground(refImage){
} }
function drawEntity(entity){ function drawEntity(entity){
if (entity.show){
push(); push();
imageMode(CENTER); imageMode(CENTER);
translate(entity.x*(worldScale.value()/100), entity.y*(worldScale.value()/100), 0); translate(entity.x, entity.y, 0);
if (entity.type == entityTypes.COMET){ if (entity.type == entityTypes.COMET){
rotate((Math.atan2(entity.vx, entity.vy) - Math.atan2(-1,0)) * 180/Math.PI); rotate((Math.atan2(entity.vx, entity.vy) - Math.atan2(-1,0)) * 180/Math.PI);
}else{ }else{
rotate(entity.rot); rotate(entity.rot);
} }
image(images[entity.type], 0,0); image(images[entity.type], 0,0);
pop(); pop();
} }
}
function preload(){ function preload(){
images[entityTypes.METERORITE_SMALL] = loadImage("/media/Art/meteorite_small_1.png"); images[entityTypes.METERORITE_SMALL] = loadImage("/media/Art/meteorite_small_1.png");
@ -125,11 +189,10 @@ function setup(){
describe("A space physics simulator"); describe("A space physics simulator");
canvas.position(0,0); canvas.position(0,0);
worldScale = createSlider();
//Load Entities //Load Entities
let entityCount = 50;
let rotationSpeed = 100.0; for(var i = 0; i <= Settings.entityCount; i+=1){
for(let i = 0; i <= entityCount; i+=1){
createEntity( createEntity(
Math.floor(Math.random() * windowWidth), //X Location Math.floor(Math.random() * windowWidth), //X Location
Math.floor(Math.random() * windowHeight), //Y Location Math.floor(Math.random() * windowHeight), //Y Location
@ -138,8 +201,9 @@ function setup(){
0.0, //X Acceleration 0.0, //X Acceleration
0.0, //Y Acceleration 0.0, //Y Acceleration
0.0, //Current Rotation 0.0, //Current Rotation
(Math.random() * 2 *(Math.PI / rotationSpeed))-(Math.PI / rotationSpeed), //Rotation Velocity (Math.random() * 2 *(Math.PI / Settings.rotationSpeed))-(Math.PI / Settings.rotationSpeed), //Rotation Velocity
getRandomType(), getRandomType(),
id=i
); );
} }
} }
@ -149,7 +213,6 @@ function mouseClicked(){
simulator.forEach((entity) =>{ simulator.forEach((entity) =>{
}) })
console.log(worldScale.value());
} }
function draw(){ function draw(){
@ -157,7 +220,7 @@ function draw(){
//Draw Tiled Background //Draw Tiled Background
drawBackground(images["background"]); drawBackground(images["background"]);
for(let e = 1; e < simulator.length; e++){ for(var e = 1; e < simulator.length; e++){
let entity = simulator[e] let entity = simulator[e]
//Physics Update //Physics Update
@ -167,22 +230,40 @@ function draw(){
//Window Wrap //Window Wrap
if (Settings.windowWrap){ if (Settings.windowWrap){
if (entity.x * (worldScale.value() /100) > windowWidth){ if (entity.x > windowWidth){
entity.x = 0; entity.x = 0;
} }
if (entity.x < 0){ if (entity.x < 0){
entity.x = windowWidth / (worldScale.value() /100); entity.x = windowWidth;
} }
if (entity.y * (worldScale.value() /100) > windowHeight){ if (entity.y > windowHeight){
entity.y = 0; entity.y = 0;
} }
if (entity.y < 0){ if (entity.y < 0){
entity.y = windowHeight / (worldScale.value() /100); entity.y = windowHeight;
} }
} }
//Draw Entity //Draw Entity
drawEntity(entity); drawEntity(entity);
} }
if (Settings.respawn){
if(Settings.emptyEntries.length > 5){
if(frameCount % 20 == 0){
createEntity(
Math.floor(Math.random() * windowWidth)+windowHeight, //X Location
Math.floor(Math.random() * windowHeight)+windowHeight, //Y Location
(Math.random() * maxSpeed * 2)-maxSpeed, //X Velocity
(Math.random() * maxSpeed * 2)-maxSpeed, //Y Velocity
0.0, //X Acceleration
0.0, //Y Acceleration
0.0, //Current Rotation
(Math.random() * 2 *(Math.PI / Settings.rotationSpeed))-(Math.PI / Settings.rotationSpeed), //Rotation Velocity
getRandomType()
);
}
}
}
} }
function windowResized() { function windowResized() {

View File

@ -244,10 +244,9 @@ a.member{
@media (max-width: 800px){ @media (max-width: 800px){
div.post{ div.post{
width: auto; width: 40vw;
} }
ul.member{
ul.mebere{
margin: 0 0 0 0; margin: 0 0 0 0;
} }
li.member{ li.member{
@ -281,6 +280,13 @@ a.member{
left: 30vw; left: 30vw;
right: 30vw; right: 30vw;
} }
canvas{
position: fixed;
bottom: 0;
top: 0;
left: 0;
right: 0;
}
} }