Fix should draw condition
This commit is contained in:
parent
9aef368324
commit
b6bef3c77d
9 changed files with 54 additions and 15 deletions
|
|
@ -7,7 +7,7 @@ import { GameObject } from '../game-object';
|
|||
import { CircleLight } from './circle-light';
|
||||
|
||||
export class Camera extends GameObject {
|
||||
private inViewArea = 1920 * 1080;
|
||||
private inViewArea = 1920 * 1080 * 5;
|
||||
private cursorPosition = vec2.create();
|
||||
|
||||
constructor(private light: CircleLight) {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,14 @@
|
|||
import { vec2, vec3 } from 'gl-matrix';
|
||||
import { DrawCommand } from '../../commands/types/draw';
|
||||
import { MoveToCommand } from '../../commands/types/move-to';
|
||||
import { Circle } from '../../math/circle';
|
||||
import { GameObject } from '../game-object';
|
||||
|
||||
const range = 2000;
|
||||
|
||||
export class CircleLight extends GameObject {
|
||||
private boundingCircle: Circle;
|
||||
|
||||
constructor(
|
||||
private center: vec2,
|
||||
private radius: number,
|
||||
|
|
@ -11,12 +16,14 @@ export class CircleLight extends GameObject {
|
|||
) {
|
||||
super();
|
||||
|
||||
this.boundingCircle = new Circle(center, range);
|
||||
|
||||
this.addCommandExecutor(DrawCommand, this.draw.bind(this));
|
||||
this.addCommandExecutor(MoveToCommand, this.moveTo.bind(this));
|
||||
}
|
||||
|
||||
private draw(c: DrawCommand) {
|
||||
if (c.drawer.isOnScreen(this.center)) {
|
||||
if (c.drawer.isOnScreen(this.boundingCircle)) {
|
||||
c.drawer.appendToUniformList('lights', {
|
||||
center: this.center,
|
||||
radius: this.radius,
|
||||
|
|
@ -27,5 +34,6 @@ export class CircleLight extends GameObject {
|
|||
|
||||
private moveTo(c: MoveToCommand) {
|
||||
this.center = c.position;
|
||||
this.boundingCircle.center = c.position;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { DrawCommand } from '../../commands/types/draw';
|
||||
import { Circle } from '../../math/circle';
|
||||
import { GameObject } from '../game-object';
|
||||
|
||||
export interface Line {}
|
||||
|
||||
export class Tunnel extends GameObject {
|
||||
private boundingCircle: Circle;
|
||||
|
||||
constructor(
|
||||
private from: vec2,
|
||||
private to: vec2,
|
||||
|
|
@ -13,11 +16,15 @@ export class Tunnel extends GameObject {
|
|||
) {
|
||||
super();
|
||||
|
||||
this.boundingCircle = new Circle(
|
||||
vec2.fromValues(from.x / 2 + to.x / 2, from.y / 2 + to.y / 2),
|
||||
radiusFrom + radiusTo + vec2.distance(from, to)
|
||||
);
|
||||
this.addCommandExecutor(DrawCommand, this.draw.bind(this));
|
||||
}
|
||||
|
||||
private draw(c: DrawCommand) {
|
||||
if (c.drawer.isOnScreen(this.from) || c.drawer.isOnScreen(this.to)) {
|
||||
if (c.drawer.isOnScreen(this.boundingCircle)) {
|
||||
c.drawer.appendToUniformList('lines', this.from, this.to);
|
||||
c.drawer.appendToUniformList('radii', this.radiusFrom, this.radiusTo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export const createDungeon = (objects: ObjectContainer) => {
|
|||
new Tunnel(previousEnd, currentEnd, previousRadius, currentToRadius)
|
||||
);
|
||||
|
||||
if (deltaHeight > 0) {
|
||||
if (deltaHeight > 0 && Math.random() > 0.5) {
|
||||
objects.addObject(
|
||||
new CircleLight(
|
||||
currentEnd,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue