123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- import * as RE from 'rogue-engine';
- import RaycastReceiver from './RaycastReceiver.re';
- import GameLogic from './GameLogic.re';
- import { SimpleTween } from './Library/SimpleTweens'
- import Easing from './Library/Easings';
- import * as THREE from 'three'
- export default class TileRaycastReceiver extends RaycastReceiver {
- @RE.Prop("Vector2") tileSize = new THREE.Vector2(1.1, 1.1)
- @RE.Prop("Audio") dropInSound
- @RE.Prop("Audio") hoverSound
- @RE.Prop("Audio") clearSound
- onMouseOver(intersect) {
- if(this.object3d.isAnimating) {
- return
- }
- this.currentObj = intersect.object
- this.currentObj.material = this.currentObj.highlightMaterial
-
- RE.Runtime.rogueDOMContainer.style.cursor = "pointer"
- if(RE.Input.mouse.getButtonPressed(0) || RE.Input.touch.touches.length == 1) {
- let game = RE.getComponent(GameLogic)
- if(game.addTile(this)) {
- if(this.hoverSound) {
- this.hoverSound.play()
- }
- }
- }
- }
- onMouseOut(){
- if(this.object3d.isAnimating || !this.currentObj) {
- return
- }
- if(RE.Input.mouse.getButtonPressed(0)) {
- //dragged out of this tile, should track state so a second "leave" will unselect
- }
- this.currentObj.material = this.currentObj.originalMaterial
- RE.Runtime.rogueDOMContainer.style.cursor = "default"
- }
- getOriginalMaterial() {
- return this.object3d.originalMaterial
- }
- getPosition() {
- return this.object3d.position
- }
- awake() {
- }
- start() {
- if(this.dropInSound) {
- this.dropInSound.setVolume(0.7)
- this.dropInSound.setLoop(false)
- }
- if(this.hoverSound) {
- this.hoverSound.setVolume(0.7)
- this.hoverSound.setLoop(false)
- }
- if(this.clearSound) {
- this.clearSound.setVolume(1)
- this.clearSound.setLoop(false)
- }
- }
- update() {
- }
- initialize(gridPosition, originalMaterial, hoverMaterial, tweenManager, delay, startingY, easingFunction) {
- this.object3d.position.copy(new THREE.Vector3(this.tileSize.x * gridPosition.x, startingY, this.tileSize.y * gridPosition.y))
-
- this.object3d.originalMaterial = originalMaterial
- this.object3d.highlightMaterial = hoverMaterial
- this.object3d.material = originalMaterial
- this.object3d.gridPosition = gridPosition
- this.object3d.isAnimating = true
-
- setTimeout(() => {
- if(this.dropInSound) {
- this.dropInSound.play()
- }
- }, (delay/3) * Math.random())
- tweenManager.add(new SimpleTween(this.object3d.position, {y: 1}, delay, easingFunction, () => {
- this.object3d.isAnimating = false
- }))
- }
- remove(tweenManager) {
- this.object3d.isAnimating = true
- setTimeout(() => {
- if(this.clearSound) {
- this.clearSound.play()
- }
- }, 150 * Math.random())
-
- tweenManager.add(new SimpleTween(this.object3d.position, {y: -14}, Math.floor(1500 * Math.random()) + 300, Easing.Quadratic.EaseIn, () => {
- this.object3d.parent.remove(this.object3d)
- }))
- }
- }
- RE.registerComponent(TileRaycastReceiver);
|