Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,045 changes: 1,032 additions & 13 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"ecs:install-next": "npm install --save-dev decentraland-ecs@next"
},
"devDependencies": {
"decentraland-ecs": "^6.4.10-20200623153317.commit-5ced1d4"
"decentraland-ecs": "^6.11.6"
},
"dependencies": {
"decentraland": "^3.2.7-20190919135901.commit-4f347f6",
Expand Down
5 changes: 3 additions & 2 deletions src/UI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import decentralandEcsUtils from "../node_modules/decentraland-ecs-utils/index"
export const canvas = new UICanvas()

export let atlas = new Texture("textures/HeadSprites.png")
let currentHandsY: number = -20
let currentHandsY: number = -35
const handsPanel = new UIContainerRect(canvas)
handsPanel.isPointerBlocker = false
handsPanel.width = '100%'
Expand All @@ -13,7 +13,7 @@ handsPanel.positionY = currentHandsY
export let leftHandImage = new UIImage(handsPanel, atlas)
leftHandImage.hAlign = 'left'
leftHandImage.vAlign = 'bottom'
leftHandImage.positionX = '10%'
leftHandImage.positionX = '5%'
leftHandImage.positionY = currentHandsY - 10
leftHandImage.sourceWidth = 425
leftHandImage.sourceHeight = 425
Expand All @@ -25,6 +25,7 @@ leftHandImage.height = leftHandImage.sourceHeight * 1.6
const rightHandImage = new UIImage(handsPanel, atlas)
rightHandImage.hAlign = 'right'
rightHandImage.vAlign = 'bottom'
rightHandImage.positionX = '-5%'
rightHandImage.positionY = currentHandsY
rightHandImage.sourceWidth = 425
rightHandImage.sourceHeight = 425
Expand Down
18 changes: 9 additions & 9 deletions src/book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ export class Page extends Entity {
this.addComponent(new PageComponent())
this.addComponent(
new OnPointerDown((e) => {
if (e.hit.length > 3) return
this.grab(totalPages)
}, {
hoverText: "Grab",
distance: 3
})
)
}
Expand All @@ -85,7 +87,7 @@ export class Page extends Entity {
book.activateGlow()

radarMicaDialogueUIText.value =
'Now place me by the book and I shall cast the spell!'
'Now place me by the book, I will cast the spell!'
micaDialogueSystem.enabled = false
}
}
Expand Down Expand Up @@ -261,12 +263,10 @@ export const book = new Book(

book.addComponentOrReplace(
new OnPointerDown((e) => {
if (e.hit.length > 4) {
return
}
if (hasAllPages && creature.currentState == CreatureState.Hunting) {
// book.trapCreature()
releaseMicasHead()
}
if (hasAllPages && creature.currentState != CreatureState.Hunting) return

releaseMicasHead()
}, {
distance: 4
})
)
9 changes: 5 additions & 4 deletions src/candles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export class Candle extends Entity {
isOn: boolean = false
) {
super();


this.addComponent(offModel);
this.addComponent(new Transform(transform))
Expand All @@ -32,11 +31,14 @@ export class Candle extends Entity {
this.onModel = onModel
this.offModel = offModel


this.addComponent(
new OnPointerDown(e => {
if (e.hit.length > 4 || this.isOn) return
if (this.isOn) return

this.turnOn()
}, {
hoverText: "Light",
distance: 4
})
)
}
Expand All @@ -46,7 +48,6 @@ export class Candle extends Entity {
this.offModel.visible = false
candlesOnCounter += 1
if (candlesOnCounter == candles.length) {
log("YOU WIN")
creature.getKilled()

micaTextShape.value = ""
Expand Down
110 changes: 50 additions & 60 deletions src/creature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class Creature extends Entity {
rotationSpeed: number = 60
currentState: CreatureState = CreatureState.Dormant
transform: Transform
laserLength: number = 10
laserL: IEntity = null
laserR: IEntity = null
beingWatched: boolean = false
Expand All @@ -52,40 +53,40 @@ export class Creature extends Entity {
speed: number = 0.3,
currentState: CreatureState = CreatureState.Dormant
) {
super();
this.addComponent(model)
this.addComponent(new Transform(transform))
this.addComponent(new CreatureComponent())
engine.addEntity(this)
this.currentState = currentState
this.transform = this.getComponent(Transform)

// animations
this.invokeAnim = new AnimationState("Invoke")
this.searchAnim = new AnimationState("Search")
this.attackAnim = new AnimationState("Attack")
this.raysAnim = new AnimationState("Rays")

this.addComponent(new Animator()).addClip(this.invokeAnim)
this.getComponent(Animator).addClip(this.searchAnim)
this.getComponent(Animator).addClip(this.attackAnim)
this.invokeAnim.play()

// sounds
let mumblingClip = new AudioClip("sounds/Search.mp3")
this.addComponent(new AudioSource(mumblingClip))
this.searchSound = this.getComponent(AudioSource)

let attackAudioEnt = new Entity()
engine.addEntity(attackAudioEnt)
attackAudioEnt.setParent(this)
let attackClip = new AudioClip("sounds/Attack.mp3")
let attackSource = new AudioSource(attackClip)
this.attackSound = attackSource
attackAudioEnt.addComponent(this.attackSound)
super();
this.addComponent(model)
this.addComponent(new Transform(transform))
this.addComponent(new CreatureComponent())
engine.addEntity(this)
this.currentState = currentState
this.transform = this.getComponent(Transform)
// animations
this.invokeAnim = new AnimationState("Invoke")
this.searchAnim = new AnimationState("Search")
this.attackAnim = new AnimationState("Attack")
this.raysAnim = new AnimationState("Rays")
this.addComponent(new Animator()).addClip(this.invokeAnim)
this.getComponent(Animator).addClip(this.searchAnim)
this.getComponent(Animator).addClip(this.attackAnim)
this.invokeAnim.play()
// sounds
let mumblingClip = new AudioClip("sounds/Search.mp3")
this.addComponent(new AudioSource(mumblingClip))
this.searchSound = this.getComponent(AudioSource)
let attackAudioEnt = new Entity()
engine.addEntity(attackAudioEnt)
attackAudioEnt.setParent(this)
let attackClip = new AudioClip("sounds/Attack.mp3")
let attackSource = new AudioSource(attackClip)
this.attackSound = attackSource
attackAudioEnt.addComponent(this.attackSound)
}

public getInvoked() : void {
public getInvoked() : void {
this.currentState = CreatureState.Hunting
this.invokeAnim.playing = true
this.attackAnim.playing = false
Expand All @@ -97,7 +98,6 @@ export class Creature extends Entity {
}

public getTrapped() : void {
this.currentState = CreatureState.Trapped
this.startLaser()
this.transform.position = creature.trappedPosition
this.transform.rotation = Quaternion.Euler(0,0,0)
Expand All @@ -106,6 +106,7 @@ export class Creature extends Entity {
this.searchSound.playing = false
this.attackSound.playing = false
this.raysAnim.playing = true
this.currentState = CreatureState.Trapped
}

public getKilled() : void {
Expand All @@ -121,8 +122,6 @@ export class Creature extends Entity {

this.searchSound.playing = false
this.attackSound.playing = false


}

public getReset() : void {
Expand Down Expand Up @@ -185,7 +184,6 @@ export class Creature extends Entity {
}

public adjustSpeed(cameraForward: ReadOnlyVector3, playerPos: Vector3): void {

let viewAngle = Math.abs(Vector3.GetAngleBetweenVectors(
new Vector3(cameraForward.x, cameraForward.y, cameraForward.z),
this.transform.position.subtract(playerPos), Vector3.Up())
Expand Down Expand Up @@ -216,12 +214,10 @@ export class Creature extends Entity {
this.searchAnim.playing = true
this.attackSound.playing = false
}

}

public startLaser(): void {

if (this.laserL){
if (this.laserL) {
this.laserL.getComponent(BoxShape).visible = true
this.laserR.getComponent(BoxShape).visible = true
} else {
Expand All @@ -230,7 +226,7 @@ export class Creature extends Entity {
laserL.getComponent(BoxShape).withCollisions = false
laserL.addComponent(new Transform({
scale: new Vector3(0.05 ,0.05, 10 ),
position: new Vector3(-0.065, 0.55, 5.2)
position: new Vector3(-0.065, 0.472, 0)
}))
laserL.addComponent(rayMaterial)
laserL.setParent(this)
Expand All @@ -242,7 +238,7 @@ export class Creature extends Entity {
laserR.getComponent(BoxShape).withCollisions = false
laserR.addComponent(new Transform({
scale: new Vector3(0.05 ,0.05, 10 ),
position: new Vector3(0.065, 0.55, 5.2)
position: new Vector3(0.065, 0.472, 0)
}))
laserR.addComponent(rayMaterial)
laserR.setParent(this)
Expand All @@ -264,50 +260,46 @@ export class Creature extends Entity {
let newRay: Ray = {
origin: this.transform.position,
direction: Vector3.Forward().rotate(this.transform.rotation),
distance: 15
distance: this.laserLength
}

PhysicsCast.instance.hitFirst(newRay, (e) => {
let laserLen: number
let playerSafe: boolean = false
if (e.didHit){
//debugCube.getComponent(Transform).position.set(e.hitPoint.x, e.hitPoint.y, e.hitPoint.z)
let hitPoint = new Vector3(e.hitPoint.x, e.hitPoint.y, e.hitPoint.z)
laserLen = Vector3.Distance(this.transform.position, hitPoint) - 2
this.drawLaserLength(laserLen)
//log(" laserLen: ", laserLen, " id: ", e.entity.entityId)
this.drawLaserLength(Vector3.Distance(this.transform.position, hitPoint) - 1)
} else {
laserLen = 15
this.drawLaserLength(laserLen)
this.drawLaserLength(this.laserLength)
}

const rayToPlayer: Ray = PhysicsCast.instance.getRayFromPositions(this.transform.position, playerPos)
rayToPlayer.direction = new Vector3(rayToPlayer.direction.x, 0, rayToPlayer.direction.z)

PhysicsCast.instance.hitFirst(rayToPlayer, (e) => {
if(e.didHit){
if(e.didHit){ // hit an obstacle between the creature and the player
playerSafe = true
} else {
let angle = Vector3.GetAngleBetweenVectors(
new Vector3(rayToPlayer.direction.x, rayToPlayer.direction.y, rayToPlayer.direction.z),
new Vector3(newRay.direction.x, newRay.direction.y, newRay.direction.z)
, Vector3.Up()
)
if (Math.abs(angle) < 0.2 && rayToPlayer.distance < laserLen + 0.5){
log("PLAYER HIT, laserLen: ", laserLen, " player distance: ", rayToPlayer.distance)
if (Math.abs(angle) < 0.2 && rayToPlayer.distance < this.laserLength + 5){
log("PLAYER HIT, laserLen: ", this.laserLength, " player distance: ", rayToPlayer.distance)
resetGame()
}
}
}, 3)


//log(laserLen)
this.waitingForRay = false
}, 2)
}

public drawLaserLength(laserLen: number): void {
this.laserL.getComponent(Transform).scale.z = laserLen
this.laserR.getComponent(Transform).scale.z = laserLen
this.laserL.getComponent(Transform).position.z = laserLen/2 + 0.5
this.laserR.getComponent(Transform).position.z = laserLen/2 + 0.5
this.laserL.getComponent(Transform).position.z = laserLen/2 + 0.3
this.laserR.getComponent(Transform).position.z = laserLen/2 + 0.3
}

public laserOff () :void {
Expand Down Expand Up @@ -336,8 +328,6 @@ export class CreatureSystem {
this.playerPos = camera.position.clone()

for (let creature of creatures) {

//let creatureComponent = creature.getComponent(CreatureComponent)
let creatureTransform = creature.getComponent(Transform)

switch (creature.currentState) {
Expand Down Expand Up @@ -373,7 +363,7 @@ export class CreatureSystem {

let cameraForward = PhysicsCast.instance.getRayFromCamera(1).direction
creature.adjustSpeed(cameraForward, this.playerPos)

break;

////// TRAPPED //////
Expand All @@ -400,7 +390,7 @@ engine.addSystem(new CreatureSystem())



// Instance creature
// Instantiate creature
export let creature = new Creature(
{
position: new Vector3(32, -1.5, 32),
Expand Down
17 changes: 16 additions & 1 deletion src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,19 @@ let owl1 = new AmbientSound(
{position: new Vector3(15, 4, 22)},
"sounds/owl1.mp3",
30000
)
)

// 1st Person Camera Area covering the whole scene
const modArea = new Entity()
modArea.addComponent(
new Transform({
position: new Vector3(8 * 4, 4, 8 * 4),
})
)
modArea.addComponent(
new CameraModeArea({
area: { box: new Vector3(64, 8, 64) },
cameraMode: CameraMode.FirstPerson,
})
)
engine.addEntity(modArea)
Loading