Advertisement
Guest User

Fixed game.rb (WTFPL)

a guest
Sep 11th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 93.36 KB | None | 0 0
  1. class Game
  2.     attr_accessor :entities,:scx,:scy,:map,:player,:powerup,:time,:area,:came,:messages,:save,:gameover,:way,:unstoppable
  3.   attr_reader :temp
  4.   def initialize(session=nil)
  5.         $game=self
  6.     @temp=[]
  7.     @time=0
  8.    
  9.     $bossrush=false
  10.     if session==true
  11.       place=$save[:session][1][:id]
  12.       pos=$save[:session][0]
  13.       qs=false
  14.       @came=$save[:session][0]
  15.       if !$save[:session][2]
  16.         $save[:session]=nil
  17.         Marshal.dump($save,f=File.open("data/save#{$save[:id]}",'w'))
  18.         f.close
  19.         $save=Marshal.load(f=File.open("data/save#{$save[:id]}s",'r'))
  20.         f.close
  21.         File.delete("data/save#{$save[:id]}s")
  22.       else
  23.         qs=true
  24.         $save=Marshal.load(f=File.open("data/save#{$save[:id]}s",'r'))
  25.         f.close
  26.       end
  27.       reset(place)
  28.       (@player=Mario.new(*pos)).init(:solid)
  29.       @player.model.mirror_x=true if @player.x>@map.data[:width]*320
  30.       @entities[0].find{|ent| ent.class==QuickSave}.tp if qs
  31.     elsif session
  32.       $bossrush=["r1",false,0,nil,session==2 ? 0 : nil]
  33.       $save[:dimension]=$bossrush[4]
  34.       reset('r1')
  35.       (@player=Mario.new(320,392)).init(:solid)
  36.     elsif $save[:saved]
  37.       reset('s')
  38.       (@player=Mario.new(320,392)).init(:solid)
  39.       @map.data[:id]=$save[:saved][1][:id]
  40.       @map.data[:origin]=$save[:saved][1][:origin]
  41.       $save[:saved][0].init
  42.       @player.model.mirror_x=true if $save[:saved][0].x==0
  43.       2.times{|x| 4.times{|y| $game[Tile.new(($save[:saved][0].x==0 ? 576 : 0)+x*32,192+y*32,'Castle',(x==0 ? 0 : 2)+[0,7,7,14][y])]}}
  44.       Save.new
  45.       if $save[:session] and !$save[:session][2]
  46.         $save[:session]=nil
  47.         File.delete("data/save#{$save[:id]}s")
  48.       end
  49.       Marshal.dump($save,f=File.open("data/save#{$save[:id]}",'w'))
  50.       f.close
  51.     else
  52.       reset('i1')
  53.       (@player=Mario.new(416,320)).init(:solid)
  54.     end
  55.    
  56.     @scx=[[@player.x-320,0].max,@map.data[:width]*640-640].min.to_i
  57.     @scy=[[@player.y-240,0].max,@map.data[:height]*480-480].min.to_i
  58.     if !$bossrush
  59.       @map.music($save[:area]) if !['s','t','c','i1'].include?(@map.data[:id])
  60.     else
  61.       Msc["Item Room"].play(true)
  62.     end
  63.     @messages=[]
  64.     @removed=[]
  65.    
  66.     refresh_stats
  67.   end
  68.  
  69.   def update
  70.     return @way.way if @way
  71.     if @gameover
  72.       @gameover+=1
  73.       if @gameover<36
  74.         return
  75.       elsif @gameover==36
  76.         @player.remove
  77.         Corpse.new(@player.x-16,@player.y-40,@player.vx,@player.vy)
  78.       elsif @gameover==180
  79.         return $game=GameOver.new
  80.       end
  81.     end
  82.    
  83.     @level=nil if @level and (@level-=3)<0
  84.     @powerup=nil if @powerup and (@powerup[1]-=3)<0
  85.     @area=nil if @area and (@area[1]-=1)<-120
  86.     @save=nil if @save and (@save+=1)==120
  87.    
  88.     return if @level or @powerup or @area or !@messages.empty? && @messages.find{|mess| mess.guide}
  89.     @time+=1 if !@stoptime
  90.     $save[:time]+=1
  91.         @entities[0].each {|ent| ent.update if ent.respond_to?(:update) and !ent.stop and not @stoptime && !ent.unstoppable and !@start} if !$bossrush || $bossrush[1]
  92.    
  93.     @removed.each{|ent| @entities.each{|grp| grp.delete(ent)}}
  94.     @removed.clear
  95.    
  96.     @stoptime.resume if @stoptime and @stoptime.paused?
  97.     if Keypress[:start,false] and !@gameover
  98.       @stoptime.pause if @stoptime
  99.       Snd['Sys5'].play
  100.       $temp=self
  101.       return $game=Menu.new
  102.     end
  103.     if Keypress[:select,false] and !@gameover
  104.       Snd['Sys5'].play
  105.       $temp=self
  106.       return $game=Minimap.new(@map.data[:origin],@player.x,@player.y)
  107.     end
  108.    
  109.     if ($save[:exp]-$save[:all])>=$save[:next]
  110.       Snd['Level Up'].play
  111.       lv=$save[:level]+=1
  112.       $save[:all]+=$save[:next]
  113.       $save[:next]=10*lv**2-5*lv+(75-(lv-1))
  114.       $save[:max_hp]+=12
  115.       $save[:hp]+=12
  116.       $save[:max_mp]+=8
  117.       $save[:mp]+=8
  118.       $save[:max_stars]+=4
  119.       $save[:stars]+=4
  120.       $save[:base_strength]+=(1+(lv%3==0 ? 1 : 0)+(lv%5==3 ? 1 : 0)+(lv%8==7 ? 1 : 0))
  121.       $save[:base_constitution]+=(1+(lv%3==1 ? 1 : 0)+(lv%5==4 ? 1 : 0)+(lv%8==4 ? 1 : 0))
  122.       $save[:base_intelligence]+=(1+(lv%3==0 ? 1 : 0)+(lv%5==2 ? 1 : 0)+(lv%8==6 ? 1 : 0))
  123.       $save[:base_mind]+=(1+(lv%3==2 ? 1 : 0)+(lv%5==1 ? 1 : 0)+(lv%8==3 ? 1 : 0))
  124.       $save[:base_luck]+=1
  125.       refresh_stats
  126.       @level=400
  127.     end
  128.    
  129.     magic=nil
  130.     $save[:magic].length.times{|mag| next if !$save[:magic][mag]
  131.       sp=$save[:magic][mag][0]
  132.       $save[:magic][mag][1].times{|i| sp-=$items[:magic][mag][:levels][i]}
  133.       if $save[:magic][mag][1]<$items[:magic][mag][:levels].length and sp>=$items[:magic][mag][:levels][$save[:magic][mag][1]] ; magic=mag ; break end}
  134.     if magic
  135.       $save[:magic][magic][1]+=1
  136.       Snd['Level Up'].play
  137.       Info.new($game.player.x-((cnd=($save[:magic][magic][1]==$items[:magic][magic][:levels].length)) ? 28 : 21),$game.player.y-48,nil,cnd ? Tls['System/Master',56,16] : Tls['System/Magic Up',42,32])
  138.       @player.set_att(magic)
  139.     end
  140.    
  141.     @map.update
  142.    
  143.     screen
  144.    
  145.     if $save[:hp]<=0 and !@gameover
  146.       @stoptime.stop if @stoptime
  147.       Msc['Fail'].play
  148.       @gameover=0
  149.       @shake=nil
  150.     end
  151.     if @shop
  152.       @shop=nil
  153.       $temp=self
  154.       $game=Shop.new
  155.     end
  156.    
  157.     if @stoptime and !@stoptime.playing?
  158.       Song.current_song.play(!$premusic) if Song.current_song
  159.       @stoptime=nil
  160.     end
  161.    
  162.     4.times{|i| if !$save[:plans][i] and $save[:items][:misc].include?(i)
  163.       $save[:plans][i]=true
  164.       map=Marshal.load(f=File.open("data/plan#{i}",'r'))
  165.       f.close
  166.       map.each{|plan| $save[:map].find{|room| room.x/10==plan[0] and room.y/10==plan[1]}.map!}
  167.     end}
  168.    
  169.     $save[:kills][0]||=0;$save[:kills][35]||=0;$save[:kills][36]||=0
  170.     if $save[:magic][6]
  171.       value=($save[:kills][0] ? $save[:kills][0] : 0)+($save[:kills][35] ? $save[:kills][35] : 0)+($save[:kills][36] ? $save[:kills][36] : 0)+($save[:kills][86] ? $save[:kills][86] : 0)+($save[:kills][101] ? $save[:kills][101] : 0)*1000
  172.       $items[:magic][6][:attack]=value/($save[:magic][6][1]==1 ? 1 : 2)
  173.       $items[:magic][6][:use]=[30+value,$save[:max_mp]].min/($save[:magic][6][1]==1 ? 2 : 1)
  174.     end
  175.     $items[:pants][6][:defence]=$save[:coins]/250
  176.     $items[:boots][7][:stomp]=$save[:allkills]/100
  177.     $items[:accessory][10][:luck]=$save[:time]/54000
  178.     refresh_stats
  179.    
  180.     if $bossrush
  181.       if !$bossrush[1]
  182.         @entities[0].each{|ent| ent.remove if ent.class==Waypoint}
  183.         case $bossrush[0]
  184.           when "r1"
  185.           Waypoint.new(640-32,0,false,$bossrush[4] ? "b" : 7)
  186.          
  187.           when "b"
  188.           @player.y=480-96-24
  189.           Waypoint.new(0,0,false,$bossrush[4]<12 ? "b" : "r2")
  190.           Waypoint.new(608,0,false,$bossrush[4]<12 ? "b" : "r2")
  191.          
  192.           when 7
  193.           @player.y=480-64-24
  194.           Waypoint.new(640-32,0,false,38)
  195.          
  196.           when 38
  197.           @player.y=480-96-24
  198.           Waypoint.new(640-32,0,false,77)
  199.          
  200.           when 77
  201.           @player.y=480-160-24
  202.           Waypoint.new(0,0,false,107)
  203.          
  204.           when 107
  205.           @player.y=480-192-24
  206.           Waypoint.new(1280-32,480,false,190)
  207.          
  208.           when 190
  209.           @player.y=480-64-24
  210.           Waypoint.new(0,0,false,159)
  211.          
  212.           when 159
  213.           @player.y=960-32-24
  214.           Waypoint.new(1280-32,480,false,182)
  215.          
  216.           when 182
  217.           @player.y=480-128-24
  218.           Waypoint.new(640-32,0,false,223)
  219.          
  220.           when 223
  221.           @player.y=480-64-24
  222.           Waypoint.new(1280-32,0,false,252)
  223.          
  224.           when 252
  225.           @player.y=480-160-24
  226.           Waypoint.new(0,0,false,136)
  227.          
  228.           when 136
  229.           @player.y=480-160-24
  230.           Waypoint.new(0,0,false,207)
  231.          
  232.           when 207
  233.           @player.y=480-160-24
  234.           Waypoint.new(0,0,false,243)
  235.          
  236.           when 243
  237.           @player.y=384-24
  238.           Waypoint.new(1280-32,0,false,249)
  239.          
  240.           when 249
  241.           @player.x=1279
  242.           @player.y=480-64-24
  243.           @player.vx=-2
  244.           Waypoint.new(1280-32,0,false,"r2")
  245.          
  246.           when "r2"
  247.           @player.x=256
  248.           @player.y=480-64-24
  249.           Msc["Item Room"].play(true)
  250.          
  251.           if !$bossrush[4]
  252.             if $bossrush[2]<28800 and not $save[:items][:weapon].include?(16) or $save[:equip][2]==16
  253.               type=:weapon
  254.               id=16
  255.               $config[4][5]=true
  256.             elsif $bossrush[2]<43200 and not $save[:items][:magic].include?(12) or $save[:equip][1]==12
  257.               type=:magic
  258.               id=12
  259.               $config[4][4]=true
  260.             elsif $bossrush[2]<57600 and not $save[:items][:boots].include?(11) or $save[:equip][5]==11
  261.               type=:boots
  262.               id=11
  263.               $config[4][3]=true
  264.             else
  265.               type=:usable
  266.               id=12
  267.             end
  268.           else
  269.             if $bossrush[2]<21600 and not $save[:items][:suit].include?(12) or $save[:equip][0]==12
  270.               type=:suit
  271.               id=12
  272.               $config[4][6]=true
  273.             else
  274.               type=:usable
  275.               id=5
  276.             end
  277.           end
  278.           @_item=Item.new(480,288,type,id)
  279.         end
  280.         $bossrush[1]=true
  281.       end
  282.      
  283.       if $bossrush[0]=="r2" and !@_gotomenu and !@entities[0].find{|e| e.class==Item}
  284.         save=Marshal.load(f=File.open("data/save#{$save[:id]}",'r'))
  285.         f.close
  286.         save[:items][@_item.type] << @_item.id
  287.         Marshal.dump(save,f=File.open("data/save#{$save[:id]}",'w'))
  288.         f.close
  289.         $config[$bossrush[4] ? 3 : 2]<<[$save[:name],$bossrush[2]]
  290.         f=File.open('data/config','w')
  291.         Marshal.dump($config,f)
  292.         f.close
  293.         @_gotomenu=true
  294.       end
  295.      
  296.       if @_gotomenu and !@item
  297.         $game=MainMenu.new
  298.       end
  299.      
  300.       @entities[1].each{|ent| ent.nodrop=:br}
  301.       if $bossrush[3]
  302.         Song.current_song.stop
  303.         $premusic=nil
  304.         $bossrush[3]=false
  305.         case $bossrush[0]
  306.           when 7,38,159,182,223,243
  307.           @entities[0].find{|ent| ent.class==BossDoor and ent.x>0}.open=true
  308.           when 77,190,252,136,207
  309.           @entities[0].find{|ent| ent.class==BossDoor and ent.x==0}.open=true
  310.           when 107
  311.           @entities[0].find{|ent| ent.class==BossDoor and ent.x>0 and ent.y>480}.open=true
  312.         end
  313.       end
  314.      
  315.       $bossrush[2]+=1 if $bossrush[0] != "r2"
  316.     end
  317.    
  318.     return ###DEBUGGGG
  319.     if Keypress[KbF8,false]
  320.       QuickSave.new(@player.x,@player.y-128)
  321.     end
  322.    
  323.     if Keypress[KbF2]
  324.       map=$save[:map]
  325.       $save[:map]=Marshal.load(f=File.open('data/map','r'))
  326.       map.each{|r| if r.discovered then $save[:map].find{|ro| ro.dimension==r.dimension and ro.x==r.x and ro.y==r.y}.discover end}
  327.       $save[:plans].clear
  328.     end
  329.    
  330.     $items.each_key{|type| $items[type].length.times{|id| $save[:items][type] << id if !$save[:items][type].include?(id)}} if Keypress[KbF1,false]
  331.     $save[:exp]+=100000 if Keypress[KbF4,false]
  332.     $save[:luck]=$save[:defence]=$save[:mind]=$save[:strength]=$save[:intelligence]=$save[:stomp]=$save[:constitution]=$save[:hp]=$save[:mp]=$save[:stars]=999999999999 if Keypress[KbF6]
  333.     $save[:intelligence]=999999999999 if Keypress[KbF7]
  334.     $game=End.new(true) if Keypress[KbF10,false]
  335.     $game=MainMenu.new if Keypress[KbF12,false]
  336.    
  337.     if Keypress[KbF9,false]
  338.       Msc['World Revolution',true].play
  339.       # pl.x=640
  340.       # pl.y-=32
  341.       # pl.ignore=true
  342.       $game.reset('f')
  343.       MegaBowser.new
  344.     end
  345.    
  346.     if Keypress[KbF11]
  347.       begin
  348.         eval gets.chomp
  349.       rescue
  350.         puts "Fail"
  351.       end
  352.     end
  353.   end
  354.  
  355.   def draw
  356.     @map.init
  357.     return if @way
  358.    
  359.     if @player.starman
  360.       color=rand(3)
  361.       color2=rand(4)
  362.       $shaders[4].Red=(color==0 or color2==0)
  363.       $shaders[4].Green=(color==1 or color2==1)
  364.       $shaders[4].Blue=(color==2 or color2==2)
  365.     end
  366.    
  367.         if @shake
  368.       @shake[4]+=1
  369.       if @shake[4]==@shake[1]
  370.         @shake[4]=0
  371.         @shake[2]-=1
  372.         @shake[0]-=@shake[3][:damping] if @shake[3][:damping]
  373.         @shakex=-@shake[0]+rand(@shake[0]*2+1)
  374.         @shakey=-@shake[0]+rand(@shake[0]*2+1)
  375.       end
  376.             @scx+=@shakex
  377.             @scy+=@shakey
  378.             $screen.draw_quad(@shakex-@scx,0,c=0xff000000,-@scx,0,c,@shakex-@scx,$screen.height,c,-@scx,$screen.height,c,3.5) if @shakex<0
  379.             $screen.draw_quad(@map.data[:width]*640-@scx,0,c=0xff000000,@map.data[:width]*640-@scx+@shakex,0,c,@map.data[:width]*640-@scx+@shakex,$screen.height,c,@map.data[:width]*640-@scx,$screen.height,c,3.5) if @shakex>0
  380.             $screen.draw_quad(0,@shakey-@scy,c=0xff000000,$screen.width,@shakey-@scy,c,$screen.width,-@scy,c,0,-@scy,c,3.5) if @shakey<0
  381.             $screen.draw_quad(0,@map.data[:height]*480-@scy,c=0xff000000,0,@map.data[:height]*480-@scy+@shakey,c,$screen.width,@map.data[:height]*480-@scy+@shakey,c,$screen.width,@map.data[:height]*480-@scy,c,3.5) if @shakey>0
  382.             @shake=@shakex=@shakey=nil if @shake[2]==0
  383.         end
  384.    
  385.     if @flash
  386.       alpha=(@flash[0].alpha+(@flash[2] ? @flash[1] : -@flash[1]))
  387.       if @flash[2] and alpha>255
  388.         @flash[2]=nil
  389.         @flash[0].alpha=255
  390.       elsif !@flash[2] and alpha<0
  391.         @flash=nil
  392.       end
  393.       @flash[0].alpha=alpha if @flash
  394.       $screen.draw_quad(0,0,@flash[0],$screen.width,0,@flash[0],$screen.width,$screen.height,@flash[0],0,$screen.height,@flash[0],3) if @flash
  395.     end
  396.    
  397.     @map.draw
  398.     $screen.translate(-@scx,-@scy) do
  399.       @entities[0].each {|ent| ent.draw if ent.respond_to?(:draw) and !ent.invisible}
  400.     end
  401.    
  402.     if @makelife
  403.       16.times{|dir| Img['Effects/Make Life'].draw(@makelife[0]-offset_x(dir*22.5,-@makelife[1]*4%64)-@scx,128-offset_y(dir*22.5,-@makelife[1]*4%64)-@scy,3)}
  404.       @makelife[1]+=1
  405.       if @makelife[1]==64
  406.         Bonus.new(@makelife[0],128,0,true)
  407.         @makelife=nil
  408.       end
  409.     end
  410.    
  411.    Fnt['data/fonts/nine.ttf',100].draw_rel(@warning[0],320,240,4,0.5,0.5,1,1,0xffff0000) if @warning and $count%10<5
  412.    @warning=nil if @warning and (@warning[1]-=1)==0
  413.    
  414.     if @messages.empty? and !@player.ignore
  415.       width=[$save[:max_hp]/4,$save[:max_mp]/2].max
  416.       Img['System/BarFrame',true].draw(58,0,4,width)
  417.       Tls['System/Bars',1,8,true][0].draw(58,4,4,(([$save[:hp],0].max/$save[:max_hp].to_f)*width).to_i)
  418.       Tls['System/Bars',1,8,true][1].draw(58,40,4,(($save[:mp]/$save[:max_mp].to_f)*width).to_i)
  419.       Img['System/Stars'].draw(0,0,4)
  420.       Img['System/BarEdge'].draw(58+width,0,4)
  421.       Img['System/Exp',true].draw(1,52,4,((($save[:exp]-$save[:all])/$save[:next].to_f)*100).to_i)
  422.       Fnt[['System/Font',20,20]].draw($save[:stars],41,39,4,:scalex=>0.5,:scaley=>0.5,:align=>:right)
  423.       Fnt[['System/Font',20,20]].draw([$save[:hp],0].max,59,15,4,:scalex=>0.5,:scaley=>0.5)
  424.      
  425.       if @boss
  426.         Tls['System/Bars',1,8,true][2].draw(16,456,4,(@boss[0].hp.to_f/@boss[1])*608)
  427.       end
  428.     end
  429.    
  430.     if @enemy and (@enemy[1]-=1)>0
  431.       Tls['System/EnemyLabel',20,24][2].draw(620,456,4)
  432.       (@enemy[0].name.length-1).times{|x| Tls['System/EnemyLabel',20,24][1].draw(600-x*20,456,4)}
  433.       Tls['System/EnemyLabel',20,24][0].draw(620-@enemy[0].name.length*20,456,4)
  434.       Fnt[['System/Font',20,20]].draw(@enemy[0].name,636,460,4,:align=>:right,:scaley=>0.8)
  435.     elsif @enemy and missing(@enemy[0])
  436.       @enemy=nil
  437.     end
  438.    
  439.     if @item and (@item[1]-=1)>0
  440.       Tls['System/ItemLabel',20,24][0].draw(0,456,4)
  441.       (@item[0].length-1).times{|x| Tls['System/ItemLabel',20,24][1].draw(20+x*20,456,4)}
  442.       Tls['System/ItemLabel',20,24][2].draw(@item[0].length*20,456,4)
  443.       Fnt[['System/Font',20,20]].draw(@item[0],4,460,4,:scaley=>0.8)
  444.     elsif @item
  445.       @item=nil
  446.     end
  447.    
  448.     Img['System/Level Up'].draw_rot(320,240-[120-@level,0].max,4,0,0.5,0.5,[(@level-120)*0.5,1].max,[(@level-120)*0.1,1].max,Color.new([255-(300-@level*3),0].max,255,255,255)) if @level
  449.     Tls['System/Power Up',398,54][@powerup[0]].draw_rot(320,240-[120-@powerup[1]*2,0].max,4,0,0.5,0.5,[(@powerup[1]-120)*0.5,1].max,[200-@powerup[1],100].min*0.01,Color.new([255-(300-@powerup[1]*3),0].max,255,255,255)) if @powerup
  450.     if @area
  451.       @area[0].length.times{|x| Fnt[['System/Font',20,20]].draw(@area[0][x],310-@area[0].length*10+x*20,230+offset_y(@area[1]*4+x*40,(@area[1]/16.0)**2),4,:color=>Color.new([255-@area[1].abs*2,0].max,255,255,255))}
  452.     end
  453.     if @save
  454.       text='Game Saved'
  455.       text.length.times{|x| Fnt[['System/Font',20,20]].draw(text[x],120+x*40,480-offset_x(@save*3-x*20,80),4,:scalex=>2,:scaley=>2)}
  456.     end
  457.    
  458.     events(@map.data[:id])
  459.     @messages[0].draw if !@messages.empty?
  460.    
  461.     if $bossrush
  462.       txt=[]
  463.       txt << "#{'0' if (t=($bossrush[2]/3600%60).to_i)<10}#{t}"
  464.       txt << "#{'0' if (t=($bossrush[2]/60%60).to_i)<10}#{t}"
  465.       txt << "#{'0' if ($bossrush[2]/0.6)%100<10}#{(($bossrush[2]/0.6)%100).to_i}"
  466.      
  467.       Fnt[['System/Font',20,20]].draw(txt.join(':'),@map.data[:id]=="r2" ? 320 : 120,460,4,:scaley=>0.8)
  468.     end
  469.   end
  470.  
  471.   def screen
  472.     @scx=[[@player.x-320,0].max,@map.data[:width]*640-640].min.to_i
  473.     @scy=[[@player.y-240,0].max,@map.data[:height]*480-480].min.to_i
  474.   end
  475.  
  476.   def button_down(id)
  477.   end
  478.  
  479.     def solid?(x,y,down=nil)
  480.     @map.solid?(x.to_i,y.to_i,down) or @entities[3].find{|ent| ent.check(x,y,down)}
  481.     end
  482.  
  483.   def reset(room)
  484.     @start=true
  485.     @temp.clear
  486.         @entities=[[]] ; 5.times{@entities<<[]}
  487.     @player.init if @player
  488.     @map=Map.new(room)
  489.     if $bossrush
  490.       $bossrush[1]=false
  491.       $bossrush[0]=@map.data[:id]
  492.     end
  493.     end
  494.  
  495.     def missing(obj)
  496.         !@entities[0].include?(obj)
  497.     end
  498.  
  499.   def remove(ent)
  500.     @removed << ent
  501.   end
  502.  
  503.   def stomp(x,y,pound)
  504.     return if @player.starman
  505.     $game.entities[1].each{|ent| ent.stomp(x,y,pound)}
  506.     $game.entities[5].each{|ent| ent.stomp(x,y,pound)}
  507.   end
  508.  
  509.   def pow(x,y,width,pound)
  510.     return if @player.starman
  511.     found=nil
  512.     $game.entities[1].each{|ent| found=true if ent.pow(x,y,width,pound)}
  513.     $game.entities[2].each{|ent| found=true if ent.pow(x,y,width,pound)}
  514.     found
  515.   end
  516.  
  517.   def kill(x,y,sizex,sizey,attack,element,id,inv=nil)
  518.     damaged=nil
  519.     $game.entities[1].each{|ent| damaged=true if ent.kill(x,y,sizex,sizey,attack,element,id,inv)}
  520.     $game.entities[4].each{|ent| damaged=true if ent.kill(x,y,sizex,sizey,attack,element,id)}
  521.     damaged
  522.   end
  523.  
  524.   def refresh_stats(change=nil,item=nil)
  525.     equip=$save[:equip].dup
  526.     equip[change]=item if change
  527.     $save[:stomp]=$save[:defence]=0
  528.     $save[:strength]=$save[:base_strength]
  529.     $save[:constitution]=$save[:base_constitution]
  530.     $save[:intelligence]=$save[:base_intelligence]
  531.     $save[:mind]=$save[:base_mind]
  532.     $save[:luck]=$save[:base_luck]
  533.     $save[:intelligence]=$save[:base_intelligence]
  534.     $save[:mp_regen]=$save[:base_mp_regen]
  535.     items=[:suit,:magic,:weapon,:cap,:pants,:boots,:accessory,:accessory]
  536.     8.times{|i|
  537.     $save[:resistance][i]=nil if !equip[i]
  538.     next if !equip[i]
  539.     item=$items[items[i]][equip[i]]
  540.     $save[:strength]+=item[:strength] if item[:strength]
  541.     $save[:constitution]+=item[:constitution] if item[:constitution]
  542.     $save[:intelligence]+=item[:intelligence] if item[:intelligence]
  543.     $save[:mind]+=item[:mind] if item[:mind]
  544.     $save[:luck]+=item[:luck] if item[:luck]
  545.     $save[:mp_regen]+=item[:mp_regen] if item[:mp_regen]
  546.     $save[:stomp]+=item[:stomp] if item[:stomp]
  547.     $save[:defence]+=item[:defence] if item[:defence]
  548.     $save[:resistance][i]=item[:resist]
  549.     }
  550.     $save[:intelligence]=($save[:intelligence]*=1.5).round if equip[3]==3
  551.     $save[:mind]=($save[:mind]*1.1).round if equip[3]==6
  552.     $save[:defence]/=8 if equip[0]==8
  553.    
  554.     if equip[3]==7 && equip[4]==8 && equip[5]==8
  555.       $save[:intelligence]+=50
  556.       $save[:mind]+=50
  557.       $save[:constitution]+=50
  558.       $save[:strength]+=30
  559.       $save[:luck]+=15
  560.       $save[:mp_regen]+=5
  561.     end
  562.    
  563.     if equip[6]==4 && equip[7]==15 or equip[7]==4 && equip[6]==15
  564.       $save[:constitution]*=2
  565.       $save[:strength]*=2
  566.       $save[:mp_regen]+=1
  567.     end
  568.    
  569.     if equip[0]==12 and $save[:dimension]
  570.       $save[:strength]*=3
  571.       $save[:constitution]*=3
  572.       $save[:intelligence]*=3
  573.       $save[:mind]*=3
  574.       $save[:luck]*=3
  575.       $save[:mp_regen]*=3
  576.     end
  577.    
  578.     $save[:stomp]+=$save[:strength]
  579.     $save[:defence]+=$save[:constitution]/2
  580.     $save[:stomp]+=$save[:defence] if equip[5]==6
  581.     $save[:defence]=0 if equip[5]==6
  582.    
  583.     $save[:intelligence]=$save[:mind]=$save[:constitution]=$save[:strength]=$save[:luck]=$save[:stomp]=$save[:defence]=$save[:mp_regen]=60 if equip[4]==9
  584.    
  585.     $save[:items][:suit].uniq!
  586.     $save[:items][:magic].uniq!
  587.     $save[:items][:weapon].uniq!
  588.   end
  589.  
  590.   def enemy=(value)
  591.     @enemy=[value,180] if !@enemy or value != @enemy[0]
  592.   end
  593.  
  594.   def item=(value)
  595.     @item=[value,180]
  596.   end
  597.  
  598.   def  [](entity)
  599.     @entities[0] << entity
  600.   end
  601.  
  602.   def shop!
  603.     @shop=true
  604.   end
  605.  
  606.   def stop_time(sound)
  607.     if @unstoppable
  608.       sound.stop
  609.       Snd["Timenostop"].play
  610.       return
  611.     end
  612.     @stoptime=sound
  613.     Song.current_song.pause if Song.current_song
  614.   end
  615.  
  616.   def stopped;@stoptime;end
  617.  
  618.   def flash(color,speed,starting=nil)
  619.     @flash=[color.class==Color ? color : Color.new(color),speed,starting]
  620.   end
  621.  
  622.   def flashing
  623.     return if !@flash
  624.     @flash[0].alpha
  625.   end
  626.  
  627. def shake(max,time,num,args={})
  628.         @shake=[max,time,num,args,0]
  629.     @shakex=-@shake[0]+rand(@shake[0]*2+1)
  630.     @shakey=-@shake[0]+rand(@shake[0]*2+1)
  631.     end
  632.  
  633.   def warning(mess)
  634.     @warning=[mess,60]
  635.   end
  636.  
  637.   def make_life
  638.     if $bossrush
  639.       $bossrush[3]=true
  640.       return
  641.     end
  642.     Snd['Makelife'].play
  643.     @makelife=[@map.data[:width]*640/2-16,0]
  644.   end
  645.  
  646.   def boss(boss)
  647.     @boss=[boss,boss.hp]
  648.   end
  649. end
  650.  
  651. class Menu
  652.   def initialize
  653.     @state=:main
  654.     @select=0
  655.     @max=5
  656.     @pos=0
  657.     @enemies=[]
  658.     $enemies.each_index{|enemy| @enemies[enemy]=true if $save[:enemies][enemy] and $save[:enemies][enemy].count(true)>=$enemies[enemy][:drop].length}
  659.     @magic=[]
  660.     $save[:magic].length.times{|magic| @magic[magic]=($save[:magic][magic] and $save[:magic][magic][1]==$items[:magic][magic][:levels].length)}
  661.     @unsaveable=(['s','c','t','!','b'].include?($temp.map.data[:id]) or $bossrush)
  662.   end
  663.  
  664.   def update
  665.     if Keypress[:start,false] or @state==:main && Keypress[:shoot,false]
  666.       Snd['Sys3'].play
  667.       $game=$temp
  668.       $temp=nil
  669.     end
  670.     (@select+=1;Snd['Sys1'].play) if @select<@max and Keypress[:down,false] and @state != :enemy
  671.     (@select-=1;Snd['Sys1'].play) if @select>0 and Keypress[:up,false] and @state != :enemy
  672.    
  673.     case @state
  674.       when :main
  675.       if Keypress[:jump,false]
  676.         case @select
  677.           when 0
  678.           @state=:equip
  679.           @max=7
  680.           when 1
  681.           return Snd['Sys4'].play if ($save[:items][:usable]+$save[:items][:misc]).empty?
  682.           @state=:useitem
  683.           $save[:items][:usable].sort!
  684.           @pos=0
  685.           when 2
  686.           @state=:relics
  687.           @max=$relics.length-1
  688.           when 3
  689.           @state=:guides
  690.           @max=$guides.length-1
  691.           when 4
  692.           @state=:enemies
  693.           @max=$enemies.length-1
  694.           when 5
  695.           return Snd['Sys4'].play if @unsaveable
  696.           save=Marshal.load(f=File.open("data/save#{$save[:id]}",'r'))
  697.           f.close
  698.           save[:session]=[$temp.came,$temp.map.data]
  699.           save[:session][2]=nil
  700.           Marshal.dump(save,f=File.open("data/save#{$save[:id]}",'w'))
  701.           f.close
  702.           Marshal.dump($save,f=File.open("data/save#{$save[:id]}s",'w'))
  703.           f.close
  704.           $game=MainMenu.new
  705.           Snd['Sys5'].play
  706.           return
  707.         end
  708.         @select=0
  709.         Snd['Sys2'].play
  710.         return
  711.       end
  712.      
  713.       when :equip
  714.       items=[:suit,:magic,:weapon,:cap,:pants,:boots,:accessory,:accessory]
  715.       @pos=0 if !@choose
  716.       if Keypress[:jump,false] and !@choose and not @select==0 && $save[:items][:suit].empty?
  717.         Snd['Sys2'].play
  718.         @choose=@select
  719.         @select=0
  720.         @max=$save[:items][items[@choose]].uniq.length
  721.         @max-=1 if @choose==0
  722.       elsif Keypress[:jump,false] and @choose
  723.         Snd['Sys2'].play
  724.         last=$save[:equip][@choose]
  725.         $save[:equip][@choose]=((@select==0 and @choose>0) ? nil : $save[:items][items[@choose]].uniq[@choose==0 ? @select : @select-1])
  726.         $save[:items][items[@choose]].delete_at($save[:items][items[@choose]].index($save[:equip][@choose])) if $save[:equip][@choose]# if @select>0 || @choose==0
  727.         $save[:items][items[@choose]].unshift last if last
  728.         @select=@choose
  729.         @choose=nil
  730.         @max=7
  731.         $temp.refresh_stats
  732.       end
  733.       if Keypress[:shoot,false] and !@choose
  734.         Snd['Sys3'].play
  735.         @state=:main
  736.         @select=0
  737.       elsif Keypress[:shoot,false]
  738.         Snd['Sys3'].play
  739.         @max=7
  740.         @select=@choose
  741.         @choose=nil
  742.       end
  743.      
  744.       (@select+=1;Snd['Sys1'].play if Keypress[:right,false]) if @choose and @select<@max and Keypress[:down,false] || Keypress[:right,false]
  745.       (@select-=1;Snd['Sys1'].play if Keypress[:left,false]) if @choose and @select>0 and Keypress[:up,false] || Keypress[:left,false]
  746.       @pos+=2 if @choose and @select-@pos>7
  747.       @pos-=2 if @choose and @select-@pos<0
  748.      
  749.       when :useitem
  750.       @max=$save[:items][:usable].uniq.length+$save[:items][:misc].uniq.length-1
  751.       if Keypress[:jump,false] and @select<$save[:items][:usable].uniq.length
  752.         Snd['Use'].play
  753.         item=$items[:usable][$save[:items][:usable].uniq[@select]]
  754.         $save[:hp]=[$save[:hp]+item[:hp],$save[:max_hp]].min if item[:hp]
  755.         $save[:mp]=[$save[:mp]+item[:mp],$save[:max_mp]].min if item[:mp]
  756.         $save[:stars]=[$save[:stars]+item[:stars],$save[:max_stars]].min if item[:stars]
  757.         $save[:status]='GOOD' if item[:status]==$save[:status]
  758.         $save[:recoil]=item[:recoil]
  759.         $save[:items][:usable].delete_at($save[:items][:usable].index($save[:items][:usable].uniq[@select]))
  760.         @max=$save[:items][:usable].uniq.length+$save[:items][:misc].uniq.length-1
  761.         @select-=1 if @select>@max
  762.       end
  763.      
  764.       if Keypress[:shoot,false]
  765.         Snd['Sys3'].play
  766.         @state=:main
  767.         @select=1
  768.       end
  769.      
  770.       (@select+=1;Snd['Sys1'].play if Keypress[:right,false]) if @select<@max and Keypress[:down,false] || Keypress[:right,false]
  771.       (@select-=1;Snd['Sys1'].play if Keypress[:left,false]) if @select>0 and Keypress[:up,false] || Keypress[:left,false]
  772.      
  773.       @pos+=2 if @select-@pos>13
  774.       @pos-=2 if @select-@pos<0
  775.      
  776.       when :relics
  777.       (@select+=1;Snd['Sys1'].play if Keypress[:right,false]) if @select<@max and Keypress[:down,false] || Keypress[:right,false]
  778.       (@select-=1;Snd['Sys1'].play if Keypress[:left,false]) if @select>0 and Keypress[:up,false] || Keypress[:left,false]
  779.      
  780.       if Keypress[:shoot,false]
  781.         Snd['Sys3'].play
  782.         @state=:main
  783.         @select=2
  784.       end
  785.       if Keypress[:jump,false]
  786.         if  $save[:relics][@select]!=nil
  787.           $save[:relics][@select]=!$save[:relics][@select]
  788.           Snd["Sys#{$save[:relics][@select] ? 2 : 3}"].play
  789.         else
  790.           Snd['Sys4'].play
  791.         end
  792.       end
  793.      
  794.       when :guides
  795.       if Keypress[:jump,false] and !@guide and $save[:guides][@select]
  796.         @guide=@select
  797.         @name=$guides[@select][0]
  798.         @text=$guides[@select][1]
  799.         @char=0
  800.         @part=1
  801.         Snd['Sys2'].play
  802.       elsif @guide
  803.         @char+=1
  804.         if @char>=@text.length and Keypress[:jump,false]
  805.           @part+=1
  806.           if $guides[@guide][@part]
  807.             @text=$guides[@guide][@part]
  808.             @char=0
  809.           else
  810.             @guide=@text=@char=@part=@name=nil
  811.           end
  812.         end
  813.       end
  814.      
  815.       @pos+=1 if @select-@pos>6
  816.       @pos-=1 if @select-@pos<0
  817.      
  818.       if Keypress[:shoot,false]
  819.         Snd['Sys3'].play
  820.         @guide=nil
  821.         @state=:main
  822.         @select=3
  823.       end
  824.    
  825.       when :infos
  826.       if Keypress[:jump,false]
  827.         @state=[:enemies,:items,:areas][@select]
  828.         @select=0
  829.         @max=$enemies.length-1 if @state==:enemies
  830.       end
  831.       if Keypress[:shoot,false]
  832.         @state=:main
  833.         @select=4
  834.       end
  835.      
  836.       when :enemies
  837.       if Keypress[:jump,false] and $save[:enemies][@select]
  838.         Snd['Sys2'].play
  839.         @state=:enemy
  840.       end
  841.       if Keypress[:shoot,false]
  842.         Snd['Sys3'].play
  843.         @state=:main
  844.         @select=4
  845.       end
  846.      
  847.       (@select+=1;Snd['Sys1'].play if Keypress[:right,false]) if @select<@max and Keypress[:down,false] || Keypress[:right,false]
  848.       (@select-=1;Snd['Sys1'].play if Keypress[:left,false]) if @select>0 and Keypress[:up,false] || Keypress[:left,false]
  849.       (@select+=28;Snd['Sys1'].play) if Keypress[KbPageDown,false] and @select<@max-27
  850.       (@select-=28;Snd['Sys1'].play) if Keypress[KbPageUp,false] and @select>27
  851.      
  852.       when :enemy
  853.       (@state=:enemies;Snd['Sys3'].play) if Keypress[:shoot,false]
  854.       ens=$enemies.length
  855.       ens.times{|id| (@select=id;Snd['Sys1'].play;break) if id>@select and $save[:enemies][id]} if Keypress[KbRight,false]
  856.       ens.times{|id| (@select=(ens-id-1);Snd['Sys1'].play;break) if (ens-id-1)<@select and $save[:enemies][ens-id-1]} if Keypress[KbLeft,false]
  857.     end
  858.   end
  859.  
  860.   def draw
  861.     case @state
  862.       when :main
  863.       Img['System/Menu1'].draw(0,0,0)
  864.       Img['Faces/Mario'].draw(9,9,0)
  865.       Fnt[['System/Font',20,20]].draw("Mario",69,150,0,:align=>:center)
  866.       Fnt['data/fonts/nine.ttf',40].draw("Lv.#{0 if $save[:level]<10}#{$save[:level]}",20,180,0)
  867.      
  868.       Fnt[['System/Font',20,20]].draw("HP     /",218,18,0)
  869.       Fnt[['System/Font',20,20]].draw($save[:hp],358,18,0,:align=>:right)
  870.       Fnt[['System/Font',20,20]].draw($save[:max_hp],478,18,0,:align=>:right)
  871.       Fnt[['System/Font',20,20]].draw("MP     /",218,48,0)
  872.       Fnt[['System/Font',20,20]].draw($save[:mp],358,48,0,:align=>:right)
  873.       Fnt[['System/Font',20,20]].draw($save[:max_mp],478,48,0,:align=>:right)
  874.       Img['System/Star'].draw(222,72,0)
  875.       Fnt[['System/Font',20,20]].draw("/",358,78,0)
  876.       Fnt[['System/Font',20,20]].draw($save[:stars],358,78,0,:align=>:right)
  877.       Fnt[['System/Font',20,20]].draw($save[:max_stars],478,78,0,:align=>:right)
  878.      
  879.       bar(492,19,100,18,$save[:hp],$save[:max_hp],0xffff8000)
  880.       bar(492,49,100,18,$save[:mp],$save[:max_mp],0xff80ff80)
  881.       bar(492,79,100,18,$save[:stars],$save[:max_stars],0xffffff00)
  882.      
  883.       time=$save[:time]
  884.       txt=[]
  885.       txt << "#{'0' if (t=(time/216000%60).to_i)<10}#{t}"
  886.       txt << "#{'0' if (t=(time/3600%60).to_i)<10}#{t}"
  887.       txt << "#{'0' if (t=(time/60%60).to_i)<10}#{t}"
  888.      
  889.       $temp.refresh_stats if $save[:equip][3]==8
  890.       Fnt[['System/Font',20,20]].draw("STR",218,118,0)
  891.       Fnt[['System/Font',20,20]].draw($save[:strength],358,118,0,:align=>:right)
  892.       Fnt[['System/Font',20,20]].draw("CON",218,148,0)
  893.       Fnt[['System/Font',20,20]].draw($save[:constitution],358,148,0,:align=>:right)
  894.       Fnt[['System/Font',20,20]].draw("INT",218,178,0)
  895.       Fnt[['System/Font',20,20]].draw($save[:intelligence],358,178,0,:align=>:right)
  896.       Fnt[['System/Font',20,20]].draw("MND",218,208,0)
  897.       Fnt[['System/Font',20,20]].draw($save[:mind],358,208,0,:align=>:right)
  898.       Fnt[['System/Font',20,20]].draw("LCK",218,238,0)
  899.       Fnt[['System/Font',20,20]].draw($save[:luck],358,238,0,:align=>:right)
  900.       Fnt[['System/Font',20,20]].draw("REG",218,268,0)
  901.       Fnt[['System/Font',20,20]].draw($save[:mp_regen],358,268,0,:align=>:right)
  902.       Fnt[['System/Font',20,20]].draw("STOMP",400,118,0)
  903.       Fnt[['System/Font',20,20]].draw($save[:stomp],600,118,0,:align=>:right)
  904.       Fnt[['System/Font',20,20]].draw("DEFEN",400,148,0)
  905.       Fnt[['System/Font',20,20]].draw($save[:defence],600,148,0,:align=>:right)
  906.       Fnt[['System/Font',20,20]].draw("EXP",400,178,0,:color=>0xff0080ff)
  907.       Fnt[['System/Font',20,20]].draw($save[:exp],400,208,0,:color=>0xff0080ff)
  908.       Fnt[['System/Font',20,20]].draw("NEXT",400,238,0,:color=>0xff0080ff)
  909.       Fnt[['System/Font',20,20]].draw($save[:all]+$save[:next]-$save[:exp],400,268,0,:color=>0xff0080ff)
  910.       Fnt[['System/Font',20,20]].draw("TIME:",218,298,0)
  911.       Fnt[['System/Font',20,20]].draw(txt.join(':'),500,298,0,:align=>:right)
  912.       Fnt[['System/Font',20,20]].draw("COINS:",218,328,0,:color=>0xffffff00)
  913.       Fnt[['System/Font',20,20]].draw($save[:coins],500,328,0,:align=>:right,:color=>0xffffff00)
  914.       Fnt[['System/Font',20,20]].draw("STATUS - #{$save[:status]}",218,358,0)
  915.       8.times{|i| x=(i==0 ? 0 : i-2) ; Tls['Icons/Elements',32,32][$save[:resistance][i]].draw(520+x%2*32,298+x/2*24,0) if $save[:resistance][i]}
  916.      
  917.       Fnt[['System/Font',20,20]].draw("Equip",20,300,0,:color=>(@select==0 ? 0xffffffff : 0x80ffffff))
  918.       Fnt[['System/Font',20,20]].draw("Item Use",20,330,0,:color=>(@select==1 ? 0xffffffff : 0x80ffffff))
  919.       Fnt[['System/Font',20,20]].draw("Relics",20,360,0,:color=>(@select==2 ? 0xffffffff : 0x80ffffff))
  920.       Fnt[['System/Font',20,20]].draw("Guides",20,390,0,:color=>(@select==3 ? 0xffffffff : 0x80ffffff))
  921.       Fnt[['System/Font',20,20]].draw("Enemies",20,420,0,:color=>(@select==4 ? 0xffffffff : 0x80ffffff))
  922.       Fnt[['System/Font',20,20]].draw("Suspend",20,450,0,:color=>(@select==5 ? 0xffffffff : 0x80ffffff))
  923.      
  924.       # Fnt[['System/Font',20,20]].draw(["Change equipment and set magic.","View or use an item.","Display list of^collected relicts.","Read hints and^information^from guides.","Show list of all^known items, enemies^and areas.","Hold up the game to^continue later."][@select],216,400,0,:max=>424)
  925.       Fnt[['System/Font',20,20]].draw(["Change equipment and set magic.","View or use an item.","Display list of^collected relicts.","Read hints and^information^from guides.","Show database of^defeated enemies.",@unsaveable ? "You can't suspend in^special rooms.": "Hold up the game to^continue later."][@select],216,400,0,:max=>424)
  926.      
  927.       when :equip #suit | magic, weapon | cap, pants | boots | accessory1, accessory2
  928.       Img['System/Menu2'].draw(0,0,0)
  929.       Fnt['data/fonts/nine.ttf',50].draw("Equip",0,0,0)
  930.       items=[:suit,:magic,:weapon,:cap,:pants,:boots,:accessory,:accessory]
  931.       seletc=(@choose ? @choose : @select)
  932.       8.times{|i| Fnt[['System/Font',20,20]].draw($save[:equip][i] ? $items[items[i]][$save[:equip][i]][:name] : '---',40,100+30*i,0,:color=>(seletc==i ? 0xffffffff : 0x80ffffff))
  933.       Img["Icons/#{items[i]}/#{$save[:equip][i]}"].draw(8,98+i*30,0) if $save[:equip][i]}
  934.       # Fnt[['System/Font',20,20]].draw(items[seletc].to_s.capitalize,20,50,0,:scalex=>1.5,:scaley=>1.5)
  935.       Fnt['data/fonts/nine.ttf',30].draw(items[seletc].to_s.capitalize,20,50,0)
  936.      
  937.       Fnt[['System/Font',20,20]].draw($save[:equip][@select] ? $items[items[@select]][$save[:equip][@select]][:descr] : "You are not wearing any #{items[@select]}.",44,440,0,:xspacing=>15) if !@choose
  938.       Img["Icons/#{items[@select]}/#{$save[:equip][@select]}"].draw(4,444,0) if !@choose and $save[:equip][@select]
  939.      
  940.       type=items[seletc]
  941.       list=(type==:suit ? [] : [nil])+$save[:items][type]
  942.       select=(@choose ? @select : 0)
  943.       $screen.clip_to(0,340,640,99){$screen.translate(0,-@pos*10){
  944.       list.uniq.length.times{|id| Fnt[['System/Font',20,20]].draw((id==0 and seletc>0) ? '---' : $items[type][list.uniq[id]][:name],32+id%2*320,350+id/2*20,0,:color=>Color.new((@choose and select==id) ? 255 : 128,(seletc==1 and id>0 and @magic[list.uniq[id]]) ? 0 : 255,255,255),:scalex=>0.75,:scaley=>0.75)
  945.       Fnt[['System/Font',20,20]].draw(list.count(list.uniq[id]),320+id%2*320,350+id/2*20,0,:color=>(select==id ? 0xffffffff : 0x80ffffff),:scalex=>0.75,:scaley=>0.75,:align=>:right) if id>0 and seletc>2}}}
  946.       Fnt[['System/Font',20,20]].draw((seletc==0 or @select>0) ? $items[type][list.uniq[@select]][:descr] : "Don't wear any #{items[@choose]}.",44,440,0,:xspacing=>15) if @choose
  947.       Img["Icons/#{type}/#{list.uniq[@select]}"].draw(4,444,0) if @choose and @select>0 || seletc==0
  948.      
  949.       if [1,2].include?(seletc) and !@choose && $save[:equip][seletc] || @choose && @select>0
  950.         item=$items[type][@choose ? list.uniq[@select] : $save[:equip][@select]]
  951.         Fnt[['System/Font',20,20]].draw("Damage",320,100,0)
  952.         Fnt[['System/Font',20,20]].draw(item[:attack].class==String ? item[:attack] : item[:attack]+($save[[:intelligence,:strength][seletc-1]]/(item[:divide] ? item[:divide] : 1)).to_i,560,100,0,:align=>:right)
  953.         Fnt[['System/Font',20,20]].draw(seletc==1 ? 'MP use' : 'Stars:',320,120,0)
  954.         Fnt[['System/Font',20,20]].draw(item[:use],560,120,0,:align=>:right)
  955.         Fnt[['System/Font',20,20]].draw("Recoil",320,140,0) if seletc==1
  956.         Fnt[['System/Font',20,20]].draw(item[:recoil],560,140,0,:align=>:right) if seletc==1
  957.         Tls['Icons/Elements',32,32][item[:element]].draw(564,94,0) if item[:element]
  958.         if seletc==1
  959.           magic=(@choose ? $save[:items][:magic][select-1] : $save[:equip][1])
  960.           return if !magic
  961.           $save[:magic][magic]||=[0,0]
  962.           # mag=[]
  963.           # $save[:magic][magic][1].times{|i| mag[i]=(i==0 ? 0 : mag[i-1])+$items[:magic][:levels][i]}
  964.           mag=$save[:magic][magic][0]
  965.           $save[:magic][magic][1].times{|i| mag-=$items[:magic][magic][:levels][i]}
  966.           $items[:magic][magic][:levels].length.times{|x| Tls['System/Mastery',26,26][1].draw(320+x*26,180,0) ; bar(320+x*26,180,26,26,$save[:magic][magic][1]>x ? 1 : mag,$save[:magic][magic][1]>x ? 1 : $items[:magic][magic][:levels][x],$save[:magic][magic][1]==$items[:magic][magic][:levels].length ? 0xff00ffff : $save[:magic][magic][1]>x ? 0xff00ff00 : 0xffff0000) if x<=$save[:magic][magic][1] ; Tls['System/Mastery',26,26][0].draw(320+x*26,180,0)}
  967.           Fnt[['System/Font',20,20]].draw($save[:magic][magic][1]==$items[:magic][magic][:levels].length ? "MASTER" : "SP: #{mag} / #{$items[:magic][magic][:levels][$save[:magic][magic][1]]}",320,220,0)
  968.         end
  969.       elsif ![1,2].include?(seletc)
  970.         Fnt[['System/Font',20,20]].draw("STOMP",400,100,0,:scalex=>0.5)
  971.         Fnt[['System/Font',20,20]].draw("DEFEN",400,120,0,:scalex=>0.5)
  972.         Fnt[['System/Font',20,20]].draw("STR",400,140,0)
  973.         Fnt[['System/Font',20,20]].draw("CON",400,160,0)
  974.         Fnt[['System/Font',20,20]].draw("INT",400,180,0)
  975.         Fnt[['System/Font',20,20]].draw("MND",400,200,0)
  976.         Fnt[['System/Font',20,20]].draw("LCK",400,220,0)
  977.         Fnt[['System/Font',20,20]].draw("REG",400,240,0)
  978.         attrs=[:stomp,:defence,:strength,:constitution,:intelligence,:mind,:luck,:mp_regen]
  979.         old=[]
  980.         8.times{|i| old[i]=$save[attrs[i]] ; Fnt[['System/Font',20,20]].draw($save[attrs[i]],540,100+i*20,0,:align=>:right)}
  981.         if @choose
  982.           $temp.refresh_stats(@choose,list.uniq[@select])
  983.           8.times{|i| Tls['Icons/Elements',32,32][$save[:resistance][i]].draw(320+i*32,24,0) if $save[:resistance][i]}
  984.           8.times{|i| Fnt[['System/Font',20,20]].draw($save[attrs[i]],640,100+i*20,0,:align=>:right,:color=>c=(old[i]>$save[attrs[i]] ? 0xffff0000 : old[i]<$save[attrs[i]] ? 0xff00ff00 : 0xffffffff))
  985.           Tls['System/Arrow',20,20][[0xff00ff00,0xffffffff,0xffff0000].index(c)].draw(540,100+i*20,0)}
  986.           $temp.refresh_stats
  987.         else
  988.           8.times{|i| Tls['Icons/Elements',32,32][$save[:resistance][i]].draw(320+i*32,24,0) if $save[:resistance][i]}
  989.         end
  990.         Fnt[['System/Font',20,20]].draw("Resistance",320,0,0)
  991.       end
  992.      
  993.       when :useitem
  994.       Img['System/Menu4'].draw(0,0,0)
  995.       Fnt['data/fonts/nine.ttf',50].draw("Use Item",0,0,0)
  996.       list1=$save[:items][:usable]
  997.       list2=$save[:items][:misc]
  998.       border=list1.uniq.length
  999.       return (@state=:main ; @select=1) if (list1+list2).empty?
  1000.       $screen.clip_to(0,236,640,203){$screen.translate(0,-@pos*15){
  1001.       (list1.uniq.length+list2.uniq.length).times{|id| Fnt[['System/Font',20,20]].draw($items[id<border ? :usable : :misc][(list1.uniq+list2.uniq)[id]][:name],32+id%2*320,240+id/2*30,0,:color=>(@select==id ? 0xffffffff : 0x80ffffff),:scalex=>0.75,:scaley=>0.75,:xspacing=>13)
  1002.       Fnt[['System/Font',20,20]].draw((id < border ? list1 : list2).count((list1.uniq+list2.uniq)[id]),320+id%2*320,240+id/2*30,0,:color=>(@select==id ? 0xffffffff : 0x80ffffff),:scalex=>0.75,:scaley=>0.75,:align=>:right)}}}
  1003.      
  1004.       Fnt[['System/Font',20,20]].draw("HP     /",18,68,0)
  1005.       Fnt[['System/Font',20,20]].draw($save[:hp],158,68,0,:align=>:right)
  1006.       Fnt[['System/Font',20,20]].draw($save[:max_hp],278,68,0,:align=>:right)
  1007.       Fnt[['System/Font',20,20]].draw("MP     /",18,98,0)
  1008.       Fnt[['System/Font',20,20]].draw($save[:mp],158,98,0,:align=>:right)
  1009.       Fnt[['System/Font',20,20]].draw($save[:max_mp],278,98,0,:align=>:right)
  1010.       Img['System/Star'].draw(22,122,0)
  1011.       Fnt[['System/Font',20,20]].draw("/",158,128,0)
  1012.       Fnt[['System/Font',20,20]].draw($save[:stars],158,128,0,:align=>:right)
  1013.       Fnt[['System/Font',20,20]].draw($save[:max_stars],278,128,0,:align=>:right)
  1014.      
  1015.       bar(292,69,200,18,$save[:hp],$save[:max_hp],0xffff8000)
  1016.       bar(292,99,200,18,$save[:mp],$save[:max_mp],0xff80ff80)
  1017.       bar(292,129,200,18,$save[:stars],$save[:max_stars],0xffffff00)
  1018.       Fnt[['System/Font',20,20]].draw("STATUS - #{$save[:status]}",18,158,0)
  1019.      
  1020.       Fnt[['System/Font',20,20]].draw($items[@select<border ? :usable : :misc][(list1.uniq+list2.uniq)[@select]][:descr],44,440,0,:xspacing=>15)
  1021.       Img["Icons/#{@select < border ? 'Usable' : 'Misc'}/#{(list1.uniq+list2.uniq)[@select]}"].draw(4,444,0)
  1022.      
  1023.       when :relics
  1024.       Img['System/Menu5'].draw(0,0,0)
  1025.       Fnt['data/fonts/nine.ttf',50].draw("Relics",0,0,0)
  1026.       $relics.length.times{|id| Fnt[['System/Font',20,20]].draw(($save[:relics][id]!=nil) ? $relics[id][0] : '?'*$relics[id][0].length,32+id%2*240,64+id/2*30,1,:color=>(@select==id ? 0xffffffff : 0x80ffffff),:scalex=>0.75,:scaley=>0.75)
  1027.       Tls['System/Relic',400,30][($save[:relics][id] ? 1 : 0)+id%2*2].draw(id%2*240,59+id/2*30,0) if $save[:relics][id]!=nil}
  1028.       Fnt[['System/Font',20,20]].draw(($save[:relics][@select]!=nil) ? $relics[@select][1] : "You don't have this relic.",44,440,0,:xscale=>0.75,:xspacing=>14)
  1029.       Img["Icons/Relics/#{$save[:relics][@select]!=nil ? @select : 'None'}"].draw(4,444,0)
  1030.      
  1031.       when :guides
  1032.       Img['System/Menu7'].draw(0,0,0)
  1033.       Fnt['data/fonts/nine.ttf',50].draw("Guides",0,0,0)
  1034.      
  1035.       $screen.clip_to(0,144,640,336){$screen.translate(0,-@pos*45){
  1036.         $guides.length.times{|id| Fnt[['System/Font',20,20]].draw("Guide ##{id+1}",32,144+id*45,1,:color=>(@select==id ? 0xffffffff : 0x80ffffff),:scalex=>0.75,:scaley=>0.75)
  1037.           Fnt[['System/Font',20,20]].draw($save[:guides][id] ? $guides[id][0] : 'Unavailable',32,144+id*45+15,1,:color=>Color.new(@select==id ? 255 : 128,255,$save[:guides][id] ? 255 : 0,255),:scalex=>0.75,:scaley=>0.75)}
  1038.       }}
  1039.        
  1040.       if @guide
  1041.         Fnt[['System/Font',20,20]].draw(@text[(0...@char)],150,20,4,:xspacing=>15)
  1042.         Fnt[['System/Font',20,20]].draw(@name,392,0,4,:align=>:center)
  1043.       else
  1044.         Fnt[['System/Font',20,20]].draw($save[:guides][@select] ? "Jump to display" : "Find guide to read it",392,0,4,:align=>:center)
  1045.       end
  1046.       # $relics.length.times{|id| Fnt[['System/Font',20,20]].draw(($save[:guides][id]!=nil) ? $relics[id][0] : '?'*$relics[id][0].length,32+id%2*240,64+id/2*30,1,:color=>(@select==id ? 0xffffffff : 0x80ffffff),:scalex=>0.75,:scaley=>0.75)
  1047.       # Tls['System/Relic',400,30][($save[:relics][id] ? 1 : 0)+id%2*2].draw(id%2*240,59+id/2*30,0) if $save[:relics][id]!=nil}
  1048.      
  1049.       when :infos
  1050.       Fnt[['System/Font',20,20]].draw("Encyclopedia",320,100,0,:align=>:center,:scalex=>2,:scaley=>2)
  1051.       Fnt[['System/Font',20,20]].draw("Enemies",320,200,0,:align=>:center,:color=>(@select==0 ? 0xffffffff : 0x80ffffff))
  1052.       Fnt[['System/Font',20,20]].draw("Items",320,230,0,:align=>:center,:color=>(@select==1 ? 0xffffffff : 0x80ffffff))
  1053.       Fnt[['System/Font',20,20]].draw("Areas",320,260,0,:align=>:center,:color=>(@select==2 ? 0xffffffff : 0x80ffffff))
  1054.      
  1055.       when :enemies
  1056.       Img['System/Menu6'].draw(0,0,0)
  1057.       Fnt['data/fonts/nine.ttf',50].draw("Enemies' Data",0,0,0)
  1058.       Fnt[['System/Font',20,20]].draw("Killed enemies:^#{$save[:allkills]}",330,5,0)
  1059.       $screen.clip_to(0,68,640,412){$screen.translate(0,-(@select/28*420)){
  1060.       $enemies.length.times{|id| Fnt[['System/Font',20,20]].draw("#{0 if id+1<100}#{0 if id+1<10}#{id+1} "+($save[:enemies][id] ? $enemies[id][:name] : '????????'),15+id%2*320,68+id/2*30,0,:color=>Color.new(@select==id ? 255 : 128,@enemies[id] ? 0 : 255,255,255),:scalex=>0.75,:scaley=>0.75)}
  1061.       }}
  1062.       Tls['System/Page',34,30][1].draw(303,59,1) if @select>27 and $count%30<15
  1063.       Tls['System/Page',34,30][0].draw(303,450,1) if @select<@max-27 and $count%30<15
  1064.      
  1065.       when :enemy
  1066.       Img['System/Menu3'].draw(0,0,0)
  1067.       $screen.clip_to(9,9,190,190) {enemy_img($enemies[@select][:name]).draw_rot(104,104,0,0) if enemy_img($enemies[@select][:name])}
  1068.       Fnt[['System/Font',20,20]].draw("No.#{0 if @select+1<100}#{0 if @select+1<10}#{@select+1}",208,20,0)
  1069.       Fnt[['System/Font',20,20]].draw($enemies[@select][:name],208,60,0)
  1070.       Fnt[['System/Font',20,20]].draw("HP:",208,140,0)
  1071.       Fnt[['System/Font',20,20]].draw($enemies[@select][:hp],480,140,0,:align=>:right)
  1072.       Fnt[['System/Font',20,20]].draw("EXP:            SP:",208,170,0)
  1073.       Fnt[['System/Font',20,20]].draw($enemies[@select][:exp],480,170,0,:align=>:right)
  1074.       Fnt[['System/Font',20,20]].draw($enemies[@select][:sp],625,170,0,:align=>:right)
  1075.       Fnt[['System/Font',20,20]].draw("TOLERANCE:",8,220,0)
  1076.       Fnt[['System/Font',20,20]].draw("WEAKNESS:",8,250,0)
  1077.       Fnt[['System/Font',20,20]].draw("DROP:^    :",8,280,0)
  1078.       Fnt[['System/Font',20,20]].draw($enemies[@select][:drop][0] ? $save[:enemies][@select][0] ? $items[$enemies[@select][:drop][0][0]][$enemies[@select][:drop][0][1]][:name] : "???" : "---",208,280,0)
  1079.       Fnt[['System/Font',20,20]].draw($enemies[@select][:drop][1] ? $save[:enemies][@select][0] ? $items[$enemies[@select][:drop][1][0]][$enemies[@select][:drop][1][1]][:name] : "???" : "---",208,310,0)
  1080.       Fnt[['System/Font',20,20]].draw("Killed: #{$save[:kills][@select]}",8,340,0)
  1081.       Fnt[['System/Font',20,20]].draw($enemies[@select][:descr],8,420,0,:xspacing=>15)
  1082.       rare=([$save[:equip][6],$save[:equip][7]].include?(3) ? 2 : 1)
  1083.       if $enemies[@select][:drop][0]
  1084.         rarity=($enemies[@select][:drop][0][2]+$save[:luck]*0.025)*rare
  1085.         if $save[:equip][3]==9
  1086.           Fnt[['System/Font',20,20]].draw(rarity.round(2),108,282,0)
  1087.         else
  1088.           (rarity>8 ? 1 : rarity>5 ? 2 : rarity>3 ? 3 : rarity>1 ? 4 : 5).times{|x| Img['System/Rarity'].draw(108+x*16,282,0)}
  1089.         end
  1090.       end
  1091.       if $enemies[@select][:drop][1]
  1092.         rarity=($enemies[@select][:drop][1][2]+$save[:luck]*0.025)*rare
  1093.         # (rarity>8 ? 1 : rarity>2.5 ? 2 : rarity>0.8 ? 3 : rarity>0.2 ? 4 : 5).times{|x| Img['System/Rarity'].draw(108+x*16,312,0)}
  1094.         if $save[:equip][3]==9
  1095.           Fnt[['System/Font',20,20]].draw(rarity,108,312,0)
  1096.         else
  1097.           (rarity>8 ? 1 : rarity>5 ? 2 : rarity>3 ? 3 : rarity>1 ? 4 : 5).times{|x| Img['System/Rarity'].draw(108+x*16,312,0)}
  1098.         end
  1099.       end
  1100.       11.times{|x| Tls['Icons/Elements',32,32][x].draw(228+x*32,214,0) if $enemies[@select][:tolerance].include?(x)} if $enemies[@select][:tolerance]
  1101.       11.times{|x| Tls['Icons/Elements',32,32][x].draw(228+x*32,244,0) if $enemies[@select][:weakness].include?(x)} if $enemies[@select][:weakness]
  1102.     end
  1103.   end
  1104.  
  1105.   def bar(x,y,width,height,value,max,color)
  1106.     $screen.draw_quad(x,y,color,x+(value.to_f/max)*width,y,color,x+(value.to_f/max)*width,y+height,color,x,y+height,color,0)
  1107.   end
  1108.  
  1109.   def enemy_img(id)
  1110.     case id
  1111.       when 'Goomba'
  1112.       Tls['Enemies/Goomba',32,32][$count/8%2]
  1113.       when 'Green K.Troopa'
  1114.       Tls['Enemies/Green Koopa Troopa',32,48][$count/8%2]
  1115.       when 'Peeps'
  1116.       Tls['Enemies/Peeps',48,45][([0]*60+[1,2,3,2,1])[$count/4%65]]
  1117.       when 'Swooper'
  1118.       Tls['Enemies/Swooper',32,44][1+$count/8%2]
  1119.       when 'Red K.Troopa'
  1120.       Tls['Enemies/Red Koopa Troopa',32,48][$count/8%2]
  1121.       when 'Spiny'
  1122.       Tls['Enemies/Spiny',32,32][$count/8%2]
  1123.       when 'Monty Mole'
  1124.       Tls['Enemies/Monty Mole',32,32][[4,5][$count/8%2]]
  1125.       when 'Novice Ninji'
  1126.       Tls['Enemies/Ninji1',32,32][$count/8%2]
  1127.       when 'Y. Paratroopa'
  1128.       Tls['Enemies/Yellow Paratroopa',32,48][$count/8%2]
  1129.       when 'Rex'
  1130.       Tls['Enemies/Rex',32,64][$count/8%2]
  1131.       when 'Cheep-Cheep'
  1132.       Tls['Enemies/Cheep Cheep',32,32][$count/8%2]
  1133.       when 'Spiny Ch-Cheep'
  1134.       Tls['Enemies/Spiny Cheep Cheep',33,42][$count/8%2]
  1135.       when 'Sushi'
  1136.       Tls['Enemies/Sushi',144,54][$count/8%2]
  1137.       when 'Skeeter'
  1138.       Img['Enemies/Skeeter']
  1139.       when 'Buzzy Beetle'
  1140.       Tls['Enemies/Buzzy Beetle',32,32][$count/8%2]
  1141.       when 'Huckit Crab'
  1142.       Tls['Enemies/Huckit Crab',54,40][$count/4%2]
  1143.       when 'Piranha Plant'
  1144.       Tls['Enemies/Piranha Plant',32,48][$count/8%2]
  1145.       when 'Iceranha Plant'
  1146.       Tls['Enemies/Iceranha Plant',32,48][$count/8%2]
  1147.       when 'Venus Fire Trap'
  1148.       Tls['Enemies/Venus Preview',32,48][$count/8%2]
  1149.       when 'Medusa Plant'
  1150.       Tls['Enemies/Medusa Plant',32,48][$count/8%2]
  1151.       when 'Fang'
  1152.       Tls['Enemies/Fang',56,36][1+$count/8%2]
  1153.       when "Chargin' Chuck"
  1154.       Tls['Enemies/Chargin Chuck Preview',52,54][[0,0,0,1,2,3,4,4,4,3,2,1][$count/16%12]]
  1155.       when 'Bullet Bill'
  1156.       Tls['Enemies/Bullet Bill',32,28][[0,1,2,1][$count/8%4]]
  1157.       when 'Bill Blaster'
  1158.       Img['Enemies/Blaster']
  1159.       when 'Rocket Engine'
  1160.       Img['Enemies/Engine Preview']
  1161.       when 'Hammer Bro.'
  1162.       Tls['Enemies/Hammer Bro.',32,68][2+$count/8%2]
  1163.       when 'Rebound Bro.'
  1164.       Tls['Enemies/Rebound Bro.',32,48][2+$count/8%2]
  1165.       when 'Panzer Beetle'
  1166.       Tls['Enemies/Panzer Beetle',32,32][$count/8%2]
  1167.       when 'Venomous Spiny'
  1168.       Tls['Enemies/Venom Spiny',32,32][$count/8%2]
  1169.       when 'Shy Guy'
  1170.       Tls['Enemies/Shy Guy',32,32][$count/8%2]
  1171.       when 'Fire Bro.'
  1172.       Tls['Enemies/Fire Bro.',32,48][2+$count/8%2]
  1173.       when 'Bob-omb'
  1174.       Tls['Enemies/Bob-omb',32,32][$count/8%2]
  1175.       when 'Mecha-Plant'
  1176.       Tls['Enemies/Mecha Plant Preview',32,64][$count/8%2]
  1177.       when 'Sniper Koopa'
  1178.       Img['Enemies/SK Preview']
  1179.       when 'Holy Goomba'
  1180.       Tls['Enemies/Holy Goomba',48,48][$count/8%2]
  1181.       when 'Chain-Chomp'
  1182.       Tls['Enemies/ChainChomp Preview',96,96][$count/8%2]
  1183.       when 'Paragoomba'
  1184.       Tls['Enemies/Paragoomba',40,48][$count/8%4]
  1185.       when 'B. Paratroopa'
  1186.       Tls['Enemies/Blue Paratroopa',32,48][$count/8%2]
  1187.       when 'Para-Beetle'
  1188.       Tls['Enemies/ParaBeetle',32,32][$count/8%2]
  1189.       when 'Fire Chomp'
  1190.       Tls['Enemies/FireChomp',32,32][$count/8%2]
  1191.       when "A. Flyin' H. B."
  1192.       Tls['Enemies/FlyingHB',108,78][$count/15%2]
  1193.       when 'Banzai Bill'
  1194.       Img['Enemies/Banzai Bill']
  1195.       when 'Stoney Koopa'
  1196.       Tls['Enemies/Stoney',46,26][$count/8%2+2]
  1197.       when 'Ninji'
  1198.       Tls['Enemies/Ninji2',32,32][$count/8%2]
  1199.       when 'Boomerang Bro.'
  1200.       Tls['Enemies/Boomerang Bro.',32,48][2+$count/8%2]
  1201.       when "Pokey"
  1202.       Tls['Enemies/Pokey Preview',40,96][$count/8%4]
  1203.       when "Volcano Lotus"
  1204.       Tls['Enemies/Volcano Lotus',64,32][$count/8%2]
  1205.       when 'Scaredy Rat'
  1206.       Tls['Enemies/Scaredy Rat',41,28][[0,1,0,2][$count/8%4]]
  1207.       when 'Eerie'
  1208.       Tls['Enemies/Eerie',32,32][$count/8%2]
  1209.       when 'Boo'
  1210.       Tls['Enemies/Bou',32,32][$count/60%2]
  1211.       when 'Big Boo'
  1212.       Tls['Enemies/Big Boo',134,128][$count/60%2]
  1213.       when "Fishin' Boo"
  1214.       Tls['Enemies/Fishin Preview',86,166][$count/8%4]
  1215.       when "Dry Bones"
  1216.       Tls['Enemies/Dry Bones',48,56][$count/8%2]
  1217.       when "Bony Beetle"
  1218.       Tls['Enemies/Bony Beetle',32,32][$count/8%2]
  1219.       when "Magikoopa"
  1220.       Tls['Enemies/Magi',52,62][1+$count/8%2]
  1221.       when "Spiny Egg"
  1222.       Img['Enemies/SpikyBall']
  1223.       when "Lakitu"
  1224.       Tls['Enemies/Lakitu',32,64][0]
  1225.       when "Stony"
  1226.       Tls['Enemies/Stony',32,32][$count/8%2]
  1227.       when "Scuttle Bug"
  1228.       Img['Enemies/ScuttleBug']
  1229.       when "Koopa Priest"
  1230.       Tls['Enemies/Priest',70,78][1+$count/8%2]
  1231.       when "Necrokoopa"
  1232.       Tls['Enemies/Necro',52,62][1+$count/8%2]
  1233.       when "Dino-Torch"
  1234.       Tls['Enemies/Dino-Torch',32,32][$count/8%2]
  1235.       when "Dino-Fridge"
  1236.       Tls['Enemies/Dino-Fridge',32,32][$count/8%2]
  1237.       when "Nyan Cat"
  1238.       Tls['Enemies/Nyan',94,57][$count/8%6]
  1239.       when "Hammer Giant"
  1240.       Img['Enemies/Giant']
  1241.       when "Clear Dry Bones"
  1242.       Tls['Enemies/Clear Dry Bones',48,56][$count/8%2]
  1243.       when "Zombie Yoshi"
  1244.       Tls['Enemies/Zombie',52,64][0]
  1245.       when 'Golden Goomba'
  1246.       Tls['Enemies/GoldGoomba',32,32][$count/8%2]
  1247.       when 'Titan'
  1248.       Tls['Enemies/Titan',32,32][$count/8%2]
  1249.       when 'Boom Boom Boom'
  1250.       Tls['Enemies/BBB',136,108][[1,2,3,4,3,2][$count/8%6]]
  1251.       when 'Orobunagi'
  1252.       Tls['Enemies/Unagi Preview',190,87][$count/4%10]
  1253.       when 'P-cus Ultimatus'
  1254.       Tls['Enemies/Ultimatus Preview',50,190][$count/8%2]
  1255.       when 'Thwomp Destroyer'
  1256.       Img['Enemies/Destroyer Preview']
  1257.       when 'Tox Box Max'
  1258.       Tls['Enemies/Tox Box',256,256][0]
  1259.       when 'Boo Formation'
  1260.       Tls['Enemies/Boo Formation',128,128][$count/16%4]
  1261.       when 'Goombfalloon'
  1262.       [Img['Enemies/Goombfalloon'],Tls['Enemies/Legion',48,48][0]][$count/60%2]
  1263.       when 'Death'
  1264.       Tls['Enemies/Death2',230,170][[4,9][$count/60%2]]
  1265.       when 'Chaos Core'
  1266.       Img['Enemies/Chaos Preview']
  1267.       when "Wiggler"
  1268.       rage=($count/128%2==0)
  1269.       Tls['Enemies/Wiggler',158,80][(rage ? 4 : 0)+$count/(rage ? 4 : 8)%4]
  1270.       when 'Thwomp'
  1271.       Tls['Enemies/Thwomp',72,96][0]
  1272.       when 'Chainsaw'
  1273.       Tls['Enemies/Chainsaw',32,86][$count%2]
  1274.       when 'Podoboo'
  1275.       Tls['Enemies/Podoboo',28,32][$count/8%3]
  1276.       when 'Mad Piano'
  1277.       Tls['Enemies/Mad Piano',128,121][[0,1,2,3,2,1][$count/4%6]]
  1278.       when 'Out-Boo'
  1279.       Tls['Enemies/Outoo',32,32][$count/60%2]
  1280.       when 'Floating Mine'
  1281.       Tls['Enemies/Mine',30,30][$count/16%2]
  1282.       when "Li'l Sparky"
  1283.       Img['Enemies/Sparky']
  1284.       when 'Snift'
  1285.       Tls['Enemies/Snift',32,32][$count/8%2]
  1286.       when 'Lakithunder'
  1287.       Tls['Enemies/Lakithunder',78,94][0]
  1288.       when 'Muncher'
  1289.       Tls['Enemies/Muncher',32,32][$count/8%2]
  1290.       when 'Po-ison-key'
  1291.       Tls['Enemies/Poisonkey Preview',56,144][$count/8%4]
  1292.       when 'Fuzzy'
  1293.       Tls['Enemies/Fuzzy',48,44][$count/8%4]
  1294.       when 'Ghost Vase'
  1295.       Tls['Enemies/Vase',24,48][$count/60%2]
  1296.       when 'Mad Block'
  1297.       Tls['Enemies/Mad Block',32,32][4]
  1298.       when 'Lightning Lotus'
  1299.       Tls['Enemies/Lighting Lotus',64,32][$count/16%2]
  1300.       when 'Chain-Cheep'
  1301.       Tls['Enemies/ChainCheep Preview',96,96][$count/8%2]
  1302.       when 'Shadow Bro.'
  1303.       Tls['Enemies/Shadow Bro.',32,68][2+$count/8%2]
  1304.       when 'Reznor'
  1305.       Tls['Enemies/Reznor',64,66][0]
  1306.       when 'Novaboo'
  1307.       Tls['Enemies/Novaboo',28,32][$count/8%3]
  1308.       when 'Sky Cheep-Cheep'
  1309.       Tls['Enemies/Sky Cheep Cheep',32,32][$count/8%4]
  1310.       when 'Ptooie'
  1311.       Tls['Enemies/Ptooie',32,50][$count/8%4]
  1312.       when 'Mecha-Plant v.2.6b'
  1313.       Tls['Enemies/MechaPlant Preview',32,64][$count/8%2]
  1314.       when 'Dark Star'
  1315.       Tls['Enemies/Dark Star',122,120][$count/4%12]
  1316.       when 'Sorckoopa'
  1317.       Tls['Enemies/Sorc',52,62][1+$count/8%2]
  1318.       when 'Hammer Master'
  1319.       Img['Enemies/HammerMaster']
  1320.       when 'Omnisledge Bro.'
  1321.       Tls['Enemies/Omnis',192,256][$count/4%6]
  1322.       when 'Luigi'
  1323.       Img['Enemies/Luigi']
  1324.       when 'Bang Star'
  1325.       Img['Enemies/Bang Star']
  1326.       when 'Phanto'
  1327.       Tls['Enemies/Phanto',32][0]
  1328.       when 'Kamek'
  1329.       Tls['Enemies/Kamek',100,96][$count/8%2]
  1330.       when 'Bowser'
  1331.       Tls['Enemies/Bowser',96,120][0]
  1332.       when 'Mega Bowser'
  1333.       Img['Enemies/Mega Bowser Preview']
  1334.     end
  1335.   end
  1336. end
  1337.  
  1338. class Minimap
  1339.   def initialize(origin,x,y)
  1340.     @x=origin[0]*10+x/64.0
  1341.     @y=origin[1]*10+y/48.0
  1342.     if $save[:relics][9]==true
  1343.       @image1=$screen.record(640,480){$save[:map].each{|room| room.draw(0)}}
  1344.       @image2=$screen.record(640,480){$save[:map].each{|room| room.draw(1)}}
  1345.       @image3=$screen.record(640,480){$save[:map].each{|room| room.draw(2)}}
  1346.       @mode=($save[:dimension] ? 0 : 2)
  1347.     else
  1348.       @image1=$screen.record(640,480){$save[:map].each{|room| room.draw(3)}}
  1349.     end
  1350.     @time=0
  1351.     @percent=(($save[:map].count{|room| room.discovered}/$save[:map].length.to_f)*100).round(2)
  1352.   end
  1353.  
  1354.   def update
  1355.     @time+=1
  1356.     if Keypress[:shoot,false] or Keypress[:select,false]
  1357.       Snd['Sys3'].play
  1358.       $game=$temp
  1359.       $temp=nil
  1360.     end
  1361.   end
  1362.  
  1363.   def draw
  1364.     if $save[:relics][9]
  1365.       Fnt[['System/Font',20,20]].draw(["Distortion","Combined","Normal"][@mode],320,0,0,:align=>:center)
  1366.       (@mode-=1;Snd['Sys1'].play) if Keypress[:left,false] and @mode>0
  1367.       (@mode+=1;Snd['Sys1'].play) if Keypress[:right,false] and @mode<2
  1368.       [@image3,@image1,@image2][@mode].draw(0,0,0)
  1369.     else
  1370.       @image1.draw(0,0,0)
  1371.     end
  1372.     Img['System/Position'].draw_rot(@x,@y,0,0,0.5,0.5,(100-@time%100)*0.01,(100-@time%100)*0.01,Color.new((@time%100*2.5).to_i,255,255,255)) if not @mode==0 && !$save[:dimension] || @mode==2 && $save[:dimension]
  1373.     Fnt[['System/Font',20,20]].draw("#{@percent}%",10,10,0)
  1374.   end
  1375. end
  1376.  
  1377. class Shop
  1378.   def initialize
  1379.     Snd['Sys5'].play
  1380.     @state=:main
  1381.     @select=0
  1382.     @max=2
  1383.     @items={:misc=>[],:usable=>[],:cap=>[],:pants=>[],:boots=>[],:accessory=>[]}
  1384.  
  1385.     add_item(:misc,'Castle Map 2')
  1386.    
  1387.     add_item(:usable,'Super Mushroom')
  1388.     add_item(:usable,'Ultra Mushroom') if $save[:events][10]
  1389.     add_item(:usable,'Hyper Mushroom') if $save[:events][23]
  1390.     add_item(:usable,'Mana Potion')
  1391.     add_item(:usable,'Mana Bottle') if $save[:events][10]
  1392.     add_item(:usable,'Star Prism') if $save[:events][10]
  1393.     add_item(:usable,'Star Refresh') if $save[:events][23]
  1394.     add_item(:usable,'De-Poisoned Mushroom')
  1395.     add_item(:usable,'Holy Mushroom')
  1396.    
  1397.     add_item(:boots,'Wooden Boots')
  1398.    
  1399.     add_item(:accessory,'A Ring') if $save[:cores].length>0
  1400.     add_item(:accessory,'4-leaf Clover')
  1401.     add_item(:accessory,'New Scarf') if $save[:events][7]
  1402.     add_item(:accessory,'Mushroom Badge') if $save[:events][23]
  1403.     add_item(:accessory,"Ring'o Drop") if $save[:events][23]
  1404.     add_item(:accessory,"Sorcerer Necklace") if $save[:enemies][94] and $save[:enemies][94][0]
  1405.    
  1406.     add_item(:pants,'Elven Pants') if $save[:events][7]
  1407.    
  1408.     add_item(:cap,'Metal Cap') if $save[:events][6]
  1409.     add_item(:cap,'Geeks') if $save[:events][14]
  1410.   end
  1411.  
  1412.   def update
  1413.     (@select+=1;Snd['Sys1'].play) if @select<@max and Keypress[:down,false]
  1414.     (@select-=1;Snd['Sys1'].play) if @select>0 and Keypress[:up,false]
  1415.     case @state
  1416.       when :main
  1417.       @max=2
  1418.       if Keypress[:jump,false]
  1419.         case @select
  1420.           when 0
  1421.           Snd['Sys2'].play
  1422.           @select=0
  1423.           @state=:buy
  1424.           @max=-1
  1425.           @items.values.each{|val| @max+=val.length}
  1426.           @amm=1
  1427.           @old=nil
  1428.           @pos=0
  1429.           when 1
  1430.           return Snd['Sys4'].play if !select2
  1431.           Snd['Sys2'].play
  1432.           @select=0
  1433.           @state=:sell
  1434.           @max=-1
  1435.           $save[:items].each_pair{|type,ary| @max+=ary.uniq.length if ![:suit,:magic,:weapon,:misc].include?(type)}
  1436.           @amm=1
  1437.           @old=nil
  1438.           @pos=0
  1439.           when 2
  1440.           Snd['Sys5'].play
  1441.           $game=$temp
  1442.           $temp=nil
  1443.           message
  1444.         end
  1445.       end
  1446.      
  1447.       if Keypress[:shoot,false]
  1448.         $game=$temp
  1449.         $temp=nil
  1450.         message
  1451.         if $save[:items][:misc].include?(1)
  1452.           map=Marshal.load(f=File.open("data/plan1",'r'))
  1453.           f.close
  1454.           map.each{|plan| room=$save[:map].find{|room| room.x/10==plan[0] and room.y/10==plan[1]} ; room.map! if room}
  1455.         end
  1456.       end
  1457.      
  1458.       when :buy
  1459.       @amm=1 if @old != @select
  1460.       @old=@select
  1461.       if Keypress[:jump,false] and (price=$items[select][@items[select][@sel]][:price]*@amm)<=$save[:coins]
  1462.         Snd['Item'].play
  1463.         $save[:coins]-=price
  1464.         $save[:items][select]=$save[:items][select]+[@items[select][@sel]]*@amm
  1465.       elsif Keypress[:jump,false]
  1466.         Snd['Sys4'].play
  1467.       end
  1468.      
  1469.       if Keypress[KbRight]
  1470.         @hold||=0
  1471.         if @amm<99 and (@hold%8)==0
  1472.           @amm+=1
  1473.           Snd['Sys1'].play
  1474.         end
  1475.         @hold+=1
  1476.       elsif Keypress[KbLeft]
  1477.         @hold||=0
  1478.         if @amm>1 and (@hold%8)==0
  1479.           @amm-=1
  1480.           Snd['Sys1'].play
  1481.         end
  1482.         @hold+=1
  1483.       else
  1484.         @hold=0
  1485.       end
  1486.      
  1487.       if Keypress[:shoot,false]
  1488.         Snd['Sys3'].play
  1489.         @select=0
  1490.         @state=:main
  1491.       end
  1492.      
  1493.       @pos+=1 if @select-@pos>7
  1494.       @pos-=1 if @select-@pos<0
  1495.      
  1496.       when :sell
  1497.       @amm=1 if @old != @select
  1498.       @old=@select
  1499.       if Keypress[:jump,false]
  1500.         Snd['Sys2'].play
  1501.         $save[:coins]+=$items[select2][$save[:items][select2].uniq[@sel]][:price]/2*@amm
  1502.         @amm.times{$save[:items][select2].delete_at($save[:items][select2].index($save[:items][select2].uniq[@sel]))}
  1503.         return @state=:main if !select2
  1504.         @amm=[@amm,$save[:items][select2].count($save[:items][select2].uniq[@sel])].min
  1505.         @max=-1
  1506.         $save[:items].each_pair{|type,ary| @max+=ary.uniq.length if ![:suit,:magic,:weapon,:misc].include?(type)}
  1507.         @select=[@select,@max].min
  1508.         return @state=:main if !$save[:items].values.find{|cat| !cat.empty?}
  1509.       end
  1510.      
  1511.       if Keypress[KbRight]
  1512.         @hold||=0
  1513.         if @amm<$save[:items][select2].count($save[:items][select2].uniq[@sel]) and (@hold%8)==0
  1514.           @amm+=1
  1515.           Snd['Sys1'].play
  1516.         end
  1517.         @hold+=1
  1518.       elsif Keypress[KbLeft]
  1519.         @hold||=0
  1520.         if @amm>1 and (@hold%8)==0
  1521.           @amm-=1
  1522.           Snd['Sys1'].play
  1523.         end
  1524.         @hold+=1
  1525.       else
  1526.         @hold=0
  1527.       end
  1528.      
  1529.       if Keypress[:shoot,false]
  1530.         Snd['Sys3'].play
  1531.         @select=1
  1532.         @state=:main
  1533.       end
  1534.      
  1535.       @pos+=1 if @select-@pos>7
  1536.       @pos-=1 if @select-@pos<0
  1537.     end
  1538.   end
  1539.  
  1540.   def draw
  1541.     case @state
  1542.       when :main
  1543.       Fnt[['System/Font',20,20]].draw("Buy",320,120,0,:align=>:center,:color=>(@select==0 ? 0xffffffff : 0x80ffffff))
  1544.       Fnt[['System/Font',20,20]].draw("Sell",320,150,0,:align=>:center,:color=>(@select==1 ? 0xffffffff : 0x80ffffff))
  1545.       Fnt[['System/Font',20,20]].draw("Exit",320,180,0,:align=>:center,:color=>(@select==2 ? 0xffffffff : 0x80ffffff))
  1546.      
  1547.       Img['Faces/Toad3'].draw(16,316,0)
  1548.       Fnt[['System/Font',20,20]].draw(["So you want to buy? I have good deals for^you.","Is there something you don't need? Give me^for a fair price.","Leaving already? Come back later for new^items."][@select],0,440,0,:xspacing=>15)
  1549.       when :buy
  1550.       Img['System/Shop'].draw(0,0,0)
  1551.       Fnt['data/fonts/nine.ttf',128].draw("Buy",138,0,0)
  1552.       Fnt[['System/Font',20,20]].draw("Coins: #{$save[:coins]}",20,160,0,:color=>0xffffff00)
  1553.       y=0
  1554.       $screen.clip_to(0,196,640,200){$screen.translate(0,-@pos*25){
  1555.       @items.keys.length.times{|type| typ=[:misc,:usable,:cap,:pants,:boots,:accessory][type] ; @items[typ].each{|id| Fnt[['System/Font',20,20]].draw($items[typ][id][:name],40,200+y*25,0,:xspacing=>15,:color=>(@select==y ? 0xffffffff : 0x80ffffff)) ; Fnt[['System/Font',20,20]].draw(price=$items[typ][id][:price],600,200+y*25,0,:xspacing=>15,:align=>:right,:color=>(price>$save[:coins] ? 0xffff0000 : 0xffffffff)) ; y+=1}}}}
  1556.      
  1557.       Fnt[['System/Font',20,20]].draw($items[select][@items[select][@sel]][:descr],44,440,0,:xspacing=>15)
  1558.       Img["Icons/#{select}/#{@items[select][@sel]}"].draw(4,444,0)
  1559.      
  1560.       Fnt[['System/Font',20,20]].draw("Buy x#{@amm} - #{price=$items[select][@items[select][@sel]][:price]*@amm}",20,410,0,:color=>(price>$save[:coins] ? 0xffff0000 : 0xffffffff))
  1561.       Fnt[['System/Font',20,20]].draw("Keeping: #{$save[:items][select].count(@items[select][@sel])}",400,410,0)
  1562.      
  1563.       Fnt[['System/Font',20,20]].draw("STOMP",400,20,0,:scalex=>0.5)
  1564.       Fnt[['System/Font',20,20]].draw("DEFEN",400,40,0,:scalex=>0.5)
  1565.       Fnt[['System/Font',20,20]].draw("STR",400,60,0)
  1566.       Fnt[['System/Font',20,20]].draw("CON",400,80,0)
  1567.       Fnt[['System/Font',20,20]].draw("INT",400,100,0)
  1568.       Fnt[['System/Font',20,20]].draw("MND",400,120,0)
  1569.       Fnt[['System/Font',20,20]].draw("LCK",400,140,0)
  1570.       Fnt[['System/Font',20,20]].draw("REG",400,160,0)
  1571.       attrs=[:stomp,:defence,:strength,:constitution,:intelligence,:mind,:luck,:mp_regen]
  1572.       old=[]
  1573.       8.times{|i| old[i]=$save[attrs[i]] ; Fnt[['System/Font',20,20]].draw($save[attrs[i]],540,20+i*20,0,:align=>:right)}
  1574.       if [:cap,:boots,:pants,:accessory].include?(select)
  1575.         items=[:suit,:magic,:weapon,:cap,:pants,:boots,:accessory,:accessory]
  1576.         $temp.refresh_stats(items.index(select),@items[select][@sel])
  1577.         8.times{|i| Fnt[['System/Font',20,20]].draw($save[attrs[i]],640,20+i*20,0,:align=>:right,:color=>c=(old[i]>$save[attrs[i]] ? 0xffff0000 : old[i]<$save[attrs[i]] ? 0xff00ff00 : 0xffffffff))
  1578.         Tls['System/Arrow',20,20][[0xff00ff00,0xffffffff,0xffff0000].index(c)].draw(540,20+i*20,0)}
  1579.         $temp.refresh_stats
  1580.       end
  1581.       Img['System/Further'].draw(8,204,2) if @pos>0 and $count%60<30
  1582.       Img['System/Further'].draw(8,390,2,1,-1) if @pos<@max-7 and $count%60<30
  1583.      
  1584.       when :sell
  1585.       Img['System/Shop'].draw(0,0,0)
  1586.       Fnt['data/fonts/nine.ttf',128].draw("Sell",138,0,0)
  1587.       Fnt[['System/Font',20,20]].draw("Coins: #{$save[:coins]}",20,160,0,:color=>0xffffff00)
  1588.       y=0
  1589.       keys=$save[:items].keys-[:misc,:magic,:weapon,:suit]
  1590.       $screen.clip_to(0,196,640,200){$screen.translate(0,-@pos*25){
  1591.       keys.length.times{|type| typ=[:usable,:cap,:pants,:boots,:accessory][type] ; $save[:items][typ].uniq.each{|id| Fnt[['System/Font',20,20]].draw($items[typ][id][:name],40,200+y*25,0,:xspacing=>15,:color=>(@select==y ? 0xffffffff : 0x80ffffff)) ; Fnt[['System/Font',20,20]].draw($save[:items][typ].count(id),600,200+y*25,0,:xspacing=>15,:align=>:right) ; y+=1}}}}
  1592.      
  1593.       Fnt[['System/Font',20,20]].draw($items[select2][$save[:items][select2].uniq[@sel]][:descr],44,440,0,:xspacing=>15)
  1594.       Img["Icons/#{select2}/#{$save[:items][select2].uniq[@sel]}"].draw(4,444,0)
  1595.      
  1596.       Fnt[['System/Font',20,20]].draw("Sell x#{@amm} - #{$items[select2][$save[:items][select2].uniq[@sel]][:price]/2*@amm}",20,410,0)
  1597.      
  1598.       Fnt[['System/Font',20,20]].draw("STOMP",400,20,0,:scalex=>0.5)
  1599.       Fnt[['System/Font',20,20]].draw("DEFEN",400,40,0,:scalex=>0.5)
  1600.       Fnt[['System/Font',20,20]].draw("STR",400,60,0)
  1601.       Fnt[['System/Font',20,20]].draw("CON",400,80,0)
  1602.       Fnt[['System/Font',20,20]].draw("INT",400,100,0)
  1603.       Fnt[['System/Font',20,20]].draw("MND",400,120,0)
  1604.       Fnt[['System/Font',20,20]].draw("LCK",400,140,0)
  1605.       Fnt[['System/Font',20,20]].draw("REG",400,160,0)
  1606.       attrs=[:stomp,:defence,:strength,:constitution,:intelligence,:mind,:luck,:mp_regen]
  1607.       old=[]
  1608.       8.times{|i| old[i]=$save[attrs[i]] ; Fnt[['System/Font',20,20]].draw($save[attrs[i]],540,20+i*20,0,:align=>:right)}
  1609.       if [:cap,:boots,:pants,:accessory].include?(select2)
  1610.         items=[:suit,:magic,:weapon,:cap,:pants,:boots,:accessory,:accessory]
  1611.         $temp.refresh_stats(items.index(select2),$save[:items][select2].uniq[@sel])
  1612.         8.times{|i| Fnt[['System/Font',20,20]].draw($save[attrs[i]],640,20+i*20,0,:align=>:right,:color=>c=(old[i]>$save[attrs[i]] ? 0xffff0000 : old[i]<$save[attrs[i]] ? 0xff00ff00 : 0xffffffff))
  1613.         Tls['System/Arrow',20,20][[0xff00ff00,0xffffffff,0xffff0000].index(c)].draw(540,20+i*20,0)}
  1614.         $temp.refresh_stats
  1615.       end
  1616.       Img['System/Further'].draw(8,204,2) if @pos>0 and $count%60<30
  1617.       Img['System/Further'].draw(8,390,2,1,-1) if @pos<@max-7 and $count%60<30
  1618.     end
  1619.   end
  1620.  
  1621.   def select
  1622.     @sel=@select
  1623.     return :misc if @sel<@items[:misc].length
  1624.     return :usable if (@sel-=@items[:misc].length)<@items[:usable].length
  1625.     return :cap if (@sel-=@items[:usable].length)<@items[:cap].length
  1626.     return :pants if (@sel-=@items[:cap].length)<@items[:pants].length
  1627.     return :boots if (@sel-=@items[:pants].length)<@items[:boots].length
  1628.     return :accessory if (@sel-=@items[:boots].length)<@items[:accessory].length
  1629.   end
  1630.  
  1631.   def select2
  1632.     @sel=@select
  1633.     return :usable if @sel<$save[:items][:usable].uniq.length
  1634.     return :cap if (@sel-=$save[:items][:usable].uniq.length)<$save[:items][:cap].uniq.length
  1635.     return :pants if (@sel-=$save[:items][:cap].uniq.length)<$save[:items][:pants].uniq.length
  1636.     return :boots if (@sel-=$save[:items][:pants].uniq.length)<$save[:items][:boots].uniq.length
  1637.     return :accessory if (@sel-=$save[:items][:boots].uniq.length)<$save[:items][:accessory].uniq.length
  1638.   end
  1639.  
  1640.   def add_item(type,name)
  1641.     @items[type] << $items[type].index{|item| item[:name]==name}
  1642.   end
  1643.  
  1644.   def message
  1645.     if !$save[:events][37]
  1646.       $save[:events][37]=true
  1647.       Message.new("Toad","Toad3","Be sure to come back,^to check if I have new wares.")
  1648.     end
  1649.   end
  1650. end
  1651.  
  1652. class MainMenu
  1653.   def initialize
  1654.     @select=0
  1655.     @max=2
  1656.     @state=:intro
  1657.     Msc['Zelda2'].play
  1658.     @saves=[]
  1659.     5.times{|id|@saves[id]=if File.exists?("data/save#{id}")
  1660.       data=Marshal.load(f=File.new("data/save#{id}",'r'))
  1661.       f.close ; data end}
  1662.     @sessions=[]
  1663.     5.times{|id|@sessions[id]=if File.exists?("data/save#{id}s")
  1664.       data=Marshal.load(f=File.new("data/save#{id}s",'r'))
  1665.       f.close ; data end}
  1666.     @music=[]
  1667.     (Dir.entries('data/music')-['.','..']).each{|msc| @music << msc.chop.chop.chop.chop}
  1668.     @music.delete_if{|mus| mus.include?('-pre')}
  1669.    
  1670.     @games={'Castlevania: Aria of Sorrow'=>['Clock Tower','Confrontation','Forbidden Area'],'Castlevania: Dawn of Sorrow'=>['The Abyss','Platinum Moonlight'],'Chrono Trigger'=>['World Revolution'],'Castlevania: Circle of the Moon'=>['Nightmare','Awake'],'Castlevania: Portrait of Ruin'=>['Piercing Silence',"Crucifix Held Close","Iron Blue Intention","Chaotic Playground"],"Castlevania: Symphony of the Night"=>["Dracula's Castle"],"Castlevania: Order of Ecclesia"=>["An Empty Tome","Malak's Labyrinth"],
  1671.     "Super Mario Galaxy"=>["Haunty Halls"],"Super Smash Bros. Brawl"=>["Zelda2"],"Castlevania: Harmony of Dissonance"=>["Successor of Fate","Boss A","Chapel of Dissonance"],"Super Metroid"=>["Item Room"],"Super Mario Bros."=>["Fail","Game Over","Castle"],"New Super Mario Bros."=>["Starman"],"Super Mario RPG"=>["Weapons Factory","Fight Against Culex","Fight Against Monsters"],"Other/Unknown"=>["YkY","level_zameczek"]}
  1672.    
  1673.     @soundtest=$config[4][0]
  1674.     @bossrush=$config[4][1]
  1675.     @bossrush2=$config[4][2]
  1676.   end
  1677.  
  1678.   def update
  1679.     case @state
  1680.       when :intro
  1681.       return (@state=:main;Snd['Sys5'].play) if Keypress[KbReturn,false]
  1682.      
  1683.       when :credits
  1684.       return (@state=:main;Snd['Sys3'].play) if Keypress[:shoot,false]
  1685.      
  1686.       when :main
  1687.       (@select+=1;Snd['Sys1'].play) if Keypress[KbDown,false] and @select<@max
  1688.       (@select-=1;Snd['Sys1'].play) if Keypress[KbUp,false] and @select>0
  1689.       if Keypress[:jump,false]
  1690.         case @select
  1691.           when 0
  1692.           Snd['Sys2'].play
  1693.           @boss=nil
  1694.           @state=:saves
  1695.           when 1
  1696.           Snd['Sys2'].play
  1697.           @state=:config
  1698.           @select=0
  1699.           when 2
  1700.           Snd['Sys2'].play
  1701.           @state=:credits
  1702.           when 3
  1703.           Snd['Sys5'].play
  1704.           $screen.close
  1705.           when 4
  1706.           Song.current_song.stop
  1707.           Snd['Sys5'].play
  1708.           @state=:sound
  1709.           @select=0
  1710.           when 5
  1711.           Song.current_song.stop
  1712.           Snd['Sys5'].play
  1713.           @state=:boss
  1714.           @select=0
  1715.         end
  1716.         return
  1717.       end
  1718.       when :saves
  1719.       return (@state=:main;@select=0;Snd['Sys3'].play) if Keypress[:shoot,false] and !@save and !@name and !@boss
  1720.       return (@state=:boss;@select=@boss-1;Snd['Sys3'].play) if Keypress[:shoot,false] and @boss
  1721.       (@select+=1;Snd['Sys1'].play) if Keypress[KbRight,false] and @select<4 and !@save and !@new
  1722.       (@select-=1;Snd['Sys1'].play) if Keypress[KbLeft,false] and @select>0 and !@save and !@new
  1723.       if @saves[@select]
  1724.         (@select2+=1;Snd['Sys1'].play) if Keypress[KbRight,false] and@save and @select2<3 and !@action and !@copy
  1725.         (@select2-=1;Snd['Sys1'].play) if Keypress[KbLeft,false] and @save and @select2>0 and !@action and !@copy
  1726.         (@select2+=1;Snd['Sys1'].play) if Keypress[KbRight] and @select2==1 and !@saves[@select][:session]
  1727.         (@select2-=1;Snd['Sys1'].play) if Keypress[KbLeft] and @select2==1 and !@saves[@select][:session]
  1728.         if Keypress[KbRight,false] and @copy and !5.times{|id| if id>@copy and !@saves[id] then @anoth=id  ; break end} then Snd['Sys1'].play; @copy=@anoth ; @anoth=nil end
  1729.         if Keypress[KbLeft,false] and @copy and !5.times{|id| if id<@copy and !@saves[id] then @anoth=id  ; break end} then Snd['Sys1'].play ; @copy=@anoth ; @anoth=nil end
  1730.        
  1731.         if Keypress[:jump,false] and !@save
  1732.           if @boss
  1733.             if @boss==1 && @saves[@select][:clear] or @boss==2 && @saves[@select][:superclear]
  1734.               $save=@saves[@select]
  1735.               return Game.new(@boss)
  1736.             else
  1737.               return Snd['Sys4'].play
  1738.             end
  1739.           end
  1740.           Snd['Sys2'].play
  1741.           @save=true
  1742.           @select2=(@saves[@select][:session] ? 1 : 0)
  1743.         elsif Keypress[:jump,false] and !@action
  1744.           case @select2
  1745.             when 0
  1746.             if @saves[@select][:session] and !@saves[@select][:session][2]
  1747.               Snd['Sys2'].play
  1748.               @action=0
  1749.               @question="Suspended game will be erased. Continue?"
  1750.               return @choose=true
  1751.             else
  1752.               Snd['Sys5'].play
  1753.               Song.current_song.stop
  1754.               $save=@saves[@select]
  1755.               Game.new
  1756.             end
  1757.             when 1
  1758.             if !@saves[@select][:session][2]
  1759.               Snd['Sys2'].play
  1760.               @action=1
  1761.               @question="You can continue suspended game only once. Proceed?"
  1762.               return @choose=true
  1763.             else
  1764.               Snd['Sys5'].play
  1765.               Song.current_song.stop
  1766.               $save=@saves[@select]
  1767.               Game.new(true)
  1768.             end
  1769.             when 2
  1770.             Snd['Sys2'].play
  1771.             @action=2
  1772.             return @question="Deleted save will be gone forever. Are you sure?"
  1773.             when 3
  1774.             if @saves.compact.length<5 and !@copy
  1775.               Snd['Sys2'].play
  1776.               @copy=@saves.index(nil)
  1777.             elsif @copy
  1778.               Snd['Sys2'].play
  1779.               @saves[@copy]=@saves[@select].dup
  1780.               @saves[@copy][:id]=@copy
  1781.               @saves[@copy][:session]=nil
  1782.               Marshal.dump(@saves[@copy],f=File.new("data/save#{@copy}",'w'))
  1783.               f.close
  1784.               @copy=nil
  1785.             elsif !@info
  1786.               Snd['Sys4'].play
  1787.               @info=["No free slot available",60]
  1788.             end
  1789.           end
  1790.         end
  1791.         if @save and Keypress[:shoot,false]
  1792.           Snd['Sys3'].play
  1793.           if @copy
  1794.             @copy=nil
  1795.           else
  1796.             @save=@select2=nil
  1797.           end
  1798.         end
  1799.         if @action and Keypress[KbRight,false]
  1800.           Snd['Sys1'].play
  1801.           @choose=false
  1802.         elsif @action and Keypress[KbLeft,false]
  1803.           Snd['Sys1'].play
  1804.           @choose=true
  1805.         elsif @action and Keypress[:jump,false]
  1806.           return (Snd['Sys3'].play;@action=nil) if !@choose
  1807.           case @action
  1808.             when 0
  1809.             Snd['Sys5'].play
  1810.             Song.current_song.stop
  1811.             $save=@saves[@select]
  1812.             @saves[@select][:id]=@select
  1813.             Game.new
  1814.             when 1
  1815.             Snd['Sys5'].play
  1816.             Song.current_song.stop
  1817.             $save=@saves[@select]
  1818.             @saves[@select][:id]=@select
  1819.             Game.new(true)
  1820.             when 2
  1821.             Snd['Sys2'].play
  1822.             @saves[@select]=nil
  1823.             File.delete("data/save#{@select}")
  1824.             @save=@select2=nil
  1825.           end
  1826.           @action=nil
  1827.         elsif @action and Keypress[:shoot,false]
  1828.           @action=nil
  1829.         end
  1830.       else
  1831.         if Keypress[:jump,false] and !@new
  1832.           Snd['Sys2'].play
  1833.           @new=0
  1834.           @name=[]
  1835.         elsif Keypress[:jump,false] and @new
  1836.           Snd['Sys2'].play
  1837.           @name<<chars[@new] if @name.length<6
  1838.         elsif Keypress[:shoot,false] and @new
  1839.           Snd['Sys3'].play
  1840.           if @name.length>0
  1841.             @name.pop
  1842.           else
  1843.             @new=@name=nil
  1844.           end
  1845.         elsif Keypress[KbReturn,false] and @new
  1846.           Snd['Sys5'].play
  1847.           save={:name=>@name.join,:id=>@select,:events=>[],:area=>0,:areas=>[],:plans=>[],:brekables=>[],:warps=>[[14,29,0,5,0]],:hp=>200,:max_hp=>200,:mp=>100,:max_mp=>100,:mp_regen=>1,:base_mp_regen=>1,:stars=>25,:max_stars=>25,:stomp=>0,:defence=>0,:base_strength=>1,:base_constitution=>1,:base_intelligence=>1,:base_mind=>1,:base_luck=>1,:exp=>0,:next=>80,:all=>0,:level=>1,:coins=>0,:time=>0,:status=>'GOOD',:equip=>[0,nil,nil,0,0,0],:relics=>[],:items=>{:magic=>[],:weapon=>[],:suit=>[],:cap=>[],:pants=>[],:boots=>[],:accessory=>[],:usable=>[],:misc=>[]},:enemies=>{},:bonus=>[],:dimension=>false,:kills=>[],:allkills=>0,:magic=>[],:resistance=>[],:guides=>[],:cores=>[]}
  1848.           save[:map]=Marshal.load(f=File.open('data/map','r'))
  1849.           f.close
  1850.           Marshal.dump(save,f=File.new("data/save#{@select}",'w'))
  1851.           f.close
  1852.           $save=save
  1853.           Game.new
  1854.         end
  1855.         if @new
  1856.           (@new+=1;Snd['Sys1'].play) if Keypress[KbRight,false] and @new<chars.length-1
  1857.           (@new-=1;Snd['Sys1'].play) if Keypress[KbLeft,false] and @new>0
  1858.           (@new+=20;Snd['Sys1'].play) if Keypress[KbDown,false] and @new<chars.length-20
  1859.           (@new-=20;Snd['Sys1'].play) if Keypress[KbUp,false] and @new>19
  1860.         end
  1861.       end
  1862.      
  1863.       when :config
  1864.       if !@set
  1865.         (@select+=1;Snd['Sys1'].play) if Keypress[KbDown,false] and @select<11
  1866.         (@select-=1;Snd['Sys1'].play) if Keypress[KbUp,false] and @select>0
  1867.         if Keypress[:jump,false] and @select<9 and !@pressed
  1868.           Snd['Sys2'].play
  1869.           @set=[:up,:down,:left,:right,:jump,:shoot,:spin,:start,:select][@select]
  1870.         elsif Keypress[:jump,false] and @select==9
  1871.           Snd['Sys4'].play
  1872.           # Snd['Sys2'].play
  1873.           # $config[0]=!$config[0]
  1874.         elsif Keypress[:jump,false] and @select==10
  1875.           Snd['Sys2'].play
  1876.           f=File.open('data/config','w')
  1877.           Marshal.dump($config,f)
  1878.           f.close
  1879.           @state=:main
  1880.           @select=1
  1881.         elsif Keypress[:jump,false] and !@pressed
  1882.           Snd['Sys3'].play
  1883.           f=File.open('data/config','r')
  1884.           $config=Marshal.load(f)
  1885.           f.close
  1886.           @state=:main
  1887.           @select=1
  1888.         end
  1889.         @pressed=nil
  1890.       end
  1891.      
  1892.       when :sound
  1893.       (@select+=1;Snd['Sys1'].play) if Keypress[KbDown,false] and @select<@music.length-1
  1894.       (@select-=1;Snd['Sys1'].play) if Keypress[KbUp,false] and @select>0
  1895.       if Keypress[:jump,false] and !@song || @song!=@select
  1896.         @song=@select
  1897.         Msc[@music[@select],:auto].play(!$premusic)
  1898.       elsif Keypress[:jump,false] and @song==@select
  1899.         Song.current_song.play(!$premusic)
  1900.       end
  1901.       Song.current_song.pause if Keypress[:spin,false] and Song.current_song
  1902.       $premusic=@song=Song.current_song.stop if Keypress[:shoot,false] and Song.current_song
  1903.       if Keypress[KbReturn,false]
  1904.         Snd['Sys3'].play
  1905.         Msc['Zelda2'].play
  1906.         @song=nil
  1907.         @select=@max=3
  1908.         @state=:main
  1909.       end
  1910.      
  1911.       when :boss
  1912.       if Keypress[:shoot,false]
  1913.         Snd['Sys3'].play
  1914.         return (@state=:main;@select=4;Msc['Zelda2'].play) if !@highscores and !@prizes
  1915.         @prizes=@highscores=nil
  1916.       end
  1917.       @max=3
  1918.       if !@highscores and !@prizes
  1919.         (@select+=1;Snd['Sys1'].play) if Keypress[KbDown,false] and @select<@max
  1920.         (@select-=1;Snd['Sys1'].play) if Keypress[KbUp,false] and @select>0
  1921.       end
  1922.       if Keypress[:jump,false] and !@highscores and !@prizes
  1923.         case @select
  1924.           when 0
  1925.           Snd['Sys2'].play
  1926.           @boss=1
  1927.           @select=0
  1928.           @state=:saves
  1929.          
  1930.           when 1
  1931.           return Snd['Sys4'].play if !@bossrush2
  1932.           Snd['Sys2'].play
  1933.           @boss=2
  1934.           @select=0
  1935.           @state=:saves
  1936.          
  1937.           when 2
  1938.           Snd['Sys2'].play
  1939.           @highscores=true
  1940.          
  1941.           when 3
  1942.           Snd['Sys2'].play
  1943.           @prizes=true
  1944.         end
  1945.       end
  1946.     end
  1947.   end
  1948.  
  1949.   def draw
  1950.     case @state
  1951.       when :intro
  1952.       Img['System/Title Screen'].draw(0,0,0)
  1953.       Img['System/Title'].draw(116,64,0)
  1954.       Fnt[['System/Font',20,20]].draw("Press Enter",320,440,0,:align=>:center) if $count%60<30
  1955.      
  1956.       when :main
  1957.       Img['System/Title Screen'].draw(0,0,0)
  1958.       Img['System/Title'].draw(116,64,0)
  1959.       texts=["Start game","Config","Credits","Quit"]
  1960.       texts << "Sound Test" if @soundtest
  1961.       texts << "Boss Rush" if @bossrush
  1962.       @max=texts.length-1
  1963.       texts.length.times{|text| Fnt[['System/Font',20,20]].draw(texts[text],320,240+text*30,0,:align=>:center) if @select != text or $count%30<15}
  1964.      
  1965.       when :config
  1966.       Img['System/Config Screen'].draw(0,0,0)
  1967.       keys=[:up,:down,:left,:right,:jump,:shoot,:spin,:start,:select]
  1968.       names=["Up","Down","Left",:"Right","Jump","Shoot","Spin","Menu","Map"]
  1969.       texts=["Up - #{key($config[1][:up])}","Down - #{key($config[1][:down])}","Left - #{key($config[1][:left])}","Right - #{key($config[1][:right])}",
  1970.       "Jump - #{key($config[1][:jump])}","Shoot - #{key($config[1][:shoot])}","Spin - #{key($config[1][:spin])}","Menu - #{key($config[1][:start])}","Map - #{key($config[1][:select])}",
  1971.       $config[0] ? "Fullscreen Mode" : "Windowed Mode","Apply changes","Cancel"]
  1972.       texts.length.times{|text| Fnt[['System/Font',20,20]].draw((text<9 and @set==keys[text]) ? "Press key for #{names[text]}" : texts[text],320,60+text*30,0,:align=>:center,:color=>(@select==text ? 0xffffffff : 0x80ffffff))}
  1973.       Fnt[['System/Font',20,20]].draw("Restart game to apply #{$config[0] ? "Fullscreen Mode" : "Windowed Mode"}",10,460,0,:xspacing=>15) if $config[0] != $screen.fullscreen?
  1974.       Fnt[['System/Font',20,20]].draw("Fullscreen currently not supported :(",10,460,0,:xspacing=>15) if @select==9
  1975.      
  1976.       when :credits
  1977.       Img['System/Sound Screen'].draw(0,0,0)
  1978.       credits=["#Game programming, design","#graphic and sound editing","KoBeWi","#Game engine","Ruby","Gosu",
  1979.       "#Graphics","MFGG","$Featured (cuz request)","$Teek","$Theo402","The ShyGuy Kingdom",
  1980.       "Spriters Resource","Super Mario Bros. X","LF2 mod by neo_w43","#Sounds","MFGG","Super Mario Bros. X",
  1981.       "freesound.org","#Music","KHInsider Soundtracks","(check Sound Test for list of all tracks)"]
  1982.       y=28
  1983.       credits.each do |crd|
  1984.         y+=(crd.include?("#") ? 25 : 15)
  1985.         Fnt[['System/Font',20,20]].draw(crd.delete("$#"),crd.include?("$") ? 30 : 10,y,0,:color=>(crd.include?("#") ? 0xffffff00 : 0xffffffff),:scalex=>0.75,:scaley=>0.75)
  1986.       end
  1987.      
  1988.       when :saves
  1989.       Img['System/Save Screen'].draw(0,0,0)
  1990.       5.times{|x| Img['System/Save'].draw(x*128,0,0)
  1991.       Fnt[['System/Font',20,20]].draw("State#{x+1}",4+x*128,4,0)
  1992.       Fnt[['System/Font',20,20]].draw((@saves[x][:name] if @saves[x]),4+x*128,32,0)}
  1993.       Img['System/Savesel'].draw(48+@select*128,72+offset_y($count*8,4),0)
  1994.       Img['System/Savesel'].draw(48+@copy*128,72+offset_y($count*8,4),0,1,1,0xff00ffff) if @copy
  1995.       if @saves[@select]
  1996.         save=(@select2==1 ? @sessions[@select] : @saves[@select])
  1997.         Fnt[['System/Font',20,20]].draw(@info[0],32,340,0,:color=>0xffff0000) if @info
  1998.         @info=nil if @info and (@info[1]-=1)==0
  1999.         time=save[:time]
  2000.         txt=[]
  2001.         txt << "#{'0' if (t=(time/216000%60).to_i)<10}#{t}"
  2002.         txt << "#{'0' if (t=(time/3600%60).to_i)<10}#{t}"
  2003.         txt << "#{'0' if (t=(time/60%60).to_i)<10}#{t}"
  2004.         Fnt[['System/Font',20,20]].draw("Level #{save[:level]}",32,128,0)
  2005.         Fnt[['System/Font',20,20]].draw(areas[save[:area]],32,158,0)
  2006.         Fnt[['System/Font',20,20]].draw("Time #{txt.join(':')}",32,188,0)
  2007.         Fnt[['System/Font',20,20]].draw("Cleared",32,256,0,:color=>(save[:superclear] ? 0xffff0000 : 0xffffff00)) if save[:clear]
  2008.         if @save
  2009.           Img['System/Savesel'].draw(48+@select2*128,408+offset_y($count*8,4),0,1,-1)
  2010.           Img['System/Action'].draw(0,416,0)
  2011.           Fnt[['System/Font',20,20]].draw("Start^game",8,424,0)
  2012.           Img['System/Action'].draw(128,416,0) if @saves[@select][:session]
  2013.           Fnt[['System/Font',20,20]].draw(@saves[@select][:session][2] ? "Load^quicksave" : "Continue^session",136,424,0,:xspacing=>13) if @saves[@select][:session]
  2014.           Img['System/Action'].draw(256,416,0)
  2015.           Fnt[['System/Font',20,20]].draw("Delete^save",264,424,0)
  2016.           Img['System/Action'].draw(384,416,0)
  2017.           Fnt[['System/Font',20,20]].draw("Copy^data",392,424,0)
  2018.           if @action
  2019.             Fnt[['System/Font',20,20]].draw(@question,320,240,0,:align=>:center,:xspacing=>12)
  2020.             Fnt[['System/Font',20,20]].draw("Yes",160,280,0,:align=>:center)
  2021.             Fnt[['System/Font',20,20]].draw("No",480,280,0,:align=>:center)
  2022.             Img['System/Savesel'].draw(@choose ? 144 : 464,308+offset_y($count*8,4),0)
  2023.           end
  2024.         end
  2025.       else
  2026.         if !@new
  2027.           Fnt[['System/Font',20,20]].draw("This position is unused",32,128,0)
  2028.         else
  2029.           Fnt[['System/Font',20,20]].draw("Type your name",320,128,0,:align=>:center)
  2030.           Fnt[['System/Font',20,20]].draw(@name.join,120,160,0,:scalex=>2,:scaley=>2)
  2031.           Fnt[['System/Font',20,20]].draw('-'*6,120,190,0,:scalex=>2,:scaley=>2)
  2032.           chars.length.times{|char| Fnt[['System/Font',20,20]].draw(chars[char],20+(char%20)*30,240+(char/20)*30,0)
  2033.           Img['System/Charsel'].draw(14+(char%20)*30,234+(char/20)*30,0) if @new==char}
  2034.           Fnt[['System/Font',20,20]].draw("Enter - Accept",20,390,0,:scalex=>0.75,:scaley=>0.75)
  2035.           Fnt[['System/Font',20,20]].draw("Jump - Select",20,420,0,:scalex=>0.75,:scaley=>0.75)
  2036.           Fnt[['System/Font',20,20]].draw("Shoot - Delete/Cancel",20,450,0,:scalex=>0.75,:scaley=>0.75)
  2037.         end
  2038.       end
  2039.      
  2040.       when :sound
  2041.       Img['System/Sound Screen'].draw(0,0,0)
  2042.       game=@games.keys.find{|key| @games[key].include?(@music[@select])}
  2043.       Fnt[['System/Font',20,20]].draw('Sound Test',320,20,0,:align=>:center,:scalex=>2,:scaley=>2)
  2044.       Fnt[['System/Font',20,20]].draw('Game',320,140,0,:align=>:center)
  2045.       Fnt[['System/Font',20,20]].draw(game,320,170,0,:align=>:center,:xspacing=>15)
  2046.       Fnt[['System/Font',20,20]].draw('Title',320,210,0,:align=>:center)
  2047.       Fnt[['System/Font',20,20]].draw(@music[@select],320,240,0,:align=>:center)
  2048.       Fnt[['System/Font',20,20]].draw("#{@select+1} / #{@music.length}",320,310,0,:align=>:center)
  2049.       Fnt[['System/Font',20,20]].draw('Up/Down - select music',20,360,0)
  2050.       Fnt[['System/Font',20,20]].draw('Jump - play/resume',20,380,0)
  2051.       Fnt[['System/Font',20,20]].draw('Shoot - stop',20,400,0)
  2052.       Fnt[['System/Font',20,20]].draw('Spin - pause',20,420,0)
  2053.       Fnt[['System/Font',20,20]].draw('Enter - return to main menu',20,440,0)
  2054.      
  2055.       when :boss
  2056.       Img['System/Boss Screen'].draw(0,0,0)
  2057.       Fnt[['System/Font',20,20]].draw('Boss Rush',320,20,0,:align=>:center,:scalex=>2,:scaley=>2)
  2058.       if @highscores
  2059.         Fnt[['System/Font',20,20]].draw("Highscores",320,100,0,:align=>:center)
  2060.         Fnt[['System/Font',20,20]].draw("Normal Course",320,130,0,:align=>:center,:color=>0xffffff00)
  2061.         Fnt[['System/Font',20,20]].draw(@bossrush2 ? 'Chaos Course' : "???",320,270,0,:align=>:center,:color=>0xffffff00)
  2062.         $config[2].sort!{|x,y| x[1]<=>y[1]}
  2063.         $config[3].sort!{|x,y| x[1]<=>y[1]}
  2064.         5.times do |y|
  2065.           Fnt[['System/Font',20,20]].draw($config[2][y] ? "#{time($config[2][y][1])} #{$config[2][y][0]}" : "99:99:99 ???",320,160+y*20,0,:align=>:center)
  2066.           Fnt[['System/Font',20,20]].draw($config[3][y] ? "#{time($config[3][y][1])} #{$config[3][y][0]}" : "99:99:99 ???",320,300+y*20,0,:align=>:center)
  2067.         end
  2068.       elsif @prizes
  2069.         Fnt[['System/Font',20,20]].draw("Unlockable Items",320,100,0,:align=>:center)
  2070.         Fnt[['System/Font',20,20]].draw("Normal Course",320,270,0,:align=>:center,:color=>0xffffff00)
  2071.         Fnt[['System/Font',20,20]].draw("8 minutes - #{$config[4][5] ? 'Starman' : '???'}",320,300,0,:align=>:center)
  2072.         Fnt[['System/Font',20,20]].draw("12 minutes - #{$config[4][4] ? 'Noobshot' : '???'}",320,320,0,:align=>:center)
  2073.         Fnt[['System/Font',20,20]].draw("16 minutes - #{$config[4][3] ? 'Overlord Boots' : '???'}",320,340,0,:align=>:center)
  2074.         Fnt[['System/Font',20,20]].draw("Any - Cool OMeGa Mushroom",320,360,0,:align=>:center)
  2075.         Fnt[['System/Font',20,20]].draw(@bossrush2 ? 'Chaos Course' : "???",320,390,0,:align=>:center,:color=>0xffffff00)
  2076.         Fnt[['System/Font',20,20]].draw("6 minutes - #{$config[4][6] ? 'Shadow Suit' : '???'}",320,420,0,:align=>:center)
  2077.         Fnt[['System/Font',20,20]].draw("Any - 3-UP Moon",320,440,0,:align=>:center)
  2078.       else
  2079.         texts=['Normal Course',@bossrush2 ? 'Chaos Course' : "???",'Highscores','Unlockables']
  2080.         texts.length.times{|text| Fnt[['System/Font',20,20]].draw(texts[text],320,240+text*30,0,:align=>:center) if @select != text or $count%30<15}
  2081.       end
  2082.     end
  2083.   end
  2084.  
  2085.   def time(tm)
  2086.     txt=[]
  2087.     txt << "#{'0' if (t=(tm/3600%60).to_i)<10}#{t}"
  2088.     txt << "#{'0' if (t=(tm/60%60).to_i)<10}#{t}"
  2089.     txt << "#{'0' if (tm/0.6)%100<10}#{((tm/0.6)%100).to_i}"
  2090.     txt.join(":")
  2091.   end
  2092.  
  2093.   def chars
  2094.     ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0','.','/',':','!','@','%','?','_','-',',','<','>','+',"'"]
  2095.   end
  2096.  
  2097.     def key(id)
  2098.     unless defined? @button_names
  2099.       button_constants = Gosu.constants(false)
  2100.       .grep(/^(?:Gp|Kb|Ms)/)
  2101.       .inject({}) { |h, k| h.merge! Gosu.const_get(k) => k }
  2102.      
  2103.       @button_names = Hash.new do |names, id|
  2104.       ch = $screen.button_id_to_char id
  2105.       names[id] = (ch and ch.ord > 0x20) ? ch.upcase : button_constants[id]
  2106.       end
  2107.     end
  2108.     @button_names[id].to_s.reverse.chomp('bK').reverse
  2109.   end
  2110.  
  2111.   def button_down(id)
  2112.     if @set
  2113.       Snd['Sys2'].play
  2114.       $config[1][@set]=id
  2115.       @set=nil
  2116.       @pressed=true
  2117.     end
  2118.   end
  2119. end
  2120.  
  2121. class GameOver
  2122.   def initialize
  2123.     Msc['Game Over'].play
  2124.   end
  2125.  
  2126.   def update;end
  2127.  
  2128.   def draw
  2129.     Img['System/Game Over'].draw(0,0,0)
  2130.   end
  2131.  
  2132.   def button_down(id)
  2133.     $game=MainMenu.new
  2134.   end
  2135. end
  2136.  
  2137. class End
  2138.   def initialize(good)
  2139.     @good=good
  2140.     @txt=0
  2141.     @percent=(($save[:map].count{|room| room.discovered}/$save[:map].length.to_f)*100).round(2)
  2142.     @old=$config[4].dup
  2143.     $config[4][0]=true
  2144.     $config[4][1]=true
  2145.     $config[4][2]=true if @good
  2146.     f=File.open('data/config','w')
  2147.     Marshal.dump($config,f)
  2148.     f.close
  2149.    
  2150.     $save[:session]=nil
  2151.     $save[:clear]=true
  2152.     $save[:superclear]=true if @good
  2153.     $save[:hp]=$save[:max_hp]
  2154.     Marshal.dump($save,f=File.open("data/save#{$save[:id]}",'w'))
  2155.     f.close
  2156.   end
  2157.  
  2158.   def update
  2159.     @txt+=1 if @txt<txt.length
  2160.     if @txt==txt.length and Keypress[:jump]
  2161.       @stats=true
  2162.     end
  2163.     if @stats and Keypress[KbReturn]
  2164.       $game=MainMenu.new
  2165.     end
  2166.   end
  2167.  
  2168.   def draw
  2169.     Img["System/" + (@good ? "Sound Screen" : "Boss Screen")].draw(0,0,0)
  2170.     if @stats
  2171.       Fnt[['System/Font',20,20]].draw("Final Stats",320,120,1,:align=>:center,:color=>0xffffff00)
  2172.       Fnt[['System/Font',20,20]].draw("Time #{time($save[:time])}",320,160,1,:align=>:center)
  2173.       Fnt[['System/Font',20,20]].draw("Map #{@percent}%",320,200,1,:align=>:center)
  2174.       Fnt[['System/Font',20,20]].draw("Sound test unlocked!",320,240,1,:align=>:center) if @old[0] != $config[4][0]
  2175.       Fnt[['System/Font',20,20]].draw("Boss rush unlocked!",320,280,1,:align=>:center) if @old[1] != $config[4][1]
  2176.       Fnt[['System/Font',20,20]].draw("Chaos boss course unlocked!",320,320,1,:align=>:center) if @old[2] != $config[4][2]
  2177.       Fnt[['System/Font',20,20]].draw("Press Enter",320,440,0,:align=>:center) if $count%60<30
  2178.     else
  2179.       Fnt[['System/Font',20,20]].draw(txt[0...@txt],60,120,1)
  2180.     end
  2181.   end
  2182.  
  2183.   def txt
  2184.     if @good
  2185.       "Mario has succeeded in^destroying Castlevania,^banishing it from^Mushroom Kingdom forever.^Bowser has never more^been so powerful, and^stopping his actions^became boring. So from^time to time, Mario^was giving rescuing^mission to Luigi, so two^brothers shared the^princess. And everyone^lived happily ever after.^^Except Bowser."
  2186.     else
  2187.       "Castlevania remained in^Mushroom Kingdom and^Mario had to live by^the castle. Saving Peach^took him longer each^time and he couldn't^even sleep, because of^noise coming from castle.^Soon, he lost his^sanity and was closed^in Mushroom Asylum.^No one else was capable^of rescuing princess,^so she stayed with Bowser.^^Forever."
  2188.     end
  2189.   end
  2190.  
  2191.   def time(tm)
  2192.     txt=[]
  2193.     txt << "#{'0' if (t=(tm/216000%60).to_i)<10}#{t}"
  2194.     txt << "#{'0' if (t=(tm/3600%60).to_i)<10}#{t}"
  2195.     txt << "#{'0' if (t=(tm/60%60).to_i)<10}#{t}"
  2196.     txt << "#{'0' if (tm/0.6)%100<10}#{((tm/0.6)%100).to_i}"
  2197.     txt.join(":")
  2198.   end
  2199. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement