improcket/js/world/celestial.mjs
Asraelite c73130e3ff General improvements
I forgot what I actually changed. It may not even be playable, I just want to get this up there.
2023-03-31 11:43:56 +02:00

42 lines
1.1 KiB
JavaScript

import {tempCanvas, tempContext} from '../graphics/index.mjs';
import {images as assets} from '../assets.mjs';
import Body from './body.mjs';
import { PLANET_IMAGE_SIZE } from '../consts.mjs';
export default class Celestial extends Body {
constructor(x, y, radius, {
density = 1,
type = 'rock'
}) {
let mass = (radius ** 2) * density
super(x, y, mass);
this.radius = radius;
this.type = type;
const imageArr = Object.values(assets.celestials[this.type]);
const svgImage = imageArr[Math.random() * imageArr.length | 0];
tempCanvas.width = PLANET_IMAGE_SIZE;
tempCanvas.height = PLANET_IMAGE_SIZE;
tempContext.clearRect(0, 0, PLANET_IMAGE_SIZE, PLANET_IMAGE_SIZE);
tempContext.drawImage(svgImage, 0, 0, PLANET_IMAGE_SIZE, PLANET_IMAGE_SIZE);
this.image = new Image();
this.image.src = tempCanvas.toDataURL();
// this.image = tempContext.getImageData(0, 0, PLANET_IMAGE_SIZE, PLANET_IMAGE_SIZE);
}
get com() {
return [this.x + this.radius, this.y + this.radius];
}
get escapeVelocity() {
}
tick() {
}
get diameter() {
return this.radius * 2;
}
}