Compare commits
14 Commits
4a847a74d9
...
e6daabf16d
| Author | SHA1 | Date | |
|---|---|---|---|
| e6daabf16d | |||
| ab79e95734 | |||
| ffe9bc6156 | |||
| 24d0a07be9 | |||
| 2e9320f9ac | |||
| 7ad1dcc44b | |||
| 5084d969ba | |||
| dd29fb8571 | |||
| da186279b6 | |||
| 9ff7d3d284 | |||
| c5730952f9 | |||
| 210e190f11 | |||
| 1202cd0221 | |||
| 0b1a622b99 |
@ -159,4 +159,3 @@
|
|||||||
<script src="/javascript/remeber.js"></script>
|
<script src="/javascript/remeber.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
<!--Gitea Discord Test 2-->
|
|
||||||
|
|||||||
@ -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
|
||||||
Explode(entity1);
|
&& 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);
|
||||||
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,17 +161,18 @@ 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(){
|
||||||
@ -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() {
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user