home *** CD-ROM | disk | FTP | other *** search
/ CyberMycha 2006 April / SGP.iso / dema / Keepsake-Demo-en-li-v1.0.exe / res / puzzles / gardenWatch.puzzle.tcl < prev    next >
Text File  |  2006-01-25  |  13KB  |  428 lines

  1. class Maze {
  2.     set (OX) 0.343750
  3.     set (OY) 0.097656
  4.  
  5.     set (TW) 0.073242
  6.     set (TH) 0.097656
  7.     
  8.     proc Maze {this wall} {set ($this,wall) $wall}
  9.  
  10.     proc WallUp?    {this x y} {lindex $($this,wall) [expr $x + $y * 17]}
  11.     proc WallDown?  {this x y} {lindex $($this,wall) [expr $x + $y * 17 + 17]}
  12.     proc WallLeft?  {this x y} {lindex $($this,wall) [expr $x + $y * 17 + 8]}
  13.     proc WallRight? {this x y} {lindex $($this,wall) [expr $x + $y * 17 + 9]}
  14. }
  15.  
  16. class Peon {
  17.     proc Peon {this peon maze} oz'widget {Peon} {
  18.         set ($this,x) 0
  19.         set ($this,y) 0
  20.  
  21.         set ($this,maze) $maze
  22.  
  23.         set ($this,peon)  [new oz'sprite $peon]
  24.  
  25.         oz'widget::child $this $($this,peon) 0.5
  26.  
  27.         set ($this,wo) [expr ($Maze::(TW) - [oz'sprite::width  $($this,peon)]) / 2]
  28.         set ($this,ho) [expr ($Maze::(TH) - [oz'sprite::height $($this,peon)])]
  29.  
  30.         oz'widget::property $this -alpha 0
  31.     }
  32.  
  33.     proc ~Peon {this} {
  34.         delete $($this,peon)
  35.     }
  36.  
  37.     proc qShow {this} {
  38.         oz'event {
  39.             oz'widget::fadeto $this 1
  40.         }
  41.     }
  42.  
  43.     proc qHide {this} {
  44.         oz'event {
  45.             oz'widget::fadeto $this 0
  46.         }
  47.     }
  48.     
  49.     proc X {this} {
  50.         return [expr $Maze::(OX) + $($this,x) * $Maze::(TW) + $($this,wo)]
  51.     }
  52.  
  53.     proc Y {this} {
  54.         return [expr $Maze::(OY) + $($this,y) * $Maze::(TH) + $($this,ho)]
  55.     }
  56.         
  57.     proc Move {this} {
  58.         oz'widget::moveto $this [X $this] [Y $this]
  59.     }
  60.  
  61.     proc qSetPosition {this x y} {
  62.         set ($this,x) $x
  63.         set ($this,y) $y
  64.  
  65.         oz'widget::property $this -pos [Peon::X $this] [Peon::Y $this]
  66.     }
  67.  
  68.     proc qMoveUp {this} {
  69.         oz'event {
  70.             incr Peon::($this,y) -1
  71.             Peon::Move $this
  72.             delay 900
  73.         }
  74.     }
  75.  
  76.     proc qMoveDown {this} {
  77.         oz'event {
  78.             incr Peon::($this,y)
  79.             Peon::Move $this
  80.             delay 900
  81.         }
  82.     }
  83.  
  84.     proc qMoveLeft {this} {
  85.         oz'event {
  86.             incr Peon::($this,x) -1
  87.             Peon::Move $this
  88.             delay 900
  89.         }
  90.     }
  91.  
  92.     proc qMoveRight {this} {
  93.         oz'event {
  94.             incr Peon::($this,x)
  95.             Peon::Move $this
  96.             delay 900
  97.         }
  98.     }
  99.  
  100.     proc WallUp? {this} {
  101.         Maze::WallUp? $($this,maze) $($this,x) $($this,y)
  102.     }
  103.  
  104.     proc WallDown? {this} {
  105.         Maze::WallDown? $($this,maze) $($this,x) $($this,y)
  106.     }
  107.  
  108.     proc WallLeft? {this} {
  109.         Maze::WallLeft? $($this,maze) $($this,x) $($this,y)
  110.     }
  111.  
  112.     proc WallRight? {this} {
  113.         Maze::WallRight? $($this,maze) $($this,x) $($this,y)
  114.     }
  115. }
  116.     
  117. class Goblin {
  118.     proc Goblin {this maze p_logic} Peon {"goblin" $maze} {
  119.         set ($this,p_logic) $p_logic
  120.         
  121.         set ($this,arrow.up)    [new oz'button "U"]
  122.         set ($this,arrow.down)  [new oz'button "D"]
  123.         set ($this,arrow.left)  [new oz'button "L"]
  124.         set ($this,arrow.right) [new oz'button "R"]
  125.  
  126.         oz'widget::property $($this,arrow.up)    -pos -$Peon::($this,wo) [expr -$Maze::(TH) - $Peon::($this,ho)]
  127.         oz'widget::property $($this,arrow.down)  -pos -$Peon::($this,wo) [expr  $Maze::(TH) - $Peon::($this,ho)]
  128.         oz'widget::property $($this,arrow.left)  -pos [expr -$Maze::(TW) - $Peon::($this,wo)] -$Peon::($this,ho)
  129.         oz'widget::property $($this,arrow.right) -pos [expr  $Maze::(TW) - $Peon::($this,wo)] -$Peon::($this,ho)
  130.  
  131.         oz'button::property $($this,arrow.up)    -click Goblin::qMoveUp    $this \
  132.                                                  -sclick "sound/puzzles/puzzleMinotaurMaze/goblinArrowClick.ogg" \
  133.                                                  -sover "sound/puzzles/puzzleMinotaurMaze/goblinArrow.ogg"
  134.         oz'button::property $($this,arrow.down)  -click Goblin::qMoveDown  $this \
  135.                                                  -sclick "sound/puzzles/puzzleMinotaurMaze/goblinArrowClick.ogg" \
  136.                                                  -sover "sound/puzzles/puzzleMinotaurMaze/goblinArrow.ogg"
  137.         oz'button::property $($this,arrow.left)  -click Goblin::qMoveLeft  $this \
  138.                                                  -sclick "sound/puzzles/puzzleMinotaurMaze/goblinArrowClick.ogg" \
  139.                                                  -sover "sound/puzzles/puzzleMinotaurMaze/goblinArrow.ogg"
  140.         oz'button::property $($this,arrow.right) -click Goblin::qMoveRight $this \
  141.                                                  -sclick "sound/puzzles/puzzleMinotaurMaze/goblinArrowClick.ogg" \
  142.                                                  -sover "sound/puzzles/puzzleMinotaurMaze/goblinArrow.ogg"
  143.         
  144.         oz'widget::child $this $($this,arrow.up)    1
  145.         oz'widget::child $this $($this,arrow.down)  1
  146.         oz'widget::child $this $($this,arrow.left)  1
  147.         oz'widget::child $this $($this,arrow.right) 1
  148.    }
  149.  
  150.     proc ~Goblin {this} {
  151.         delete $($this,arrow.up)
  152.         delete $($this,arrow.down)
  153.         delete $($this,arrow.left)
  154.         delete $($this,arrow.right)
  155.     }
  156.  
  157.     proc qEnableArrows {this} {
  158.         oz'event {
  159.             if [Peon::WallUp? $this ] {
  160.                 oz'widget::fadeto $($this,arrow.up) 0
  161.             } else {
  162.                 oz'widget::fadeto $($this,arrow.up) 1
  163.             }
  164.     
  165.             if [Peon::WallDown? $this] {
  166.                 oz'widget::fadeto $($this,arrow.down) 0
  167.             } else {
  168.                 oz'widget::fadeto $($this,arrow.down) 1
  169.             }
  170.     
  171.             if [Peon::WallLeft? $this] {
  172.                 oz'widget::fadeto $($this,arrow.left) 0
  173.             } else {
  174.                 oz'widget::fadeto $($this,arrow.left) 1
  175.             }
  176.         
  177.             if [Peon::WallRight? $this] {
  178.                 oz'widget::fadeto $($this,arrow.right) 0
  179.             } else {
  180.                 oz'widget::fadeto $($this,arrow.right) 1
  181.             }
  182.         }
  183.     }
  184.     
  185.     proc qDisableArrows {this} {
  186.         oz'event {
  187.             oz'widget::fadeto $($this,arrow.up)    0
  188.             oz'widget::fadeto $($this,arrow.down)  0
  189.             oz'widget::fadeto $($this,arrow.left)  0
  190.             oz'widget::fadeto $($this,arrow.right) 0
  191.         }
  192.     }
  193.  
  194.     proc qMoveUp {this} {
  195.         wizDisableMouse
  196.         qDisableArrows $this
  197.         oz'event {
  198.             ozqSound::NewFX "sound/puzzles/puzzleMinotaurMaze/goblinMove.ogg"
  199.         }
  200.         Peon::qMoveUp $this
  201.         oz'event {$($this,p_logic)}
  202.     }
  203.  
  204.     proc qMoveDown {this} {
  205.         wizDisableMouse
  206.         qDisableArrows $this
  207.         oz'event {
  208.             ozqSound::NewFX "sound/puzzles/puzzleMinotaurMaze/goblinMove.ogg"
  209.         }
  210.         Peon::qMoveDown $this
  211.         oz'event {$($this,p_logic)}
  212.     }
  213.  
  214.     proc qMoveLeft {this} {
  215.         wizDisableMouse
  216.         qDisableArrows $this
  217.         oz'event {
  218.             ozqSound::NewFX "sound/puzzles/puzzleMinotaurMaze/goblinMove.ogg"
  219.         }
  220.         Peon::qMoveLeft $this
  221.         oz'event {$($this,p_logic)}
  222.     }
  223.  
  224.     proc qMoveRight {this} {
  225.         wizDisableMouse
  226.         qDisableArrows $this
  227.         oz'event {
  228.             ozqSound::NewFX "sound/puzzles/puzzleMinotaurMaze/goblinMove.ogg"
  229.         }
  230.         Peon::qMoveRight $this
  231.         oz'event {$($this,p_logic)}
  232.     }
  233. }
  234.  
  235. class Minotaur {
  236.     proc Minotaur {this maze} Peon {"minotaur" $maze} {}
  237.  
  238.     proc ~Minotaur {this} {}
  239.  
  240.     proc qMoveToward {this peon} {
  241.         oz'event {
  242.             if {\$Peon::($peon,x) < \$Peon::($this,x)} {
  243.                 if ![Peon::WallLeft? $this] {
  244.                     oz'event {
  245.                         ozqSound::NewFX "sound/puzzles/puzzleMinotaurMaze/minoMove.ogg"
  246.                     }
  247.                     Peon::qMoveLeft $this
  248.                     return
  249.                 }
  250.             } elseif {\$Peon::($peon,x) > \$Peon::($this,x)} {
  251.                 if ![Peon::WallRight? $this] {
  252.                     oz'event {
  253.                         ozqSound::NewFX "sound/puzzles/puzzleMinotaurMaze/minoMove.ogg"
  254.                     }
  255.                     Peon::qMoveRight $this
  256.                     return
  257.                 }
  258.             }
  259.         
  260.             if {\$Peon::($peon,y) < \$Peon::($this,y)} {
  261.                 if ![Peon::WallUp? $this] {
  262.                     oz'event {
  263.                         ozqSound::NewFX "sound/puzzles/puzzleMinotaurMaze/minoMove.ogg"
  264.                     }
  265.                     Peon::qMoveUp $this
  266.                     return
  267.                 }
  268.             } elseif {\$Peon::($peon,y) > \$Peon::($this,y)} {
  269.                 if ![Peon::WallDown? $this] {
  270.                     oz'event {
  271.                         ozqSound::NewFX "sound/puzzles/puzzleMinotaurMaze/minoMove.ogg"
  272.                     }
  273.                     Peon::qMoveDown $this
  274.                     return
  275.                 }
  276.             }
  277.         }
  278.     }
  279. }
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.         
  287.  
  288. namespace eval pzlmm {}
  289.     
  290. proc pzlmm::qInit {} {
  291.     if {[ozGet "minotaurMazeFigurines"] == ""} return
  292.    
  293.     variable {}
  294.  
  295.     set (maze) [new Maze " 1 1 1 1 1 1 1 1  \
  296.                           0 0 0 0 0 0 0 0 1 \
  297.                            1 0 0 0 1 0 0 0  \
  298.                           1 0 0 0 0 0 0 0 1 \
  299.                            0 0 0 0 0 0 1 0  \
  300.                           1 0 0 0 0 0 1 0 1 \
  301.                            0 0 0 0 0 0 0 0  \
  302.                           1 0 0 0 0 0 0 0 1 \
  303.                            0 0 0 0 1 0 0 0  \
  304.                           1 1 0 0 0 0 1 1 1 \
  305.                            0 0 0 0 0 0 0 1  \
  306.                           1 0 0 1 0 0 0 0 1 \
  307.                            0 0 1 0 0 0 0 0  \
  308.                           1 0 0 0 0 0 1 0 1 \
  309.                            0 0 0 0 0 1 0 0  \
  310.                           1 0 0 0 0 0 0 0 1 \
  311.                            1 1 1 1 1 1 1 1"]
  312.  
  313.     set (goblin)   [new Goblin $(maze) pzlmm::logic]
  314.     set (minotaur) [new Minotaur $(maze)]
  315.  
  316.     oz'widget::child [FOREGROUNDWIDGET] $(goblin)   1
  317.     oz'widget::child [FOREGROUNDWIDGET] $(minotaur) 0
  318.  
  319.  
  320.     Peon::qSetPosition $(goblin)   0 5
  321.     Peon::qSetPosition $(minotaur) 6 4
  322.  
  323.     Goblin::qEnableArrows $(goblin)
  324.     Peon::qShow $(goblin)
  325.     Peon::qShow $(minotaur)
  326. }
  327.  
  328. proc pzlmm::qQuit {} {
  329.     if {[ozGet "minotaurMazeFigurines"] == ""} return
  330.  
  331.     variable {}
  332.  
  333.     oz'event {
  334.         Peon::qHide $(goblin)
  335.         Peon::qHide $(minotaur)
  336.     }
  337.  
  338.     oz'event {delay 900}
  339.     
  340.     oz'event {
  341.         delete $(goblin)
  342.         delete $(minotaur)
  343.     }
  344. }
  345.  
  346. proc pzlmm::logic {} {
  347.     variable {}
  348.     Minotaur::qMoveToward $(minotaur) $(goblin)
  349.     Minotaur::qMoveToward $(minotaur) $(goblin)
  350.     oz'event {
  351.         if {\$Peon::($(goblin),x) == \$Peon::($(minotaur),x) &&
  352.             \$Peon::($(goblin),y) == \$Peon::($(minotaur),y)} {
  353.             oz'event {
  354.                 ozqSound::NewFX "sound/puzzles/puzzleMinotaurMaze/goblinLose.ogg"
  355.             }
  356.             oz'event {
  357.                 Peon::qHide $(goblin)
  358.                 Peon::qHide $(minotaur)
  359.             }
  360.             oz'event {
  361.                 delay 900
  362.             }                    
  363.             oz'event {
  364.                 Peon::qSetPosition $(goblin)   0 5
  365.                 Peon::qSetPosition $(minotaur) 6 4
  366.                 Peon::qShow $(goblin)
  367.                 Peon::qShow $(minotaur)
  368.             }
  369.         } else {
  370.             if {$Peon::($(goblin),x) == 0 && $Peon::($(goblin),y) == 0} {
  371.                 oz'event {
  372.                     ozqSound::NewFX "sound/puzzles/puzzleMinotaurMaze/goblinWin.ogg"
  373.                 }
  374.                 oz'event {
  375.                     Peon::qHide $(goblin)
  376.                     Peon::qHide $(minotaur)
  377.                     playMusic silence
  378.                 }
  379.                 oz'event {
  380.                     delay 900
  381.                 }
  382.                 oz'event {
  383.                     setCrossfadeCamera "minotaurMazeCloseUpOff"
  384.                     delay 1000
  385.                 }
  386.                 PlayMovieSound minotaurMazeCloseUp nigilisBean "puzzles/puzzleMinotaurMaze/seedMaterialize"
  387.                 oz'event {
  388.                     setCamera "minotaurMazeCloseUpComplete"
  389.                     wizhCameraChange
  390.                     callEvent "gardenWatch.mMazeWin"
  391.                 }
  392.                 return
  393.             }
  394.         }
  395.     }
  396.     Goblin::qEnableArrows $(goblin)
  397.     wizqEnableMouse
  398. }
  399.  
  400. proc useMinotaurMazeResetProc {} {
  401.     PlayMovieSound minotaurMazeCloseUp reset "/puzzles/common/reset"
  402.  
  403.     if {[ozGet "minotaurMazeFigurines"] == ""} return
  404.     
  405.     oz'event {Goblin::qDisableArrows $pzlmm::(goblin)}
  406.     oz'event {
  407.         Peon::qHide $pzlmm::(goblin)
  408.         Peon::qHide $pzlmm::(minotaur)
  409.     }
  410.     oz'event {
  411.         delay 900
  412.     }                    
  413.     oz'event {
  414.         Peon::qSetPosition $pzlmm::(goblin)   0 5
  415.         Peon::qSetPosition $pzlmm::(minotaur) 6 4
  416.     }
  417.     oz'event {Goblin::qEnableArrows $pzlmm::(goblin)}
  418.     oz'event {
  419.         Peon::qShow $pzlmm::(goblin)
  420.         Peon::qShow $pzlmm::(minotaur)
  421.     }
  422. }
  423.  
  424. event "useMinotaurMazeReset" {
  425.     useMinotaurMazeResetProc
  426. }
  427.  
  428.