Add blob and fix some issues
This commit is contained in:
parent
5b4e67cbf0
commit
edca93fcfe
13 changed files with 237 additions and 67 deletions
|
|
@ -13,11 +13,10 @@ export class Camera extends GameObject {
|
|||
private cursorPosition = vec2.create();
|
||||
private boundingBox: BoundingBox;
|
||||
|
||||
constructor(physics: Physics, private light: Lamp) {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.boundingBox = new BoundingBox(null);
|
||||
//physics.addDynamicBoundingBox(this.boundingBox);
|
||||
|
||||
this.addCommandExecutor(BeforeRenderCommand, this.draw.bind(this));
|
||||
this.addCommandExecutor(MoveToCommand, this.moveTo.bind(this));
|
||||
|
|
@ -40,7 +39,6 @@ export class Camera extends GameObject {
|
|||
|
||||
private moveTo(c: MoveToCommand) {
|
||||
this.boundingBox.topLeft = c.position;
|
||||
this.light.sendCommand(c);
|
||||
}
|
||||
|
||||
private zoom(c: ZoomCommand) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
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';
|
||||
|
|
@ -10,22 +9,28 @@ import { Physics } from '../../physics/physics';
|
|||
import { GameObject } from '../game-object';
|
||||
import { Camera } from './camera';
|
||||
import { IShape } from '../../shapes/i-shape';
|
||||
import { rotate90Deg } from '../../helper/rotate-90-deg';
|
||||
import { max } from 'gl-matrix/src/gl-matrix/vec2';
|
||||
import { Blob } from '../../shapes/types/blob';
|
||||
import { RenderCommand } from '../../drawing/commands/render';
|
||||
import { DrawableBlob } from '../../drawing/drawables/drawable-blob';
|
||||
import { Lamp } from './lamp';
|
||||
|
||||
export class Character extends GameObject {
|
||||
private keysDown: Set<string> = new Set();
|
||||
|
||||
private shape: Circle;
|
||||
private shape: DrawableBlob;
|
||||
private static speed = 1.5;
|
||||
|
||||
constructor(private physics: Physics, private camera: Camera) {
|
||||
constructor(
|
||||
private physics: Physics,
|
||||
private camera: Camera,
|
||||
private light: Lamp
|
||||
) {
|
||||
super();
|
||||
|
||||
this.shape = new Circle();
|
||||
this.shape.radius = 80;
|
||||
this.shape = new DrawableBlob(vec2.create());
|
||||
|
||||
this.addCommandExecutor(StepCommand, this.stepHandler.bind(this));
|
||||
this.addCommandExecutor(RenderCommand, this.draw.bind(this));
|
||||
this.addCommandExecutor(TeleportToCommand, (c) =>
|
||||
this.setPosition(c.position)
|
||||
);
|
||||
|
|
@ -38,6 +43,10 @@ export class Character extends GameObject {
|
|||
});
|
||||
}
|
||||
|
||||
private draw(c: RenderCommand) {
|
||||
c.renderer.drawShape(this.shape);
|
||||
}
|
||||
|
||||
private tryMoving(delta: vec2, isFirstIteration = true) {
|
||||
const maxStep = 2;
|
||||
if (vec2.length(delta) > maxStep) {
|
||||
|
|
@ -95,7 +104,7 @@ export class Character extends GameObject {
|
|||
}
|
||||
|
||||
private getNearShapesTo(
|
||||
shape: Circle
|
||||
shape: Blob
|
||||
): Array<{ shape: IShape; distance: number }> {
|
||||
return this.physics
|
||||
.findIntersecting(shape.boundingBox)
|
||||
|
|
@ -108,8 +117,10 @@ export class Character extends GameObject {
|
|||
}
|
||||
|
||||
private setPosition(value: vec2) {
|
||||
this.shape.center = value;
|
||||
this.camera.sendCommand(new MoveToCommand(this.shape.center));
|
||||
this.shape.position = value;
|
||||
this.camera.sendCommand(new MoveToCommand(value));
|
||||
vec2.add(value, value, vec2.fromValues(80, 0));
|
||||
this.light.sendCommand(new MoveToCommand(value));
|
||||
}
|
||||
|
||||
public stepHandler(c: StepCommand) {
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ export const createCharacter = (
|
|||
2
|
||||
);
|
||||
|
||||
const camera = new Camera(physics, light);
|
||||
const character = new Character(physics, camera);
|
||||
const camera = new Camera();
|
||||
const character = new Character(physics, camera, light);
|
||||
objects.addObject(light);
|
||||
objects.addObject(camera);
|
||||
objects.addObject(character);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue