Sint.icl 93.9 KB
Newer Older
Mike Wiering's avatar
Mike Wiering committed
1
2
3
module Sint

/*
4
    Sint Nicolaas '99
Mike Wiering's avatar
Mike Wiering committed
5
6
7
8

    Written by Mike Wiering (mike.wiering@cs.kun.nl)
    Katholieke Universiteit Nijmegen
    
Mike Wiering's avatar
Mike Wiering committed
9
10
    For more information, see: http://www.cs.kun.nl/is/sint/
    
11
    Compile with 4000K heap space (Project, Application options)
Mike Wiering's avatar
Mike Wiering committed
12
13
*/

14
15
import StdEnv, StdIO, StdGameDef, StdGame, StdGSt, notes
import osgame, gst, gameobjectutils, Random
Mike Wiering's avatar
Mike Wiering committed
16
17
/* import ArgEnv */

18
import SintGfx  /* generated by Tile Studio */
Mike Wiering's avatar
Mike Wiering committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

VERSION :== "Sint '99 - Versie 1.0"

/* layers */
LYR_BACKGROUND   :==   1
LYR_MIDGROUND    :==   2
LYR_FOREGROUND   :==   3
LYR_KADO         :==   8
LYR_PLAYER       :==   9
LYR_INFRONT      :==  10
LYR_GLITTER      :==  20
LYR_STATUS       :==  30

/* main character defaults */
DEFAULT_LIVES :== 3
DEFAULT_TIME  :== 250
BONUS_TIME    :== 125
TODO          :== (5 * (5 + 1))

BONUS_PPN     :== 50
EXTRA_PPN     :== 15

/* scrolling text positions */
START_MSG     :== 340
STOP_MSG      :== -340

/* level result codes */
EC_NONE       :==  0
EC_SUCCESS    :==  1
EC_FAILURE    :==  2
EC_QUIT       :==  3

FIRST_TIME    :== -1000

SHOW_PERS_HIS :== -2000
SHOW_HIS      :== -2001

FPS           :== 70
FADE          :== True
ESC_QUIT      :== True

CARDWARE      :== False

/* high scores */

HIGH_SCORES_FILE :== "SINT99.HIS"

::  HiS
    = { name    :: !String
      , hiscore :: !Int
      }
70
      
Mike Wiering's avatar
Mike Wiering committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
::  CodedHiS
    = { codedhiscore :: !String    /* binary representation of name and score */
      }

emptyhis = { codedhiscore = "" }

MAX_NUMBER_LEN :== 16
MAX_NAME_LEN   :== 32

GRONDTAL  :==  10


DecodeHiS :: CodedHiS -> [HiS]
DecodeHiS chis
    = decodehis ([c \\ c <-: chis.codedhiscore] ++ ['\n']) "" 0 0
where
    decodehis :: [Char] !String !Int !Int -> [HiS]
    decodehis [] _ _ _ = []
    decodehis [c:cs] s i n
        | n < MAX_NUMBER_LEN                 = decodehis cs s ((i * GRONDTAL) + (toInt c)) (n + 1)
        | n < MAX_NAME_LEN + MAX_NUMBER_LEN  = decodehis cs (s +++ (if (toInt c == 0) "" (toString c))) i (n + 1)
        | otherwise                          = [{name = s, hiscore = i}: decodehis [c:cs] "" 0 0] 

EncodeHiS :: [HiS] -> CodedHiS
EncodeHiS his
    # chis = codehis his
    = { codedhiscore = {c \\ c <- chis}}
where
    codehis :: [HiS] -> [Char]
    codehis [] = []
    codehis [h:hs] = (codeh h) ++ (codehis hs)

    codeh h =: {name, hiscore} = (reverse (addzero (codehiscore hiscore) MAX_NUMBER_LEN)) ++
                                 (addzero [c \\ c <-: name] MAX_NAME_LEN)

    codehiscore :: Int -> [Char]
    codehiscore 0 = []
    codehiscore score
        = [toChar (score rem GRONDTAL)] ++ codehiscore (score / GRONDTAL)

    addzero :: [Char] Int -> [Char]
    addzero c n
        | length c < n = (addzero c (n - 1)) ++ [toChar 0]
        | otherwise    = c


ReadScores :: !String !*Files -> (!(!*File, !CodedHiS), !*Files)
ReadScores filename files
    # (exists, file, files) = fopen fpath FReadText files
    | exists
        # (codedhis, file) = ReadHiS file
        = ((file, codedhis), files)
    # (_, file, files) = fopen fpath FWriteText files
    | otherwise
        = ((file, emptyhis), files)
where
    fpath = filename

    ReadHiS :: !*File -> (!CodedHiS, !*File)
    ReadHiS file
        | sfend file
            = (emptyhis, file)
        # (codedhi, file) = freadline file
        = ({codedhiscore = codedhi}, file)

WriteScores :: !*File !CodedHiS !*Files -> *Files
WriteScores file codedhis files
    # (ok, file) = freopen file FWriteText
    | not ok
        = snd (fclose file files)
    # file = WriteHiS codedhis file    
    = snd (fclose file files)
where
    WriteHiS :: !CodedHiS !*File -> *File
    WriteHiS codedhis file
        = file <<< codedhis.codedhiscore <<< '\n'


FindScore :: String CodedHiS -> Int
FindScore s codedhis
    = findscore s (DecodeHiS codedhis)
where
    findscore :: String [HiS] -> Int
    findscore _ [] = 0
    findscore s [h:hs]
        | h.name == s   = h.hiscore
        | otherwise     = findscore s hs

UpdateScore gst
    # personalscore = FindScore gst.player gst.codedhis
    | (gst.score == 0) || (gst.player == "")
        = {gst & pershiscore = personalscore, rank = 10000}
    # hislist = DecodeHiS gst.codedhis
    # (hislist, newrank) = addscoretolist hislist {name = gst.player, hiscore = gst.score} 1
    # gst = {gst & codedhis = EncodeHiS hislist}
    = {gst & pershiscore = personalscore, rank = newrank}
where
    addscoretolist :: [HiS] HiS Int -> ([HiS], Int)
    addscoretolist [] h n = ([h], n)
    addscoretolist [x:xs] h n
        | h.hiscore > x.hiscore = ([h:[x:xs]], n)
        | otherwise
             # (newxs, newn) = addscoretolist xs h (n + 1)
             = ([x:newxs], newn)


/* the game state definition */
178

Mike Wiering's avatar
Mike Wiering committed
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
::  GameState
    = { curlevel    :: !Int         /* 1 = title, 2 = level1, 3 = bonus1, 4 = level2, etc */
      , maxlevel    :: !Int
      , titlescreen :: !Bool
      , quit        :: !Bool
      , statusline  :: !Bool
      , exitcode    :: !Int
      , lives       :: !Int
      , ppn         :: !Int         /* pepernoten */
      , time        :: !Int
      , score       :: !Int
      , gameover    :: !Bool
      , bonus       :: !Bool
      , bonusmsg    :: !Int         /* current position of scrolling message */
      , morningmsg  :: !Int
      , readymsg    :: !Int
      , notreadymsg :: !Int
      , player      :: !String      /* player's name */
      , codedhis    :: !CodedHiS
      , pershiscore :: !Int
      , rank        :: !Int
      , cursor      :: !Int
      , randseed    :: !RandomSeed
      }

initialGameState = { curlevel    = 0
                   , maxlevel    = 5
                   , titlescreen = True
                   , quit        = False
                   , statusline  = True
                   , exitcode    = EC_NONE
                   , lives       = DEFAULT_LIVES
                   , ppn         = 0
                   , time        = FIRST_TIME
                   , score       = 0
                   , gameover    = False
                   , bonus       = False
                   , bonusmsg    = STOP_MSG
                   , morningmsg  = STOP_MSG
                   , readymsg    = STOP_MSG
                   , notreadymsg = STOP_MSG
                   , player      = ""
                   , codedhis    = emptyhis
                   , pershiscore = 0
                   , rank        = 0
                   , cursor      = 0
                   , randseed    = nullRandomSeed
                   }

/* ---------- main program: load game definition and run the game! ---------- */

Start world
    # (randomSeed, world) = getNewRandomSeed world
    # initgs = {initialGameState & randseed = randomSeed}
    = startIO SDI initgs init [ProcessClose closeProcess] world
where
    init ps=:{ls=initgs}
        # ((hisfile, codedhis), ps) = accFiles (ReadScores HIGH_SCORES_FILE) ps
        # gs = {initgs & codedhis = codedhis}
        # (finalgamestate, _, ps) = openGame gs SintGame [ColorDepth depth, ScreenSize {w=320,h=200}] ps
        # ps = appFiles (WriteScores hisfile finalgamestate.codedhis) ps
        = closeProcess ps

    depth = 16
/*
    depth = if ((parameter "/8") || (parameter "-8")) 8 16

    parameter arg
        = checkpar arg getCommandLine 0
    where
        checkpar arg cmdline n
            | n >= (size cmdline) = False
            | cmdline.[n] == arg  = True
            | otherwise           = (checkpar arg cmdline (n + 1)) 
*/    

/* ---------- the complete game definition starts here ---------- */

SintGame :: (Game GameState)
SintGame =
    { levels = [ TitleScreen
               , Level1
               , Level1b
               , Level2
               , Level2b

               ]
    , quitlevel = accGSt QuitFunction
    , nextlevel = accGSt NextLevelFunction
    , textitems = accGSt GameTexts
    }


/* if the quit function returns true, the game engine quits the level */

QuitFunction :: GameState -> (Bool, GameState)
QuitFunction gst
    = (gst.quit, {gst & quit = False})


/* function that returns the next level to run, 0 = end game */

NextLevelFunction :: GameState -> (Int, GameState)
NextLevelFunction gst =: {curlevel, maxlevel, exitcode, lives, gameover, bonus}
    | exitcode == EC_QUIT
        = (0, gst)
    | (curlevel == 0) || gameover
        = title gst
    | curlevel == 1  // title screen
        = (next, resetgame gst)
    | exitcode == EC_FAILURE
        | lives > 0
            = (curlevel, {(resetlevel gst) & lives = lives - 1})
        = title gst
    | exitcode == EC_SUCCESS
        | not (normallevel curlevel)
            # (lev, gst) = nextlevel
            = (lev, {gst & bonus = False})
        = nextlevel
    = title gst
where
    resetgame gst
        = { resetlevel gst 
          & titlescreen = False
          , statusline = True
          , lives = DEFAULT_LIVES
          , score = 0
          , curlevel = next
          }

    resetlevel gst
        = { gst
          & ppn = 0
          , time = DEFAULT_TIME
          , gameover = False
          , bonus = False
          }

    title gst
        # gst = UpdateScore gst
        # gst = if (gst.time == FIRST_TIME) gst {gst & time = SHOW_PERS_HIS}
        = (1, gsttitle gst)
    where
        gsttitle gst
            = { gst 
              & titlescreen = True
              , statusline = False
              , gameover = False
              , curlevel = 1
              }

    nextlevel = if (next > maxlevel)
                     (title gst)
                     (next, { gst 
                            & curlevel = next
                            , time = if (normallevel next) DEFAULT_TIME BONUS_TIME
                            , bonusmsg    = STOP_MSG
                            , morningmsg  = STOP_MSG
                            , readymsg    = STOP_MSG
                            , notreadymsg = STOP_MSG
                            })

    next
        | (normallevel curlevel)
            | bonus
                = curlevel + 1  // play bonus level
            = curlevel + 2      // next (normal) level
        = curlevel + 1          // coming from a bonus level, play next level

    normallevel n = ((n rem 2) == 0)


/* function that returns text to be displayed */

GameTexts :: GameState -> ([GameText], GameState)
GameTexts gst
    | gst.statusline
        # (msg, gst) = if (gst.morningmsg > STOP_MSG) 
                           ([Morning gst.morningmsg], {gst & morningmsg = gst.morningmsg - 2})
                           ([], gst)
        # (msg, gst) = if (gst.bonusmsg > STOP_MSG) 
                           ([Bonus gst.bonusmsg], {gst & bonusmsg = gst.bonusmsg - 2})
                           (msg, gst)
        # (msg, gst) = if (gst.readymsg > STOP_MSG) 
                           ([Ready gst.readymsg], {gst & readymsg = gst.readymsg - 2})
                           (msg, gst)
        # (msg, gst) = if (gst.notreadymsg > STOP_MSG) 
                           ([NotReady gst.notreadymsg], {gst & notreadymsg = gst.notreadymsg - 2})
                           (msg, gst)
        = ([ Lives    gst.lives
           , TimeLeft (if (gst.time < 0) 0 gst.time)
           , PPN      gst.ppn
           , Score    gst.score
           ] 
           ++ (if gst.gameover [GameOver] [])
           ++ (if (gst.time < 0) [TimeUp] [])
           ++ msg
           , gst)
    | gst.time == FIRST_TIME
        # gst = {gst & cursor = gst.cursor + 1}
        = ([Version, TypeNaam, Naam (" " +++ gst.player +++ (if ((gst.cursor / 10) rem 2 == 0) " " "|"))], gst)
    | gst.time == FIRST_TIME - 1
        # gst = {gst & cursor = gst.cursor + 1}
        = ([Version, TypeNaam, Naam gst.player, Pers (FindScore gst.player gst.codedhis)], gst)
    | gst.time == SHOW_PERS_HIS
        = ((PersHiScores (DecodeHiS gst.codedhis) gst.score gst.pershiscore gst.player gst.rank), gst)
    | gst.time == SHOW_HIS
        = ((HiScores (DecodeHiS gst.codedhis)), gst)
    = ([], gst)


/* ---------- bounds and event codes ---------- */

/* bounds: groups of objects that collide in the same way */

BND_MAIN_CHARACTER     :==  (1 <<  0)
BND_POWER_UP           :==  (1 <<  1)
BND_KADO               :==  (1 <<  2)
BND_ENEMY              :==  (1 <<  3)
BND_BLOCKS             :==  (1 <<  4)
BND_CHIMNEY            :==  (1 <<  5)
BND_ENDING             :==  (1 <<  6)
BND_STAT               :==  (1 <<  7)
BND_HURT               :==  (1 <<  8)
/* predefined bounds
404
405
BND_MAP_CODES          :==  (1 << 30)  // codes defined in the level editor
BND_STATIC_BOUNDS      :==  (1 << 31)  // bounds defined in the level editor
Mike Wiering's avatar
Mike Wiering committed
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
*/

/* event codes objects can send to each other (use createUserGameEvent) */

EV_QUIT_LEVEL          :==    1
EV_GAME_OVER           :==    2
EV_TIME_UP             :==    3

EV_READY               :==    5
EV_KADO_DROPPED        :==    6
EV_PEPERNOOT           :==    7
EV_ALL_DONE            :==    8

EV_STOP_BLINKING       :==   10
EV_STOP_MOVING         :==   11

EV_COUNT_SCORE         :==   14
EV_PPN_SCORE           :==   15
EV_ADD_BIRD_SCORE      :==   16

EV_SUNRISE             :==   18

EV_HEALTH              :==   20
EV_TIMER               :==   21

EV_POS                 :==  100


/* ---------- objects ---------- */

/* object codes (must correspond with level map) */

OBJ_AUTOINIT           :==     0

440
/* OBJ_START              :==  0x10 */
Mike Wiering's avatar
Mike Wiering committed
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
OBJ_STATIC_PEPERNOOT   :==  0x10
OBJ_FALLING_PEPERNOOT  :==  0x11
OBJ_LETTER             :==  0x12
OBJ_HEART              :==  0x13
OBJ_LIFE               :==  0x14

OBJ_FALLING_KADO1      :==  0x15
OBJ_FALLING_KADO2      :==  0x16
OBJ_FALLING_KADO3      :==  0x17
OBJ_FALLING_KADO4      :==  0x18
OBJ_FALLING_KADO5      :==  0x19

OBJ_BOUNCEBLOCK        :==  0x20
OBJ_TRAMP              :==  0x21

OBJ_CHIMNEY1           :==  0x25
OBJ_CHIMNEY2           :==  0x26
OBJ_CHIMNEY3           :==  0x27
OBJ_CHIMNEY4           :==  0x28
OBJ_CHIMNEY5           :==  0x29

OBJ_ANTENNE            :==  0x30

OBJ_CAR                :==  0x40

OBJ_FRONT              :==  0x5F

OBJ_FADE               :==  0x60

OBJ_BIRD               :==  0x81


OBJ_MAIN_CHAR          :==  0xF0

OBJ_ENDING             :==  0xFE


OBJ_KADO1              :== 0x101
OBJ_KADO2              :== 0x102
OBJ_KADO3              :== 0x103
OBJ_KADO4              :== 0x104
OBJ_KADO5              :== 0x105

OBJ_FLITS              :== 0x110
OBJ_STAT               :== 0x111

OBJ_SUN                :== 0x115


// default block size
W :== 20
H :== 20

BLOCK_SIZE :== {w = W, h = H}
ITEM_SIZE  :== {w = W, h = 16}

NEVER_FORGET :== {x = 10000, y = 10000}

