Guest User

Re-corrected objects.rb (WTFPL)

a guest
Sep 12th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 35.03 KB | None | 0 0
  1. class Bonus < Entity
  2.   def initialize(x,y,type,open=nil)
  3.     return if $save[:bonus].include?([$game.map.data[:id],x,y])
  4.     @x,@y,@type,@open=x,y,type,open
  5.     @unstoppable=true
  6.     init
  7.   end
  8.  
  9.   def update
  10.     gravity(32) if !$game.stopped
  11.     if $game.player.x+12>@x and $game.player.x-12<@x+32 and $game.player.y-40<@y+32 and $game.player.y+20>@y
  12.       Snd['Power Up'].play
  13.       $game.powerup=[@type,400]
  14.       case @type
  15.         when 0
  16.         $save[:max_hp]+=20
  17.         $save[:hp]=$save[:max_hp]
  18.         when 1
  19.         $save[:max_mp]+=15
  20.         $save[:mp]=$save[:max_mp]
  21.         $save[:base_mp_regen]+=1
  22.         $game.refresh_stats
  23.         when 2
  24.         $save[:max_stars]+=5
  25.         $save[:stars]+=5
  26.       end
  27.       remove
  28.       $save[:bonus] << [$game.map.data[:id],@x,@y] if !@open
  29.       $game.entities[3].each{|ent| ent.open=true if ent.class==BossDoor} if @open
  30.     end
  31.   end
  32.  
  33.   def draw
  34.     Img['Effects/Octagram'].draw_rot(@x+16,@y+16,2,$game.time*4,0.5,0.5,1,1,[0xff00ff00,0xff0000ff,[0xff00ffff,0xffffff00,0xff0000ff,0xffffff00][-$game.time/8%4]][@type])
  35.     (@type<2 ? Img["Objects/#{['HP Max Up','MP Max Up'][@type]}"] :Tls['Objects/Stars Max Up',32,32][[0,1,2,1][$game.time/8%4]]).draw(@x,@y,2)
  36.   end
  37. end
  38.  
  39. class Item < Entity
  40.   attr_writer :vy
  41.   attr_reader :type,:id
  42.   def initialize(x,y,type,id,out=0)
  43.     @x,@y,@type,@id=x,y,type,id
  44.     if type==:magic or type==:weapon or type==:suit
  45.       return if $save[:items][type].include?(id) or $save[:equip][[:suit,:magic,:weapon].index(type)]==id
  46.       Snd['Spelldrop'].play
  47.       @fx=0
  48.       $game.flash(0xffffffff,16)
  49.     end
  50.     @unstoppable=true
  51.     @out=out
  52.     init
  53.   end
  54.  
  55.   def update
  56.     gravity(32) if @out==0 and !$game.stopped
  57.     @y+=(@out<=>0)
  58.     @out-=(@out<=>0)
  59.    
  60.     if @out==0 and $game.player.x+12>@x and $game.player.x-12<@x+32 and $game.player.y-40<@y+32 and $game.player.y+20>@y
  61.       Snd['Item'].play
  62.       $game.item=$items[@type][@id][:name]
  63.       $save[:items][@type] << @id
  64.       remove
  65.     end
  66.   end
  67.  
  68.   def draw
  69.     Img["Icons/#{@type}/#{@id}"].draw(@x,@y,1.5)
  70.     if @fx
  71.       16.times{|dir| Img['Effects/Spelldrop'].draw_rot(@x+16-offset_x(dir*22.5,-@fx*4%64),@y+16-offset_y(dir*22.5,-@fx*4%64),3,rand(360),0.5,0.5,1,1,0xffffffff,:additive)}
  72.       @fx+=1
  73.     end
  74.   end
  75. end
  76.  
  77. class Relic < Entity
  78.   def initialize(x,y,id)
  79.     @x,@y,@id=x,y,id
  80.     @unstoppable=true
  81.     @sprout=-32
  82.     init
  83.   end
  84.  
  85.   def update
  86.     gravity(32)
  87.     if !@relic and $game.player.x+12>@x and $game.player.x-12<@x+32 and $game.player.y-40<@y+32 and $game.player.y+20>@y
  88.       Snd['Save'].play
  89.       $save[:relics][@id]=true
  90.       @relic=0
  91.     end
  92.     @y-=1 if @sprout and (@sprout+=1)<0
  93.   end
  94.  
  95.   def draw
  96.     Img["Icons/Relics/#{@id}"].draw(@x,@y,1.5) if !@relic
  97.    
  98.     if @relic
  99.       @relic+=1
  100.       Fnt[['System/Font',20,20]].draw($relics[@id][0],44+$game.scx,410+$game.scy,4,:xscale=>0.75,:xspacing=>14,:color=>Color.new(@relic>180 ? 255-(@relic-180)*4 : 255,255,255,255))
  101.       Fnt[['System/Font',20,20]].draw($relics[@id][1],44+$game.scx,440+$game.scy,4,:xscale=>0.75,:xspacing=>14,:color=>Color.new(@relic>180 ? 255-(@relic-180)*4 : 255,255,255,255))
  102.       if @relic==360
  103.         @remove
  104.       end
  105.     end
  106.   end
  107. end
  108.  
  109. class Save < Entity
  110.   def initialize#(x,y)
  111.     # @x,@y=x,y
  112.     @x,@y=256,208
  113.     @pow=0
  114.     splice
  115.     init(:powable)
  116.   end
  117.  
  118.   def update
  119.     @pow+=1 if @pow<0
  120.   end
  121.  
  122.   def draw
  123.     Img['Objects/Save'].draw(@x,@y+@pow,2)
  124.   end
  125.  
  126.   def pow(x,y,width,pound)
  127.     if x<@x+128 and x+width>@x and y<@y+70 and y>@y
  128.       $save[:hp]=$save[:max_hp]
  129.       $save[:mp]=$save[:max_mp]
  130.       $save[:stars]=$save[:max_stars] if $save[:relics][8]
  131.       $save[:status]='GOOD'
  132.       wayp=$game.entities[0].find{|ent| ent.class==Waypoint}
  133.       $save[:saved]=[wayp,$game.map.data]
  134.       Snd['Save'].play
  135.       @pow=-8
  136.       File.delete("data/save#{$save[:id]}s") if $save[:session]
  137.       $save[:session]=nil
  138.       Marshal.dump($save,f=File.open("data/save#{$save[:id]}",'w'))
  139.       f.close
  140.       $game.save=0
  141.     end
  142.   end
  143.  
  144.   def splice
  145.     $game.map.modify_mask(@x,@y,:splice,'objects/save-mask')
  146.   end
  147. end
  148.  
  149. class BonusBlock < Entity
  150.   def initialize(x,y,type,id,sealed=nil)
  151.     @x,@y,@type,@id,@sealed=x,y,type,id,sealed
  152.     @pow=0
  153.     $game.map.modify_mask(@x,@y,:rect,[31,31,0xff000000])
  154.     @sprouted=true if $save[:bonus].include?([$game.map.data[:id],@x,@y])
  155.     @sealed=nil if @sealed and !@sprouted and $save[:bonus].include?([$game.map.data[:id],@x,@y,:unsealed])
  156.     @unstoppable=true
  157.     init(:powable)
  158.   end
  159.  
  160.   def update
  161.     @pow-=(@pow<=>0)*0.5 if @pow !=0
  162.     if @item and $game.missing(@item)
  163.       @item=nil
  164.       $save[:bonus] << [$game.map.data[:id],@x,@y]
  165.       $save[:bonus].delete [$game.map.data[:id],@x,@y,:unsealed]
  166.     end
  167.    
  168.     if !@sprouted and @sealed and !@unseal and $save[:items][:misc].include?(5) and $game.player.x.between?(@x-8,@x+40) and $game.player.y.between?(@y-64,@y)
  169.       @unseal=0
  170.     elsif @unseal and (@unseal<=60)
  171.       @unseal+=1
  172.       @unseal=nil if not $game.player.x.between?(@x-8,@x+40) && $game.player.y.between?(@y-64,@y)
  173.     elsif @unseal
  174.       Snd['Star'].play
  175.       $save[:items][:misc].delete_at($save[:items][:misc].index(5))
  176.       $save[:bonus] << [$game.map.data[:id],@x,@y,:unsealed]
  177.       @sealed=@unseal=nil
  178.     end
  179.   end
  180.  
  181.   def draw
  182.     Tls['Objects/BonusBlock',32,32][@sprouted ? 4 : $count/8%4+(@sealed ? 5 : 0)].draw(@x,@y+@pow,2)
  183.   end
  184.  
  185.   def pow(x,y,width,pound)
  186.     if !@sprouted and x<@x+32 and x+width>@x and y<@y+70 and y>@y
  187.       @pow=((pound && pound!=:spin) ? 8 : -8)
  188.       return Snd['Sys4'].play if @sealed
  189.       Snd['Sprout'].play
  190.       @sprouted=true
  191.       @item=(@type==:coin ? Coin.new(@x+16-[10,14,14,16,20,14,16,20,48][@id],@y-[32,32,32,50,42,32,50,42,96][@id],@id) : Item.new(@x,@y,@type,@id,(pound && pound!=:spin) ? 32 : -32))
  192.     end
  193.   end
  194. end
  195.  
  196. class Warp < Entity
  197.   def initialize
  198.     @x,@y=288,240
  199.     @select=$game.map.data[:origin]
  200.     @map=$screen.record(640,480){$save[:map].each{|room| room.draw(1)}}
  201.     init
  202.   end
  203.  
  204.   def update
  205.     if !@warping and !@distortfx and !@exit and !@warpfx and !@leave and Keypress[:down,false] and !$save[:dimension] and $game.player.x.between?(@x,@x+64) and $game.player.y>@y-32
  206.       Snd['Sys5'].play
  207.       @warping=true
  208.       $game.player.x=@x+32
  209.       $game.player.vx=0
  210.       $game.player.ignore=true
  211.     elsif @warping
  212.       sel=[]
  213.       $save[:warps].delete_if{|wrp| wrp[0]==19}
  214.       if Keypress[:right,false]
  215.         $save[:warps].each{|warp| sel << warp[0] if warp[0]>@select[0]}
  216.         if !sel.empty?
  217.           Snd['Sys1'].play
  218.           @select=$save[:warps].find{|wrps| wrps[0]==sel.min} if !sel.empty?
  219.         else
  220.           Snd['Sys4'].play
  221.         end
  222.       end
  223.       if Keypress[:left,false]
  224.         $save[:warps].each{|warp| sel << warp[0] if warp[0]<@select[0]}
  225.         if !sel.empty?
  226.           Snd['Sys1'].play
  227.           @select=$save[:warps].find{|wrps| wrps[0]==sel.max} if !sel.empty?
  228.         else
  229.           Snd['Sys4'].play
  230.         end
  231.       end
  232.       if Keypress[:down,false]
  233.         $save[:warps].each{|warp| sel << warp[1] if warp[1]>@select[1]}
  234.         if !sel.empty?
  235.           Snd['Sys1'].play
  236.           @select=$save[:warps].find{|wrps| wrps[1]==sel.min}
  237.         else
  238.           Snd['Sys4'].play
  239.         end
  240.       end
  241.       if Keypress[:up,false]
  242.         $save[:warps].each{|warp| sel << warp[1] if warp[1]<@select[1]}
  243.         if !sel.empty?
  244.           Snd['Sys1'].play
  245.           @select=$save[:warps].find{|wrps| wrps[1]==sel.max} if !sel.empty?
  246.         else
  247.           Snd['Sys4'].play
  248.         end
  249.       end
  250.       if Keypress[:jump,false] and !@warpfx and @select[(0..1)] != $game.map.data[:origin]
  251.         Snd['Sys2'].play
  252.         @warpfx=0
  253.         @warping=nil
  254.         Snd['Warp Charge'].play
  255.       elsif Keypress[:jump,false] and !@warpfx
  256.         Snd['Sys4'].play
  257.       end
  258.      
  259.       $game.player.ignore=@warping=nil if Keypress[:shoot,false]
  260.     end
  261.      
  262.     if !@warping and !@exit and !@warpfx and !@distortfx and !@leave and Keypress[:up,false] and $save[:relics][9] and $game.player.x.between?(@x,@x+64) and $game.player.y>@y-32 and !@distortfx
  263.       @distortfx=0
  264.       $game.player.ignore=$distorting=true
  265.       Snd['Distort'].play
  266.     end
  267.   end
  268.  
  269.   def draw
  270.     if @warping
  271.       Img['System/Menu1'].draw(0,0,4,1,1,0xc0000000)
  272.       @map.draw(0,0,4)
  273.       area=$save[:warps].find{|warp| warp[0]==@select[0] and warp[1]==@select[1]}
  274.       Fnt[['System/Font',20,20]].draw(areas[area[4]],320,20,4,:align=>:center) if area
  275.       Img['System/Select'].draw_rot(@select[0]*10+5,@select[1]*10+5,4,$count*4)
  276.     end
  277.    
  278.     if @warpfx
  279.       @warpfx+=1
  280.       if @warpfx<120
  281.         (@warpfx).times{Img['Effects/Warp FX'].draw_rot(@x+rand(64),@y+16,3,315+rand(90),0.5,1,1,32+rand(8),Color.new(@warpfx*2,255,255,255))}
  282.         Img['Effects/Warp FX2'].draw_rot(@x+32,@y+16,3,$count*8,0.5,0.5,1,1,0x80ffffff) if @warpfx>100
  283.       elsif @warpfx==120
  284.         Snd['Teleport'].play
  285.         $game.player.warp(:down)
  286.         $game.player.y+=12
  287.       elsif @warpfx<152
  288.         Img['Effects/Warp FX2'].draw_rot(@x+32,@y+16,3,$count*8,0.5,0.5,1,1,0x80ffffff)
  289.       elsif @warpfx==152
  290.         $game.reset('t')
  291.         sel=$save[:warps].find{|warp| warp[0]==@select[0] and warp[1]==@select[1]}
  292.         Warp.new.exit(sel[0],sel[1])
  293.         Waypoint.new(sel[2],0,false,sel[3])
  294.         2.times{|x| 4.times{|y| $game[Tile.new((sel[2]==0 ? 576 : 0)+x*32,192+y*32,'Castle',(x==0 ? 0 : 2)+[0,7,7,14][y])]}}
  295.         $premusic=nil
  296.         Song.current_song.stop if Song.current_song
  297.         $save[:warps][0][2]=0
  298.         $save[:area]=@select[4]
  299.         $game.flash(0xffffffff,8)
  300.       end
  301.     end
  302.      
  303.     if @distortfx
  304.       @distortfx+=1
  305.       if @distortfx<240
  306.         Img['Effects/Distorsion'].draw_rot(@x+32,@y+16,1.4,0,0.5,0.5,3-(@distortfx-1+rand(3))*0.05,3-(@distortfx-1+rand(3))*0.05)
  307.         $game.flash(0xff000000,16) if rand(@distortfx)==0
  308.       else
  309.         Song.current_song.stop if Song.current_song
  310.         $premusic=nil
  311.         orig=$game.map.data[:origin]
  312.         area=($save[:dimension] ? $save[:dimension] : $save[:area])
  313.         $save[:dimension]=($save[:dimension] ? false : $save[:area])
  314.        
  315.         way=$game.entities[0].find{|ent| ent.class==Waypoint}
  316.         way.x=(way.x==0 ? 608 : 0) if area==10
  317.        
  318.         $game.reset('t')
  319.         translate={5=>0,15=>2,48=>3,75=>4,95=>5,170=>8,86=>10,184=>11,188=>16,209=>17,133=>45,239=>69,259=>80}
  320.         Waypoint.new(way.x,0,false,$save[:dimension] ? translate[way.target] : translate.key(way.target.to_i))
  321.         2.times{|x| 4.times{|y| $game[Tile.new((way.x==0 ? 576 : 0)+x*32,192+y*32,'Castle',(x==0 ? 0 : 2)+[0,7,7,14][y])]}}
  322.         $game.map.data[:origin]=orig
  323.         Warp.new.distort
  324.         if $save[:dimension]
  325.           $save[:area]=3
  326.         else
  327.           $save[:area]=$save[:warps].find{|warp| warp[0]==orig[0] and warp[1]==orig[1]}[4]
  328.         end
  329.       end
  330.     end
  331.    
  332.     if @exit
  333.       @exit+=1
  334.       if @exit<60
  335.         (60-@exit).times{Img['Effects/Warp FX'].draw_rot(@x+rand(64),@y+16,3,315+rand(90),0.5,1,1,32+rand(8),Color.new(255-@exit*4,255,255,255))}
  336.         Img['Effects/Warp FX2'].draw_rot(@x+32,@y+16,3,$count*8,0.5,0.5,1,1,Color.new([128-@exit*4,0].max,255,255,255))
  337.       else
  338.         $game.player.y-=20
  339.         Snd['Jump3'].play
  340.         $game.player.vy=-20
  341.         @exit=$game.player.ignore=nil
  342.       end
  343.     end
  344.    
  345.     if @leave
  346.       @leave+=1
  347.       if @leave<60
  348.         Img['Effects/Distorsion'].draw_rot(@x+32,@y+16,1.4,0,0.5,0.5,6-(@leave-2+rand(4))*0.1,6-(@leave-2+rand(4))*0.1)
  349.       else
  350.         @leave=$game.player.ignore=$distorting=nil
  351.       end
  352.     end
  353.   end
  354.  
  355.   def exit(x,y)
  356.     Snd['Warp Shot'].play
  357.     @exit=0
  358.     $game.map.data[:origin]=@select=[x,y]
  359.   end
  360.  
  361.   def distort
  362.     @leave=0
  363.   end
  364. end
  365.  
  366. class BossDoor < Entity
  367.   attr_writer :open
  368.   def initialize(x,y,fall=nil)
  369.     @x,@y,@fall=x,y,fall
  370.     @y2=@y
  371.     @y-=96 if @fall
  372.     @unstoppable=true
  373.     init(:solid)
  374.   end
  375.  
  376.   def update
  377.     @fall=nil if @open
  378.     if $game.player.x.between?(@x-64,@x+96) and $game.player.y.between?(@y2-16,@y2+112) && !@fall or @open
  379.       Snd['Bossdoor'].play if @y==@y2
  380.       @y-=2 if @y>@y2-96
  381.     else
  382.       Snd['Bossdoor'].play if @y==@y2-96
  383.       @y+=2 if @y<@y2
  384.     end
  385.     $game.player.vx=(@x==0 ? 4 : -4) if @fall and @y<@y2-72 and $game.player.x.between?(@x-16,@x+48)
  386.   end
  387.  
  388.   def draw
  389.     Img["Objects/#{$save[:dimension] ? 'Chaos' : 'Boss'} Door"].draw(@x,@y,1.9)
  390.   end
  391.  
  392.   def check(x,y,down);x.between?(@x,@x+31) and y.between?(@y,@y+96);end
  393. end
  394.  
  395. class Spawner < Entity
  396.   def initialize(x,y,max,delay,spawns,previous=[])
  397.     @x,@y,@max,@delay,@spawns,@previous=x,y,max,delay,spawns,previous
  398.     @enemies=[]
  399.     @time=0
  400.     init
  401.   end
  402.  
  403.   def update
  404.     return if @previous.find{|prev| !$game.missing(prev)}
  405.     @enemies.delete_if{|enemy| $game.missing(enemy) and @time=@delay}
  406.     @time-=1
  407.     if @time<=0 and @spawns.length>0 and @enemies.length<@max
  408.       enemy=case @spawns[0]
  409.         when :goomba
  410.         Goomba.new(@x,@y,@x>$game.player.x ? :left : :right)
  411.         when :gktroopa
  412.         GKTroopa.new(@x,@y,@x>$game.player.x ? :left : :right)
  413.         when :spiny
  414.         Spiny.new(@x,@y,@x>$game.player.x ? :left : :right)
  415.         when "iplant0","iplant1","iplant2","iplant3"
  416.         IPlant.new(@x,@y,@spawns[0].reverse.to_i)
  417.         when "mplant0","mplant1","mplant2","mplant3"
  418.         MPlant.new(@x,@y,@spawns[0].reverse.to_i)
  419.         when "hplant0","hplant1","hplant2","hplant3"
  420.         MechaP.new(@x,@y,@spawns[0].reverse.to_i)
  421.         when "venus0","venus1","venus2","venus3"
  422.         id=@spawns[0].reverse.to_i
  423.         VenusFT.new(@x+[0,-16,0,0][id],@y,id)
  424.         when :vspiny
  425.         VenomSpiny.new(@x,@y,@x>$game.player.x ? :left : :right)
  426.         when :sniper
  427.         SniperKoopa.new(@x,@y,@x+16>$game.player.x ? :left : :right)
  428.       end
  429.       @enemies<<enemy
  430.       enemy.active=true
  431.       @spawns.shift
  432.       @time=@delay
  433.     end
  434.    
  435.     remove if @enemies.empty? and @spawns.empty?
  436.   end
  437. end
  438.  
  439. class QSwitch < Entity
  440.   def initialize(x,y,event,action,tiles)
  441.     @x,@y,@event,@action,@tiles=x,y,event,action,tiles
  442.     @affects=[]
  443.     @pressed=true if $save[:events][event]
  444.     if !@action && !@pressed or @action && @pressed
  445.       @tiles.each{|tile| t=Tile.new(*tile) ; $game[t] ; @affects<<t
  446.       Trail.new(tile[0]-4,tile[1]-4,3,['Effects/Qsw',40,40],(0..7).to_a,4)}
  447.     end
  448.     init
  449.   end
  450.  
  451.   def update
  452.     if !@pressed and $game.player.vy>0 and $game.player.x.between?(@x,@x+32) and $game.player.y.between?(@y-24,@y)
  453.       Snd['Switch'].play
  454.       press
  455.     end
  456.   end
  457.  
  458.   def draw
  459.     Tls['Objects/QSwitch',24,24][@pressed ? 1 : 0].draw(@x+4,@y+8,0)
  460.   end
  461.  
  462.   def press
  463.     @pressed=true
  464.     $save[:events][@event]=true
  465.     if @action
  466.       @tiles.each{|tile| $game[Tile.new(*tile)]
  467.         Trail.new(tile[0]-4,tile[1]-4,3,['Effects/Qsw',40,40],(0..7).to_a,4)}
  468.     else
  469.       @affects.each{|affect| affect.unsplice ; affect.remove
  470.         Trail.new(affect.x-4,affect.y-4,3,['Effects/Qsw',40,40],(0..7).to_a,4)}
  471.     end
  472.   end
  473. end
  474.  
  475. class NPC < Entity
  476.   def initialize(x,y,name)
  477.     @x,@y,@name=x,y,name
  478.     init
  479.   end
  480.  
  481.   def update
  482.     if $game.player.x.between?(@x+16,@x+48) and Keypress[:up]
  483.       $game.shop!
  484.     end
  485.   end
  486.  
  487.   def draw
  488.     Img["Objects/#{@name}"].draw(@x,@y,1)
  489.   end
  490. end
  491.  
  492. class Breakable < Entity
  493.   def initialize(x,y,skin)
  494.     @x,@y,@skin=x,y,skin
  495.     @life=5
  496.     @broken=$save[:brekables].include?([$game.map.data[:id],$save[:dimension]])
  497.     init(:solid,:hittable,:powable)
  498.   end
  499.  
  500.   def draw
  501.     @damaged=nil if @damaged and (@damaged-=1)==0
  502.     if @life<=0 and !@broken
  503.       $save[:brekables]<<[$game.map.data[:id],$save[:dimension]]
  504.       @broken=true
  505.       @damaged=nil
  506.       Snd['Bricks'].play
  507.     end
  508.    
  509.     img[@broken ? 5 : 4-(@life-1)].draw(@x+(@damaged ? -4+rand(9) : 0),@y+(@damaged ? -4+rand(9) : 0),2.1)
  510.     xs=[0,-269,img[0].width+16,0,0,-269,0,-269]
  511.     ys=[-158,0,0,-158,img[0].height+16,0,img[0].height+16,0]
  512.     imgs=[0,3,2,0,1,3,1,3]
  513.     Tls['System/Here!',253,142][imgs[@skin]].draw(@x+xs[@skin],@y+ys[@skin],3) if !@broken and [$save[:equip][6],$save[:equip][7]].include?(1) and $count%60<30
  514.   end
  515.  
  516.   def img;Tls["Objects/Breakable#{@skin+1}",-1,-6];end
  517.  
  518.   def check(x,y,down);!@broken and x.between?(@x,@x+img[0].width) and y.between?(@y,@y+img[0].height);end
  519.  
  520.   def kill(x,y,sizex,sizey,attack,element,id)
  521.     return if @broken
  522.     if element==0 and x+sizex>@x and x<@x+img[0].width and y+sizey>@y-8 and y<@y+img[0].height
  523.       Snd['Stone'].play
  524.       @life-=1
  525.       @damaged=30
  526.     end
  527.   end
  528.  
  529.   def pow(x,y,width,pound)
  530.     return if @broken
  531.     if pound and x<@x+img[0].width and x+width>@x and y<@y+img[0].height and y>@y
  532.       Snd['Stone'].play
  533.       @life-=2
  534.       @damaged=30
  535.     end
  536.   end
  537. end
  538.  
  539. class Coin < Entity
  540.   def initialize(x,y,size)
  541.     @x,@y,@size=x,y,size
  542.     @unstoppable=true
  543.     init
  544.   end
  545.  
  546.   def update
  547.     gravity(img.width,img.height) if !$game.stopped
  548.     if $game.player.x+12>@x and $game.player.x-12<@x+img.width and $game.player.y-40<@y+img.height and $game.player.y+20>@y
  549.       Snd['Coin'].play
  550.       value=[1,2,5,50,100,250,500,1000,2000][@size]
  551.       $save[:coins]+=value
  552.       $game.item="#{value} coin#{'s' if value>1}"
  553.       remove
  554.     end
  555.   end
  556.  
  557.   def draw
  558.     img.draw(@x,@y,2)
  559.   end
  560.  
  561.   def img;[Tls['Objects/Coin1',20,32][$game.time/8%4],Tls['Objects/Coin2',28,32][$game.time/8%4],Tls['Objects/Coin3',28,32][$game.time/8%7],Tls['Objects/Coin4',32,50][$game.time/8%4],Tls['Objects/Coin5',41,42][$game.time/4%6],Tls['Objects/Coin6',28,32][$game.time/8%4],Tls['Objects/Coin7',32,50][$game.time/8%4],Tls['Objects/Coin8',41,42][$game.time/4%6],Tls['Objects/Coin9',96,96][$game.time/4%6]][@size];end
  562. end
  563.  
  564. class Gate < Entity
  565.   def initialize(fallen=nil)
  566.     @x,@y,@fallen=160,(fallen ? 1088 : 864),fallen
  567.     if !fallen
  568.       Snd['Gate'].play
  569.       $game.player.vx=-2
  570.       $game.player.ignore=true
  571.     end
  572.     init(:solid)
  573.   end
  574.  
  575.   def update
  576.     if !@fallen and @y<1088
  577.       @y+=2
  578.     elsif !@fallen
  579.       @mess=Message.new('Mario','Mario',"Great! Now I can't go^back.")
  580.       @fallen=true
  581.     end
  582.     $game.player.ignore=nil if @mess and @mess.closed
  583.   end
  584.  
  585.   def draw
  586.     Img['Objects/Gate'].draw(@x,@y,2)
  587.   end
  588.  
  589.   def check(x,y,down);x.between?(@x,@x+64) and y.between?(@y,@y+224);end
  590. end
  591.  
  592. class Destructible < Entity
  593.   def initialize(x,y,name,contain)
  594.     @x,@y,@contain=x,y,contain
  595.     name=Dir.entries('data/gfx/objects').find{|img| img.include?("Destr#{name}")}.chomp('.png')
  596.     @size=name.split('-')[1].to_i
  597.     @imgs=Tls['Objects/'+name,-@size,-1]
  598.     init(:hittable,:stompable)
  599.   end
  600.  
  601.   def draw
  602.     @imgs[$game.time/8% @size].draw(@x,@y,1.1)
  603.   end
  604.  
  605.   def kill(x,y,sizex,sizey,attack,element,id)
  606.     if x+sizex>@x and x<@x+@imgs[0].width and y+sizey>@y-8 and y<@y+@imgs[0].height
  607.       destroy
  608.     end
  609.   end
  610.  
  611.   def stomp(x,y,pound)
  612.     if x+12>@x and x-12<@x+@imgs[0].width and y+24>@y-8 and y-40<@y+@imgs[0].height
  613.       $game.player.bounce
  614.       destroy
  615.     end
  616.   end
  617.  
  618.   def destroy
  619.     return if @removed
  620.     Snd['Destruct'].play
  621.     w=@imgs[0].width/2 ; h=@imgs[0].height/2
  622.     Particle.new(@x,@y,3,@imgs[0].subimage(0,0,w,h),-rand(6),-8)
  623.     Particle.new(@x+w,@y,3,@imgs[0].subimage(w,0,w,h),rand(6),-8)
  624.     Particle.new(@x,@y+h,3,@imgs[0].subimage(0,h,w,h),-rand(6),-8)
  625.     Particle.new(@x+w,@y+h,3,@imgs[0].subimage(w,h,w,h),rand(6),-8)
  626.     remove
  627.     if [$save[:equip][6],$save[:equip][7]].include?(13) and rand(10)==0
  628.       Item.new(@x+w-16,@y+@imgs[0].height-32,:usable,1)
  629.     else
  630.       if @contain<2
  631.         Star.new(@x+w-16,@y+@imgs[0].height-32,@contain==1)
  632.       else
  633.         Coin.new(@x+w-[10,14,14,16,20,14,16,20][@contain-2],@y+@imgs[0].height-[32,32,32,50,42,32,50,42][@contain-2],@contain-2)
  634.       end
  635.     end
  636.   end
  637. end
  638.  
  639. class Star < Entity
  640.   def initialize(x,y,big)
  641.     @x,@y,@big=x,y,big
  642.     @unstoppable=true
  643.     init
  644.   end
  645.  
  646.   def update
  647.     gravity(32) if !$game.stopped
  648.     if $game.player.x+12>@x and $game.player.x-12<@x+32 and $game.player.y-40<@y+32 and $game.player.y+20>@y
  649.       Snd['Star'].play
  650.       remove
  651.       $save[:stars]=[$save[:stars]+(@big ? 8 : 2),$save[:max_stars]].min
  652.     end
  653.   end
  654.  
  655.   def draw
  656.     Tls['Objects/Star',32,32][@big ? 1 : 0].draw(@x,@y,2)
  657.   end
  658. end
  659.  
  660. class Switchable < Entity
  661.   def initialize(x,y,off,type)
  662.     @x,@y,@off,@type=x,y,off,type
  663.     @off=!@off if $save["Switch#{type}"]
  664.     $game.map.modify_mask(@x,@y,:rect,[31,31,0xff000000]) if !@off
  665.     init
  666.   end
  667.  
  668.   def draw
  669.     color=[Color::RED,Color::GREEN,Color::BLUE,Color::YELLOW,Color::BLACK][@type]
  670.     if @off
  671.       Tls["Objects/!-Block",32,32][0].draw(@x,@y,2.1,1,1,color)
  672.     else
  673.       Tls["Objects/!-Block",32,32][1].draw(@x,@y,2.1,1,1,color)
  674.       Tls["Objects/!-Block",32,32][2].draw(@x,@y,2.1)
  675.     end
  676.   end
  677. end
  678.  
  679. class Guide < Entity
  680.   def initialize(x,y,id)
  681.     @x,@y,@id=x,y,id
  682.     @pow=0
  683.     $game.map.modify_mask(@x,@y,:rect,[31,31,0xff000000])
  684.     init(:powable)
  685.   end
  686.  
  687.   def draw
  688.     Img['Objects/Guide'].draw(@x,@y+@pow,2)
  689.     @pow+=0.5 if @pow<0
  690.   end
  691.  
  692.   def pow(x,y,width,pound)
  693.     if x<@x+32 and x+width>@x and y<@y+32 and y>@y
  694.       Snd['Guide'].play
  695.       @pow=-8
  696.       $save[:guides][@id]=true
  697.       ($guides[@id].length-1).times{|id| Message.new($guides[@id][0],"Guide",$guides[@id][1+id],true)}
  698.     end
  699.   end
  700. end
  701.  
  702. class Ice < Entity
  703.   def initialize(x,y)
  704.     @x,@y=x,y
  705.     $game.map.modify_mask(@x,@y,:rect,[31,31,0xff000000])
  706.     init(:hittable)
  707.   end
  708.  
  709.   def update
  710.   end
  711.  
  712.   def draw
  713.     Img['Objects/Ice'].draw(@x,@y,2)
  714.   end
  715.  
  716.   def kill(x,y,sizex,sizey,attack,element,id)
  717.     if element==3 and  x+sizex>@x-8 and x<@x+40 and y+sizey>@y-8 and y<@y+40
  718.       Snd['Fizz'].play
  719.       Trail.new(@x+5,@y+5,2.1,['Effects/Smoke',22,22],(0..7).to_a,4,:movey=>-0.25)
  720.       $game.map.modify_mask(@x,@y,:rect,[31,31,0xffffffff])
  721.       remove
  722.       true
  723.     end
  724.   end
  725. end
  726.  
  727. class RelicBox < Entity
  728.   def initialize(x,y,id)
  729.     @x,@y,@id=x,y,id
  730.     @pow=0
  731.     $game.map.modify_mask(@x,@y,:rect,[64,64,0xff000000])
  732.     $game.map.modify_mask(@x+32,@y,:rect,[32,64,0xff000000])
  733.     @sprouted=true if $save[:relics][@id]!=nil or $save[:bonus].include?([$game.map.data[:id],@x,@y])
  734.     init(:powable)
  735.   end
  736.  
  737.   def update
  738.     @pow+=0.5 if @pow<0
  739.     if @item and $game.missing(@item)
  740.       @item=nil
  741.       $save[:bonus] << [$game.map.data[:id],@x,@y]
  742.     end
  743.   end
  744.  
  745.   def draw
  746.     Tls["Objects/#{@id==12 ? 'Blood' : 'Relic'} Box",64,64][@sprouted ? 4 : $count/8%4].draw(@x,@y+@pow,2)
  747.     if @id==12
  748.       Fnt[['System/Font',20,20]].draw("#{$save[:allkills]}/5000",@x+32,@y+72,3,:align=>:center)
  749.     end
  750.   end
  751.  
  752.   def pow(x,y,width,pound)
  753.     if x<@x+64 and x+width>@x and y<@y+102 and y>@y and !@sprouted
  754.       @pow=-8
  755.       return Snd['Sys4'].play if @id==12 and $save[:allkills]<5000
  756.       Snd['Sprout Relic'].play
  757.       @sprouted=true
  758.       if @id==12
  759.         @item=Item.new(@x+16,@y,:magic,14,-32)
  760.       else
  761.         @item=Relic.new(@x+16,@y,@id)
  762.       end
  763.     end
  764.   end
  765. end
  766.  
  767. class Bricks < Entity
  768.   def initialize(x,y,coins)
  769.     @x,@y,@coins=x,y,coins
  770.     @pow=0
  771.     $game.map.modify_mask(@x,@y,:rect,[31,31,0xff000000])
  772.     init(:powable)
  773.   end
  774.  
  775.   def update
  776.     @pow+=0.5 if @pow<0
  777.   end
  778.  
  779.   def draw
  780.     Tls['Objects/Bricks',32,32][@coins==0 ? 1 : 0].draw(@x,@y+@pow,2)
  781.   end
  782.  
  783.   def pow(x,y,width,pound)
  784.     if x<@x+32 and x+width>@x and y<@y+70 and y>@y and @coins !=0
  785.       if @coins
  786.         Snd['Coin'].play
  787.         $save[:coins]+=1
  788.         @coins-=1
  789.         @pow=-8
  790.         Trail.new(@x+6,@y,1,['Objects/Coin1',20,32],[0,1,2,3],2,:movey=>-4)
  791.       else
  792.         Snd['Bricks'].play
  793.         remove
  794.         $game.map.modify_mask(@x,@y,:rect,[31,31,0xffffffff])
  795.         $game.player.pound! if pound and pound!=:spin
  796.         8.times{Particle.new(@x+rand(16),@y+rand(20),3,'Effects/Brick',vx=-6+rand(13),-6-rand(7),:rotate=>vx)}
  797.       end
  798.     end
  799.   end
  800. end
  801.  
  802. class ESwitch < Entity
  803.   def initialize(id)
  804.     @x,@y,@id=288,352,id
  805.     @pressed=true if $save["Switch#{id}"]
  806.     $game.area=["#{['Red','Green','Blue','Yellow','Black'][@id]} Switch Chamber",120] if !@pressed
  807.     init
  808.   end
  809.  
  810.   def update
  811.     if !@pressed and $game.player.vy>0 and $game.player.x.between?(@x,@x+64) and $game.player.y.between?(@y-24,@y)
  812.       Snd['!Switch'].play
  813.       @pressed=true
  814.       $save["Switch#{@id}"]=true
  815.       Message.new('Info','Guide',"#{['Red','Green','Blue','Yellow','Black'][@id]} Switch has been pressed!^All blocks with this color will^open new paths.")
  816.       $game.player.bounce
  817.     end
  818.   end
  819.  
  820.   def draw
  821.     Tls['Objects/!-Switch',64,64][@pressed ? 1 : 0].draw(@x,@y,1,1,1,[Color::RED,Color::GREEN,Color::BLUE,Color::YELLOW,Color::BLACK][@id])
  822.     Tls['Objects/!-Switch',64,64][@pressed ? 3 : 2].draw(@x,@y,1)
  823.   end
  824. end
  825.  
  826. class Belt < Entity
  827.   def initialize(x,y,part,left)
  828.     @x,@y,@part,@left=x,y,part,left
  829.     # $game.map.modify_mask(x,y,:rect,[31,31,0xff000000])
  830.     $game.map.modify_mask(x,y,:splice,["System/Mask",32,32,0])
  831.     init
  832.   end
  833.  
  834.   def update
  835.     if $game.player.down? and $game.player.x.between?(@x-16,@x+48) and $game.player.y.between?(@y-32,@y-16)
  836.       $game.player.x+=(@left ? -2 : 2) if not @left && $game.player.left || !@left && $game.player.right
  837.     end
  838.     $game.entities[1].each{|ent| if ent.class==Bobomb and ent.y>@y-64 and ent.y<@y and ent.x.between?(@x-48,@x+48) then ent.move(@left) end}
  839.     $game.entities[0].each{|ent| if ent.class==Crate and !ent.moved and ent.y==@y-ent.size*32 and ent.x.between?(@x-ent.size*32,@x+32) then ent.x+=(@left ? -2 : 2) ; ent.moved=true end}
  840.   end
  841.  
  842.   def draw
  843.     Tls['Objects/Conveyor Belt',32,32][@part+(@left ? 3-$game.time/2%4 : $game.time/2%4)*3].draw(@x,@y,2)
  844.   end
  845. end
  846.  
  847. class CapeTri < Entity
  848.   def initialize(x,y,right)
  849.     @x,@y,@right=x,y,right
  850.     init
  851.     $game.map.modify_mask(@x,@y,:splice,["Objects/CapeTri-mask",32,32,@right ? 1 : 0])
  852.     @unstoppable=true
  853.     @vx=0
  854.   end
  855.  
  856.  
  857.   def update
  858.     @vx=$game.player.vx.abs if $game.player.vx.to_i != 0
  859.     if !$game.player.wall and Keypress[@right ? :right : :left] and @vx>4 and $game.player.y.between?(@y-32,@y) and $game.player.x.between?(@x-64,@x+96) and @right && $game.player.dir==:right && $game.player.right  || !@right && $game.player.dir==:left && $game.player.left
  860.       Snd['Cape'].play
  861.       $game.player.wall=(@right ? :right : :left)
  862.       $game.player.vy=-@vx
  863.     end
  864.   end
  865.  
  866.   def draw
  867.     Img['Objects/CapeTri'].draw(@x+(@right ? 32 : 0),@y,2,(@right ? -1 : 1))
  868.   end
  869. end
  870.  
  871. class Crate < Entity
  872.   attr_accessor :moved
  873.   attr_reader :size
  874.   def initialize(x,y,size)
  875.     @x,@y,@size=x,y,size
  876.     @pound=true
  877.     init(:solid)
  878.   end
  879.  
  880.   def update
  881.     @solid=@moved=nil
  882.     gravity(@size*32,@size*32,1,false)
  883.     @solid=true
  884.     Snd['Pound'].play if @vy==0 and !@pound
  885.     @pound=true if @vy==0
  886.     @pound=nil if @vy!=0
  887.     remove if @y>$game.map.data[:height]*480
  888.    
  889.     return if $game.gameover
  890.     while $game.player.y.between?(@y,@y+@size*32) and $game.player.x.between?(@x-16,@x+@size*32+16) do $game.player.x+=($game.player.x<@x+@size*16 ? -1 : 1) end if @vy==0
  891.     if !$game.player.inv and $game.player.x.between?(@x,@x+@size*32) and $game.player.y.between?(@y,@y+@size*32)
  892.       $game.player.reset
  893.       Snd["MarioDamage#{1+rand(5)}"].play
  894.       damage=@size*75
  895.       $save[:hp]-=damage
  896.       Info.new($game.player.x-damage.to_s.length*7,$game.player.y-40,damage,"Damage1")
  897.       $game.player.vx=12*($game.player.x<@x+@size*16 ? -1 : 1)
  898.     end
  899.   end
  900.  
  901.   def draw
  902.     Img['Objects/Crate'].draw(@x,@y,2,@size*0.25,@size*0.25)
  903.   end
  904.  
  905.   def check(x,y,down);@solid and x.between?(@x,@x+@size*32-1) and y.between?(@y,@y+@size*32-1);end
  906. end
  907.  
  908. class Cog < Entity
  909.   def initialize(x,y,type,inverted)
  910.     @x,@y,@type,@reversed=x,y,type,inverted
  911.     init(:solid)
  912.   end
  913.  
  914.   def update
  915.     if $game.player.down? and @reversed && $game.player.vx>-2 && !Keypress[:right] && $save[:status] != 'STONE' || !@reversed && $game.player.vx<2 && !Keypress[:left] && $save[:status] != 'STONE' and $game.player.x.between?(@x-16,@x+[270,144][@type%2]) and $game.player.y.between?(@y-32,@y+[160,32][@type%2])
  916.       # $game.player.x+=(@left ? -2 : 2) if not @left && $game.player.left || !@left && $game.player.right
  917.       $game.player.vx+=(@reversed ? -1 : 1)# if not @left && $game.player.left || !@left && $game.player.right
  918.     end
  919.   end
  920.  
  921.   def draw
  922.     case @type
  923.       when 0,2
  924.       Img["Objects/Cog#{@type+1}"].draw_rot(@x+127,@y+129,1.3,@reversed ? -$game.time : $game.time)
  925.       when 1,3
  926.       Tls["Objects/Cog#{@type+1}",128,32][@reversed ? 5-$game.time/4%6 : $game.time/4%6].draw(@x,@y,2)
  927.     end
  928.   end
  929.  
  930.   def check(x,y,down);case @type
  931.     when 0,2
  932.     down and x.between?(@x,@x+254) and y.between?(chk=(@y+129-offset_y((@x+127-x)*0.72,129).abs).to_i,chk+8)
  933.     when 1,3
  934.     x.between?(@x,@x+127) and y.between?(@y,@y+31)
  935.     end
  936.   end
  937. end
  938.  
  939. class Spikes < Enemy
  940.   attr_reader :harmless
  941.   def initialize(x,y,dir,supp=nil)
  942.     @x,@y,@dir,@super=x,y,dir,supp
  943.     @attack=(supp ? 500+$save[:level]*2 : [$save[:max_hp]/8,$save[:defence]+20].max)
  944.     @element=1
  945.     @setinv=(supp ? 15 : 60)
  946.     @immortal=true
  947.     @omnir=@super
  948.     @unstoppable=true
  949.     init(:enemy)
  950.   end
  951.  
  952.   def action
  953.     if @attacked and $save[:equip][0]==2
  954.       Snd['BlasterCrash'].play
  955.       Particle.new(@x,@y,3,"Objects/#{'super' if @super}Spikes",vx=-8+rand(17),-6-rand(7),:angle=>0,:rotate=>vx*4,:unstop=>true)
  956.       @harmless=rand(4)
  957.     end
  958.   end
  959.  
  960.   def draw
  961.     (@harmless ? Tls['Objects/Wreck',32][@harmless] : Img["Objects/#{'super' if @super}Spikes"]).draw_rot(@x+16,@y+16,2,@dir*90)
  962.   end
  963.  
  964.   def size;[32,32];end
  965. end
  966.  
  967. class Pendulum < Entity
  968.   def initialize(x,y,phase)
  969.     @x,@y=x,y
  970.     @time=(phase ? 90 : 0)
  971.     init(:solid)
  972.   end
  973.  
  974.   def update
  975.     offx=offset_x(-45+(@time%180-90).abs,160)
  976.     offy=offset_y(-45+(@time%180-90).abs,128)
  977.     @time+=1
  978.     if @player
  979.       $game.player.x+=offx-offset_x(-45+(@time%180-90).abs,160)
  980.       $game.player.y+=offy-offset_y(-45+(@time%180-90).abs,128)
  981.       @player=nil
  982.     end
  983.   end
  984.  
  985.   def draw
  986.     angle=-45+(@time%180-90).abs
  987.     Tls['Objects/Pendulum',64,214][0].draw_rot(@x,@y,2,0,0.5,0)
  988.     Tls['Objects/Pendulum',64,214][1].draw_rot(@x,@y+32,1,angle,0.5,0)
  989.     Tls['Objects/Pendulum',64,214][2].draw(@x-32-offset_x(angle,160),@y-112-offset_y(angle,128),2)
  990.   end
  991.  
  992.   def check(x,y,down)
  993.     angle=-45+(@time%180-90).abs
  994.     if down and x.between?(@x-32-offset_x(angle,160),@x-32-offset_x(angle,160)+64) and y.between?(@y+38-offset_y(angle,128),@y+102-offset_y(angle,128))
  995.       @player=true if $down==$game.player
  996.       true
  997.     end
  998.   end
  999. end
  1000.  
  1001. class Portal < Entity
  1002.   def initialize(x,y,target,area)
  1003.     @x,@y,@target,@area=x,y,target,area
  1004.     init
  1005.   end
  1006.  
  1007.   def update
  1008.     if !@portal and distance($game.player.x,$game.player.y,@x+64,@y+64)<64
  1009.       Snd['Portal'].play
  1010.       $game.player.portal(@x+64,@y+64)
  1011.       @portal=0
  1012.     end
  1013.    
  1014.     if @portal
  1015.       @portal+=1
  1016.      
  1017.       Snd['Portal FX'].play if @portal==60
  1018.       $game.flash(0xffffffff,16) if @portal>60 and @portal%15==0
  1019.      
  1020.       if @portal==180
  1021.         Snd['Portal FX'].play
  1022.         $save[:dimension]=false
  1023.         $game.reset(@target)
  1024.         $save[:area]=@area
  1025.         $game.map.music(@area)
  1026.         $game.came=[$game.player.x,$game.player.y]
  1027.         init
  1028.       end
  1029.      
  1030.       if @portal==240
  1031.         remove
  1032.         $game.player.deportal
  1033.       end
  1034.     end
  1035.   end
  1036.  
  1037.   def draw
  1038.     scale=((@portal and @portal>180) ? 240.0/(@portal*2+60) : 1)
  1039.     Img['Objects/Portal'].draw_rot(@x+64,@y+64,1,rand(360),0.5,0.5,scale,scale)
  1040.   end
  1041. end
  1042.  
  1043. class QuickSave < Entity
  1044.   def initialize(x,y)
  1045.     save=Marshal.load(f=File.open("data/save#{$save[:id]}",'r'))
  1046.     f.close
  1047.     @obsolete=true if save[:session] and save[:session][1][:id]==$game.map.data[:id]
  1048.     @x,@y=x,y
  1049.     @pow=0
  1050.     splice if !@obsolete
  1051.     init(:powable)
  1052.   end
  1053.  
  1054.   def update
  1055.     remove if @obsolete
  1056.     @pow+=1 if @pow<0
  1057.   end
  1058.  
  1059.   def draw
  1060.     Img['Objects/Quicksave'].draw(@x,@y,2)
  1061.   end
  1062.  
  1063.   def pow(x,y,width,pound)
  1064.     if x<@x+64 and x+width>@x and y<@y+70 and y>@y
  1065.       Snd['Save'].play
  1066.       save=Marshal.load(f=File.open("data/save#{$save[:id]}",'r'))
  1067.       f.close
  1068.       save[:session]=[$game.came]+[$game.map.data]+[true]
  1069.       Marshal.dump(save,f=File.open("data/save#{$save[:id]}",'w'))
  1070.       f.close
  1071.       Marshal.dump($save,f=File.open("data/save#{$save[:id]}s",'w'))
  1072.       f.close
  1073.       remove
  1074.       $game.map.modify_mask(@x,@y,:splice,'Objects/Quicksave-demask')
  1075.       $game.save=0
  1076.     end
  1077.   end
  1078.  
  1079.   def splice
  1080.     $game.map.modify_mask(@x,@y,:splice,'Objects/Quicksave-mask')
  1081.   end
  1082.  
  1083.   def tp
  1084.     $game.player.x=x+32
  1085.     $game.player.y=y+96
  1086.   end
  1087. end
  1088.  
  1089. class TheDoor < Entity
  1090.   attr_writer :open
  1091.   def initialize(x,y)
  1092.     @x,@y=x,y
  1093.     init(:solid)
  1094.   end
  1095.  
  1096.   def update
  1097.     if !@openning and $game.player.x.between?(@x-16,@x+48) and $game.player.y.between?(@y,@y+64) and $save[:items][:misc].include?(4)
  1098.       @openning=1
  1099.       Snd['Door'].play
  1100.     elsif @openning
  1101.       @openning+=1
  1102.       @open=true if @openning==24
  1103.     end
  1104.   end
  1105.  
  1106.   def draw
  1107.     Tls["Objects/The Door",32,64][@open ? 4 : @openning ? 1+@openning/8 : 0].draw(@x,@y,1)
  1108.   end
  1109.  
  1110.   def check(x,y,down);!@openning and x.between?(@x,@x+31) and y.between?(@y,@y+63);end
  1111. end
  1112.  
  1113. class Sprite < Entity
  1114.   attr_writer :angle
  1115.   def initialize(x,y,gfx,w,h,top=false)
  1116.     @x,@y,@gfx,@width,@height,@top=x,y,gfx,w,h,top
  1117.     @time=@frame=0
  1118.     init
  1119.   end
  1120.  
  1121.   def update
  1122.     @time+=1
  1123.    
  1124.     if @animation and @time% @delay==0
  1125.       @sequence+=1
  1126.       @sequence=0 if @sequence==@animation.length
  1127.       @frame=@animation[@sequence]
  1128.     end
  1129.   end
  1130.  
  1131.   def draw
  1132.     if @angle
  1133.       Tls[@gfx, @width, @height][@frame].draw_rot(@x, @y, 1.4, @angle, @mirror_x ? -1 : 1)
  1134.     else
  1135.       Tls[@gfx, @width, @height][@frame].draw(@x + (@mirror_x ? @width : 0), @y, @top ? 2.3 : 1.4, @mirror_x ? -1 : 1)
  1136.     end
  1137.   end
  1138.  
  1139.   def animation(delay,*sequence)
  1140.     @time=@sequence=0
  1141.     @delay=delay
  1142.     @animation=sequence
  1143.     @frame=@animation.first
  1144.   end
  1145.  
  1146.   def mirror_x
  1147.     @mirror_x=!@mirror_x
  1148.   end
  1149.  
  1150.   def frame=(value)
  1151.     @frame=value
  1152.     @animation=nil
  1153.   end
  1154. end
  1155.  
  1156. class Donut < Entity
  1157.   def initialize(x,y)
  1158.     @x,@y=x,y
  1159.     @y1=y
  1160.     @stand=0
  1161.     init(:solid)
  1162.   end
  1163.  
  1164.   def update
  1165.     @stand-=1 if @stand>0
  1166.     @fall=true if @stand>90
  1167.     @y+=8 if @fall
  1168.     if @y>$game.scy+480 and !@invisible
  1169.       @fall=nil
  1170.       @invisible=300
  1171.     elsif @invisible
  1172.       @stand=0
  1173.       @invisible-=1
  1174.       if @invisible==0
  1175.         @invisible=nil
  1176.         @y=@y1
  1177.       end
  1178.     end
  1179.   end
  1180.  
  1181.   def draw
  1182.     v=((@stand>0 and !@fall) ? -2+rand(5) : 0)
  1183.     Img["Objects/Donut"].draw(@x+v,@y+v,2)
  1184.   end
  1185.  
  1186.   def check(x,y,down)
  1187.     if !@invisible and down and x.between?(@x,@x+31) and y==@y
  1188.       @stand+=2
  1189.     end
  1190.   end
  1191. end
Add Comment
Please, Sign In to add comment