Skip to content

Commit

Permalink
feat: fill in the game displays when a game is found
Browse files Browse the repository at this point in the history
  • Loading branch information
meszaros-lajos-gyorgy committed Sep 7, 2023
1 parent 0c95358 commit d58b7a3
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 33 deletions.
2 changes: 1 addition & 1 deletion assets/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@
"english": "The mirror is missing from the wall"
},
"unmounted-game-display": {
"english": "Empty game display"
"english": "A pc game is missing from the display"
}
}
15 changes: 9 additions & 6 deletions src/entities/GameDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ export class GameDisplay extends Entity {
this.propVariant = new Variable('string', 'variant', variant)
this.propIsMounted = new Variable('bool', 'isMounted', false)

this.script?.properties.push(
new Label('[unmounted-game-display]'),
Interactivity.off,
this.propVariant,
this.propIsMounted,
)
this.script?.properties.push(this.propVariant, this.propIsMounted)

this.script?.on('init', () => {
return `
Expand All @@ -53,6 +48,7 @@ export class GameDisplay extends Entity {

this.script?.on('initend', () => {
return [
new Label(`[unmounted-game-display]`),
`
if (${this.propVariant.name} == "mesterlovesz") {
${new TweakSkin(TEXTURES['blank'], TEXTURES['mesterlovesz'])}
Expand Down Expand Up @@ -81,6 +77,13 @@ export class GameDisplay extends Entity {
`,
]
})

this.script?.on('mount', () => {
return `
${new Transparency(1)}
${new Label(`[game--~${this.propVariant.name}~]`)}
`
})
}

get variant() {
Expand Down
6 changes: 4 additions & 2 deletions src/entities/Goblin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Goblin extends Entity {
isBusy: Variable<boolean>
doneSpeaking: ScriptSubroutine

constructor({ gameStateMarker, ...props }: EntityConstructorPropsWithoutSrc & { gameStateMarker: Entity }) {
constructor({ gameStateManager, ...props }: EntityConstructorPropsWithoutSrc & { gameStateManager: Entity }) {
super({
src: 'npc/goblin_base',
...props,
Expand Down Expand Up @@ -85,7 +85,9 @@ export class Goblin extends Entity {
set ${isBusy.name} 1
if (^$param1 isclass pcgame) {
sendevent goblin_received_a_game ${gameStateMarker.ref} nop
set £variant $~^$param1~__variant
sendevent goblin_received_a_game ${gameStateManager.ref} ~£variant~
random 20 {
speak -h [goblin_victory3_shorter] ${doneSpeaking.invoke()}
Expand Down
4 changes: 2 additions & 2 deletions src/entities/MirrorOnWall.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Entity, EntityConstructorPropsWithoutSrc, EntityModel } from 'arx-level-generator'
import { Interactivity, Label, Scale, Transparency, Variable } from 'arx-level-generator/scripting/properties'
import { Interactivity, Label, Scale, Shadow, Transparency, Variable } from 'arx-level-generator/scripting/properties'

export class MirrorOnWall extends Entity {
protected propIsMounted: Variable<boolean>
Expand Down Expand Up @@ -41,6 +41,6 @@ export class MirrorOnWall extends Entity {
`
})

this.script?.properties.push(new Label('[unmounted-mirror-on-wall]'), new Scale(2), this.propIsMounted)
this.script?.properties.push(new Label('[unmounted-mirror-on-wall]'), Shadow.off, new Scale(2), this.propIsMounted)
}
}
9 changes: 8 additions & 1 deletion src/entities/PCGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const pcGameMesh = await loadOBJ('./pcgame', {

export class PCGame extends Entity {
private propVariant: Variable<string>
private propVariantPublic: Variable<string>

constructor({ variant, ...props }: PCGameConstructorProps) {
super({
Expand All @@ -91,8 +92,10 @@ export class PCGame extends Entity {
this.withScript()

this.propVariant = new Variable('string', 'variant', variant)
// a copy of propVariant to be able to read it outside the entity
this.propVariantPublic = new Variable('global string', `${this.ref}__variant`, variant)

this.script?.properties.push(this.propVariant)
this.script?.properties.push(this.propVariant, this.propVariantPublic)

this.script?.on('init', () => {
if (!this.script?.isRoot) {
Expand All @@ -107,6 +110,9 @@ export class PCGame extends Entity {
return ''
}

// at this point this.ref is pointing to the root entity, not the invoker, so
// we have to use the private version of variant

return [
new Label(`[game--~${this.propVariant.name}~]`),
`
Expand Down Expand Up @@ -145,5 +151,6 @@ export class PCGame extends Entity {

set variant(value: PCGameVariant) {
this.propVariant.value = value
this.propVariantPublic.value = value
}
}
20 changes: 10 additions & 10 deletions src/gameStateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ const achievementLittering = new ScriptSubroutine('achievement_littering', () =>
export const createGameStateManager = (settings: Settings) => {
const manager = Entity.marker.withScript()

const numberOfGamesTheGoblinHas = new Variable('int', 'number_of_games_the_goblin_has', 0)
const numberOfCollectedGames = new Variable('int', 'number_of_collected_games', 0)
const playerFoundAnyGames = new Variable('bool', 'player_found_any_games', false)
const isGoblinDead = new Variable('bool', 'is_goblin_dead', false)
const haveLittered = new Variable('bool', 'have_littered', false)

manager.script?.properties.push(numberOfGamesTheGoblinHas, playerFoundAnyGames, isGoblinDead)
manager.script?.properties.push(numberOfCollectedGames, playerFoundAnyGames, isGoblinDead)

manager.script?.subroutines.push(
tutorialWelcome,
Expand All @@ -81,25 +81,25 @@ export const createGameStateManager = (settings: Settings) => {
if (settings.mode === 'production') {
manager.script?.on('init', () => {
return `
TIMERwelcome -m 1 3000 ${tutorialWelcome.invoke()}
`
TIMERwelcome -m 1 3000 ${tutorialWelcome.invoke()}
`
})
}

manager.script?.on('goblin_received_a_game', () => {
manager.script?.on('game_collected', () => {
return `
inc ${numberOfGamesTheGoblinHas.name} 1
inc ${numberOfCollectedGames.name} 1
if (${numberOfGamesTheGoblinHas.name} == 1) {
if (${numberOfCollectedGames.name} == 1) {
${tutorialGaveGameToGoblin.invoke()}
}
if (${numberOfGamesTheGoblinHas.name} == 2) {
if (${numberOfCollectedGames.name} == 2) {
${achievementListenSmall.invoke()}
}
if (${numberOfGamesTheGoblinHas.name} == 5) {
if (${numberOfCollectedGames.name} == 5) {
${achievementListenMedium.invoke()}
}
if (${numberOfGamesTheGoblinHas.name} == 8) {
if (${numberOfCollectedGames.name} == 8) {
${achievementListenLarge.invoke()}
}
`
Expand Down
76 changes: 66 additions & 10 deletions src/rooms/leftCorridor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,71 @@ export const createLeftCorridor = async (
350,
variants.length,
theta + MathUtils.degToRad(2.4),
).map((position, i) => {
return new GameDisplay({
variant: variants[i],
position,
orientation: new Rotation(
MathUtils.degToRad(90) + i * angle + theta,
MathUtils.degToRad(180),
MathUtils.degToRad(-90),
),
).reduce(
(acc, position, i) => {
const variant = variants[i]
const gameDisplay = new GameDisplay({
variant,
position,
orientation: new Rotation(
MathUtils.degToRad(90) + i * angle + theta,
MathUtils.degToRad(180),
MathUtils.degToRad(-90),
),
})

return { ...acc, [variant]: gameDisplay }
},
{} as Record<PCGameVariant, GameDisplay>,
)

gameStateManager.script?.on('goblin_received_a_game', () => {
return `
sendevent game_collected ${gameStateManager.ref} nop
if (^$param1 == "mesterlovesz") {
sendevent mount ${gameDisplays['mesterlovesz'].ref} nop
}
if (^$param1 == "mortyr") {
sendevent mount ${gameDisplays['mortyr'].ref} nop
}
if (^$param1 == "wolfschanze") {
sendevent mount ${gameDisplays['wolfschanze'].ref} nop
}
if (^$param1 == "traktor-racer") {
sendevent mount ${gameDisplays['traktor-racer'].ref} nop
}
if (^$param1 == "americas-10-most-wanted") {
sendevent mount ${gameDisplays['americas-10-most-wanted'].ref} nop
}
if (^$param1 == "big-rigs") {
sendevent mount ${gameDisplays['big-rigs'].ref} nop
}
if (^$param1 == "streets-racer") {
sendevent mount ${gameDisplays['streets-racer'].ref} nop
}
if (^$param1 == "bikini-karate-babes") {
sendevent mount ${gameDisplays['bikini-karate-babes'].ref} nop
}
`
})

Object.entries(gameDisplays).forEach(([variant, gameDisplay]) => {
gameDisplay.script?.on('combine', () => {
return `
if (^$param1 isclass pcgame) {
set £variant $~^$param1~__variant
if (£variant == "${variant}") {
sendevent game_collected ${gameStateManager.ref} nop
destroy ^$param1
play clip
sendevent mount ${gameDisplay.ref} nop
} else {
speak -p [player_not_this_way]
}
}
`
})
})

Expand All @@ -55,7 +111,7 @@ export const createLeftCorridor = async (

return {
meshes: [...bases],
entities: [rootMirror, mirror, ...gameDisplays],
entities: [rootMirror, mirror, ...Object.values(gameDisplays)],
lights: [],
zones: [],
_: {},
Expand Down
2 changes: 1 addition & 1 deletion src/rooms/mainHall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const createMainHall = async (
const goblin = new Goblin({
position: new Vector3(-200, -2, 425),
orientation: new Rotation(0, MathUtils.degToRad(-100), 0),
gameStateMarker: gameStateManager,
gameStateManager,
})

if (settings.mode === 'production') {
Expand Down

0 comments on commit d58b7a3

Please sign in to comment.