-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add server for MMO sync. basic movimentation working
- Loading branch information
Showing
37 changed files
with
964 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Behaviour } from 'behaviour.js' | ||
|
||
import lerp from 'lerp' | ||
|
||
export default class GameObject extends Behaviour { | ||
|
||
onAttach (generator) { | ||
this.nextPoint = null | ||
this.generator = generator | ||
|
||
this.on('patch', this.onPatch.bind(this)) | ||
} | ||
|
||
update () { | ||
if (this.nextPoint) { | ||
this.object.position.x = lerp(this.object.position.x, this.nextPoint.x, 0.09) | ||
this.object.position.z = lerp(this.object.position.z, this.nextPoint.z, 0.09) | ||
} | ||
} | ||
|
||
onPatch (state, patch) { | ||
if (patch.path.indexOf('position') !== -1) { | ||
// TODO: possible leak here | ||
this.nextPoint = this.generator.fixTilePosition(this.object.position.clone(), state.position.y, state.position.x) | ||
|
||
var direction = null | ||
|
||
if (this.object.userData.x < state.position.x) { | ||
direction = 'bottom' | ||
} else if (this.object.userData.x > state.position.x) { | ||
direction = 'top' | ||
} else if (this.object.userData.y > state.position.y) { | ||
direction = 'left' | ||
} else if (this.object.userData.y < state.position.y) { | ||
direction = 'right' | ||
} | ||
|
||
if (direction) this.object.direction = direction | ||
|
||
this.object.userData.x = state.position.x | ||
this.object.userData.y = state.position.y | ||
} | ||
|
||
} | ||
|
||
onDestroy () { } | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Behaviour } from 'behaviour.js' | ||
|
||
export default class NearPlayerOpacity extends Behaviour { | ||
|
||
onAttach () { } | ||
|
||
update () { | ||
// no need to apply opacity on daylight | ||
if (!IS_DAY && player) { | ||
var v1 = this.object.position | ||
, v2 = player.position | ||
|
||
, dx = v1.x - v2.x | ||
, dy = v1.y - v2.y | ||
, dz = v1.z - v2.z | ||
, distance = Math.sqrt(dx*dx+dy*dy+dz*dz); | ||
|
||
// TODO: improve me | ||
// make it dynamic accouding to player illumination | ||
(this.object.material || this.object.children[0].material).opacity = 5 / distance | ||
} | ||
} | ||
|
||
onDestroy () { } | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.