1+ import MulleState from './base'
2+
3+ import MulleSprite from '../objects/sprite'
4+ import MulleBuildCar from '../objects/buildcar'
5+ import MulleActor from '../objects/actor'
6+ import blinkThing from '../util/blinkThing'
7+ import SubtitleLoader from '../objects/SubtitleLoader'
8+
9+ class ViolaState extends MulleState {
10+ preload ( ) {
11+ super . preload ( )
12+ this . game . load . pack ( 'viola' , 'assets/viola.json' , null , this )
13+ this . subtitles = new SubtitleLoader ( this . game , 'viola' , [ 'english' ] )
14+ this . subtitles . preload ( )
15+ }
16+
17+ create ( ) {
18+ super . create ( )
19+
20+ this . game . mulle . addAudio ( 'viola' )
21+ this . subtitles . load ( )
22+
23+ // Play background sound
24+ this . game . mulle . playAudio ( '89e001v0' )
25+
26+ // Background
27+ var background = new MulleSprite ( this . game , 320 , 240 )
28+ background . setDirectorMember ( '89.DXR' , 1 )
29+ this . game . add . existing ( background )
30+
31+ // The car (without Salka/Mulle)
32+ this . car = new MulleBuildCar ( this . game , 445 , 370 , null , false , false )
33+ this . game . add . existing ( this . car )
34+
35+ // Buffa with animation
36+ var buffa = new MulleActor ( this . game , 360 , 320 , 'buffa' )
37+ buffa . setDirectorMember ( '00.CXT' , 214 )
38+ this . game . add . existing ( buffa )
39+ this . game . mulle . actors . buffa = buffa
40+
41+ let animationCount = 0
42+ let isWaiting = false
43+ let buffaTimer = this . game . time . events . loop ( 150 , ( ) => {
44+ if ( ! isWaiting && animationCount < 8 ) {
45+ buffa . animations . play ( 'scratch1' , null , false )
46+ buffa . animations . currentAnim . onComplete . addOnce ( ( ) => {
47+ buffa . setDirectorMember ( '00.CXT' , 214 )
48+ animationCount ++
49+
50+ if ( animationCount >= 8 ) {
51+ isWaiting = true
52+ this . game . time . events . add ( 3000 , ( ) => {
53+ animationCount = 0
54+ isWaiting = false
55+ } )
56+ }
57+ } )
58+ }
59+ } )
60+
61+ // Viola in the window
62+ var viola = new MulleSprite ( this . game , 246 , 154 )
63+ viola . setDirectorMember ( '89.DXR' , 18 )
64+ this . game . add . existing ( viola )
65+
66+ // Window animation
67+ let frame = 18
68+ let animationTimer = this . game . time . events . loop ( 300 , ( ) => {
69+ frame ++
70+ if ( frame > 20 ) {
71+ frame = 18
72+ }
73+ viola . setDirectorMember ( '89.DXR' , frame )
74+ } )
75+
76+ // Show the tank directly with correct properties
77+ var tank = new MulleSprite ( this . game , 2 , 332 )
78+ tank . setDirectorMember ( 'CDDATA.CXT' , 436 )
79+ tank . partId = 172
80+ tank . properties = {
81+ Weight : 4 ,
82+ Color : 1 ,
83+ Funnyfactor : 5
84+ }
85+ tank . requires = [ '#b1' ]
86+ tank . covers = [ '#a5' , '#a6' , '#a7' , '#b1' ]
87+ this . game . add . existing ( tank )
88+
89+ // Play the dialogs one after another
90+ this . game . mulle . playAudio ( '89d001v0' , ( ) => {
91+ this . game . mulle . playAudio ( '89d003v0' , ( ) => {
92+ this . game . mulle . user . Junk . yard [ 172 ] = {
93+ x : this . game . rnd . integerInRange ( 290 , 580 ) ,
94+ y : 440
95+ }
96+
97+ this . game . time . events . remove ( buffaTimer )
98+ buffa . animations . stop ( )
99+
100+ // Use blinkThing for the disappearing effect
101+ new blinkThing ( this . game , tank , ( ) => {
102+ this . game . mulle . stopAudio ( '89e001v0' )
103+ this . game . time . events . remove ( animationTimer )
104+ this . game . time . events . remove ( buffaTimer )
105+ buffa . animations . stop ( )
106+ this . game . state . start ( 'world' )
107+ } , this )
108+ } )
109+ } )
110+ }
111+
112+ shutdown ( ) {
113+ this . game . mulle . stopAudio ( 'viola' )
114+ super . shutdown ( )
115+ }
116+ }
117+
118+ export default ViolaState
0 commit comments