GameObjectList = [ AutoInitObject
                 , StatHeartObject

                 , StaticPepernoot
                 , FallingPepernoot
                 , FallingLetter
                 , HeartObject
                 , LifeObject
                 
508
509
510
511
512
                 , Kado1, Kado2, Kado3, Kado4, Kado5

                 , KadoObject 1, KadoObject 2, KadoObject 3, KadoObject 4, KadoObject 5

                 , ChimneyObject 1, ChimneyObject 2, ChimneyObject 3, ChimneyObject 4
Mike Wiering's avatar
Mike Wiering committed
513
                 , ChimneyObject 5
514

Mike Wiering's avatar
Mike Wiering committed
515
516
517
518
519
                 , BounceBlockObject
                 , TrampObject

                 , BirdObject

520
521
                 , FadeObject 0, FadeObject 1, FadeObject 2, FadeObject 3, FadeObject 4
                 , FadeObject 5, FadeObject 6, FadeObject 7, FadeObject 8, FadeObject 9
Mike Wiering's avatar
Mike Wiering committed
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
                 
                 , AntenneObject
                 
                 , FlitsObject

                 , SunObject
                 
                 , EndingObject

                 , CarObject
                 
                 , MainCharObject
                 ] 


/* ---------- autoinit object ---------- */

/*
   this object is automatically initialized when the level starts
*/

STY :== 183
STS :== -5

AutoInitObject
    # obj = defaultGameObject OBJ_AUTOINIT size Void
    # obj = { obj
            & init  = (newinit size Void)
            }
    = obj
where
    size = {w = 1, h = 1}
    newinit size state subcode pos time gs
        # gs = setexitcode EC_NONE gs
        # (_, gs) = createNewGameObject OBJ_STAT  1       {x = 181-4, y = STY} gs
        # (_, gs) = createNewGameObject OBJ_STAT  2       {x = 193-4, y = STY} gs
        # (_, gs) = createNewGameObject OBJ_STAT  3       {x = 205-4, y = STY} gs
        # (_, gs) = createNewGameObject OBJ_STAT ST_X     {x =  29, y = STY} gs
        # (_, gs) = createNewGameObject OBJ_STAT ST_COLON {x = 257, y = STY} gs
561
        # (_, gs) = createNewGameObject OBJ_STAT ST_TIME  {x =  83, y = STY} gs
Mike Wiering's avatar
Mike Wiering committed
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
        # (_, gs) = createUserGameEvent EV_TIMER
                        0 0 (BoundType BND_STAT) ST_TIME (FPS) gs
        # (_, gs) = createNewGameObject OBJ_STAT ST_COLON {x =  83, y = STY} gs
        # (_, gs) = createNewGameObject OBJ_STAT ST_PPN   {x = 133-4, y = STY} gs
        # (_, gs) = createNewGameObject OBJ_STAT ST_X     {x = 142-4, y = STY} gs

        # (objrec, gs) = defaultObjectRec subcode pos size time gs
        # objrec = {objrec & active = False}
        # (bonus, gs) = getbonus gs
        | bonus
            = {st=state, or=objrec, gs = msgbonus gs}
        = {st=state, or=objrec, gs=gs}


/* ---------- chimney objects ---------- */

ChimneyObject n
    # obj = defaultGameObject (OBJ_CHIMNEY1 + n - 1) ITEM_SIZE Void
    # obj = { obj
            & sprites = [ ChimneySprite 0, ChimneySprite 2, ChimneySprite 3
                        , ChimneySprite 4, ChimneySprite 5, ChimneySprite 6 
                        , ChimneySprite (m + 1), ChimneySprite (m + 2), ChimneySprite (m + 3)
                        , ChimneySprite (m + 4), ChimneySprite (m + 5), ChimneySprite (m + 6) 
                        ]
            , init      = (newinit ITEM_SIZE Void)
            , userevent = newuserevent
            }
    = obj
where
    m = n * 6
    
    newinit size state subcode pos time gs
        # pos = {x = pos.x + W / 2, y = pos.y + H / 2}
        # (objrec, gs) = defaultObjectRec subcode pos size time gs
        # objrec = { objrec
                   & layer          = AtLayer LYR_FOREGROUND
                   , currentsprite  = 12
                   , ownbounds      = BND_CHIMNEY
                   , offset         = {x = 0, y = BLOCK_SIZE.h} 
                   , forgetdistance = NEVER_FORGET
                   }
        = {st=state, or=objrec, gs=gs}
            
    newuserevent ev evpar1 evpar2 {st, or, gs}
        | (ev == EV_PEPERNOOT) && (evpar1 == n)
            = {st=st, or = {or & currentsprite = or.currentsprite - 1}, gs = addscore 100 gs}
        | (ev == EV_KADO_DROPPED) && (evpar1 == n)
            = {st=st, or = {or & currentsprite = or.currentsprite - 6}, gs = addscore 500 gs}
        = {st=st, or=or, gs=gs}


/* ---------- Fading block ---------- */

FadeObject n
    # obj = defaultGameObject (OBJ_FADE + n) size Void
    # obj = { obj
            & sprites   = [FadeSprite1 n, FadeSprite2 n]
            , init      = (newinit size Void)
            , collide   = newcollide
            , animation = killobject
            }
    = obj  
where
    size    = {w = 20, h = 14}

    newinit size state subcode pos time gs
        # (objrec, gs) = defaultObjectRec subcode pos size time gs
        # objrec = { objrec
                   & ownbounds      = BND_STATIC_BOUNDS
                   , collidebounds  = BND_MAIN_CHARACTER
                   , forgetdistance = {x = 10, y = 12}
                   , layer          = AtLayer LYR_FOREGROUND
                   } 
        = {st=state, or=objrec, gs=gs}

    newcollide bnds objtype objrec {st, or, gs}
        # or = {or & collidebounds = 0
                   , currentsprite = 2
                   , options.removemapcode = True
                   }
        = {st=st, or=or, gs = addscore 10 gs}


/* ---------- Antenne ---------- */

AntenneObject
    # obj = defaultGameObject OBJ_ANTENNE size Void
    # obj = { obj
            & init    = (newinit size Void)
            }
    = obj  
where
    size    = {w = 20, h = 16}

    newinit size state subcode pos time gs
        # (objrec, gs) = defaultObjectRec subcode pos size time gs
        # objrec = { objrec
                   & ownbounds      = BND_HURT + BND_STATIC_BOUNDS
                   , subcode        = fromDirectionSet {left = False, right = False,
                                                        top = True, bottom = True}
                   } 
        = {st=state, or=objrec, gs=gs}


/* ---------- in front ---------- */

Level1FrontObj = [ L1FrontObject 1
                 , L1FrontObject 2
                 , L1FrontObject 3
                 , L1FrontObject 4
                 ]


L1FrontObject n
    # obj = defaultGameObject (OBJ_FRONT - n + 1) BLOCK_SIZE Void
    # obj = { obj
            & sprites = [L1FrontObjectSprite n]
            , init = (newinit BLOCK_SIZE Void)
            }
    = obj
where
    newinit size state subcode pos time gs
        # (objrec, gs) = defaultObjectRec subcode pos size time gs
        # objrec = { objrec & layer = AtLayer LYR_INFRONT }
        = {st=state, or=objrec, gs=gs}
        
ChimneyList = [ OBJ_CHIMNEY1
              , OBJ_CHIMNEY2
              , OBJ_CHIMNEY3
              , OBJ_CHIMNEY4
              , OBJ_CHIMNEY5
              ]
              
KadoList = [ OBJ_FALLING_KADO1
           , OBJ_FALLING_KADO2
           , OBJ_FALLING_KADO3
           , OBJ_FALLING_KADO4
           , OBJ_FALLING_KADO5
           ]

/* ---------- Sun ---------- */

SunObject
    # obj = defaultGameObject OBJ_SUN size Void
    # obj = { obj
707
            & sprites = [SunSprite1]
Mike Wiering's avatar
Mike Wiering committed
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
            , init = (newinit size Void)
            , userevent = newuserevent
            }
    = obj
where
    size = {w = 40, h = 32}

    newinit size state subcode pos time gs
        # (objrec, gs) = defaultObjectRec subcode pos size time gs
        # objrec = { objrec & layer = AtLayer LYR_BACKGROUND
                            , options = { objrec.options & static = True }
                            , subcode = 1
                   }
//        # (rnd, gs) = IRRnd 5 gs
//        # (_, gs) = playSoundSample SND_COCK DefaultVolume PAN_CENTER 
//                       (getnotefreq (90 + rnd)) 0 gs
        # (_, gs) = createUserGameEvent EV_SUNRISE 0 0 Self ANY_SUBTYPE 3 gs
        = {st=state, or=objrec, gs=gs}

    newuserevent ev _ _ {st, or, gs}
        | ev == EV_SUNRISE
            # or = {or & pos = {x = or.pos.x, y = or.pos.y - 1}}
            | or.pos.y > 2
                # (_, gs) = createUserGameEvent EV_SUNRISE 0 0 Self ANY_SUBTYPE 1 gs
                = {st=st, or=or, gs=gs}
            = {st=st, or=or, gs=gs}
        = {st=st, or=or, gs=gs}

/* ---------- items ---------- */

738
739
StaticPepernoot  = StaticGameItem  OBJ_STATIC_PEPERNOOT  PepernootSprite1  {w = 14, h = 12}
FallingPepernoot = FallingGameItem OBJ_FALLING_PEPERNOOT PepernootSprite1  {w = 14, h = 12}
Mike Wiering's avatar
Mike Wiering committed
740
741

FallingLetter = FallingGameItem OBJ_LETTER (LetterSprite 0) ITEM_SIZE
742
743
HeartObject   = FallingGameItem OBJ_HEART  ItemSprite1 ITEM_SIZE
LifeObject    = FallingGameItem OBJ_LIFE   ItemSprite5  ITEM_SIZE
Mike Wiering's avatar
Mike Wiering committed
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759

Kado1 = FallingGameItem OBJ_FALLING_KADO1 (KadoSprite 1) ITEM_SIZE
Kado2 = FallingGameItem OBJ_FALLING_KADO2 (KadoSprite 2) ITEM_SIZE
Kado3 = FallingGameItem OBJ_FALLING_KADO3 (KadoSprite 3) ITEM_SIZE
Kado4 = FallingGameItem OBJ_FALLING_KADO4 (KadoSprite 4) ITEM_SIZE
Kado5 = FallingGameItem OBJ_FALLING_KADO5 (KadoSprite 5) ITEM_SIZE



FallingGameItem objecttype sprite size
    # obj = StaticGameItem objecttype sprite size
    # obj = { obj
            & init = (newinit size Void)
            }
    | (objecttype == OBJ_LETTER)
        = {obj & sprites = [LetterSprite 0, LetterSprite 1, LetterSprite 2, LetterSprite 3, 
760
                                ItemAnimation2]}
Mike Wiering's avatar
Mike Wiering committed
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
    = obj
where
    newinit size state subcode pos time gs
        # oldpos = pos
        # pos = {pos & x = if (subcode == 1) (pos.x + W / 2) (pos.x)}
        # (objrec, gs) = defaultObjectRec subcode pos size time gs
        # objrec = { objrec
                   & acceleration   = {rx = 0.0, ry = 1.0 / 16.0}
                   , slowdown       = {fvx = Factor (1.0 / 24.0), fvy = Value 0.0}
                   , bounce         = {fvx = Value 0.0, fvy = Factor (3.0 / 5.0)}
                   , ownbounds      = BND_POWER_UP
                   , bouncebounds   = BND_STATIC_BOUNDS
                   , collidebounds  = BND_MAIN_CHARACTER + BND_ENEMY
                   , layer          = AtLayer LYR_FOREGROUND
                   , forgetdistance = {x = 8, y = 10}
                   }
        | (objecttype == OBJ_LETTER)
            = {st=state, or = {objrec & currentsprite = subcode + 1, pos = oldpos}, gs=gs}
        | (isMember objecttype [OBJ_FALLING_PEPERNOOT, OBJ_STATIC_PEPERNOOT])
            = {st=state, or = {objrec & pos.x = objrec.pos.x + (20 - 14) / 2}, gs=gs}
        | (objecttype == OBJ_LIFE)
            # (ppn, gs) = getppn gs
            | ppn == BONUS_PPN
                = {st=state, or=objrec, gs=gs}
            = killobject {st=state, or=objrec, gs=gs}
        = {st=state, or=objrec, gs=gs}


StaticGameItem objecttype sprite size
    # obj = defaultGameObject objecttype size Void
    # obj = { obj
792
            & sprites   = [sprite, ItemAnimation2]
Mike Wiering's avatar
Mike Wiering committed
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
            , init      = (newinit size Void)
            , animation = killobject
            , collide   = newcollide
            }
    = obj
where
    newinit size state subcode pos time gs
        # (dx, gs) = 
            case subcode of
                0         -> (0, gs)
                1         -> (W / 2, gs)
                otherwise -> (IRRnd (W * subcode) gs)
        # pos = {pos & x = pos.x + dx}
        # (objrec, gs) = defaultObjectRec subcode pos size time gs
        # objrec = { objrec
                   & pos            = { x = pos.x + ((BLOCK_SIZE.w - size.w) / 2)
                                      , y = pos.y + (BLOCK_SIZE.h - size.h)
                                      }
                   , ownbounds      = BND_POWER_UP
                   , bouncebounds   = BND_STATIC_BOUNDS
                   , collidebounds  = BND_MAIN_CHARACTER
                   , layer          = AtLayer LYR_FOREGROUND
                   , forgetdistance = NEVER_FORGET
                   }
        = {st=state, or=objrec, gs=gs}
        
    newcollide bnds objtype objrec {st, or, gs}
        | objtype == OBJ_BIRD
            | (isMember objecttype ([OBJ_FALLING_PEPERNOOT, OBJ_LETTER, OBJ_HEART, OBJ_LIFE] ++ KadoList) &&
               (objrec.speed.ry < 0.0)) 
                # or = {or & speed = {objrec.speed & ry = objrec.speed.ry}
                           , pos.x = objrec.pos.x + (objrec.size.w - or.size.w) / 2}
                = {st=st, or=or, gs=gs}
            = {st=st, or=or, gs=gs}
        | objtype == OBJ_MAIN_CHAR
            # points = itemscore objecttype
            # gs = addscore points gs
            # gs = itemsound objecttype gs
            # or = { or 
                   & currentsprite         = if (objecttype == OBJ_LETTER) 5 2
                   , options.removemapcode = True
                   , layer                 = AtLayer LYR_GLITTER
                   , ownbounds             = 0
                   , collidebounds         = 0
                   , offset                = { x = (size.w - ITEM_SIZE.w) / 2
                                             , y = (size.h - ITEM_SIZE.h) / 2
                                             }
                   }
            = {st=st, or=or, gs=gs}
        = {st=st, or=or, gs=gs}
    where
        itemscore tp
            | isMember tp [OBJ_STATIC_PEPERNOOT, OBJ_FALLING_PEPERNOOT]
                = 50
            | isMember tp KadoList
                = 250
            | isMember tp [OBJ_HEART]
                = 500
            | isMember tp [OBJ_LIFE]
                = 750
            = 150
                
        itemsound tp gs
            # (pan, gs) = RandomPan gs
            # vol = HighVolume
            | isMember tp [OBJ_STATIC_PEPERNOOT, OBJ_FALLING_PEPERNOOT]
                # instr = SND_PPN
                # vol = DefaultVolume
                # (_, gs) = playSoundSample instr vol pan (getnotefreq 69) 0 gs
                # (_, gs) = playSoundSample instr vol pan (getnotefreq 80) 3 gs
                = gs
            | isMember tp KadoList
                # instr = SND_FLUTE
                # (_, gs) = playSoundSample instr vol pan (getnotefreq 104) 0 gs
                # (_, gs) = playSoundSample instr vol pan (getnotefreq 108) 2 gs
                # (_, gs) = playSoundSample instr vol pan (getnotefreq 111) 4 gs
                = gs
            | isMember tp [OBJ_HEART]
                # ins = SND_XYLOFOON
                
                /* Sinterklaas Kapoentje... */
                # gs = PlaySong ins vol pan 106 0 [(7,16),(7,8),(9,16),(9,8),(7,24),(4,24)] gs
                # gs = PlaySong ins vol pan 106 0 [(4,16),(4,8),(5,16),(5,8),(4,24),(0,24)] gs
                = gs
            | isMember tp [OBJ_LIFE]
                = AddLife gs
            # instr = SND_XYLOFOON
            # (_, gs) = playSoundSample instr vol pan (getnotefreq 127) 0 gs
            # (_, gs) = playSoundSample instr vol pan (getnotefreq 130) 3 gs
            # (_, gs) = playSoundSample instr vol pan (getnotefreq 134) 3 gs
            = gs


killobject {st, or, gs}
    = {st = st, or = {or & active = False}, gs = gs}

AddLife gs
    # (pan, gs) = RandomPan gs
    # vol = HighVolume
    # ins = SND_FLUTE
    # gs = PlaySong ins vol pan 100 0 [(-4,5),(0,5),(3,5),(8,5),(12,5),(15,5),(20,5)] gs
    = inclives gs


Beep gs
    # (_, gs) = playSoundSample SND_PPN DefaultVolume PAN_CENTER (getnotefreq 69) 0 gs
    = gs

PlaySong instr vol pan base delay [] gs = gs
PlaySong instr vol pan base delay [(note,duration):ls] gs
    # (_, gs) = playSoundSample instr vol pan (getnotefreq (base + note)) delay gs
    = PlaySong instr vol pan base (delay + duration) ls gs


/* ---------- textitems objects ---------- */

ST_X        :==  10
ST_COLON    :==  11
ST_PPN      :==  12
ST_TIME     :==  13

:: StatState
   = { skyr  :: !Int
     , skyg  :: !Int
     , skyb  :: !Int
     , addr  :: !Int
     , addg  :: !Int
     , addb  :: !Int
     }

StatHeartObject
    # obj = defaultGameObject OBJ_STAT size state
    # obj = { obj
926
927
            & sprites   = [StatusSprite1, StatusSprite2, StatusSprite3,
                           StatusSprite4, StatusSprite5, StatusSprite6]
Mike Wiering's avatar
Mike Wiering committed
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
            , init      = (newinit size state)
            , userevent = newuserevent
            }
    = obj
where
    size    = {w = 12, h = 12}

    state   = { skyr = 0
              , skyg = 0
              , skyb = 0
              , addr = 2
              , addg = 2
              , addb = 2
              }

    newinit size state subcode pos time gs
        # (objrec, gs) = defaultObjectRec subcode pos size time gs
        # objrec = { objrec
                   & options = {objrec.options & static = True}
                   , layer = AtLayer LYR_STATUS
                   , currentsprite = if (subcode >= ST_X) (subcode - 7) 2
                   , ownbounds = BND_STAT
                   }
        # (lev, gs) = getlevel gs
        # rgb = BackGroundColor lev
        # state = 
            {state & skyr = (fromRGB rgb).r
                   , skyg = (fromRGB rgb).g
                   , skyb = (fromRGB rgb).b
            }
        = {st=state, or=objrec, gs=gs}
    where
        fromRGB (RGB rgb) = rgb

    newuserevent ev evpar1 evpar2 {st, or, gs}
        | (ev == EV_POS) && (or.subcode == ST_COLON) && (or.pos.x < 160)
            # or = {or & pos.x = or.pos.x + evpar1}
            = {st=st, or=or, gs=gs}
        | (ev == EV_TIMER) && (or.subcode == ST_TIME)
            # (_, gs) = createUserGameEvent EV_TIMER
                        0 0 (BoundType BND_STAT) ST_TIME (FPS) gs
            # (st, gs) = tick st gs
            = {st=st, or=or, gs=gs}
        | (ev == EV_HEALTH) && (or.subcode < 10)
            # or = {or & currentsprite = if (evpar1 < or.subcode) 1 2}
            = {st=st, or=or, gs=gs}
        = {st=st, or=or, gs=gs}


/* ---------- ending of the level ---------- */

EndingObject
    # obj = defaultGameObject OBJ_ENDING size Void
    # obj = { obj
            & sprites   = []
            , init      = (newinit size Void)
            , collide   = newcollide
            , userevent = newuserevent
            }
    = obj
where
    size    = {w = 6 * 20, h = 40}

    newinit size state subcode pos time gs
        # pos = {pos & y = pos.y + 20}
        # (objrec, gs) = defaultObjectRec subcode pos size time gs
        # objrec = { objrec
                   & layer          = AtLayer LYR_FOREGROUND
                   , ownbounds      = BND_ENDING
                   , collidebounds  = 0
                   , currentsprite  = 0
                   , forgetdistance = {x = 12, y = 12}

                   }
        = {st=state, or=objrec, gs=gs}

    newcollide bnds othertype otherobjrec {st, or, gs}
        = {st=st, or = {or & collidebounds = 0}, gs=gs}

    newuserevent ev evpar1 evpar2 {st, or, gs}
        | ev == EV_ALL_DONE
            = {st=st, or = {or & collidebounds = BND_MAIN_CHARACTER}, gs=gs}
        = {st=st, or=or, gs=gs}


/* ---------- car ---------- */

:: CarState
   = { sound :: Int
     , count :: Int
     }

CarObject
    # obj = defaultGameObject OBJ_CAR size state
    # obj = { obj
1023
            & sprites   = [CarSprite1]
Mike Wiering's avatar
Mike Wiering committed
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
            , init      = (newinit size state)
            , move      = newmove
            }
    = obj
where
    state   = { sound = 0, count = 0 }
    size    = {w = 80 - 8, h = 50 - 20}

    newinit size state subcode pos time gs
        # pos = {pos & y = pos.y - size.h + BLOCK_SIZE.h}
        # (objrec, gs) = defaultObjectRec subcode pos size time gs
        # objrec = { objrec
                   & layer                 = AtLayer LYR_FOREGROUND
                   , ownbounds             = BND_HURT
                   , collidebounds         = 0
                   , options.removemapcode = True
                   , speed                 = {rx = -4.0, ry = 0.0}
                   , skipmove              = 0
                   , subcode               = fromDirectionSet {left = True, 
                                                right = True, top = True, bottom = True}
                   , offset                = {x = -5, y = -20}
                   }
        # (_, gs) = playSoundSample SND_FLUTE2 HighVolume PAN_RIGHT 56000 0 gs
        # (_, gs) = playSoundSample SND_FLUTE2 HighVolume PAN_RIGHT 56000 6 gs
        # (_, gs) = playSoundSample SND_FLUTE2 HighVolume PAN_RIGHT 56000 1 gs
        # (_, gs) = playSoundSample SND_FLUTE2 HighVolume PAN_RIGHT 56000 7 gs
        # (_, gs) = playSoundSample SND_FLUTE2 HighVolume PAN_RIGHT 56000 8 gs
        = {st=state, or=objrec, gs=gs}

    newmove {st, or, gs}
        # (freq, gs) = IRRnd 60 gs
        # st = {st & sound = st.sound + freq + 25, count = st.count + 1}
        # freq = freq + st.sound
        # x = ((80 - st.count) - 40)
        # (rnd, gs) = IRRnd ((abs x) + 10) gs
        | (abs rnd) < 2
            # (_, gs) = playSoundSample SND_PLOF LowVolume (x * PAN_RIGHT / 45)
                              (5500 + freq) 13 gs
            = {st=st, or=or, gs=gs}
        | freq > 1000
            = {st = {st & sound = 0}, or=or, gs=gs}
        = {st=st, or=or, gs=gs}


/* ---------- flits ---------- */

FlitsObject
    # obj = defaultGameObject OBJ_FLITS size Void
    # obj = { obj 
1073
            & sprites   = [ItemAnimation3]
Mike Wiering's avatar
Mike Wiering committed
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
            , init      = (newinit size Void)
            , animation = killobject
            }
    = obj
where
    size    = {w = 24, h = 20}

    newinit size state subcode pos time gs
        # (objrec, gs) = defaultObjectRec subcode pos size time gs
        # objrec = { objrec
                   & layer         = AtLayer LYR_INFRONT
                   }
        = {st=state, or=objrec, gs=gs}



/* ---------- flying enemies ---------- */

1092
BirdObject = FlyingObject OBJ_BIRD [ItemSprite6, ItemSprite7]
Mike Wiering's avatar
Mike Wiering committed
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173

FlyingObject objtype sprlist
    # obj = defaultGameObject objtype size Void
    # obj = { obj
            & sprites = sprlist
            , init    = (newinit size Void)
            , collide = newcollide
            , move    = newmove
            }
    = obj  
where
    size    = {w = 20, h = 16}

    newinit size state subcode pos time gs
        # (objrec, gs) = defaultObjectRec subcode pos size time gs
        # objrec = { objrec
                   & offset         = {x = 0, y = -3}
                   , speed          = {rx = -0.5, ry = 0.0}
                   , bounce         = {fvx = Factor 1.0, fvy = Factor 1.0} 
                   , layer          = AtLayer (LYR_FOREGROUND + 1)
                   , options        = { objrec.options
                                      & automirrorleftright = True
                                      }
                   , ownbounds      = BND_ENEMY
                   , bouncebounds   = BND_STATIC_BOUNDS + BND_ENEMY + BND_MAP_CODES
                   , collidebounds  = BND_MAIN_CHARACTER
                   , currentsprite  = (1 + subcode)
                   , forgetdistance = {x = 6, y = 4}
                   , skipmove       = 0
                   } 
        = {st=state, or=objrec, gs=gs}

    newcollide bnds othertype otherobjrec {st, or, gs}
        | ((othertype == OBJ_MAIN_CHAR) && (bnds.bottom))
            # (freq, gs) = IRRnd 1000 gs
            # (_, gs) = playSoundSample SND_BIRD LowVolume PAN_CENTER 
                            ((getnotefreq 100) + freq) 0 gs
            # (_, gs) = playSoundSample SND_FLUTE LowVolume PAN_CENTER
                                          (90000 + freq * 2) 1 gs
            # (_, gs) = playSoundSample SND_FLUTE LowVolume PAN_CENTER
                                          (45000 + freq) 0 gs
            = {st=st, or = kill or, gs=gs}
        = {st=st, or=or, gs=gs}

    newmove {st, or, gs}
        # (turn, gs) = IRnd 30 gs
        # (xadd, gs) = RRnd 0.05 gs
        # (yadd, gs) = RRnd 0.085 gs
        # (skmv, gs) = IRnd 25 gs
        # rxv = (if (turn == 1) (~or.speed.rx) (or.speed.rx)) + xadd
        # ryv = or.speed.ry + yadd + 0.005
        # or = {or & skipmove = skmv, speed = {rx=rxv, ry=ryv}}
        = {st=st, or=or, gs=gs}


kill :: GameObjectRec -> GameObjectRec
kill or =
    {or & displayoptions.mirrorupdown = True
        , acceleration = {rx = 0.0, ry = 1.0 / 16.0}
        , speed = {rx = ~(or.speed.rx / 2.0), ry = -3.0}
        , ownbounds = 0
        , bouncebounds = 0
        , collidebounds = 0
        , forgetdistance = {x = 1, y = 1}
        , layer = InFront
        , options.removemapcode = True
        }


/* ---------- tramp / bounce block ---------- */

TrampObject = BounceObject OBJ_TRAMP False 4 (-2) 4

BounceBlockObject = BounceObject OBJ_BOUNCEBLOCK True 1 4 (ITEM_SIZE.h)

BounceObject objnr isLamp base rely hght
    # obj = defaultGameObject objnr size Void
    # obj = { obj
            & sprites   = [ {(LampSprite 0) & loop = False},
                            {(LampSprite 1) & loop = False},
                              LampSprite 2,
1174
                              ItemAnimation4
Mike Wiering's avatar
Mike Wiering committed
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
                          ]
            , init      = (newinit size Void)
            , collide   = newcollide
            , animation = newanimation
            }
    = obj
where
    size    = {w = ITEM_SIZE.w, h = hght}

    newinit size state subcode pos time gs
        # pos = {pos & y = pos.y + rely}
        # (time, gs) = GetTime gs
        # (bonus, gs) = getbonus gs
        # (objrec, gs) = defaultObjectRec subcode pos size time gs
        # objrec = { objrec
                   & layer           = AtLayer LYR_FOREGROUND
                   , speed           = {rx = ~(toReal subcode), ry = 0.0}
                   , bounce          = {fvx = Factor 1.0, fvy = Value 0.0}
                   , forgetdistance  = {x = 5 + 15 * subcode, y = 5} 
                   , ownbounds       = BND_BLOCKS
                   , collidebounds   = BND_MAIN_CHARACTER
                   , bouncebounds    = BND_STATIC_BOUNDS
                   , currentsprite   = if (isLamp) (if ((not bonus) && (time < 30)) 3 1) base
                   }
        = {st=state, or=objrec, gs=gs}

    newcollide bnds othertype otherobjrec {st, or, gs}
        | othertype == OBJ_MAIN_CHAR
            | (bnds.top || bnds.bottom)
                = {st=st, or = {or & offset.y = (if bnds.top 4 (-4))
                                   , currentsprite = if isLamp 2 base}, gs=gs}
            = {st=st, or=or, gs=gs}
        = {st=st, or=or, gs=gs}

    newanimation {st, or, gs}
        | (or.offset.y == 0)
            = {st=st, or = {or & currentsprite = base}, gs=gs}
        # or = {or & offset.y = ~(decr or.offset.y)}
        | not isLamp
            = {st=st, or=or, gs=gs}
        # (time, gs) = GetTime gs
        # (bonus, gs) = getbonus gs
        | (or.currentsprite == 1) && (time < 30) && (time > 0) && (not bonus)
            = {st=st, or = {or & currentsprite = 3}, gs=gs}
        = {st=st, or=or, gs=gs}
    where
        decr x
            | x < 0     = x + 1
            | otherwise = x - 1 


/* ---------- trail ---------- */

KadoObject n
    # obj = defaultGameObject (OBJ_KADO1 + n - 1) size Void
    # obj = { obj
            & sprites    = [KadoSprite n]
            , init       = (newinit size Void)
            , userevent  = newuserevent
            }
    = obj
where
    size = ITEM_SIZE
    
    newinit size state subcode pos time gs
        # (objrec, gs) = defaultObjectRec subcode pos size time gs
        # objrec = { objrec
                   & ownbounds      = BND_KADO
                   , bouncebounds   = 0
                   , collidebounds  = 0
                   , layer          = AtLayer (LYR_KADO - subcode)
                   , forgetdistance = {x = 10, y = 10}
                   }
        = {st=state, or=objrec, gs=gs}

    newuserevent ev evpar1 evpar2 {st, or, gs}
        | ev == (EV_POS + or.subcode)
            = {st=st, or = {or & pos = {x = evpar1, y = evpar2}}, gs=gs}
        | ev == EV_KADO_DROPPED
            | or.subcode == 0
                = {st=st, or = {or & active = False}, gs=gs}
            = {st=st, or = {or & subcode = or.subcode - 1, 
                          layer = AtLayer ((getlayer or.layer) + 1)}, gs=gs}
        = {st=st, or=or, gs=gs}

getlayer :: LayerPosition -> Int
getlayer InFront     = 0
getlayer (AtLayer n) = n


/* ---------- main character ---------- */

MC_IDLE  :==  1
MC_WALK  :==  2
MC_JUMP  :==  3
MC_FALL  :==  4
MC_FFST  :==  5

MC_TURN  :==  6
MC_DEAD  :==  7

TRAILXMIN   :== -20 - 4
TRAILXMAX   :==  32 - 4

TRAILTURNSPEED :==   2


:: MainCharState
   = { action      :: !Int
     , keyLeft     :: !Bool
     , keyRight    :: !Bool
     , lastpos1    :: !Point2
     , lastpos2    :: !Point2
     , lastspeed1  :: !RealXY
     , lastspeed2  :: !RealXY
     , lasthdir    :: !HDirection
     , turning     :: !Bool
     , traildelta  :: !Int
     , trail       :: [!Int]
     , lastypos    :: !Int
     , readytodrop :: !Bool
     , pepernoten  :: !Int
     , letters     :: !Int
     , health      :: !Int
     , enemynote   :: !Int
     , todo        :: !Int
     , extra       :: !Int
     , birdskilled :: !Int
     }

MainCharObject
    # obj = defaultGameObject OBJ_MAIN_CHAR size newstate
    # obj = { obj
1308
1309
1310
1311
1312
1313
1314
            & sprites    = [ SintAnimation1   // Idle
                           , SintAnimation2   // Walk
                           , SintAnimation3   // Jump
                           , SintAnimation4   // Fall
                           , SintAnimation5   // FFst
                           , SintAnimation6   // Turn
                           , SintSprite7      // Dead
Mike Wiering's avatar
Mike Wiering committed
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
                           ]
            , init       = (newinit size newstate)
            , move       = newmove
            , animation  = newanimation
            , keydown    = newkeydown
            , keyup      = newkeyup
            , collide    = newcollide
            , userevent  = newuserevent
            }
    = obj
