mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2024-11-23 08:00:51 +01:00
Add shake & rotate
This commit is contained in:
parent
55ac359959
commit
178ca3c2b4
@ -21,6 +21,10 @@ export interface IRoomRenderingCanvas
|
||||
handleMouseEvent(x: number, y: number, type: string, altKey: boolean, ctrlKey: boolean, shiftKey: boolean, buttonDown: boolean): boolean;
|
||||
getSortableSpriteList(): RoomObjectSpriteData[];
|
||||
getDisplayAsTexture(): RenderTexture;
|
||||
moveLeft(): void;
|
||||
moveRight(): void;
|
||||
moveUp(): void;
|
||||
moveDown(): void;
|
||||
id: number;
|
||||
geometry: IRoomGeometry;
|
||||
master: DisplayObject;
|
||||
|
@ -12,6 +12,7 @@ import { RoomObjectSpriteType } from '../object/enum/RoomObjectSpriteType';
|
||||
import { IRoomObject } from '../object/IRoomObject';
|
||||
import { IRoomObjectSprite } from '../object/visualization/IRoomObjectSprite';
|
||||
import { IRoomObjectSpriteVisualization } from '../object/visualization/IRoomObjectSpriteVisualization';
|
||||
import { RoomRotatingEffect, RoomShakingEffect } from '../utils';
|
||||
import { IRoomGeometry } from '../utils/IRoomGeometry';
|
||||
import { RoomEnterEffect } from '../utils/RoomEnterEffect';
|
||||
import { RoomGeometry } from '../utils/RoomGeometry';
|
||||
@ -63,6 +64,14 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
|
||||
private _eventId: number;
|
||||
private _scale: number;
|
||||
|
||||
private _SafeStr_4507: boolean = false;
|
||||
private _rotation: number = 0;
|
||||
private _rotationOrigin: Vector3d = null;
|
||||
private _rotationRodLength: number = 0;
|
||||
private _effectDirection: Vector3d;
|
||||
private _effectLocation: Vector3d;
|
||||
private _SafeStr_795: number = 0;
|
||||
|
||||
private _restrictsScaling: boolean;
|
||||
private _noSpriteVisibilityChecking: boolean;
|
||||
private _usesExclusionRectangles: boolean;
|
||||
@ -336,6 +345,8 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
|
||||
|
||||
if(!this._container || !this._geometry) return;
|
||||
|
||||
this.doMagic();
|
||||
|
||||
if((this._width !== this._renderedWidth) || (this._height !== this._renderedHeight)) update = true;
|
||||
|
||||
if((this._display.x !== this._screenOffsetX) || (this._display.y !== this._screenOffsetY))
|
||||
@ -1033,6 +1044,177 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
|
||||
return renderTexture;
|
||||
}
|
||||
|
||||
private doMagic(): void
|
||||
{
|
||||
const geometry = (this.geometry as RoomGeometry);
|
||||
|
||||
if(this._rotation !== 0)
|
||||
{
|
||||
let direction = this._effectDirection;
|
||||
|
||||
geometry.direction = new Vector3d((direction.x + this._rotation), direction.y, direction.z);
|
||||
|
||||
direction = (geometry.direction as Vector3d);
|
||||
|
||||
geometry.setDepthVector(new Vector3d(direction.x, direction.y, 5));
|
||||
|
||||
const location = new Vector3d();
|
||||
|
||||
location.assign(this._rotationOrigin);
|
||||
|
||||
location.x = (location.x + ((this._rotationRodLength * Math.cos((((direction.x + 180) / 180) * 3.14159265358979))) * Math.cos(((direction.y / 180) * 3.14159265358979))));
|
||||
location.y = (location.y + ((this._rotationRodLength * Math.sin((((direction.x + 180) / 180) * 3.14159265358979))) * Math.cos(((direction.y / 180) * 3.14159265358979))));
|
||||
location.z = (location.z + (this._rotationRodLength * Math.sin(((direction.y / 180) * 3.14159265358979))));
|
||||
|
||||
geometry.location = location;
|
||||
|
||||
this._effectLocation = new Vector3d();
|
||||
this._effectLocation.assign(location);
|
||||
this._effectDirection = new Vector3d();
|
||||
this._effectDirection.assign(geometry.direction);
|
||||
}
|
||||
|
||||
if(RoomShakingEffect.isVisualizationOn() && !this._SafeStr_4507)
|
||||
{
|
||||
this.changeShaking();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!RoomShakingEffect.isVisualizationOn() && this._SafeStr_4507) this.changeShaking();
|
||||
}
|
||||
|
||||
if(RoomRotatingEffect.isVisualizationOn()) this.changeRotation();
|
||||
|
||||
if(this._SafeStr_4507)
|
||||
{
|
||||
this._SafeStr_795++;
|
||||
|
||||
const _local_4 = this._effectDirection;
|
||||
const _local_1 = Vector3d.sum(_local_4, new Vector3d((Math.sin((((this._SafeStr_795 * 5) / 180) * 3.14159265358979)) * 2), (Math.sin(((this._SafeStr_795 / 180) * 3.14159265358979)) * 5), (Math.sin((((this._SafeStr_795 * 10) / 180) * 3.14159265358979)) * 2)));
|
||||
|
||||
geometry.direction = _local_1;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._SafeStr_795 = 0;
|
||||
|
||||
geometry.direction = this._effectDirection;
|
||||
}
|
||||
}
|
||||
|
||||
private changeShaking(): void
|
||||
{
|
||||
this._SafeStr_4507 = !this._SafeStr_4507;
|
||||
|
||||
if(this._SafeStr_4507)
|
||||
{
|
||||
const direction = this.geometry.direction;
|
||||
|
||||
this._effectDirection = new Vector3d(direction.x, direction.y, direction.z);
|
||||
}
|
||||
}
|
||||
|
||||
private changeRotation(): void
|
||||
{
|
||||
if(this._SafeStr_4507) return;
|
||||
|
||||
const geometry = (this.geometry as RoomGeometry);
|
||||
|
||||
if(!geometry) return;
|
||||
|
||||
if(this._rotation === 0)
|
||||
{
|
||||
const location = geometry.location;
|
||||
const directionAxis = geometry.directionAxis;
|
||||
|
||||
this._effectLocation = new Vector3d();
|
||||
this._effectLocation.assign(location);
|
||||
this._effectDirection = new Vector3d();
|
||||
this._effectDirection.assign(geometry.direction);
|
||||
|
||||
const intersection = RoomGeometry.getIntersectionVector(location, directionAxis, new Vector3d(0, 0, 0), new Vector3d(0, 0, 1));
|
||||
|
||||
if(intersection !== null)
|
||||
{
|
||||
this._rotationOrigin = new Vector3d(intersection.x, intersection.y, intersection.z);
|
||||
this._rotationRodLength = Vector3d.dif(intersection, location).length;
|
||||
this._rotation = 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this._rotation = 0;
|
||||
|
||||
geometry.location = this._effectLocation;
|
||||
geometry.direction = this._effectDirection;
|
||||
geometry.setDepthVector(new Vector3d(this._effectDirection.x, this._effectDirection.y, 5));
|
||||
}
|
||||
|
||||
public moveLeft(): void
|
||||
{
|
||||
if(this._rotation !== 0)
|
||||
{
|
||||
if(this._rotation === 1)
|
||||
{
|
||||
this._rotation = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._rotation = (this._rotation - 1);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const geometry = (this.geometry as RoomGeometry);
|
||||
const direction = (((geometry.direction.x - 90) / 180) * 3.14159265358979);
|
||||
|
||||
geometry.location = Vector3d.sum(geometry.location, new Vector3d((Math.cos(direction) * Math.sqrt(2)), (Math.sin(direction) * Math.sqrt(2))));
|
||||
}
|
||||
|
||||
public moveRight(): void
|
||||
{
|
||||
if(this._rotation !== 0)
|
||||
{
|
||||
if(this._rotation === -1)
|
||||
{
|
||||
this._rotation = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._rotation = (this._rotation + 1);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const geometry = (this.geometry as RoomGeometry);
|
||||
const direction = (((geometry.direction.x + 90) / 180) * 3.14159265358979);
|
||||
|
||||
geometry.location = Vector3d.sum(geometry.location, new Vector3d((Math.cos(direction) * Math.sqrt(2)), (Math.sin(direction) * Math.sqrt(2))));
|
||||
}
|
||||
|
||||
public moveUp(): void
|
||||
{
|
||||
if(this._rotation !== 0) return;
|
||||
|
||||
const geometry = (this.geometry as RoomGeometry);
|
||||
const direction = ((geometry.direction.x / 180) * 3.14159265358979);
|
||||
|
||||
geometry.location = Vector3d.sum(geometry.location, new Vector3d((Math.cos(direction) * Math.sqrt(2)), (Math.sin(direction) * Math.sqrt(2))));
|
||||
}
|
||||
|
||||
public moveDown(): void
|
||||
{
|
||||
if(this._rotation !== 0) return;
|
||||
|
||||
const geometry = (this.geometry as RoomGeometry);
|
||||
const direction = (((geometry.direction.x + 180) / 180) * 3.14159265358979);
|
||||
|
||||
geometry.location = Vector3d.sum(geometry.location, new Vector3d((Math.cos(direction) * Math.sqrt(2)), (Math.sin(direction) * Math.sqrt(2))));
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
|
75
src/room/utils/RoomRotatingEffect.ts
Normal file
75
src/room/utils/RoomRotatingEffect.ts
Normal file
@ -0,0 +1,75 @@
|
||||
import { Nitro } from '../../nitro/Nitro';
|
||||
|
||||
export class RoomRotatingEffect
|
||||
{
|
||||
public static STATE_NOT_INITIALIZED: number = 0;
|
||||
public static STATE_START_DELAY: number = 1;
|
||||
public static STATE_RUNNING: number = 2;
|
||||
public static STATE_OVER: number = 3;
|
||||
|
||||
private static _SafeStr_448: number = 0;
|
||||
private static _SafeStr_4512: boolean = false;
|
||||
private static _SafeStr_4513: number = 0;
|
||||
private static _SafeStr_4514: number = 0;
|
||||
private static _SafeStr_4515: number = 20000;
|
||||
private static _SafeStr_4516: number = 5000;
|
||||
private static _SafeStr_4524: ReturnType<typeof setTimeout>;
|
||||
|
||||
public static init(_arg_1: number, _arg_2: number): void
|
||||
{
|
||||
this._SafeStr_4513 = 0;
|
||||
this._SafeStr_4515 = _arg_1;
|
||||
this._SafeStr_4516 = _arg_2;
|
||||
this._SafeStr_4514 = Nitro.instance.time;
|
||||
this._SafeStr_448 = 1;
|
||||
}
|
||||
|
||||
public static turnVisualizationOn(): void
|
||||
{
|
||||
if((this._SafeStr_448 === 0) || (this._SafeStr_448 === 3)) return;
|
||||
|
||||
if(!this._SafeStr_4524) this._SafeStr_4524 = setTimeout(() => this.turnVisualizationOff(), this._SafeStr_4516);
|
||||
|
||||
const _local_1 = (Nitro.instance.time - this._SafeStr_4514);
|
||||
|
||||
if(_local_1 > (this._SafeStr_4515 + this._SafeStr_4516))
|
||||
{
|
||||
this._SafeStr_448 = 3;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this._SafeStr_4512 = true;
|
||||
|
||||
if(_local_1 < this._SafeStr_4515)
|
||||
{
|
||||
this._SafeStr_448 = 1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this._SafeStr_448 = 2;
|
||||
this._SafeStr_4513 = ((_local_1 - this._SafeStr_4515) / this._SafeStr_4516);
|
||||
}
|
||||
|
||||
public static turnVisualizationOff():void
|
||||
{
|
||||
this._SafeStr_4512 = false;
|
||||
|
||||
clearTimeout(this._SafeStr_4524);
|
||||
|
||||
this._SafeStr_4524 = null;
|
||||
}
|
||||
|
||||
public static isVisualizationOn(): boolean
|
||||
{
|
||||
return (this._SafeStr_4512 && this.isRunning());
|
||||
}
|
||||
|
||||
private static isRunning(): boolean
|
||||
{
|
||||
if((this._SafeStr_448 === 1) || (this._SafeStr_448 === 2)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
75
src/room/utils/RoomShakingEffect.ts
Normal file
75
src/room/utils/RoomShakingEffect.ts
Normal file
@ -0,0 +1,75 @@
|
||||
import { Nitro } from '../../nitro/Nitro';
|
||||
|
||||
export class RoomShakingEffect
|
||||
{
|
||||
public static STATE_NOT_INITIALIZED: number = 0;
|
||||
public static STATE_START_DELAY: number = 1;
|
||||
public static STATE_RUNNING: number = 2;
|
||||
public static STATE_OVER: number = 3;
|
||||
|
||||
private static _SafeStr_448: number = 0;
|
||||
private static _SafeStr_4512: boolean = false;
|
||||
private static _SafeStr_4513: number;
|
||||
private static _SafeStr_4514: number = 0;
|
||||
private static _SafeStr_4515: number = 20000;
|
||||
private static _SafeStr_4516: number = 5000;
|
||||
private static _SafeStr_4524: ReturnType<typeof setTimeout>;
|
||||
|
||||
public static init(_arg_1: number, _arg_2: number): void
|
||||
{
|
||||
this._SafeStr_4513 = 0;
|
||||
this._SafeStr_4515 = _arg_1;
|
||||
this._SafeStr_4516 = _arg_2;
|
||||
this._SafeStr_4514 = Nitro.instance.time;
|
||||
this._SafeStr_448 = 1;
|
||||
}
|
||||
|
||||
public static turnVisualizationOn(): void
|
||||
{
|
||||
if((this._SafeStr_448 === 0) || (this._SafeStr_448 === 3)) return;
|
||||
|
||||
if(!this._SafeStr_4524) this._SafeStr_4524 = setTimeout(() => this.turnVisualizationOff(), this._SafeStr_4516);
|
||||
|
||||
const _local_1 = (Nitro.instance.time - this._SafeStr_4514);
|
||||
|
||||
if(_local_1 > (this._SafeStr_4515 + this._SafeStr_4516))
|
||||
{
|
||||
this._SafeStr_448 = 3;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this._SafeStr_4512 = true;
|
||||
|
||||
if(_local_1 < this._SafeStr_4515)
|
||||
{
|
||||
this._SafeStr_448 = 1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this._SafeStr_448 = 2;
|
||||
this._SafeStr_4513 = ((_local_1 - this._SafeStr_4515) / this._SafeStr_4516);
|
||||
}
|
||||
|
||||
public static turnVisualizationOff():void
|
||||
{
|
||||
this._SafeStr_4512 = false;
|
||||
|
||||
clearTimeout(this._SafeStr_4524);
|
||||
|
||||
this._SafeStr_4524 = null;
|
||||
}
|
||||
|
||||
public static isVisualizationOn(): boolean
|
||||
{
|
||||
return (this._SafeStr_4512 && this.isRunning());
|
||||
}
|
||||
|
||||
private static isRunning(): boolean
|
||||
{
|
||||
if((this._SafeStr_448 === 1) || (this._SafeStr_448 === 2)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -7,6 +7,8 @@ export * from './Rasterizer';
|
||||
export * from './RoomEnterEffect';
|
||||
export * from './RoomGeometry';
|
||||
export * from './RoomId';
|
||||
export * from './RoomRotatingEffect';
|
||||
export * from './RoomShakingEffect';
|
||||
export * from './SpriteUtilities';
|
||||
export * from './TextureUtils';
|
||||
export * from './Vector3d';
|
||||
|
Loading…
Reference in New Issue
Block a user