Compare commits
2 Commits
3bf4e2fdd9
...
4a847a74d9
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a847a74d9 | |||
| 4272edd145 |
@ -13,7 +13,7 @@
|
|||||||
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
|
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1 id="intotitle">Welcome to the Void System</h1>
|
<h1 id="introtitle">Welcome to the Void System</h1>
|
||||||
<div id="mainview">
|
<div id="mainview">
|
||||||
<div id="postarea">
|
<div id="postarea">
|
||||||
<div id="blogList">
|
<div id="blogList">
|
||||||
|
|||||||
@ -2,7 +2,7 @@ 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 = {
|
||||||
@ -24,16 +24,19 @@ function getMass(type){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createEntity(x, y, vx, vy, type){
|
function createEntity(x, y, vx, vy, ax, ay, rot, rotv, type){
|
||||||
let entity = {
|
let entity = {
|
||||||
x: x,
|
x: x,
|
||||||
y: y,
|
y: y,
|
||||||
ax: 0.0,
|
ax: ax,
|
||||||
ay: 0.0,
|
ay: ay,
|
||||||
vx: vx,
|
vx: vx,
|
||||||
vy: vy,
|
vy: vy,
|
||||||
rot: 0,
|
rot: rot,
|
||||||
|
rotv: rotv,
|
||||||
mass: getMass(type),
|
mass: getMass(type),
|
||||||
|
forcex: 0.0,
|
||||||
|
forcey: 0.0,
|
||||||
type: type,
|
type: type,
|
||||||
}
|
}
|
||||||
simulator.push(entity);
|
simulator.push(entity);
|
||||||
@ -57,9 +60,30 @@ function physicsUpdate(entity){
|
|||||||
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onHit(entity){
|
function onHit(entity1, entity2){
|
||||||
|
if(entity1.type == entityTypes.METERORITE_LARGE){
|
||||||
|
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{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function Explode(entity){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,8 +100,13 @@ function drawBackground(refImage){
|
|||||||
function drawEntity(entity){
|
function drawEntity(entity){
|
||||||
push();
|
push();
|
||||||
imageMode(CENTER);
|
imageMode(CENTER);
|
||||||
translate(entity.x, entity.y, 0);
|
translate(entity.x*(worldScale.value()/100), entity.y*(worldScale.value()/100), 0);
|
||||||
rotate((Math.atan2(entity.vx, entity.vy) - Math.atan2(-1,0)) * 180/Math.PI);
|
if (entity.type == entityTypes.COMET){
|
||||||
|
rotate((Math.atan2(entity.vx, entity.vy) - Math.atan2(-1,0)) * 180/Math.PI);
|
||||||
|
|
||||||
|
}else{
|
||||||
|
rotate(entity.rot);
|
||||||
|
}
|
||||||
image(images[entity.type], 0,0);
|
image(images[entity.type], 0,0);
|
||||||
pop();
|
pop();
|
||||||
}
|
}
|
||||||
@ -96,15 +125,20 @@ 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 entityCount = 50;
|
||||||
|
let rotationSpeed = 100.0;
|
||||||
for(let i = 0; i <= entityCount; i+=1){
|
for(let i = 0; i <= entityCount; i+=1){
|
||||||
createEntity(
|
createEntity(
|
||||||
Math.floor(Math.random() * windowWidth),
|
Math.floor(Math.random() * windowWidth), //X Location
|
||||||
Math.floor(Math.random() * windowHeight),
|
Math.floor(Math.random() * windowHeight), //Y Location
|
||||||
(Math.random() * maxSpeed * 2)-maxSpeed,
|
(Math.random() * maxSpeed * 2)-maxSpeed, //X Velocity
|
||||||
(Math.random() * maxSpeed * 2)-maxSpeed,
|
(Math.random() * maxSpeed * 2)-maxSpeed, //Y Velocity
|
||||||
|
0.0, //X Acceleration
|
||||||
|
0.0, //Y Acceleration
|
||||||
|
0.0, //Current Rotation
|
||||||
|
(Math.random() * 2 *(Math.PI / rotationSpeed))-(Math.PI / rotationSpeed), //Rotation Velocity
|
||||||
getRandomType(),
|
getRandomType(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -115,6 +149,7 @@ function mouseClicked(){
|
|||||||
simulator.forEach((entity) =>{
|
simulator.forEach((entity) =>{
|
||||||
|
|
||||||
})
|
})
|
||||||
|
console.log(worldScale.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw(){
|
function draw(){
|
||||||
@ -132,20 +167,24 @@ function draw(){
|
|||||||
|
|
||||||
//Window Wrap
|
//Window Wrap
|
||||||
if (Settings.windowWrap){
|
if (Settings.windowWrap){
|
||||||
if (entity.x > windowWidth){
|
if (entity.x * (worldScale.value() /100) > windowWidth){
|
||||||
entity.x = 0;
|
entity.x = 0;
|
||||||
}
|
}
|
||||||
if (entity.x < 0){
|
if (entity.x < 0){
|
||||||
entity.x = windowWidth;
|
entity.x = windowWidth / (worldScale.value() /100);
|
||||||
}
|
}
|
||||||
if (entity.y > windowHeight){
|
if (entity.y * (worldScale.value() /100) > windowHeight){
|
||||||
entity.y = 0;
|
entity.y = 0;
|
||||||
}
|
}
|
||||||
if (entity.y < 0){
|
if (entity.y < 0){
|
||||||
entity.y = windowHeight;
|
entity.y = windowHeight / (worldScale.value() /100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Draw Entity
|
//Draw Entity
|
||||||
drawEntity(entity);
|
drawEntity(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function windowResized() {
|
||||||
|
resizeCanvas(windowWidth, windowHeight);
|
||||||
|
}
|
||||||
@ -12,7 +12,7 @@ body{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h1{
|
#introtitle{
|
||||||
font-family: SPACEMAN;
|
font-family: SPACEMAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@ a{
|
|||||||
cursor:crosshair;
|
cursor:crosshair;
|
||||||
}
|
}
|
||||||
|
|
||||||
#intotitle{
|
#introtitle{
|
||||||
text-align: center;
|
text-align: center;
|
||||||
size: 50pt;
|
size: 50pt;
|
||||||
margin: 50px;
|
margin: 50px;
|
||||||
|
|||||||
Reference in New Issue
Block a user