Fix some bugs
This commit is contained in:
parent
345e183e34
commit
15151e53a7
10 changed files with 69 additions and 74 deletions
|
|
@ -1,12 +1,12 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { BeforeRenderCommand } from '../../drawing/commands/before-render';
|
||||
import { CursorMoveCommand } from '../../input/commands/cursor-move-command';
|
||||
import { GameObject } from '../game-object';
|
||||
import { Lamp } from './lamp';
|
||||
import { ZoomCommand } from '../../input/commands/zoom';
|
||||
import { MoveToCommand } from '../../physics/commands/move-to';
|
||||
import { BoundingBox } from '../../physics/containers/bounding-box';
|
||||
import { Physics } from '../../physics/physics';
|
||||
import { GameObject } from '../game-object';
|
||||
import { Lamp } from './lamp';
|
||||
|
||||
export class Camera extends GameObject {
|
||||
private inViewArea = 1920 * 1080 * 5;
|
||||
|
|
@ -33,25 +33,14 @@ export class Camera extends GameObject {
|
|||
}
|
||||
|
||||
private draw(c: BeforeRenderCommand) {
|
||||
console.log('camera', this.boundingBox.topLeft);
|
||||
|
||||
c.renderer.setCameraPosition(this.boundingBox.topLeft);
|
||||
c.renderer.setCursorPosition(this.cursorPosition);
|
||||
this.boundingBox.size = c.renderer.setInViewArea(this.inViewArea);
|
||||
}
|
||||
|
||||
private moveTo(c: MoveToCommand) {
|
||||
console.log('camera', c.position);
|
||||
this.boundingBox.topLeft = c.position;
|
||||
this.light.sendCommand(
|
||||
new MoveToCommand(
|
||||
vec2.add(
|
||||
vec2.create(),
|
||||
c.position,
|
||||
vec2.scale(vec2.create(), this.boundingBox.size, 0.5)
|
||||
)
|
||||
)
|
||||
);
|
||||
this.light.sendCommand(c);
|
||||
}
|
||||
|
||||
private zoom(c: ZoomCommand) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import { SwipeCommand } from '../../input/commands/swipe';
|
|||
import { MoveToCommand } from '../../physics/commands/move-to';
|
||||
import { StepCommand } from '../../physics/commands/step';
|
||||
import { TeleportToCommand } from '../../physics/commands/teleport-to';
|
||||
import { BoundingBox } from '../../physics/containers/bounding-box';
|
||||
import { Physics } from '../../physics/physics';
|
||||
import { GameObject } from '../game-object';
|
||||
import { Camera } from './camera';
|
||||
|
|
@ -21,7 +20,7 @@ export class Character extends GameObject {
|
|||
super();
|
||||
|
||||
this.primitive = new Circle(this);
|
||||
this.primitive.radius = 20;
|
||||
this.primitive.radius = 40;
|
||||
|
||||
this.addCommandExecutor(StepCommand, this.stepHandler.bind(this));
|
||||
this.addCommandExecutor(TeleportToCommand, (c) =>
|
||||
|
|
@ -41,29 +40,20 @@ export class Character extends GameObject {
|
|||
}
|
||||
|
||||
private checkAndSetPosition(value: vec2) {
|
||||
const size = this.camera.viewAreaSize;
|
||||
const realCenter = vec2.fromValues(
|
||||
value.x + size.x / 2,
|
||||
value.y + size.y / 2
|
||||
);
|
||||
const nextPrimitive = this.primitive.clone();
|
||||
nextPrimitive.center = value;
|
||||
|
||||
const targetBoundingBox = new BoundingBox(
|
||||
null,
|
||||
value.x + size.x / 2,
|
||||
value.x + size.x / 2 + 10,
|
||||
value.y + size.y / 2,
|
||||
value.y + size.y / 2 + 10
|
||||
);
|
||||
console.log(this.physics
|
||||
.findIntersecting(nextPrimitive.boundingBox)
|
||||
.filter(b => b.value)
|
||||
.map((b) => b.value.distance(nextPrimitive.center) + 2 * nextPrimitive.radius)
|
||||
)
|
||||
|
||||
console.log(
|
||||
this.physics
|
||||
.findIntersecting(targetBoundingBox)
|
||||
.map((b) => b.value.distance(realCenter))
|
||||
);
|
||||
if (
|
||||
this.physics
|
||||
.findIntersecting(targetBoundingBox)
|
||||
.map((b) => b.value.distance(realCenter))
|
||||
.findIntersecting(nextPrimitive.boundingBox)
|
||||
.filter(b => b.value)
|
||||
.map((b) => b.value.distance(nextPrimitive.center) + 2 * nextPrimitive.radius)
|
||||
.find((d) => d < 0) !== undefined
|
||||
) {
|
||||
this.setPosition(value);
|
||||
|
|
@ -71,7 +61,7 @@ export class Character extends GameObject {
|
|||
}
|
||||
|
||||
private setPosition(value: vec2) {
|
||||
console.log('character', value);
|
||||
// console.log('character', value);
|
||||
|
||||
this.primitive.center = value;
|
||||
this.camera.sendCommand(new MoveToCommand(this.primitive.center));
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import { vec2, vec3 } from 'gl-matrix';
|
||||
import { vec2 } from 'gl-matrix';
|
||||
import { Physics } from '../../physics/physics';
|
||||
import { Objects } from '../objects';
|
||||
import { Tunnel } from '../types/tunnel';
|
||||
import { Physics } from '../../physics/physics';
|
||||
import { GameObject } from '../game-object';
|
||||
|
||||
export const createDungeon = (objects: Objects, physics: Physics): Tunnel => {
|
||||
let previousRadius = 350;
|
||||
|
|
@ -10,7 +9,7 @@ export const createDungeon = (objects: Objects, physics: Physics): Tunnel => {
|
|||
|
||||
let first: Tunnel;
|
||||
|
||||
for (let i = 0; i < 1; i += 500) {
|
||||
for (let i = 0; i < 50000; i += 500) {
|
||||
const deltaHeight = (Math.random() - 0.5) * 2000;
|
||||
const height = previousEnd.y + deltaHeight;
|
||||
const currentEnd = vec2.fromValues(i, height);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue