Advertisement
Guest User

Fixex map.rb (WTFPL)

a guest
Sep 11th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 24.21 KB | None | 0 0
  1. #0entrance, 1garden, 2waterway, 3distortion, 4corridor, 5pipeline, 6library, 7factory, 8goomba, 9chapel, 10clock, 11bonus, 12catacombs, 13cave,14abyss,15bowser
  2. class Map
  3.   attr_reader :origin,:data,:id
  4.   def initialize(id)
  5.     $game.map=self
  6.     @data=Marshal.load(f=File.new("data/world/#{id}",'r'))
  7.     f.close
  8.     @masks={}
  9.     @data[:id]=id
  10.    
  11.     @modifies={}
  12.    
  13.     @tiles=[]
  14.     @backs=[]
  15.     @data[:objects].reject!{|obj| add(obj)}
  16.     @data[:background][0]="FinalChaos" if @data[:background][0]=="Chaos" and $save[:cores].length==12 || $bossrush && $bossrush[4]==12
  17.    
  18.     @map=$screen.record(@data[:width]*640,@data[:height]*480){@tiles.each{|tile| tile.draw}}
  19.     @map2=$screen.record(@data[:width]*640,@data[:height]*480){@backs.each{|tile| tile.draw}}
  20.     @tiles=@backs=nil
  21.   end
  22.  
  23.   def update
  24.     x=@data[:origin][0]*10+$game.player.x.to_i/640*10
  25.     y=@data[:origin][1]*10+$game.player.y.to_i/480*10
  26.     room=$save[:map].find{|r| !r.dimension==!$save[:dimension] and r.x==x and r.y==y}
  27.     if room
  28.       val=((($save[:map].count{|room| room.discovered})/($save[:map].length.to_f-1))*100).round
  29.       $items[:cap][4][:defence]=val**2/100
  30.     end
  31.     room.discover if room
  32.   end
  33.  
  34.   def draw
  35.     @modifies.each_pair{|mask,modifs| mask.render{modifs.each{|modif| modify_mask2(*modif)}}}
  36.     @modifies.clear
  37.    
  38.     @map2.draw(-$game.scx,-$game.scy,1)
  39.     @map.draw(-$game.scx,-$game.scy,$distorting ? 1.3 : 2.1)
  40.     scy=$game.scy-((@data[:background][0]=="Sky" or @data[:background][0]=="DarkSky") ? $game.time*(@data[:background][0]=="DarkSky" ? -8 : 8) : 0)
  41.     if File.exists?("data/gfx/backgrounds/#{@data[:background][0]}.png")
  42.       img=Img["backgrounds/#{@data[:background][0]}"]
  43.       (@data[:background][1] ? 640/img.width+2 : 1).times{|x| (@data[:background][2] ? 480/img.height+2 : 1).times{|y|
  44.       if @data[:background][1]
  45.         x1=-(@data[:background][3]*$game.scx+x*img.width).to_i% (img.width*(640/img.width+2))-img.width
  46.       else
  47.         x=-$game.scx*((img.width-640).to_f/(@data[:width]*640-640))
  48.         x1=((x.to_f.nan? or x.to_f.infinite?) ? @data[:background][3] : x+@data[:background][3])
  49.       end
  50.       if @data[:background][2]
  51.         y1=-(@data[:background][4]*scy+y*img.height).to_i% (img.height*(480/img.height+2))-img.height
  52.       else
  53.         y=-scy*((img.height-480).to_f/(@data[:height]*480-480))
  54.         y1=((y.to_f.nan? or y.to_f.infinite?) ? @data[:background][4] : y+@data[:background][4])
  55.       end
  56.       img.draw(x1,y1,0)}}
  57.     end
  58.   end
  59.  
  60.   def init
  61.     return if @modifies.empty?
  62.     @modifies.each_pair{|mask,modifs| mask.render{modifs.each{|modif| modify_mask2(*modif)}}}
  63.     @modifies.clear
  64.   end
  65.  
  66.   def modify_mask(x,y,method,value,down=false)
  67.     @modifies[mask(x/640,y/480)]||=[]
  68.     if down
  69.       @modifies[mask(x/640,y/480)].insert 10, [x,y,method,value]
  70.     else
  71.       @modifies[mask(x/640,y/480)]<<[x,y,method,value]
  72.     end
  73.   end
  74.  
  75.   def modify_mask2(x,y,method,value)
  76.     case method
  77.       when :splice
  78.       img=(value.class==String ? Img[value] : Tls[value[0],value[1],value[2]][value[3]])
  79.       img.draw(x%640,y%480,0)
  80.       when :rect
  81.       $screen.draw_quad(x%640,y%480,value[2],x%640+value[0],y%480,value[2],x%640+value[0],y%480+value[1],value[2],x%640,y%480+value[1],value[2],0)
  82.     end
  83.   end
  84.  
  85.   def mask(x,y)
  86.     @masks[[x,y]] ||= Ashton::WindowBuffer.new
  87.     @masks[[x,y]]
  88.   end
  89.  
  90.   def solid?(x,y,down)
  91.     return if !@masks[[x/640,y/480]]
  92.     color=@masks[[x/640,y/480]][x%640,479-y%480]
  93.     return true if color==Color::BLACK
  94.     return true if down and color==Color::GREEN and down==:super || @masks[[x/640,(y-4)/480]][x%640,480 -(y-4)%480]!=Color::GREEN
  95.   end
  96.  
  97.   def water?(x,y)
  98.     x,y=x.to_i,y.to_i
  99.     if !@masks[[x/640,y/480]]
  100.       color=@masks[[x/640,0]][x%640,479] if y<0 and @masks[[x/640,0]]
  101.       color=@masks[[x/640,@data[:height]-1]][x%640,0] if y>@data[:height]*480-1 and @masks[[x/640,@data[:height]-1]]
  102.       color=@masks[[0,y/480]][0,479-y%480] if x<0 and @masks[[0,y/480]]
  103.       color=@masks[[@data[:width]-1,y/480]][639,479-y%480] if x>@data[:width]*640-1 and @masks[[@data[:width]-1,y/480]]
  104.     else
  105.       color=@masks[[x/640,y/480]][x%640,479-y%480]
  106.     end
  107.     return true if color==Color::BLUE
  108.   end
  109.  
  110.   def add(obj)
  111.     case obj.type
  112.       when :tile
  113.       @tiles << Tile.new(obj.x,obj.y,*obj.args)
  114.       when :waypoint
  115.       Waypoint.new(obj.x,obj.y,*obj.args)
  116.       when :back
  117.       @backs << Background.new(obj.x,obj.y,*obj.args)
  118.       when :pipe
  119.       @tiles << Pipe.new(obj.x,obj.y,*obj.args)
  120.       when :item
  121.       BonusBlock.new(obj.x,obj.y,*obj.args)
  122.       when :tunnel
  123.       Tunnel.new(obj.x,obj.y,*obj.args)
  124.       when :bonus
  125.       Bonus.new(obj.x,obj.y,*obj.args)
  126.       when :breakable
  127.       Breakable.new(obj.x,obj.y,*obj.args)
  128.       when :switchable
  129.       Switchable.new(obj.x,obj.y,*obj.args)
  130.       when :destructible
  131.       Destructible.new(obj.x,obj.y,*obj.args)
  132.       when :guide
  133.       Guide.new(obj.x,obj.y,*obj.args)
  134.       when :ice
  135.       Ice.new(obj.x,obj.y,*obj.args)
  136.       when :water
  137.       Water.new(obj.x,obj.y,*obj.args)
  138.       when :aback
  139.       Aback.new(obj.x,obj.y,*obj.args)
  140.       when :rwater
  141.       RunningWater.new(obj.x,obj.y,*obj.args)
  142.       when :relic
  143.       RelicBox.new(obj.x,obj.y,*obj.args)
  144.       when :bricks
  145.       Bricks.new(obj.x,obj.y,*obj.args)
  146.       when :belt
  147.       Belt.new(obj.x,obj.y,*obj.args)
  148.       when :cape
  149.       CapeTri.new(obj.x,obj.y,*obj.args)
  150.       when :fall
  151.       Fall.new(obj.x,obj.y,*obj.args)
  152.       when :cog
  153.       Cog.new(obj.x,obj.y,*obj.args)
  154.       when :spikes
  155.       Spikes.new(obj.x,obj.y,*obj.args)
  156.       when :pendulum
  157.       Pendulum.new(obj.x,obj.y,*obj.args)
  158.       when :portal
  159.       Portal.new(obj.x,obj.y,*obj.args)
  160.       when :lava
  161.       Lava.new(obj.x,obj.y,*obj.args)
  162.       when :qsave
  163.       QuickSave.new(obj.x,obj.y,*obj.args)
  164.       when :donut
  165.       Donut.new(obj.x,obj.y,*obj.args)
  166.      
  167.       when :goomba
  168.       Goomba.new(obj.x,obj.y,*obj.args)
  169.       when :gktroopa
  170.       GKTroopa.new(obj.x,obj.y,*obj.args)
  171.       when :peeps
  172.       Peeps.new(obj.x,obj.y,*obj.args)
  173.       when :spiny
  174.       Spiny.new(obj.x,obj.y,*obj.args)
  175.       when :rktroopa
  176.       RKTroopa.new(obj.x,obj.y,*obj.args)
  177.       when :mmole
  178.       MontyMole.new(obj.x,obj.y,*obj.args)
  179.       when :nninji
  180.       NNinji.new(obj.x,obj.y,*obj.args)
  181.       when :yptroopa
  182.       YPTroopa.new(obj.x,obj.y,*obj.args)
  183.       when :rex
  184.       Rex.new(obj.x,obj.y,*obj.args)
  185.       when :swooper
  186.       Swooper.new(obj.x,obj.y,*obj.args)
  187.       when :blaster
  188.       Blaster.new(obj.x,obj.y,*obj.args)
  189.       when :cheepcheep
  190.       CheepCheep.new(obj.x,obj.y,*obj.args)
  191.       when :spinycheep
  192.       SpinyCheepCheep.new(obj.x,obj.y,*obj.args)
  193.       when :skeeter
  194.       Skeeter.new(obj.x,obj.y,*obj.args)
  195.       when :sushi
  196.       Sushi.new(obj.x,obj.y,*obj.args)
  197.       when :bbeetle
  198.       BuzzyBeetle.new(obj.x,obj.y,*obj.args)
  199.       when :hcrab
  200.       HuckitCrab.new(obj.x,obj.y,*obj.args)
  201.       when :pplant
  202.       PPlant.new(obj.x,obj.y,*obj.args)
  203.       when :iplant
  204.       IPlant.new(obj.x,obj.y,*obj.args)
  205.       when :mplant
  206.       MPlant.new(obj.x,obj.y,*obj.args)
  207.       when :venusft
  208.       VenusFT.new(obj.x,obj.y,*obj.args)
  209.       when :charginchk
  210.       CharginChuck.new(obj.x,obj.y,*obj.args)
  211.       when :hammerbro
  212.       HammerBro.new(obj.x,obj.y,*obj.args)
  213.       when :reboundbro
  214.       ReboundBro.new(obj.x,obj.y,*obj.args)
  215.       when :firebro
  216.       FireBro.new(obj.x,obj.y,*obj.args)
  217.       when :banzai
  218.       BanzaiBill.new(obj.x,obj.y,*obj.args)
  219.       when :fang
  220.       Fang.new(obj.x,obj.y,*obj.args)
  221.       when :mecha
  222.       MechaP.new(obj.x,obj.y,*obj.args)
  223.       when :sniper
  224.       SniperKoopa.new(obj.x,obj.y,*obj.args)
  225.       when :vspiny
  226.       VenomSpiny.new(obj.x,obj.y,*obj.args)
  227.       when :pbeetle
  228.       PanzerBeetle.new(obj.x,obj.y,*obj.args)
  229.       when :bptroopa
  230.       BPTroopa.new(obj.x,obj.y,*obj.args)
  231.       when :hgoomba
  232.       HolyGoomba.new(obj.x,obj.y,*obj.args)
  233.       when :shyguy
  234.       ShyGuy.new(obj.x,obj.y,*obj.args)
  235.       when :engine
  236.       Engine.new(obj.x,obj.y,*obj.args)
  237.       when :chomp
  238.       ChainChomp.new(obj.x,obj.y,*obj.args)
  239.       when :bomb
  240.       Bobomb.new(obj.x,obj.y,*obj.args)
  241.       when :parabeetle
  242.       Parabeetle.new(obj.x,obj.y,*obj.args)
  243.       when :paragoomba
  244.       Paragoomba.new(obj.x,obj.y,*obj.args)
  245.       when :firechomp
  246.       FireChomp.new(obj.x,obj.y,*obj.args)
  247.       when :flybro
  248.       AFHB.new(obj.x,obj.y,*obj.args)
  249.       when :ninji
  250.       Ninji.new(obj.x,obj.y,*obj.args)
  251.       when :pokey
  252.       Pokey.new(obj.x,obj.y,*obj.args)
  253.       when :vlotus
  254.       VLotus.new(obj.x,obj.y,*obj.args)
  255.       when :boomerangbro
  256.       BoomerangBro.new(obj.x,obj.y,*obj.args)
  257.       when :boo
  258.       Boo.new(obj.x,obj.y,*obj.args)
  259.       when :bigboo
  260.       BigBoo.new(obj.x,obj.y,*obj.args)
  261.       when :srat
  262.       SRat.new(obj.x,obj.y,*obj.args)
  263.       when :fishin
  264.       Fishin.new(obj.x,obj.y,*obj.args)
  265.       when :drybo
  266.       DryBones.new(obj.x,obj.y,*obj.args)
  267.       when :bony
  268.       BonyBeetle.new(obj.x,obj.y,*obj.args)
  269.       when :magi
  270.       Magikoopa.new(obj.x,obj.y,*obj.args)
  271.       when :necro
  272.       Necrokoopa.new(obj.x,obj.y,*obj.args)
  273.       when :priest
  274.       Priest.new(obj.x,obj.y,*obj.args)
  275.       when :ball
  276.       SpEgg.new(obj.x,obj.y,*obj.args)
  277.       when :lakitu
  278.       Lakitu.new(obj.x,obj.y,*obj.args)
  279.       when :stony
  280.       Stony.new(obj.x,obj.y,*obj.args)
  281.       when :giant
  282.       KoopaGiant.new(obj.x,obj.y,*obj.args)
  283.       when :nyan
  284.       Nyan.new(obj.x,obj.y,*obj.args)
  285.       when :scuttle
  286.       Scuttle.new(obj.x,obj.y,*obj.args)
  287.       when :dinot
  288.       DinoTorch.new(obj.x,obj.y,*obj.args)
  289.       when :dinof
  290.       DinoTorch.new(obj.x,obj.y,true)
  291.       when :thwomp
  292.       Thwomp.new(obj.x,obj.y)
  293.       when :podoboo
  294.       Podoboo.new(obj.x,obj.y)
  295.       when :titan
  296.       Titan.new(obj.x,obj.y,*obj.args)
  297.       when :chainsaw
  298.       Chainsaw.new(obj.x,obj.y,*obj.args)
  299.       when :snift
  300.       Snift.new(obj.x,obj.y,*obj.args)
  301.       when :wiggler
  302.       Wiggler.new(obj.x,obj.y,*obj.args)
  303.       when :piano
  304.       MadPiano.new(obj.x,obj.y,*obj.args)
  305.       when :outoo
  306.       Outoo.new(obj.x,obj.y,*obj.args)
  307.       when :clearbo
  308.       ClearBones.new(obj.x,obj.y,*obj.args)
  309.       when :skycheep
  310.       SkyCheep.new(obj.x,obj.y,*obj.args)
  311.       when :shadow
  312.       ShadowBro.new(obj.x,obj.y,*obj.args)
  313.       when :llotus
  314.       LLotus.new(obj.x,obj.y,*obj.args)
  315.       when :poiskey
  316.       Poisonkey.new(obj.x,obj.y,*obj.args)
  317.       when :mine
  318.       Mine.new(obj.x,obj.y,*obj.args)
  319.       when :chaincheep
  320.       ChainCheep.new(obj.x,obj.y,*obj.args)
  321.       when :novaboo
  322.       Novaboo.new(obj.x,obj.y,*obj.args)
  323.       when :mecha2
  324.       MechaP2.new(obj.x,obj.y,*obj.args)
  325.       when :sparky
  326.       Sparky.new(obj.x,obj.y,*obj.args)
  327.       when :master
  328.       Master.new(obj.x,obj.y,*obj.args)
  329.       when :reznor
  330.       Reznor.new(obj.x,obj.y,*obj.args)
  331.       when :darkstar
  332.       DarkStar.new(obj.x,obj.y,*obj.args)
  333.       when :muncher
  334.       Muncher.new(obj.x,obj.y,*obj.args)
  335.       when :fuzzy
  336.       Fuzzy.new(obj.x,obj.y,*obj.args)
  337.       when :vase
  338.       Vase.new(obj.x,obj.y,*obj.args)
  339.       when :mad
  340.       MadBlock.new(obj.x,obj.y,*obj.args)
  341.       when :sorcerer
  342.       Sorckoopa.new(obj.x,obj.y,*obj.args)
  343.       when :phanto
  344.       Phanto.new(obj.x,obj.y,*obj.args)
  345.       when :zombie
  346.       Yoshi.new(obj.x,obj.y,*obj.args)
  347.       when :ptooie
  348.       Ptooie.new(obj.x,obj.y,*obj.args)
  349.     end
  350.   end
  351.  
  352.   def add_tile(tile) @tiles << tile;end
  353.  
  354.   def music(area)
  355.     @data[:music]=true
  356.     Msc[["Dracula's Castle","Platinum Moonlight","Nightmare",["Crucifix Held Close","Iron Blue Intention","Successor of Fate","Malak's Labyrinth","The Abyss"][music2],"An Empty Tome","YkY","Haunty Halls","Weapons Factory","Castle","Chapel of Dissonance","Clock Tower","Starman","Awake","Forbidden Area","The Abyss","level_zameczek"][area],:auto].play(!$premusic)
  357.   end
  358.  
  359.   def music2
  360.     $save[:dimension] ? [2,1,3,nil,2,0,0,1,nil,2,1,nil,3,3,4,0][$save[:dimension]] : 0
  361.   end
  362. end
  363.  
  364. class Tile < Entity
  365.   def initialize(x,y,tileset,id)
  366.     @x,@y,@tileset,@id=x,y,tileset,id
  367.     if $save[:dimension] and ['t','r1','r2'].include? $game.map.data[:id]
  368.       @tileset='Dark'+tileset
  369.     end
  370.     splice
  371.   end
  372.  
  373.   def draw
  374.     Tls["Tiles/#{@tileset}",32,32][@id].draw(@x,@y,$distorting ? 1.3 : 2.1)
  375.   end
  376.  
  377.   def splice;$game.map.modify_mask(@x,@y,:splice,["Tiles/#{@tileset}-mask".sub('Dark',''),32,32,@id]);end
  378.  
  379.   def unsplice;$game.map.modify_mask(@x,@y,:rect,[32,32,0xffffffff]);end
  380. end
  381.  
  382. class Pipe < Entity
  383.   def initialize(x,y,layout,color)
  384.     @x,@y,@layout,@color=x,y,layout,color
  385.     splice
  386.     init if color==:rainbow
  387.   end
  388.  
  389.   def draw
  390.     if @color==:rainbow
  391.       2.times{|x| 2.times{|y| Tls['Objects/Pipes',32,32][layout[x+y*2]].draw(@x+x*32,@y+y*32,2.1,1,1,Color.from_hsv($game.time%360,1,1));Tls['Objects/Pipes-const',32,32][layout[x+y*2]].draw(@x+x*32,@y+y*32,2)}}
  392.     else
  393.       2.times{|x| 2.times{|y| Tls['Objects/Pipes',32,32][layout[x+y*2]].draw(@x+x*32,@y+y*32,2,1,1,Color.new(*@color));Tls['Objects/Pipes-const',32,32][layout[x+y*2]].draw(@x+x*32,@y+y*32,2)}}
  394.     end
  395.   end
  396.  
  397.   def splice
  398.     2.times{|x| 2.times{|y| $game.map.modify_mask(@x+x*32,@y+y*32,:splice,['Objects/Pipes-mask',32,32,layout[x+y*2]])}}
  399.   end
  400.  
  401.   def layout;[[2,3,8,9],[8,9,8,9],[8,9,32,33],[12,13,18,19],[13,13,19,19],[13,17,19,23],[14,15,20,21],[16,22,26,27],[14,9,20,9],[8,15,8,21],[13,13,26,27],[16,22,19,19],[0,1,6,7],[4,5,10,11],[24,25,30,31],[28,29,34,35]][@layout];end
  402. end
  403.  
  404. class Obj
  405.   attr_reader :x,:y,:type,:args
  406. end
  407.  
  408. class Waypoint < Entity
  409.   attr_accessor :target
  410.   def initialize(x,y,horizontal,target,path=nil)
  411.     @x,@y,@horizontal,@target,@path=x,y,horizontal,target,path
  412.     @target="#{@target}a" if $save[:dimension] and target.class!=String
  413.     @unstoppable=true
  414.     init
  415.   end
  416.  
  417.   def update
  418.     spec=(@target.class==String && @target.length==1 or @path)
  419.     old=[$game.map.data[:origin][0]+$game.player.x.to_i/640,$game.map.data[:origin][1]+$game.player.y.to_i/480] if spec
  420.     if !@horizontal and $game.player.y.between?(@y,@y+480) and (pos1=(@x==$game.map.data[:width]*640-32)) && $game.player.x>$game.map.data[:width]*640 || @x==0 && $game.player.x<0
  421.       $game.way=self
  422.     elsif @horizontal and $game.player.x.between?(@x,@x+640) and (pos1=(@y==$game.map.data[:height]*480-32)) && $game.player.y>$game.map.data[:height]*480 || @y==0 && $game.player.y<0
  423.       $game.way=self
  424.     end
  425.   end
  426.  
  427.   def way
  428.     spec=(@target.class==String && @target.length==1 or @path)
  429.     old=[$game.map.data[:origin][0]+$game.player.x.to_i/640,$game.map.data[:origin][1]+$game.player.y.to_i/480] if spec
  430.     if !@horizontal
  431.       pos1=(@x==$game.map.data[:width]*640-32)
  432.       $game.map.music($save[:area]) if ['s','t'].include?($game.map.data[:id]) if !Song.current_song
  433.       $game.map.music($save[:area]) if $game.map.data[:id]=='!'
  434.       origin=$game.map.data[:origin][1]
  435.       last=$game.map.data[:id]
  436.       $game.reset(@target)
  437.       $game.player.y+=(origin-((spec && !@path || @target=='b') ? origin+$game.player.y.to_i/480 : $game.map.data[:origin][1]))*480
  438.       $game.player.x=(pos1 ? 0 : $game.map.data[:width]*640)
  439.       if @target=='s'
  440.         Save.new
  441.         $game.map.data[:origin][0]=old[0]
  442.         $game.map.data[:origin][1]=old[1]
  443.         Waypoint.new(pos1 ? 0 : 608,0,false,last)
  444.         2.times{|x| 4.times{|y| $game[Tile.new((pos1 ? 576 : 0)+x*32,192+y*32,'Castle',(x==0 ? 0 : 2)+[0,7,7,14][y])]}}
  445.       elsif @target=='t'
  446.         $game.map.data[:origin][0]=old[0]
  447.         $game.map.data[:origin][1]=old[1]
  448.         w=Waypoint.new(pos1 ? 0 : 608,0,false,last)
  449.         2.times{|x| 4.times{|y| $game[Tile.new((pos1 ? 576 : 0)+x*32,192+y*32,'Castle',(x==0 ? 0 : 2)+[0,7,7,14][y])]}}
  450.         $save[:warps] << [old[0],old[1],w.x,w.target,$save[:area]] if !$save[:dimension] and !$save[:warps].include?([old[0],old[1],w.x,w.target,$save[:area]])
  451.         Warp.new
  452.       elsif @target=='!'
  453.         $premusic=nil
  454.         Msc['Item Room'].play(true)
  455.         ESwitch.new([183,97,77,210,169].index(last))
  456.         $game.map.data[:origin][0]=old[0]
  457.         $game.map.data[:origin][1]=old[1]
  458.         Waypoint.new(pos1 ? 0 : 608,0,false,last)
  459.         2.times{|x| 3.times{|y| $game[Tile.new((pos1 ? 576 : 0)+x*32,224+y*32,'Castle',(x==0 ? 0 : 2)+[0,7,14][y])]}}
  460.       elsif @target=='b'
  461.         $game.map.data[:origin][0]=old[0]
  462.         $game.map.data[:origin][1]=old[1]
  463.         Waypoint.new(pos1 ? 0 : 608,0,false,last)
  464.         3.times{|y| $game[Tile.new(pos1 ? 608 : 0,288+y*32,'Castle',pos1 ? 25 : 27)]}
  465.         if !$save[:cores].include?(last) or $bossrush
  466.           Song.current_song.stop if Song.current_song
  467.           $premusic=nil
  468.           BossDoor.new(pos1 ? 0 : 608,288,true)
  469.           Core.new
  470.           Msc['Piercing Silence',true].play if $save[:cores].length<12 or $bossrush && $bossrush[4]<12
  471.           Song.current_song.stop if $save[:cores].length==12 and !$bossrush || $bossrush[4]==12
  472.         end
  473.         $save[:map].find{|room| !room.dimension==!$save[:dimension] and room.x==(old[0]+(pos1 ? -1 : 1))*10 and room.y==old[1]*10}.setwall(pos1 ? 1 : 3,2) if @path
  474.       else
  475.         $game.came=[$game.player.x,$game.player.y]
  476.         $game.map.music(3) if last=='b' and !Song.current_song
  477.         $save[:map].find{|room| !room.dimension==!$save[:dimension] and room.x==(old[0]+(pos1 ? -1 : 1))*10 and room.y==old[1]*10}.setwall(pos1 ? 1 : 3,2) if @path
  478.       end
  479.       if $save[:dimension] and !$save[:areas].include?(3)
  480.         $game.area=["Dimensional Distortion",120]
  481.         $save[:areas] << 3
  482.       end
  483.     elsif @horizontal
  484.       pos1=(@y==$game.map.data[:height]*480-32)
  485.       origin=$game.map.data[:origin][0]
  486.       last=$game.map.data[:id]
  487.       $game.reset(@target)
  488.       $game.player.x+=(origin-((spec and !@path) ? origin+$game.player.x.to_i/640 : $game.map.data[:origin][0]))*640
  489.       $game.player.y=(pos1 ? 0 : $game.map.data[:height]*480)
  490.       $game.came=[$game.player.x,$game.player.y]
  491.       $save[:map].find{|room| !room.dimension==!$save[:dimension] and room.x==old[0]*10 and room.y==(old[1]+(pos1 ? -1 : 1))*10}.setwall(pos1 ? 2 : 0,2) if @path
  492.     end
  493.     $game.way=nil
  494.     $game.screen
  495.   end
  496. end
  497.  
  498. class Background < Entity
  499.   def initialize(x,y,name)
  500.     @x,@y,@name=x,y,name
  501.   end
  502.  
  503.   def draw
  504.     Img["Back/#{@name}"].draw(@x,@y,1)
  505.   end
  506. end
  507.  
  508. class Tunnel < Entity
  509.   attr_reader :target,:dir,:id
  510.   def initialize(x,y,dir,target,id)
  511.     @x,@y,@dir,@target,@id=x,y,dir,target,id
  512.     init
  513.   end
  514.  
  515.   def update
  516.     if !$game.player.warping?(true) and !@warping and Keypress[@dir] and (@dir==:right && $game.player.x>@x && $game.player.x<@x+64 || @dir==:left && $game.player.x<@x+32 && $game.player.x>@x-64 and $game.player.y.between?(@y,@y+32)) || (@dir==:down && $game.player.y>@y && $game.player.y<@y+64 || @dir==:up && $game.player.y<@y+48 && $game.player.y>@y-64 and $game.player.x.between?(@x,@x+32))
  517.       Snd['Warp'].play
  518.       $game.player.warp(@dir)
  519.       @warping=true
  520.       $game.player.y=@y+24 if [:left,:right].include?(@dir)
  521.       $game.player.x=@x+16 if [:up,:down].include?(@dir)
  522.       $game.player.vx=$game.player.vy=0
  523.     elsif @warping and !$game.player.warping?
  524.       if @target=='c' and $game.map.data[:id] != 'c'
  525.         Song.current_song.stop
  526.         old=$game.map.data[:id]
  527.         orig=[$game.map.data[:origin][0]+$game.player.x.to_i/640,$game.map.data[:origin][1]+$game.player.y.to_i/480]
  528.         $premusic=nil
  529.         $game.reset('c')
  530.         Tunnel.new(128,240,:left,'c',@dir==:right ? old : @id)
  531.         Tunnel.new(480,240,:right,'c',@dir==:left ? old : @id)
  532.         exit=$game.entities[0].find{|ent| ent.class==Tunnel and ent.dir==[:up,:right,:left,:down][[:down,:left,:right,:up].index(@dir)]}
  533.         $game.player.x=(@dir==:right ? 128 : 512)
  534.         $game.player.y=exit.y+24
  535.         $game.map.data[:origin]=orig
  536.         orig[0]+=(@dir==:right ? 1 : -1)
  537.       elsif @target=='c'
  538.         $game.reset(@id)
  539.         exit=$game.entities[0].find{|ent| ent.class==Tunnel and ent.target=='c'}
  540.         $game.player.x=exit.x+(@dir==:left ? 32 : -16)
  541.         $game.player.y=exit.y+24
  542.         region={10=>1,9=>0,27=>4,25=>0,26=>0,28=>2,44=>5,43=>2,61=>4,60=>5,66=>4,67=>6,71=>7,70=>4,92=>9,91=>8,115=>7,116=>10,121=>1,120=>10,142=>12,141=>4,157=>9,156=>10,163=>13,162=>5,176=>14,175=>13,103=>0,211=>15}
  543.         $save[:area]=region[@id]
  544.         $game.map.music(region[@id])
  545.         if !$save[:areas].include?(region[@id])
  546.           $game.area=[areas[region[@id]],120]
  547.           $save[:areas] << region[@id]
  548.         end
  549.       else
  550.         ($game.reset(@target) ; @exit=true) if @target!=$game.map.data[:id]
  551.         exit=$game.entities[0].find{|ent| ent.class==Tunnel and ent.id==@id and ent != self}
  552.         $game.player.x=exit.x+[16,48,16,-16][[:up,:right,:down,:left].index(exit.dir)]
  553.         $game.player.y=exit.y+[-24,24,72,24][[:up,:right,:down,:left].index(exit.dir)]
  554.       end
  555.       Snd['Warp'].play
  556.       $game.player.warp([:up,:right,:left,:down][[:down,:left,:right,:up].index(exit.dir)],(@target=='c' or @exit))
  557.       @warping=@exit=nil
  558.     end
  559.   end
  560. end
  561.  
  562. class Water < Entity
  563.   def initialize(x,y,surface)
  564.     @x,@y,@surface=x,y,surface
  565.     $game.map.modify_mask(@x,@y+(@surface ? 16 : 0),:rect,[32,@surface ? 16 : 32,0xff0000ff])
  566.     init
  567.   end
  568.  
  569.   def draw
  570.     return if @x>$game.scx+640 or @x+32<$game.scx or @y>$game.scy+480 or @y+32<$game.scy
  571.     Tls["Objects/#{'Dark' if $save[:dimension]}Water",32,32][@surface ? $game.time/8%4 : 4].draw(@x,@y,2.05,1,1,0xc0ffffff)
  572.   end
  573. end
  574.  
  575. class RunningWater < Entity
  576.   def initialize(x,y,surface,speed)
  577.     @x,@y,@surface,@speed=x,y,surface,speed
  578.     $game.map.modify_mask(@x,@y+(@surface ? 16 : 0),:rect,[32,@surface ? 16 : 32,0xff0000ff])
  579.     init
  580.   end
  581.  
  582.   def draw
  583.     return if @x>$game.scx+640 or @x+32<$game.scx or @y>$game.scy+480 or @y+32<$game.scy
  584.     if $game.player.x.between?(@x-16,@x+48) and $game.player.y.between?(@y-20,@y+16)
  585.       $game.player.x+=@speed*0.5 if not @speed<0 && $game.player.left || @speed>0 && $game.player.right
  586.     end
  587.     if @surface
  588.       $screen.clip_to(@x,@y,32,32){2.times{|x|
  589.       Tls["Objects/RunningWater",32,32][$count/8%4].draw(@x+$count*@speed%32-x*32,@y,2.05,1,1,0xc0ffffff)}}
  590.     else
  591.       Tls["Objects/RunningWater",32,32][4].draw(@x,@y,2.05,1,1,0xc0ffffff)
  592.     end
  593.   end
  594. end
  595.  
  596. class Lava < Entity
  597.   def initialize(x,y,surface,over=nil)
  598.     @x,@y,@surface,@over=x,y,surface,over
  599.     $game.map.modify_mask(@x,@y+(@surface ? 16 : 0),:rect,[32,@surface ? 16 : 32,0xff0000ff],true)
  600.     init
  601.   end
  602.  
  603.   def draw
  604.       if !$game.gameover and !$game.player.inv and $game.player.x.between?(@x-16,@x+48) and $game.player.y.between?(@y-20,@y+16)
  605.         $save[:hp]-=1
  606.         if $count % 8 == 0
  607.           Snd["MarioDamage#{1+rand(5)}"].play
  608.           Snd['Fizz'].play
  609.           Info.new($game.player.x-7,$game.player.y-40,8,"Damage1")
  610.         end
  611.       end
  612.       Tls["Objects/Lava",32,32][@surface ? $count/8%4 : 4].draw(@x,@y,@over ? 2.5 : 2.05,1,1,0xf0ffffff)
  613.   end
  614. end
  615.  
  616. class Aback < Entity
  617.   def initialize(x,y,name)
  618.     @x,@y=x,y
  619.     name=Dir.entries('data/gfx/aback').find{|img| img.chop.chop.chop.chop.chop.chop==name}
  620.     return if !name
  621.     4.times{name.chop!}
  622.     @size=name.split('-')[1].to_i
  623.     @name='Aback/'+name
  624.     tile=Tls[@name,-@size,-1][0]
  625.     @width=tile.width
  626.     @height=tile.height
  627.     init
  628.   end
  629.  
  630.   def draw
  631.     return if @x>$game.scx+640 or @x+@width<$game.scx or @y>$game.scy+480 or @y+@height<$game.scy
  632.     Tls[@name,-@size,-1][$game.time/8% @size].draw(@x,@y,1)
  633.   end
  634. end
  635.  
  636. class Fall < Entity
  637.   def initialize(x,y)
  638.     @x,@y=x,y
  639.     @unstoppable=true
  640.     init
  641.   end
  642.  
  643.   def update
  644.     @player=[$game.player.x,$game.player.y] if !@player
  645.     @player=[$game.player.x,$game.player.y] if $game.player.down?
  646.     if $game.player.x.between?(@x,@x+640) and $game.player.y>$game.map.data[:height]*480+64
  647.       if ($save[:hp]-=$save[:max_hp]/8)>0
  648.         Snd['MarioDamage4'].play
  649.         $game.player.x=@player[0]
  650.         $game.player.y=@player[1]
  651.         $game.player.vx=$game.player.vy=0
  652.         $game.player.inv=60
  653.       end
  654.     end
  655.   end
  656.  
  657.   def draw
  658.     $screen.draw_quad(@x,@y,c=0x00000000,@x+640,@y,c,@x+640,@y+32,c=0xff000000,@x,@y+32,c,1)
  659.   end
  660. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement