import { Actor, Solid, WithVelocity } from '@dill-pixel/plugin-snap-physics';
import { Signal, Size } from 'dill-pixel';
import { Texture } from 'pixi.js';
type BasicSolidConfig = {
type BasicActorConfig = {
export class BasicActor<T extends BasicActorConfig = BasicActorConfig> extends Actor<T, V8Application> {
static speed: number = 5;
static onActivated = new Signal<(actor: BasicActor) => void>();
constructor(config?: Partial<T>) {
private _active: boolean = false;
set active(value: boolean) {
if (this._active === value) {
BasicActor.onActivated.emit(this);
this.eventMode = 'static';
this.on('pointerup', this._setActive);
this.off('pointerup', this._setActive);
update(deltaTime?: number) {
if (this.app.isActionActive('move_left')) {
this.moveX(-BasicActor.speed);
if (this.app.isActionActive('move_right')) {
this.moveX(BasicActor.speed);
if (this.app.isActionActive('jump')) {
this.moveY(-BasicActor.speed);
if (this.app.isActionActive('move_down')) {
this.moveY(BasicActor.speed);
this.view.tint = this._active ? (this.config.activeColor ?? this.config.color) : this.config.color;
export class BasicSolid<T extends BasicSolidConfig = BasicSolidConfig> extends Solid<T> {
static onActivated = new Signal<(actor: BasicActor) => void>();
constructor(config?: Partial<T>) {
this.interactiveChildren = false;
this.view.tint = this.config.color;
type CircActorConfig = BasicActorConfig & {
type RectActorConfig = BasicActorConfig & {
type RectSolidConfig = BasicSolidConfig & {
type CircSolidConfig = BasicSolidConfig & {
export class CircActor extends BasicActor<CircActorConfig> {
static defaults: CircActorConfig = {
constructor(config?: Partial<CircActorConfig>) {
super({ ...CircActor.defaults, ...(config ?? {}) });
if (!CircActor.texture) {
const gfx = this.make.graphics().circle(0, 0, 250).fill({ color: 0xffffff });
CircActor.texture = this.app.renderer.generateTexture(gfx);
this.view = this.add.sprite({
asset: CircActor.texture,
width: this.config.radius * 2,
height: this.config.radius * 2,
init(config?: Partial<CircActorConfig>) {
this.config = { ...CircActor.defaults, ...(config ?? {}) };
this.removeChild(this.view);
export class RectActor extends BasicActor<RectActorConfig> {
static defaults: RectActorConfig = {
size: { width: 200, height: 100 },
constructor(config?: Partial<RectActorConfig>) {
super({ ...RectActor.defaults, ...(config ?? {}) });
.rect(0, 0, this.config.size.width, this.config.size.height)
.fill({ color: 0xffffff });
this.view = this.add.sprite({ asset: this.app.renderer.generateTexture(gfx), anchor: 0.5 });
init(config?: Partial<RectActorConfig>) {
this.config = { ...RectActor.defaults, ...(config ?? {}) };
this.removeChild(this.view);
export class RectSolid extends BasicSolid<RectSolidConfig> {
static defaults: RectSolidConfig = {
size: { width: 150, height: 100 },
constructor(config?: Partial<RectSolidConfig>) {
super({ ...RectSolid.defaults, ...(config ?? {}) });
.rect(0, 0, this.config.size.width, this.config.size.height)
.fill({ color: 0xffffff });
this.view = this.add.sprite({ asset: this.app.renderer.generateTexture(gfx), anchor: 0.5 });
export class CircSolid extends BasicSolid<CircSolidConfig> {
static defaults: CircSolidConfig = {
constructor(config?: Partial<CircSolidConfig>) {
super({ ...CircSolid.defaults, ...(config ?? {}) });
const gfx = this.make.graphics().circle(0, 0, this.config.radius).fill({ color: 0xffffff });
this.view = this.add.sprite({ asset: this.app.renderer.generateTexture(gfx), anchor: 0.5 });
export class Projectile extends WithVelocity(CircActor) {
this.interactiveChildren = false;
update(deltaTime: number) {
this.moveByVelocity(deltaTime);