Update colors

This commit is contained in:
schmelczerandras 2020-07-25 17:16:48 +02:00
parent 4ef6922da8
commit 9aef368324
8 changed files with 36 additions and 45 deletions

View file

@ -1,16 +1,16 @@
import { GameObject } from '../game-object';
import { vec2 } from 'gl-matrix';
import { BeforeDrawCommand } from '../../commands/types/before-draw';
import { CursorMoveCommand } from '../../commands/types/cursor-move-command';
import { MoveToCommand } from '../../commands/types/move-to';
import { ZoomCommand } from '../../commands/types/zoom';
import { BeforeDrawCommand } from '../../commands/types/before-draw';
import { PrimaryActionCommand } from '../../commands/types/primary-action';
import { vec2 } from 'gl-matrix';
import { CursorMoveCommand } from '../../commands/types/cursor-move-command';
import { GameObject } from '../game-object';
import { CircleLight } from './circle-light';
export class Camera extends GameObject {
private inViewArea = 1920 * 1080;
private cursorPosition = vec2.create();
constructor() {
constructor(private light: CircleLight) {
super();
this.addCommandExecutor(BeforeDrawCommand, this.draw.bind(this));
@ -30,6 +30,15 @@ export class Camera extends GameObject {
private moveTo(c: MoveToCommand) {
this._position = c.position;
this.light.sendCommand(
new MoveToCommand(
vec2.add(
vec2.create(),
c.position,
vec2.scale(vec2.create(), this.boundingBoxSize, 0.5)
)
)
);
}
private zoom(c: ZoomCommand) {

View file

@ -1,5 +1,6 @@
import { vec2, vec3 } from 'gl-matrix';
import { DrawCommand } from '../../commands/types/draw';
import { MoveToCommand } from '../../commands/types/move-to';
import { GameObject } from '../game-object';
export class CircleLight extends GameObject {
@ -11,6 +12,7 @@ export class CircleLight extends GameObject {
super();
this.addCommandExecutor(DrawCommand, this.draw.bind(this));
this.addCommandExecutor(MoveToCommand, this.moveTo.bind(this));
}
private draw(c: DrawCommand) {
@ -22,4 +24,8 @@ export class CircleLight extends GameObject {
});
}
}
private moveTo(c: MoveToCommand) {
this.center = c.position;
}
}

View file

@ -1,30 +0,0 @@
import { vec2, vec3 } from 'gl-matrix';
import { CursorMoveCommand } from '../../commands/types/cursor-move-command';
import { DrawCommand } from '../../commands/types/draw';
import { GameObject } from '../game-object';
export class CursorLight extends GameObject {
private mousePosition = vec2.create();
constructor(private radius: number, private value: vec3) {
super();
this.addCommandExecutor(DrawCommand, this.draw.bind(this));
this.addCommandExecutor(CursorMoveCommand, this.setPosition.bind(this));
}
private draw(c: DrawCommand) {
const center = c.drawer.screenUvToWorldCoordinate(this.mousePosition);
if (c.drawer.isOnScreen(center)) {
c.drawer.appendToUniformList('lights', {
center,
radius: this.radius,
value: this.value,
});
}
}
private setPosition(c: CursorMoveCommand) {
this.mousePosition = c.position;
}
}

View file

@ -1,12 +1,18 @@
import { vec3 } from 'gl-matrix';
import { vec2, vec3 } from 'gl-matrix';
import { ObjectContainer } from '../object-container';
import { Camera } from '../types/camera';
import { Character } from '../types/character';
import { CursorLight } from '../types/cursor-light';
import { CircleLight } from '../types/circle-light';
export const createCharacter = (objects: ObjectContainer) => {
const camera = new Camera();
const light = new CircleLight(
vec2.create(),
40,
vec3.fromValues(0.67, 0.0, 0.33)
);
const camera = new Camera(light);
objects.addObject(light);
objects.addObject(camera);
objects.addObject(new Character(camera));
objects.addObject(new CursorLight(40, vec3.fromValues(0.67, 0.67, 0.33)));
};

View file

@ -24,7 +24,7 @@ export const createDungeon = (objects: ObjectContainer) => {
Math.random() * 20 + 30,
vec3.scale(
vec3.create(),
vec3.normalize(vec3.create(), vec3.random(vec3.create())),
vec3.normalize(vec3.create(), vec3.fromValues(0.5, 0.1, 0.8)),
Math.random() * 0.5 + 0.5
)
)