Refactor shapes

This commit is contained in:
schmelczerandras 2020-08-16 10:24:12 +02:00
parent eb39846b75
commit 006ab3c4e6
24 changed files with 203 additions and 256 deletions

View file

@ -3,7 +3,7 @@ import { BeforeRenderCommand } from '../../drawing/commands/before-render';
import { CursorMoveCommand } from '../../input/commands/cursor-move-command';
import { ZoomCommand } from '../../input/commands/zoom';
import { MoveToCommand } from '../../physics/commands/move-to';
import { BoundingBox } from '../../physics/containers/bounding-box';
import { BoundingBox } from '../../shapes/bounding-box';
import { Physics } from '../../physics/physics';
import { GameObject } from '../game-object';
import { Lamp } from './lamp';

View file

@ -1,5 +1,5 @@
import { vec2 } from 'gl-matrix';
import { Circle } from '../../drawing/drawables/primitives/circle';
import { Circle } from '../../shapes/types/circle';
import { KeyDownCommand } from '../../input/commands/key-down';
import { KeyUpCommand } from '../../input/commands/key-up';
import { SwipeCommand } from '../../input/commands/swipe';
@ -19,7 +19,7 @@ export class Character extends GameObject {
constructor(private physics: Physics, private camera: Camera) {
super();
this.primitive = new Circle(this);
this.primitive = new Circle();
this.primitive.radius = 40;
this.addCommandExecutor(StepCommand, this.stepHandler.bind(this));
@ -45,9 +45,9 @@ export class Character extends GameObject {
const intersects = this.physics
.findIntersecting(nextPrimitive.boundingBox)
.filter((b) => b.value)
.filter((b) => b.shape)
.map(
(b) => b.value.distance(nextPrimitive.center) + nextPrimitive.radius
(b) => b.shape.distance(nextPrimitive.center) + nextPrimitive.radius
);
console.log(intersects);

View file

@ -2,12 +2,11 @@ import { vec2 } from 'gl-matrix';
import { GameObject } from '../game-object';
import { RenderCommand } from '../../drawing/commands/render';
import { Physics } from '../../physics/physics';
import { TunnelShape } from '../../drawing/drawables/primitives/tunnel-shape';
export interface Line {}
import { TunnelShape } from '../../shapes/types/tunnel-shape';
import { DrawableTunnel } from '../../drawing/drawables/drawable-tunnel';
export class Tunnel extends GameObject {
private primitive: TunnelShape;
private shape: DrawableTunnel;
constructor(
physics: Physics,
@ -18,12 +17,12 @@ export class Tunnel extends GameObject {
) {
super();
this.primitive = new TunnelShape(this, from, to, fromRadius, toRadius);
physics.addStaticBoundingBox(this.primitive.boundingBox);
this.shape = new DrawableTunnel(from, to, fromRadius, toRadius);
physics.addStaticBoundingBox(this.shape.boundingBox);
this.addCommandExecutor(RenderCommand, this.draw.bind(this));
}
private draw(c: RenderCommand) {
c.renderer.drawPrimitive(this.primitive);
c.renderer.drawShape(this.shape);
}
}