|
@@ -28,6 +28,7 @@ import * as potionInfo from './data/potions.json'
|
|
import Shopper from './shopper.js'
|
|
import Shopper from './shopper.js'
|
|
import { buildCanvasText } from './library/canvastext.js'
|
|
import { buildCanvasText } from './library/canvastext.js'
|
|
import { hideGameStatusUI, updateGameStatusUI } from './ui/gamestatusui.js'
|
|
import { hideGameStatusUI, updateGameStatusUI } from './ui/gamestatusui.js'
|
|
|
|
+import { gameOverUI, showGameOverUI } from './ui/gameoverui.js'
|
|
|
|
|
|
export const GAME_SAVE_KEY = "spookonomics-v1"
|
|
export const GAME_SAVE_KEY = "spookonomics-v1"
|
|
const raycast = new THREE.Raycaster()
|
|
const raycast = new THREE.Raycaster()
|
|
@@ -167,6 +168,17 @@ async function customerBuilder(randomPotion, delay) {
|
|
return shopper
|
|
return shopper
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+export function sellTutorialPrompt(stageData) {
|
|
|
|
+ if(stageData.shopTutorial2.alreadySeen) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ stageData.shopInactivityHandle = setTimeout(() => {
|
|
|
|
+ gsap.to(stageData.shopTutorial2.material, {duration: 1.5, opacity: 1, onStart: () => {
|
|
|
|
+ stageData.shopTutorial2.castShadow = true
|
|
|
|
+ }})
|
|
|
|
+ }, 5000)
|
|
|
|
+}
|
|
|
|
+
|
|
async function beginSell(game, stageData) {
|
|
async function beginSell(game, stageData) {
|
|
if (stageData.potionStocked.length < 1) {
|
|
if (stageData.potionStocked.length < 1) {
|
|
stageData.soundEffects['audio/witch_cackle1.ogg'].play()
|
|
stageData.soundEffects['audio/witch_cackle1.ogg'].play()
|
|
@@ -178,6 +190,8 @@ async function beginSell(game, stageData) {
|
|
|
|
|
|
stageData.isSellingPotions = true
|
|
stageData.isSellingPotions = true
|
|
|
|
|
|
|
|
+ sellTutorialPrompt(stageData)
|
|
|
|
+
|
|
let randomPotions = []
|
|
let randomPotions = []
|
|
randomPotions.push(...stageData.potionStocked)
|
|
randomPotions.push(...stageData.potionStocked)
|
|
randomPotions.push(...stageData.potionInventory)
|
|
randomPotions.push(...stageData.potionInventory)
|
|
@@ -446,6 +460,7 @@ export async function init(inGame) {
|
|
stageData.brewTutorial1.position.z = 2.4
|
|
stageData.brewTutorial1.position.z = 2.4
|
|
stageData.brewTutorial1.position.y = 0.2
|
|
stageData.brewTutorial1.position.y = 0.2
|
|
stageData.brewTutorial1.rotateOnAxis(new THREE.Vector3(1, 0, 0), -Math.PI / 2)
|
|
stageData.brewTutorial1.rotateOnAxis(new THREE.Vector3(1, 0, 0), -Math.PI / 2)
|
|
|
|
+ stageData.brewTutorial1.alreadySeen = false
|
|
stageData.brewTutorial1.material.opacity = 0
|
|
stageData.brewTutorial1.material.opacity = 0
|
|
stageData.brewTutorial1.castShadow = false
|
|
stageData.brewTutorial1.castShadow = false
|
|
game.scene.add(stageData.brewTutorial1)
|
|
game.scene.add(stageData.brewTutorial1)
|
|
@@ -584,12 +599,24 @@ export async function init(inGame) {
|
|
stageData.shopTutorial1.position.x = -15.5
|
|
stageData.shopTutorial1.position.x = -15.5
|
|
stageData.shopTutorial1.position.z = 0.2
|
|
stageData.shopTutorial1.position.z = 0.2
|
|
stageData.shopTutorial1.position.y = 1.8
|
|
stageData.shopTutorial1.position.y = 1.8
|
|
|
|
+ stageData.shopTutorial1.alreadySeen = false
|
|
|
|
|
|
stageData.shopTutorial1.scale.set(0.6, 0.6, 0.6)
|
|
stageData.shopTutorial1.scale.set(0.6, 0.6, 0.6)
|
|
stageData.shopTutorial1.material.opacity = 0
|
|
stageData.shopTutorial1.material.opacity = 0
|
|
stageData.shopTutorial1.castShadow = false
|
|
stageData.shopTutorial1.castShadow = false
|
|
game.scene.add(stageData.shopTutorial1)
|
|
game.scene.add(stageData.shopTutorial1)
|
|
|
|
|
|
|
|
+ stageData.shopTutorial2 = buildCanvasText("Pick the correct potion", { font: "72px Alice" })
|
|
|
|
+ stageData.shopTutorial2.position.x = -10
|
|
|
|
+ stageData.shopTutorial2.position.z = -3.4
|
|
|
|
+ stageData.shopTutorial2.position.y = 1.5
|
|
|
|
+ stageData.shopTutorial2.alreadySeen = false
|
|
|
|
+
|
|
|
|
+ stageData.shopTutorial2.scale.set(1, 1, 1)
|
|
|
|
+ stageData.shopTutorial2.material.opacity = 0
|
|
|
|
+ stageData.shopTutorial2.castShadow = false
|
|
|
|
+ game.scene.add(stageData.shopTutorial2)
|
|
|
|
+
|
|
stageData.coin = await loadGltf(game, 'models/coin.gltf.glb')
|
|
stageData.coin = await loadGltf(game, 'models/coin.gltf.glb')
|
|
stageData.coin.position.x = -12
|
|
stageData.coin.position.x = -12
|
|
stageData.coin.position.y = 1.1
|
|
stageData.coin.position.y = 1.1
|
|
@@ -734,6 +761,7 @@ export async function init(inGame) {
|
|
navigationUI(game, stageData)
|
|
navigationUI(game, stageData)
|
|
brewUI(game, stageData)
|
|
brewUI(game, stageData)
|
|
shopUI(game, stageData)
|
|
shopUI(game, stageData)
|
|
|
|
+ gameOverUI(game, stageData)
|
|
|
|
|
|
updateGameStatusUI(game, stageData)
|
|
updateGameStatusUI(game, stageData)
|
|
|
|
|
|
@@ -878,10 +906,11 @@ export function onClick() {
|
|
} else {
|
|
} else {
|
|
openShopUI(game, stageData)
|
|
openShopUI(game, stageData)
|
|
|
|
|
|
- if (stageData.shopTutorial1.material.opacity == 1) {
|
|
|
|
|
|
+ if (stageData.shopTutorial1.material.opacity > 0) {
|
|
gsap.to(stageData.shopTutorial1.material, {
|
|
gsap.to(stageData.shopTutorial1.material, {
|
|
duration: 1.5, opacity: 0, onComplete: () => {
|
|
duration: 1.5, opacity: 0, onComplete: () => {
|
|
stageData.shopTutorial1.castShadow = false
|
|
stageData.shopTutorial1.castShadow = false
|
|
|
|
+ stageData.shopTutorial1.alreadySeen = true
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
@@ -903,10 +932,11 @@ export function onClick() {
|
|
closeShopUI(game, stageData)
|
|
closeShopUI(game, stageData)
|
|
} else {
|
|
} else {
|
|
openShopUI(game, stageData)
|
|
openShopUI(game, stageData)
|
|
- if (stageData.shopTutorial1.material.opacity == 1) {
|
|
|
|
|
|
+ if (stageData.shopTutorial1.material.opacity > 0) {
|
|
gsap.to(stageData.shopTutorial1.material, {
|
|
gsap.to(stageData.shopTutorial1.material, {
|
|
duration: 1.5, opacity: 0, onComplete: () => {
|
|
duration: 1.5, opacity: 0, onComplete: () => {
|
|
stageData.shopTutorial1.castShadow = false
|
|
stageData.shopTutorial1.castShadow = false
|
|
|
|
+ stageData.shopTutorial1.alreadySeen = true
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
@@ -938,10 +968,22 @@ export function onClick() {
|
|
|
|
|
|
stageData.displayedPotions.forEach((potion) => {
|
|
stageData.displayedPotions.forEach((potion) => {
|
|
if (isAChildOf(potion, intersect.object)) {
|
|
if (isAChildOf(potion, intersect.object)) {
|
|
-
|
|
|
|
-
|
|
|
|
if (stageData.isSellingPotions) {
|
|
if (stageData.isSellingPotions) {
|
|
|
|
+ if (stageData.sellInactivityHandle) {
|
|
|
|
+ clearTimeout(stageData.sellInactivityHandle)
|
|
|
|
+ stageData.sellInactivityHandle = 0
|
|
|
|
+ }
|
|
|
|
+
|
|
if (stageData.customers[0].isMatchingPotion(potion.potionData)) {
|
|
if (stageData.customers[0].isMatchingPotion(potion.potionData)) {
|
|
|
|
+ if (stageData.shopTutorial2.material.opacity > 0) {
|
|
|
|
+ gsap.to(stageData.shopTutorial2.material, {
|
|
|
|
+ duration: 1.5, opacity: 0, onComplete: () => {
|
|
|
|
+ stageData.shopTutorial2.castShadow = false
|
|
|
|
+ stageData.shopTutorial2.alreadySeen = true
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
const firstCustomer = stageData.customers[0]
|
|
const firstCustomer = stageData.customers[0]
|
|
firstCustomer.hideDesire()
|
|
firstCustomer.hideDesire()
|
|
const potionMotionPath = [{ x: -11.5, y: 2.75, z: -3.25 }, { x: -12, y: 2, z: -2 }, { x: -13, y: 0.75, z: 2.5 }]
|
|
const potionMotionPath = [{ x: -11.5, y: 2.75, z: -3.25 }, { x: -12, y: 2, z: -2 }, { x: -13, y: 0.75, z: 2.5 }]
|
|
@@ -1040,10 +1082,11 @@ export function onClick() {
|
|
} else {
|
|
} else {
|
|
openBrewUI(game, stageData)
|
|
openBrewUI(game, stageData)
|
|
//cauldron.isBrewing = true
|
|
//cauldron.isBrewing = true
|
|
- if (stageData.brewTutorial1.material.opacity == 1) {
|
|
|
|
|
|
+ if (stageData.brewTutorial1.material.opacity > 0) {
|
|
gsap.to(stageData.brewTutorial1.material, {
|
|
gsap.to(stageData.brewTutorial1.material, {
|
|
duration: 1.5, opacity: 0, onComplete: () => {
|
|
duration: 1.5, opacity: 0, onComplete: () => {
|
|
stageData.brewTutorial1.castShadow = false
|
|
stageData.brewTutorial1.castShadow = false
|
|
|
|
+ stageData.brewTutorial1.alreadySeen = true
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
@@ -1064,10 +1107,11 @@ export function onClick() {
|
|
closeBrewUI(game, stageData)
|
|
closeBrewUI(game, stageData)
|
|
} else {
|
|
} else {
|
|
openBrewUI(game, stageData)
|
|
openBrewUI(game, stageData)
|
|
- if (stageData.brewTutorial1.material.opacity == 1) {
|
|
|
|
|
|
+ if (stageData.brewTutorial1.material.opacity > 0) {
|
|
gsap.to(stageData.brewTutorial1.material, {
|
|
gsap.to(stageData.brewTutorial1.material, {
|
|
duration: 1.5, opacity: 0, onComplete: () => {
|
|
duration: 1.5, opacity: 0, onComplete: () => {
|
|
stageData.brewTutorial1.castShadow = false
|
|
stageData.brewTutorial1.castShadow = false
|
|
|
|
+ stageData.brewTutorial1.alreadySeen = true
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
@@ -1175,6 +1219,10 @@ function nextCustomer() {
|
|
stageData.isSellingPotions = false
|
|
stageData.isSellingPotions = false
|
|
stageData.currentDay = addAmountToSave("currentday", 1)
|
|
stageData.currentDay = addAmountToSave("currentday", 1)
|
|
updateGameStatusUI(game, stageData)
|
|
updateGameStatusUI(game, stageData)
|
|
|
|
+
|
|
|
|
+ if(stageData.currency >= 1000) {
|
|
|
|
+ showGameOverUI(game, stageData)
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
stageData.customers[0].showDesire()
|
|
stageData.customers[0].showDesire()
|
|
if (stageData.potionStocked.length < 1) {
|
|
if (stageData.potionStocked.length < 1) {
|
|
@@ -1331,17 +1379,21 @@ export function moveToRoom(roomId) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-export function onKeyPress() {
|
|
|
|
|
|
+let keyHistory = []
|
|
|
|
+export function onKeyPress(code) {
|
|
if (game.keyboard['Digit1'] && stageData.currentRoom == ROOM_BREW) {
|
|
if (game.keyboard['Digit1'] && stageData.currentRoom == ROOM_BREW) {
|
|
moveToRoom(ROOM_SHOP)
|
|
moveToRoom(ROOM_SHOP)
|
|
|
|
+ keyHistory = []
|
|
}
|
|
}
|
|
|
|
|
|
if (game.keyboard['Digit2'] && stageData.currentRoom != ROOM_BREW) {
|
|
if (game.keyboard['Digit2'] && stageData.currentRoom != ROOM_BREW) {
|
|
moveToRoom(ROOM_BREW)
|
|
moveToRoom(ROOM_BREW)
|
|
|
|
+ keyHistory = []
|
|
}
|
|
}
|
|
|
|
|
|
if (game.keyboard['Digit3'] && stageData.currentRoom == ROOM_BREW) {
|
|
if (game.keyboard['Digit3'] && stageData.currentRoom == ROOM_BREW) {
|
|
moveToRoom(ROOM_MARKET)
|
|
moveToRoom(ROOM_MARKET)
|
|
|
|
+ keyHistory = []
|
|
}
|
|
}
|
|
|
|
|
|
if (game.keyboard['Digit9'] || game.keyboard['F9']) {
|
|
if (game.keyboard['Digit9'] || game.keyboard['F9']) {
|
|
@@ -1350,18 +1402,62 @@ export function onKeyPress() {
|
|
console.log(`position:`, game.camera.position)
|
|
console.log(`position:`, game.camera.position)
|
|
console.log(`focus:`, game.orbitControls.target)
|
|
console.log(`focus:`, game.orbitControls.target)
|
|
moveToRoom(stageData.currentRoom)
|
|
moveToRoom(stageData.currentRoom)
|
|
|
|
+ keyHistory = []
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if (game.keyboard['Escape']) {
|
|
if (game.keyboard['Escape']) {
|
|
- closeBrewUI(game, stageData)
|
|
|
|
- closeShopUI(game, stageData)
|
|
|
|
- hideNavigationUI(game, stageData)
|
|
|
|
- openMainMenuUI(game, stageData)
|
|
|
|
- hideGameStatusUI(game, stageData)
|
|
|
|
- stageData.currentRoom = ROOM_BREW
|
|
|
|
- game.camera.position.copy(stageData.cameraPositions[3].camera)
|
|
|
|
- game.lookAtFocus = stageData.cameraPositions[3].focus.clone()
|
|
|
|
|
|
+ returnToMainMenu(game, stageData)
|
|
|
|
+ keyHistory = []
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ keyHistory.push(code.replace("Key", ""))
|
|
|
|
+
|
|
|
|
+ const cheatcode = keyHistory.join("").toLowerCase()
|
|
|
|
+
|
|
|
|
+ if(cheatcode.includes("ghostbux")) {
|
|
|
|
+ keyHistory = []
|
|
|
|
+ stageData.currency += 1000
|
|
|
|
+ addAmountToSave("currency", 1000)
|
|
|
|
+ updateGameStatusUI(game, stageData)
|
|
|
|
+ stageData.soundEffects['audio/witch_cackle1.ogg'].play()
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if(cheatcode.includes("awesomesauce")) {
|
|
|
|
+ keyHistory = []
|
|
|
|
+ stageData.potionInventory.push(...stageData.potionInfo.map(info => info.name))
|
|
|
|
+ addValueToSave(stageData.potionInventory, "potion-inventory", "spooksauce")
|
|
|
|
+ stageData.soundEffects['audio/witch_cackle1.ogg'].play()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(cheatcode.includes("yeschef")) {
|
|
|
|
+ keyHistory = []
|
|
|
|
+ //TODO: grant all ingredients
|
|
|
|
+ stageData.soundEffects['audio/witch_cackle1.ogg'].play()
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export function returnToMainMenu(game, stageData) {
|
|
|
|
+ closeBrewUI(game, stageData)
|
|
|
|
+ closeShopUI(game, stageData)
|
|
|
|
+ hideNavigationUI(game, stageData)
|
|
|
|
+ openMainMenuUI(game, stageData)
|
|
|
|
+ hideGameStatusUI(game, stageData)
|
|
|
|
+ stageData.currentRoom = ROOM_BREW
|
|
|
|
+ game.camera.position.copy(stageData.cameraPositions[3].camera)
|
|
|
|
+ game.lookAtFocus = stageData.cameraPositions[3].focus.clone()
|
|
|
|
+ stageData.brewTutorial1.material.opacity = 0
|
|
|
|
+ stageData.brewTutorial1.castShadow = false
|
|
|
|
+ stageData.brewTutorial1.alreadySeen = false
|
|
|
|
+
|
|
|
|
+ stageData.shopTutorial1.material.opacity = 0
|
|
|
|
+ stageData.shopTutorial1.castShadow = false
|
|
|
|
+ stageData.shopTutorial1.alreadySeen = false
|
|
|
|
+
|
|
|
|
+ stageData.shopTutorial2.material.opacity = 0
|
|
|
|
+ stageData.shopTutorial2.castShadow = false
|
|
|
|
+ stageData.shopTutorial2.alreadySeen = false
|
|
|
|
+ updatePotionShelfDisplay()
|
|
|
|
+ updateGameStatusUI(game, stageData)
|
|
}
|
|
}
|
|
|
|
|