import { Container } from 'pixi';
import Velocity from './velocity.js';

/**
 * Base class for the game objects that are simulated client-side (starships and weapon shots).
 *
 * Positions (xx, yy) are expressed in the server-side simulation space (pixels). The display
 * container is placed in the "world" container of the game, with the y axis flipped so that the
 * server-side y-up space matches the screen y-down space.
 */
export default class GameItem
{
	constructor()
	{
		this.xx = 0;
		this.yy = 0;
		this.velocity = new Velocity();
		this.lastRenderTime = performance.now();

		this.container = new Container();
	}

	/**
	 * Place the display container at the current simulation position (with the y axis flipped).
	 */
	updatePosition()
	{
		this.container.x = this.xx;
		this.container.y = -this.yy;
	}

	destroy()
	{
		this.container.destroy({ children: true });
	}
}