where
    size     = {w = 24, h = 38}
    defofs   = {x = -4, y = -9}

    ac = 1.0 / 5.0
    
    defmaxspeed = {rx = 2.0, ry = 6.0}
    
    newstate = { action       = MC_IDLE
               , keyLeft      = False
               , keyRight     = False
               , lastpos1     = zero
               , lastpos2     = zero
               , lastspeed1   = zero
               , lastspeed2   = zero
               , lasthdir     = DirLeft
               , turning      = False
               , traildelta   = 0
               , trail        = []
               , lastypos     = 0
               , readytodrop  = True
               , pepernoten   = 0
               , letters      = 0
               , health       = 3
               , enemynote    = 0
               , todo         = 0
               , extra        = 0
               , birdskilled  = 0
               }

    newinit size state subcode pos time gs
        # pos = {x = pos.x + W / 2, y = pos.y + H - size.h}
        # (objrec, gs) = defaultObjectRec subcode pos size time gs
        # objrec = { objrec
                   & offset         = defofs
                   , acceleration   = {rx = 0.0, ry = 1.0 / 12.0}
                   , bounce         = {fvx = Value 0.0, fvy = Factor (1.0 / 16.0)} 
                   , maxspeed       = defmaxspeed
                   , slowdown       = {fvx = Factor (1.0 / 16.0), fvy = Value 0.0}
                   , layer          = AtLayer LYR_PLAYER
                   , options        = { objrec.options
                                      & checkkeyboard       = True
                                      , allowkeyboardrepeat = False
                                      , automirrorleftright = True
                                      }
                   , ownbounds      = BND_MAIN_CHARACTER
                   , bouncebounds   = BND_STATIC_BOUNDS
                   , collidebounds  = BND_ENEMY + BND_POWER_UP + BND_BLOCKS + BND_CHIMNEY
                                         + BND_ENDING + BND_HURT
                   , forgetdistance = NEVER_FORGET
                   , skipmove       = 0
                   }
        # (_, gs)  = createObjectFocus
                         { scrollleft      = 132
                         , scrollup        =  40
                         , scrollright     = 132
                         , scrolldown      =  42
                         , maxxscrollspeed =   2
                         , maxyscrollspeed =   3
                         } gs
        # (bonus, gs) = getbonus gs
        # state = { state & todo = if bonus 0 TODO
                          , extra = if bonus (-1) EXTRA_PPN
                  }
        = {st=state, or=objrec, gs=gs}


    newmove {st, or, gs}
        # newy     = (st.lastypos + or.pos.y + 1) / 2
        # st       = {st & traildelta = newdelta st.traildelta or.options.hdirection
                         , lastypos = newy}
        # trailpos = {x = or.pos.x + st.traildelta, y = newy + or.size.h - ITEM_SIZE.h - 1}
        # gs       = broadcastposition (length st.trail) trailpos.x trailpos.y 
                        (st.trail ++ [0]) gs
        | st.turning
            | (same st.lasthdir or.options.hdirection)
                = {st=st, or=or, gs=gs}
            = {st = {st & turning = False}, or = {or & currentsprite = MC_TURN}, gs=gs}
        = {st=st, or=or, gs=gs}
    where
        broadcastposition :: !Int !Int !Int [!Int] !(GSt gs) -> (GSt gs)
        broadcastposition n x y [] gs = gs
        broadcastposition n x y [l:ls] gs
            # (_, gs) = createUserGameEvent (EV_POS + n)
                        x y (BoundType BND_KADO) n (n * 11 + 4) gs
            = broadcastposition (n - 1) x y ls gs 

        same DirRight DirRight = True
        same DirLeft  DirLeft  = True
        same _ _               = False

        newdelta x DirLeft
            | x < TRAILXMAX    = x + TRAILTURNSPEED
            | otherwise        = TRAILXMAX
        newdelta x DirRight
            | x > TRAILXMIN    = x - TRAILTURNSPEED
            | otherwise        = TRAILXMIN

    newanimation {st, or, gs}
        # act = st.action
        # xstuck = ((or.pos.x == st.lastpos1.x) &&
                    (or.pos.x == st.lastpos2.x) &&
                    ((toInt or.speed.rx) == 0)
                   )
        # ystuck = ((or.pos.y == st.lastpos1.y) &&
                    (or.pos.y == st.lastpos2.y) &&
                    ((toInt or.speed.ry) == 0)
                   )
        # oldact = act
        # act = case act of
            MC_IDLE   -> if (toInt (or.speed.rx / 1.25) == 0)
                             (if (or.speed.ry > sp) MC_FALL MC_IDLE)
                             (if (or.speed.ry > sp) MC_FALL MC_WALK)
            MC_WALK   -> if (toInt (or.speed.rx / 1.25) == 0)
                             (if (or.speed.ry > sp) MC_FALL MC_IDLE)
                             (if (or.speed.ry > sp) MC_FALL MC_WALK)
            MC_JUMP   -> if (or.speed.ry > sp) MC_FALL
                              (if (xstuck && ystuck && (or.speed.ry == st.lastspeed2.ry))
                                  MC_IDLE
                                  MC_JUMP)
            MC_FALL   -> if (or.speed.ry > sp) MC_FALL MC_WALK
            otherwise -> MC_IDLE
        # st = {st & lastpos2 = st.lastpos1, lastspeed2 = st.lastspeed1}
        # st = {st & lastpos1 = or.pos, lastspeed1 = or.speed}
        # newsprite = if (or.speed.ry > 3.0) MC_FFST act

        # st = {st & action = act}
        # or = {or & currentsprite = newsprite}
        | (act == MC_WALK) && (oldact == MC_FALL)
            # (_, gs) = playSoundSample SND_PLOF LowVolume
                            PAN_CENTER DEFAULT_FREQUENCY 0 gs
            # st = {st & enemynote = 0}
            | st.lastspeed2.ry == defmaxspeed.ry
                = hurt {st=st, or = {or & speed = zero}, gs=gs}
            = {st=st, or=or, gs=gs}
        = {st=st, or=or, gs=gs}
    where
        sp = 1.0 / 4.0
        
    newkeydown key {st, or, gs}
        # action = st.action
        | key == GK_LEFT
            # st = {st & keyLeft = True}
            # newaction = if (action == MC_IDLE) MC_WALK action
            # st = {st & action = newaction}
            # or = {or & acceleration.rx = or.acceleration.rx - ac, currentsprite = newaction}
            | (newaction == MC_WALK) && (or.speed.rx > 0.0)
                = {st = {st & turning = True, lasthdir = DirRight}, or=or, gs=gs}
            = {st=st, or=or, gs=gs}
        | key == GK_RIGHT
            # st = {st & keyRight = True}
            # newaction = if (action == MC_IDLE) MC_WALK action
            # st = {st & action = newaction}
            # or = {or & acceleration.rx = or.acceleration.rx + ac, currentsprite = newaction}
            | (newaction == MC_WALK) && (or.speed.rx < 0.0)
                = {st = {st & turning = True, lasthdir = DirLeft}, or=or, gs=gs}
            = {st=st, or=or, gs=gs}
        | key == GK_SPACE
            | (isMember action [MC_IDLE, MC_WALK, MC_TURN])
                # (_, gs) = playSoundSample SND_JUMP DefaultVolume
                                PAN_CENTER DEFAULT_FREQUENCY 0 gs
                // *** play sound
                # st = {st & action = MC_JUMP}
                # or = {or & speed = jumpspeed or.speed
                                   , currentsprite = MC_JUMP
                                   , maxspeed = defmaxspeed
                                   }
                = {st=st, or=or, gs=gs}
            = {st=st, or=or, gs=gs} 
        | otherwise = {st=st, or=or, gs=gs}
    where
        jumpspeed sp=:{rx, ry} = {rx = rx, ry = ry - 3.25 - (abs rx) / 3.0}

    newkeyup key {st, or, gs}
        | (key == GK_LEFT) && (st.keyLeft)
            # st = {st & keyLeft = False}
            = {st=st, or = {or & acceleration.rx = or.acceleration.rx + ac}, gs=gs}
        | (key == GK_RIGHT) && (st.keyRight)
            # st = {st & keyRight = False}
            = {st=st, or = {or & acceleration.rx = or.acceleration.rx - ac}, gs=gs}
        | (key == GK_SPACE) && (st.action == MC_JUMP) && (or.speed.ry < (-0.5))
            = {st=st, or = {or & speed = {or.speed & ry = or.speed.ry * 3.0 / 4.0}}, gs=gs}
        | otherwise
            = {st=st, or=or, gs=gs}


    newcollide bnds othertype otherobjrec {st, or, gs}
        | (isMember othertype ChimneyList) && (or.speed.ry >= 0.0) && 
                (or.pos.y + or.size.h <= otherobjrec.pos.y + otherobjrec.size.h / 2 + 4) &&
                (st.readytodrop)
            # chimneytype = othertype - OBJ_CHIMNEY1 + 1
            # first = st.trail ++ [(-1)]
            | (first!!0 == chimneytype)
                # instr       = SND_FLUTE
                # vol         = HighVolume
                # (_, gs)     = playSoundSample instr vol PAN_CENTER (getnotefreq 100)  0 gs
                # (_, gs)     = playSoundSample instr vol PAN_CENTER (getnotefreq 101)  8 gs  
                # (_, gs)     = playSoundSample instr vol PAN_CENTER (getnotefreq 100) 16 gs
                # (_, gs)     = playSoundSample instr vol PAN_CENTER (getnotefreq  96)  0 gs  
                # (_, gs)     = playSoundSample instr vol PAN_CENTER (getnotefreq  98)  8 gs  
                # (_, gs)     = playSoundSample instr vol PAN_CENTER (getnotefreq  96) 16 gs
                # (_, gs)     = createUserGameEvent EV_READY 0 0 Self ANY_SUBTYPE (32) gs
                # (_, gs)     = createUserGameEvent EV_KADO_DROPPED chimneytype 0
                                    (BoundType (BND_KADO + BND_CHIMNEY)) ANY_SUBTYPE 0 gs
                # st          = {st & trail = drop 1 st.trail, readytodrop = False}
                = checkalldone {st=st, or=or, gs=gs}
            | (not (isMember otherobjrec.currentsprite [1, 7])) && (st.pepernoten > 0)
                # instr       = SND_FLUTE
                # vol         = HighVolume
                # (_, gs)     = playSoundSample instr vol PAN_CENTER (getnotefreq 112)  0 gs  
                # (_, gs)     = playSoundSample instr vol PAN_CENTER (getnotefreq 113)  8 gs  
                # (_, gs)     = playSoundSample instr vol PAN_CENTER (getnotefreq 112) 16 gs
                # (_, gs)     = playSoundSample instr vol PAN_CENTER (getnotefreq 108)  0 gs  
                # (_, gs)     = playSoundSample instr vol PAN_CENTER (getnotefreq 110)  8 gs  
                # (_, gs)     = playSoundSample instr vol PAN_CENTER (getnotefreq 108) 16 gs
                # (_, gs)     = createUserGameEvent EV_READY 0 0 Self ANY_SUBTYPE (32) gs
                # (_, gs)     = createUserGameEvent EV_PEPERNOOT chimneytype 0
                                    (BoundType BND_CHIMNEY) ANY_SUBTYPE 0 gs
                # st          = {st & pepernoten = st.pepernoten - 1, readytodrop = False}
                # gs          = setppn st.pepernoten gs
                = checkalldone {st=st, or=or, gs=gs}
            = {st=st, or=or, gs=gs}
        | othertype == OBJ_LETTER
            # st = {st & letters = st.letters + 1}
            | st.letters == 4
                # (_, gs) = createUserGameEvent EV_HEALTH 3 0 
                              (BoundType BND_STAT) ANY_SUBTYPE 1 gs
                = {st = {st & health = 3}, or = or, gs = AddLife gs}
            = {st=st, or=or, gs=gs}
        | othertype == OBJ_BOUNCEBLOCK
            | bnds.top
                # (_, gs) = playSoundSample SND_WJUMP DefaultVolume
                              PAN_CENTER 40000 0 gs
                = {st = {st & action = MC_JUMP}, 
                   or = {or & speed.ry = ~(abs or.speed.ry) * 2.0 - 4.25, currentsprite = MC_JUMP}, gs=gs}
            | bnds.bottom
                # (_, gs) = playSoundSample SND_WJUMP DefaultVolume
                              PAN_CENTER 35000 0 gs
                = {st = {st & action = MC_FALL}, 
                   or = {or & speed.ry = or.speed.ry + 2.5, currentsprite = MC_FALL}, gs = gs}
            = {st=st, or=or, gs=gs}
        | othertype == OBJ_TRAMP
            | bnds.top
                # (_, gs) = playSoundSample SND_WJUMP DefaultVolume
                              PAN_CENTER 70000 0 gs
                = {st = {st & action = MC_JUMP}, 
                   or = {or & speed.ry = ~(abs or.speed.ry) * 1.5 - 2.0, currentsprite = MC_JUMP}, gs = gs}
            = {st=st, or=or, gs=gs}
        | othertype == OBJ_HEART
            | not (st.health < 3)
                = {st=st, or=or, gs=gs}
            # st = {st & health = st.health + 1}
            # (_, gs) = createUserGameEvent EV_HEALTH st.health 0
                          (BoundType BND_STAT) ANY_SUBTYPE 1 gs
            = {st=st, or=or, gs=gs}
        | isMember othertype [OBJ_FALLING_PEPERNOOT, OBJ_STATIC_PEPERNOOT]
            # st = {st & pepernoten = st.pepernoten + 1}
            = {st=st, or=or, gs = setppn st.pepernoten gs}
        | isMember othertype KadoList
            # kadotype = othertype - OBJ_FALLING_KADO1 + 1
            # (_, gs)  = createNewGameObject (OBJ_KADO1 + kadotype - 1)
                          (length st.trail)
                          {x = or.pos.x + st.traildelta, 
                           y = or.pos.y + or.size.h - ITEM_SIZE.h - 1} gs
            # st = {st & trail = st.trail ++ [kadotype]}
            = {st=st, or=or, gs=gs}

        | othertype == OBJ_ENDING
            | st.todo == 0
                # or = {or & acceleration.rx = ac
                           , collidebounds = BND_POWER_UP
                           , options = {or.options & checkkeyboard = False
                                                   , ignorelevelbounds = True}}
                # (_, gs) = createUserGameEvent EV_STOP_MOVING 0 0 Self ANY_SUBTYPE 125 gs
                # (_, gs) = createObjectFocus {zero & scrollright = 160
                                                    , maxxscrollspeed = 1} gs
                # gs      = setexitcode EC_SUCCESS gs
                # (t, gs) = GetTime gs
                # t       = t * 3
                # p       = st.pepernoten * 10
                # (_, gs) = createUserGameEvent EV_COUNT_SCORE
                                0 0 Self ANY_SUBTYPE 350 gs
                # (_, gs) = createUserGameEvent EV_PPN_SCORE
                                0 0 Self ANY_SUBTYPE (500 + t) gs
                # (_, gs) = createUserGameEvent EV_ADD_BIRD_SCORE
                                0 0 Self ANY_SUBTYPE (600 + t + p) gs
                # (_, gs) = createUserGameEvent EV_QUIT_LEVEL
                                EC_SUCCESS 0 Self ANY_SUBTYPE (850 + t + p) gs
                # gs = dagsint SND_FLUTE 0 gs
                = {st=st, or=or, gs=gs}
            = {st=st, or=or, gs = msgnotready gs}
        | othertype == OBJ_HEART
            | not (st.health < 3)
                = {st=st, or=or, gs=gs}
            # st = {st & health = st.health + 1}
            # (_, gs) = createUserGameEvent EV_HEALTH st.health 0
                          (BoundType BND_STAT) ANY_SUBTYPE 1 gs
            = {st=st, or=or, gs=gs}
        | (not (otherobjrec.ownbounds bitand BND_HURT == 0))
            | or.displayoptions.blink
                = {st=st, or=or, gs=gs}
            | (not (otherobjrec.subcode bitand (fromDirectionSet bnds) == 0))
                = hurt {st=st, or=or, gs=gs}
            = {st=st, or=or, gs=gs}
        | bnds.top
            | (not (otherobjrec.ownbounds bitand BND_ENEMY == 0))
                # st = {st & birdskilled = st.birdskilled + 1}
                # gs = addscore (-500) gs
                # (_, gs) = playSoundSample SND_HIT HighVolume
                              PAN_CENTER (getnotefreq
                              (MIDDLE_C + 76 + 2 * st.enemynote)) 0 gs
                # st = {st & enemynote = st.enemynote + 1}
                # pos = {x = (or.pos.x + otherobjrec.pos.x) / 2, y = or.pos.y + 20} 
                # (_, gs) = createNewGameObject OBJ_FLITS 0 pos gs
                # st = {st & action = MC_JUMP}
                # or = {or & speed.ry = -2.5, currentsprite = MC_JUMP}
                = {st=st, or=or, gs=gs}
            = {st=st, or=or, gs=gs}

        | (not (otherobjrec.ownbounds bitand BND_ENEMY == 0))
            = hurt {st=st, or=or, gs=gs}
        = {st=st, or=or, gs=gs}
    where
        checkalldone {st, or, gs}
            # st = {st & todo = st.todo - 1}
            | st.todo == 0
                # (_, gs) = createUserGameEvent EV_ALL_DONE 0 0 
                                  (BoundType BND_ENDING) ANY_SUBTYPE 0 gs
                # gs = dagsint SND_XYLOFOON 25 gs
                = {st=st, or=or, gs = msgready gs}
            = {st=st, or=or, gs=gs}
            
        dagsint instr delay gs
            # vol = HighVolume
            # pan = PAN_CENTER
            
            /* Dag Sinterklaasje... */
            # gs = PlaySong instr vol pan 106 delay
                     [(7,24),(4,16),(2,8),(0,24),(7,24),(9,24),(5,24),(7,24),(4,24)] gs
            # gs = PlaySong instr vol pan 106 delay
                     [(4,24),(0,16),(-5,8),(-8,24),(4,24),(5,24),(2,24),(4,24),(0,24)] gs
            = gs

    newuserevent ev evpar1 evpar2 {st, or, gs}
        | ev == EV_STOP_BLINKING
            = {st=st, or = {or & displayoptions.blink = False}, gs=gs}
        | ev == EV_READY
            = {st = {st & readytodrop = True}, or=or, gs=gs}
        | ev == EV_QUIT_LEVEL
            # gs = setexitcode evpar1 gs
            # gs = quitlevel gs
            = {st=st, or=or, gs=gs}
        | ev == EV_GAME_OVER
            = {st = st, or = or, gs = setgameover gs}
        | ev == EV_TIME_UP
            # st = {st & health = 0}
            = hurt {st=st, or = {or & displayoptions = {or.displayoptions & blink = False}}, gs = gs}
        | ev == EV_STOP_MOVING
            = {st=st, or = {or & speed = zero, acceleration = zero}, gs=gs}
        | ev == EV_ADD_BIRD_SCORE
            | st.birdskilled == 0
                # (_, gs) = playSoundSample SND_PPN DefaultVolume
                            PAN_CENTER (getnotefreq 80) 0 gs
                # (_, gs) = playSoundSample SND_PPN DefaultVolume
                            PAN_CENTER (getnotefreq 99) 1 gs
                = {st=st, or=or, gs = addscore 10000 gs}
            = {st=st, or=or, gs=gs}
        | ev == EV_COUNT_SCORE
            # (t, gs) = GetTime gs
            | t > 0
                # (_, gs) = createUserGameEvent EV_COUNT_SCORE
                                0 0 Self ANY_SUBTYPE 3 gs
                # (_, gs) = dectime gs
                | (or.framecounter rem 1) == 0
                    # (_, gs) = playSoundSample SND_XYLOFOON DefaultVolume
                                  PAN_CENTER (getnotefreq 120) 0 gs
                    = {st=st, or=or, gs = addscore 50 gs}
                = {st=st, or=or, gs=gs}
            = {st=st, or=or, gs=gs}
        | ev == EV_PPN_SCORE
            # (bonus, gs) = getbonus gs
            | st.pepernoten > 0
                # (_, gs) = createUserGameEvent EV_PPN_SCORE
                                0 0 Self ANY_SUBTYPE 10 gs
                # st = {st & pepernoten = st.pepernoten -