Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Bonus < Entity
- def initialize(x,y,type,open=nil)
- return if $save[:bonus].include?([$game.map.data[:id],x,y])
- @x,@y,@type,@open=x,y,type,open
- @unstoppable=true
- init
- end
- def update
- gravity(32) if !$game.stopped
- 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
- Snd['Power Up'].play
- $game.powerup=[@type,400]
- case @type
- when 0
- $save[:max_hp]+=20
- $save[:hp]=$save[:max_hp]
- when 1
- $save[:max_mp]+=15
- $save[:mp]=$save[:max_mp]
- $save[:base_mp_regen]+=1
- $game.refresh_stats
- when 2
- $save[:max_stars]+=5
- $save[:stars]+=5
- end
- remove
- $save[:bonus] << [$game.map.data[:id],@x,@y] if !@open
- $game.entities[3].each{|ent| ent.open=true if ent.class==BossDoor} if @open
- end
- end
- def draw
- 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])
- (@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)
- end
- end
- class Item < Entity
- attr_writer :vy
- attr_reader :type,:id
- def initialize(x,y,type,id,out=0)
- @x,@y,@type,@id=x,y,type,id
- if type==:magic or type==:weapon or type==:suit
- return if $save[:items][type].include?(id) or $save[:equip][[:suit,:magic,:weapon].index(type)]==id
- Snd['Spelldrop'].play
- @fx=0
- $game.flash(0xffffffff,16)
- end
- @unstoppable=true
- @out=out
- init
- end
- def update
- gravity(32) if @out==0 and !$game.stopped
- @y+=(@out<=>0)
- @out-=(@out<=>0)
- 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
- Snd['Item'].play
- $game.item=$items[@type][@id][:name]
- $save[:items][@type] << @id
- remove
- end
- end
- def draw
- Img["Icons/#{@type}/#{@id}"].draw(@x,@y,1.5)
- if @fx
- 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)}
- @fx+=1
- end
- end
- end
- class Relic < Entity
- def initialize(x,y,id)
- @x,@y,@id=x,y,id
- @unstoppable=true
- @sprout=-32
- init
- end
- def update
- gravity(32)
- 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
- Snd['Save'].play
- $save[:relics][@id]=true
- @relic=0
- end
- @y-=1 if @sprout and (@sprout+=1)<0
- end
- def draw
- Img["Icons/Relics/#{@id}"].draw(@x,@y,1.5) if !@relic
- if @relic
- @relic+=1
- 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))
- 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))
- if @relic==360
- @remove
- end
- end
- end
- end
- class Save < Entity
- def initialize#(x,y)
- # @x,@y=x,y
- @x,@y=256,208
- @pow=0
- splice
- init(:powable)
- end
- def update
- @pow+=1 if @pow<0
- end
- def draw
- Img['Objects/Save'].draw(@x,@y+@pow,2)
- end
- def pow(x,y,width,pound)
- if x<@x+128 and x+width>@x and y<@y+70 and y>@y
- $save[:hp]=$save[:max_hp]
- $save[:mp]=$save[:max_mp]
- $save[:stars]=$save[:max_stars] if $save[:relics][8]
- $save[:status]='GOOD'
- wayp=$game.entities[0].find{|ent| ent.class==Waypoint}
- $save[:saved]=[wayp,$game.map.data]
- Snd['Save'].play
- @pow=-8
- File.delete("data/save#{$save[:id]}s") if $save[:session]
- $save[:session]=nil
- Marshal.dump($save,f=File.open("data/save#{$save[:id]}",'w'))
- f.close
- $game.save=0
- end
- end
- def splice
- $game.map.modify_mask(@x,@y,:splice,'objects/save-mask')
- end
- end
- class BonusBlock < Entity
- def initialize(x,y,type,id,sealed=nil)
- @x,@y,@type,@id,@sealed=x,y,type,id,sealed
- @pow=0
- $game.map.modify_mask(@x,@y,:rect,[31,31,0xff000000])
- @sprouted=true if $save[:bonus].include?([$game.map.data[:id],@x,@y])
- @sealed=nil if @sealed and !@sprouted and $save[:bonus].include?([$game.map.data[:id],@x,@y,:unsealed])
- @unstoppable=true
- init(:powable)
- end
- def update
- @pow-=(@pow<=>0)*0.5 if @pow !=0
- if @item and $game.missing(@item)
- @item=nil
- $save[:bonus] << [$game.map.data[:id],@x,@y]
- $save[:bonus].delete [$game.map.data[:id],@x,@y,:unsealed]
- end
- 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)
- @unseal=0
- elsif @unseal and (@unseal<=60)
- @unseal+=1
- @unseal=nil if not $game.player.x.between?(@x-8,@x+40) && $game.player.y.between?(@y-64,@y)
- elsif @unseal
- Snd['Star'].play
- $save[:items][:misc].delete_at($save[:items][:misc].index(5))
- $save[:bonus] << [$game.map.data[:id],@x,@y,:unsealed]
- @sealed=@unseal=nil
- end
- end
- def draw
- Tls['Objects/BonusBlock',32,32][@sprouted ? 4 : $count/8%4+(@sealed ? 5 : 0)].draw(@x,@y+@pow,2)
- end
- def pow(x,y,width,pound)
- if !@sprouted and x<@x+32 and x+width>@x and y<@y+70 and y>@y
- @pow=((pound && pound!=:spin) ? 8 : -8)
- return Snd['Sys4'].play if @sealed
- Snd['Sprout'].play
- @sprouted=true
- @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))
- end
- end
- end
- class Warp < Entity
- def initialize
- @x,@y=288,240
- @select=$game.map.data[:origin]
- @map=$screen.record(640,480){$save[:map].each{|room| room.draw(1)}}
- init
- end
- def update
- 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
- Snd['Sys5'].play
- @warping=true
- $game.player.x=@x+32
- $game.player.vx=0
- $game.player.ignore=true
- elsif @warping
- sel=[]
- $save[:warps].delete_if{|wrp| wrp[0]==19}
- if Keypress[:right,false]
- $save[:warps].each{|warp| sel << warp[0] if warp[0]>@select[0]}
- if !sel.empty?
- Snd['Sys1'].play
- @select=$save[:warps].find{|wrps| wrps[0]==sel.min} if !sel.empty?
- else
- Snd['Sys4'].play
- end
- end
- if Keypress[:left,false]
- $save[:warps].each{|warp| sel << warp[0] if warp[0]<@select[0]}
- if !sel.empty?
- Snd['Sys1'].play
- @select=$save[:warps].find{|wrps| wrps[0]==sel.max} if !sel.empty?
- else
- Snd['Sys4'].play
- end
- end
- if Keypress[:down,false]
- $save[:warps].each{|warp| sel << warp[1] if warp[1]>@select[1]}
- if !sel.empty?
- Snd['Sys1'].play
- @select=$save[:warps].find{|wrps| wrps[1]==sel.min}
- else
- Snd['Sys4'].play
- end
- end
- if Keypress[:up,false]
- $save[:warps].each{|warp| sel << warp[1] if warp[1]<@select[1]}
- if !sel.empty?
- Snd['Sys1'].play
- @select=$save[:warps].find{|wrps| wrps[1]==sel.max} if !sel.empty?
- else
- Snd['Sys4'].play
- end
- end
- if Keypress[:jump,false] and !@warpfx and @select[(0..1)] != $game.map.data[:origin]
- Snd['Sys2'].play
- @warpfx=0
- @warping=nil
- Snd['Warp Charge'].play
- elsif Keypress[:jump,false] and !@warpfx
- Snd['Sys4'].play
- end
- $game.player.ignore=@warping=nil if Keypress[:shoot,false]
- end
- 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
- @distortfx=0
- $game.player.ignore=$distorting=true
- Snd['Distort'].play
- end
- end
- def draw
- if @warping
- Img['System/Menu1'].draw(0,0,4,1,1,0xc0000000)
- @map.draw(0,0,4)
- area=$save[:warps].find{|warp| warp[0]==@select[0] and warp[1]==@select[1]}
- Fnt[['System/Font',20,20]].draw(areas[area[4]],320,20,4,:align=>:center) if area
- Img['System/Select'].draw_rot(@select[0]*10+5,@select[1]*10+5,4,$count*4)
- end
- if @warpfx
- @warpfx+=1
- if @warpfx<120
- (@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))}
- Img['Effects/Warp FX2'].draw_rot(@x+32,@y+16,3,$count*8,0.5,0.5,1,1,0x80ffffff) if @warpfx>100
- elsif @warpfx==120
- Snd['Teleport'].play
- $game.player.warp(:down)
- $game.player.y+=12
- elsif @warpfx<152
- Img['Effects/Warp FX2'].draw_rot(@x+32,@y+16,3,$count*8,0.5,0.5,1,1,0x80ffffff)
- elsif @warpfx==152
- $game.reset('t')
- sel=$save[:warps].find{|warp| warp[0]==@select[0] and warp[1]==@select[1]}
- Warp.new.exit(sel[0],sel[1])
- Waypoint.new(sel[2],0,false,sel[3])
- 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])]}}
- $premusic=nil
- Song.current_song.stop if Song.current_song
- $save[:warps][0][2]=0
- $save[:area]=@select[4]
- $game.flash(0xffffffff,8)
- end
- end
- if @distortfx
- @distortfx+=1
- if @distortfx<240
- 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)
- $game.flash(0xff000000,16) if rand(@distortfx)==0
- else
- Song.current_song.stop if Song.current_song
- $premusic=nil
- orig=$game.map.data[:origin]
- area=($save[:dimension] ? $save[:dimension] : $save[:area])
- $save[:dimension]=($save[:dimension] ? false : $save[:area])
- way=$game.entities[0].find{|ent| ent.class==Waypoint}
- way.x=(way.x==0 ? 608 : 0) if area==10
- $game.reset('t')
- 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}
- Waypoint.new(way.x,0,false,$save[:dimension] ? translate[way.target] : translate.key(way.target.to_i))
- 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])]}}
- $game.map.data[:origin]=orig
- Warp.new.distort
- if $save[:dimension]
- $save[:area]=3
- else
- $save[:area]=$save[:warps].find{|warp| warp[0]==orig[0] and warp[1]==orig[1]}[4]
- end
- end
- end
- if @exit
- @exit+=1
- if @exit<60
- (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))}
- 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))
- else
- $game.player.y-=20
- Snd['Jump3'].play
- $game.player.vy=-20
- @exit=$game.player.ignore=nil
- end
- end
- if @leave
- @leave+=1
- if @leave<60
- 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)
- else
- @leave=$game.player.ignore=$distorting=nil
- end
- end
- end
- def exit(x,y)
- Snd['Warp Shot'].play
- @exit=0
- $game.map.data[:origin]=@select=[x,y]
- end
- def distort
- @leave=0
- end
- end
- class BossDoor < Entity
- attr_writer :open
- def initialize(x,y,fall=nil)
- @x,@y,@fall=x,y,fall
- @y2=@y
- @y-=96 if @fall
- @unstoppable=true
- init(:solid)
- end
- def update
- @fall=nil if @open
- if $game.player.x.between?(@x-64,@x+96) and $game.player.y.between?(@y2-16,@y2+112) && !@fall or @open
- Snd['Bossdoor'].play if @y==@y2
- @y-=2 if @y>@y2-96
- else
- Snd['Bossdoor'].play if @y==@y2-96
- @y+=2 if @y<@y2
- end
- $game.player.vx=(@x==0 ? 4 : -4) if @fall and @y<@y2-72 and $game.player.x.between?(@x-16,@x+48)
- end
- def draw
- Img["Objects/#{$save[:dimension] ? 'Chaos' : 'Boss'} Door"].draw(@x,@y,1.9)
- end
- def check(x,y,down);x.between?(@x,@x+31) and y.between?(@y,@y+96);end
- end
- class Spawner < Entity
- def initialize(x,y,max,delay,spawns,previous=[])
- @x,@y,@max,@delay,@spawns,@previous=x,y,max,delay,spawns,previous
- @enemies=[]
- @time=0
- init
- end
- def update
- return if @previous.find{|prev| !$game.missing(prev)}
- @enemies.delete_if{|enemy| $game.missing(enemy) and @time=@delay}
- @time-=1
- if @time<=0 and @spawns.length>0 and @enemies.length<@max
- enemy=case @spawns[0]
- when :goomba
- Goomba.new(@x,@y,@x>$game.player.x ? :left : :right)
- when :gktroopa
- GKTroopa.new(@x,@y,@x>$game.player.x ? :left : :right)
- when :spiny
- Spiny.new(@x,@y,@x>$game.player.x ? :left : :right)
- when "iplant0","iplant1","iplant2","iplant3"
- IPlant.new(@x,@y,@spawns[0].reverse.to_i)
- when "mplant0","mplant1","mplant2","mplant3"
- MPlant.new(@x,@y,@spawns[0].reverse.to_i)
- when "hplant0","hplant1","hplant2","hplant3"
- MechaP.new(@x,@y,@spawns[0].reverse.to_i)
- when "venus0","venus1","venus2","venus3"
- id=@spawns[0].reverse.to_i
- VenusFT.new(@x+[0,-16,0,0][id],@y,id)
- when :vspiny
- VenomSpiny.new(@x,@y,@x>$game.player.x ? :left : :right)
- when :sniper
- SniperKoopa.new(@x,@y,@x+16>$game.player.x ? :left : :right)
- end
- @enemies<<enemy
- enemy.active=true
- @spawns.shift
- @time=@delay
- end
- remove if @enemies.empty? and @spawns.empty?
- end
- end
- class QSwitch < Entity
- def initialize(x,y,event,action,tiles)
- @x,@y,@event,@action,@tiles=x,y,event,action,tiles
- @affects=[]
- @pressed=true if $save[:events][event]
- if !@action && !@pressed or @action && @pressed
- @tiles.each{|tile| t=Tile.new(*tile) ; $game[t] ; @affects<<t
- Trail.new(tile[0]-4,tile[1]-4,3,['Effects/Qsw',40,40],(0..7).to_a,4)}
- end
- init
- end
- def update
- if !@pressed and $game.player.vy>0 and $game.player.x.between?(@x,@x+32) and $game.player.y.between?(@y-24,@y)
- Snd['Switch'].play
- press
- end
- end
- def draw
- Tls['Objects/QSwitch',24,24][@pressed ? 1 : 0].draw(@x+4,@y+8,0)
- end
- def press
- @pressed=true
- $save[:events][@event]=true
- if @action
- @tiles.each{|tile| $game[Tile.new(*tile)]
- Trail.new(tile[0]-4,tile[1]-4,3,['Effects/Qsw',40,40],(0..7).to_a,4)}
- else
- @affects.each{|affect| affect.unsplice ; affect.remove
- Trail.new(affect.x-4,affect.y-4,3,['Effects/Qsw',40,40],(0..7).to_a,4)}
- end
- end
- end
- class NPC < Entity
- def initialize(x,y,name)
- @x,@y,@name=x,y,name
- init
- end
- def update
- if $game.player.x.between?(@x+16,@x+48) and Keypress[:up]
- $game.shop!
- end
- end
- def draw
- Img["Objects/#{@name}"].draw(@x,@y,1)
- end
- end
- class Breakable < Entity
- def initialize(x,y,skin)
- @x,@y,@skin=x,y,skin
- @life=5
- @broken=$save[:brekables].include?([$game.map.data[:id],$save[:dimension]])
- init(:solid,:hittable,:powable)
- end
- def draw
- @damaged=nil if @damaged and (@damaged-=1)==0
- if @life<=0 and !@broken
- $save[:brekables]<<[$game.map.data[:id],$save[:dimension]]
- @broken=true
- @damaged=nil
- Snd['Bricks'].play
- end
- img[@broken ? 5 : 4-(@life-1)].draw(@x+(@damaged ? -4+rand(9) : 0),@y+(@damaged ? -4+rand(9) : 0),2.1)
- xs=[0,-269,img[0].width+16,0,0,-269,0,-269]
- ys=[-158,0,0,-158,img[0].height+16,0,img[0].height+16,0]
- imgs=[0,3,2,0,1,3,1,3]
- 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
- end
- def img;Tls["Objects/Breakable#{@skin+1}",-1,-6];end
- def check(x,y,down);!@broken and x.between?(@x,@x+img[0].width) and y.between?(@y,@y+img[0].height);end
- def kill(x,y,sizex,sizey,attack,element,id)
- return if @broken
- if element==0 and x+sizex>@x and x<@x+img[0].width and y+sizey>@y-8 and y<@y+img[0].height
- Snd['Stone'].play
- @life-=1
- @damaged=30
- end
- end
- def pow(x,y,width,pound)
- return if @broken
- if pound and x<@x+img[0].width and x+width>@x and y<@y+img[0].height and y>@y
- Snd['Stone'].play
- @life-=2
- @damaged=30
- end
- end
- end
- class Coin < Entity
- def initialize(x,y,size)
- @x,@y,@size=x,y,size
- @unstoppable=true
- init
- end
- def update
- gravity(img.width,img.height) if !$game.stopped
- 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
- Snd['Coin'].play
- value=[1,2,5,50,100,250,500,1000,2000][@size]
- $save[:coins]+=value
- $game.item="#{value} coin#{'s' if value>1}"
- remove
- end
- end
- def draw
- img.draw(@x,@y,2)
- end
- 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
- end
- class Gate < Entity
- def initialize(fallen=nil)
- @x,@y,@fallen=160,(fallen ? 1088 : 864),fallen
- if !fallen
- Snd['Gate'].play
- $game.player.vx=-2
- $game.player.ignore=true
- end
- init(:solid)
- end
- def update
- if !@fallen and @y<1088
- @y+=2
- elsif !@fallen
- @mess=Message.new('Mario','Mario',"Great! Now I can't go^back.")
- @fallen=true
- end
- $game.player.ignore=nil if @mess and @mess.closed
- end
- def draw
- Img['Objects/Gate'].draw(@x,@y,2)
- end
- def check(x,y,down);x.between?(@x,@x+64) and y.between?(@y,@y+224);end
- end
- class Destructible < Entity
- def initialize(x,y,name,contain)
- @x,@y,@contain=x,y,contain
- name=Dir.entries('data/gfx/objects').find{|img| img.include?("Destr#{name}")}.chomp('.png')
- @size=name.split('-')[1].to_i
- @imgs=Tls['Objects/'+name,-@size,-1]
- init(:hittable,:stompable)
- end
- def draw
- @imgs[$game.time/8% @size].draw(@x,@y,1.1)
- end
- def kill(x,y,sizex,sizey,attack,element,id)
- if x+sizex>@x and x<@x+@imgs[0].width and y+sizey>@y-8 and y<@y+@imgs[0].height
- destroy
- end
- end
- def stomp(x,y,pound)
- if x+12>@x and x-12<@x+@imgs[0].width and y+24>@y-8 and y-40<@y+@imgs[0].height
- $game.player.bounce
- destroy
- end
- end
- def destroy
- return if @removed
- Snd['Destruct'].play
- w=@imgs[0].width/2 ; h=@imgs[0].height/2
- Particle.new(@x,@y,3,@imgs[0].subimage(0,0,w,h),-rand(6),-8)
- Particle.new(@x+w,@y,3,@imgs[0].subimage(w,0,w,h),rand(6),-8)
- Particle.new(@x,@y+h,3,@imgs[0].subimage(0,h,w,h),-rand(6),-8)
- Particle.new(@x+w,@y+h,3,@imgs[0].subimage(w,h,w,h),rand(6),-8)
- remove
- if [$save[:equip][6],$save[:equip][7]].include?(13) and rand(10)==0
- Item.new(@x+w-16,@y+@imgs[0].height-32,:usable,1)
- else
- if @contain<2
- Star.new(@x+w-16,@y+@imgs[0].height-32,@contain==1)
- else
- 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)
- end
- end
- end
- end
- class Star < Entity
- def initialize(x,y,big)
- @x,@y,@big=x,y,big
- @unstoppable=true
- init
- end
- def update
- gravity(32) if !$game.stopped
- 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
- Snd['Star'].play
- remove
- $save[:stars]=[$save[:stars]+(@big ? 8 : 2),$save[:max_stars]].min
- end
- end
- def draw
- Tls['Objects/Star',32,32][@big ? 1 : 0].draw(@x,@y,2)
- end
- end
- class Switchable < Entity
- def initialize(x,y,off,type)
- @x,@y,@off,@type=x,y,off,type
- @off=!@off if $save["Switch#{type}"]
- $game.map.modify_mask(@x,@y,:rect,[31,31,0xff000000]) if !@off
- init
- end
- def draw
- color=[Color::RED,Color::GREEN,Color::BLUE,Color::YELLOW,Color::BLACK][@type]
- if @off
- Tls["Objects/!-Block",32,32][0].draw(@x,@y,2.1,1,1,color)
- else
- Tls["Objects/!-Block",32,32][1].draw(@x,@y,2.1,1,1,color)
- Tls["Objects/!-Block",32,32][2].draw(@x,@y,2.1)
- end
- end
- end
- class Guide < Entity
- def initialize(x,y,id)
- @x,@y,@id=x,y,id
- @pow=0
- $game.map.modify_mask(@x,@y,:rect,[31,31,0xff000000])
- init(:powable)
- end
- def draw
- Img['Objects/Guide'].draw(@x,@y+@pow,2)
- @pow+=0.5 if @pow<0
- end
- def pow(x,y,width,pound)
- if x<@x+32 and x+width>@x and y<@y+32 and y>@y
- Snd['Guide'].play
- @pow=-8
- $save[:guides][@id]=true
- ($guides[@id].length-1).times{|id| Message.new($guides[@id][0],"Guide",$guides[@id][1+id],true)}
- end
- end
- end
- class Ice < Entity
- def initialize(x,y)
- @x,@y=x,y
- $game.map.modify_mask(@x,@y,:rect,[31,31,0xff000000])
- init(:hittable)
- end
- def update
- end
- def draw
- Img['Objects/Ice'].draw(@x,@y,2)
- end
- def kill(x,y,sizex,sizey,attack,element,id)
- if element==3 and x+sizex>@x-8 and x<@x+40 and y+sizey>@y-8 and y<@y+40
- Snd['Fizz'].play
- Trail.new(@x+5,@y+5,2.1,['Effects/Smoke',22,22],(0..7).to_a,4,:movey=>-0.25)
- $game.map.modify_mask(@x,@y,:rect,[31,31,0xffffffff])
- remove
- true
- end
- end
- end
- class RelicBox < Entity
- def initialize(x,y,id)
- @x,@y,@id=x,y,id
- @pow=0
- $game.map.modify_mask(@x,@y,:rect,[64,64,0xff000000])
- $game.map.modify_mask(@x+32,@y,:rect,[32,64,0xff000000])
- @sprouted=true if $save[:relics][@id]!=nil or $save[:bonus].include?([$game.map.data[:id],@x,@y])
- init(:powable)
- end
- def update
- @pow+=0.5 if @pow<0
- if @item and $game.missing(@item)
- @item=nil
- $save[:bonus] << [$game.map.data[:id],@x,@y]
- end
- end
- def draw
- Tls["Objects/#{@id==12 ? 'Blood' : 'Relic'} Box",64,64][@sprouted ? 4 : $count/8%4].draw(@x,@y+@pow,2)
- if @id==12
- Fnt[['System/Font',20,20]].draw("#{$save[:allkills]}/5000",@x+32,@y+72,3,:align=>:center)
- end
- end
- def pow(x,y,width,pound)
- if x<@x+64 and x+width>@x and y<@y+102 and y>@y and !@sprouted
- @pow=-8
- return Snd['Sys4'].play if @id==12 and $save[:allkills]<5000
- Snd['Sprout Relic'].play
- @sprouted=true
- if @id==12
- @item=Item.new(@x+16,@y,:magic,14,-32)
- else
- @item=Relic.new(@x+16,@y,@id)
- end
- end
- end
- end
- class Bricks < Entity
- def initialize(x,y,coins)
- @x,@y,@coins=x,y,coins
- @pow=0
- $game.map.modify_mask(@x,@y,:rect,[31,31,0xff000000])
- init(:powable)
- end
- def update
- @pow+=0.5 if @pow<0
- end
- def draw
- Tls['Objects/Bricks',32,32][@coins==0 ? 1 : 0].draw(@x,@y+@pow,2)
- end
- def pow(x,y,width,pound)
- if x<@x+32 and x+width>@x and y<@y+70 and y>@y and @coins !=0
- if @coins
- Snd['Coin'].play
- $save[:coins]+=1
- @coins-=1
- @pow=-8
- Trail.new(@x+6,@y,1,['Objects/Coin1',20,32],[0,1,2,3],2,:movey=>-4)
- else
- Snd['Bricks'].play
- remove
- $game.map.modify_mask(@x,@y,:rect,[31,31,0xffffffff])
- $game.player.pound! if pound and pound!=:spin
- 8.times{Particle.new(@x+rand(16),@y+rand(20),3,'Effects/Brick',vx=-6+rand(13),-6-rand(7),:rotate=>vx)}
- end
- end
- end
- end
- class ESwitch < Entity
- def initialize(id)
- @x,@y,@id=288,352,id
- @pressed=true if $save["Switch#{id}"]
- $game.area=["#{['Red','Green','Blue','Yellow','Black'][@id]} Switch Chamber",120] if !@pressed
- init
- end
- def update
- if !@pressed and $game.player.vy>0 and $game.player.x.between?(@x,@x+64) and $game.player.y.between?(@y-24,@y)
- Snd['!Switch'].play
- @pressed=true
- $save["Switch#{@id}"]=true
- Message.new('Info','Guide',"#{['Red','Green','Blue','Yellow','Black'][@id]} Switch has been pressed!^All blocks with this color will^open new paths.")
- $game.player.bounce
- end
- end
- def draw
- 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])
- Tls['Objects/!-Switch',64,64][@pressed ? 3 : 2].draw(@x,@y,1)
- end
- end
- class Belt < Entity
- def initialize(x,y,part,left)
- @x,@y,@part,@left=x,y,part,left
- # $game.map.modify_mask(x,y,:rect,[31,31,0xff000000])
- $game.map.modify_mask(x,y,:splice,["System/Mask",32,32,0])
- init
- end
- def update
- if $game.player.down? and $game.player.x.between?(@x-16,@x+48) and $game.player.y.between?(@y-32,@y-16)
- $game.player.x+=(@left ? -2 : 2) if not @left && $game.player.left || !@left && $game.player.right
- end
- $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}
- $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}
- end
- def draw
- Tls['Objects/Conveyor Belt',32,32][@part+(@left ? 3-$game.time/2%4 : $game.time/2%4)*3].draw(@x,@y,2)
- end
- end
- class CapeTri < Entity
- def initialize(x,y,right)
- @x,@y,@right=x,y,right
- init
- $game.map.modify_mask(@x,@y,:splice,["Objects/CapeTri-mask",32,32,@right ? 1 : 0])
- @unstoppable=true
- @vx=0
- end
- def update
- @vx=$game.player.vx.abs if $game.player.vx.to_i != 0
- 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
- Snd['Cape'].play
- $game.player.wall=(@right ? :right : :left)
- $game.player.vy=-@vx
- end
- end
- def draw
- Img['Objects/CapeTri'].draw(@x+(@right ? 32 : 0),@y,2,(@right ? -1 : 1))
- end
- end
- class Crate < Entity
- attr_accessor :moved
- attr_reader :size
- def initialize(x,y,size)
- @x,@y,@size=x,y,size
- @pound=true
- init(:solid)
- end
- def update
- @solid=@moved=nil
- gravity(@size*32,@size*32,1,false)
- @solid=true
- Snd['Pound'].play if @vy==0 and !@pound
- @pound=true if @vy==0
- @pound=nil if @vy!=0
- remove if @y>$game.map.data[:height]*480
- return if $game.gameover
- 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
- if !$game.player.inv and $game.player.x.between?(@x,@x+@size*32) and $game.player.y.between?(@y,@y+@size*32)
- $game.player.reset
- Snd["MarioDamage#{1+rand(5)}"].play
- damage=@size*75
- $save[:hp]-=damage
- Info.new($game.player.x-damage.to_s.length*7,$game.player.y-40,damage,"Damage1")
- $game.player.vx=12*($game.player.x<@x+@size*16 ? -1 : 1)
- end
- end
- def draw
- Img['Objects/Crate'].draw(@x,@y,2,@size*0.25,@size*0.25)
- end
- def check(x,y,down);@solid and x.between?(@x,@x+@size*32-1) and y.between?(@y,@y+@size*32-1);end
- end
- class Cog < Entity
- def initialize(x,y,type,inverted)
- @x,@y,@type,@reversed=x,y,type,inverted
- init(:solid)
- end
- def update
- 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])
- # $game.player.x+=(@left ? -2 : 2) if not @left && $game.player.left || !@left && $game.player.right
- $game.player.vx+=(@reversed ? -1 : 1)# if not @left && $game.player.left || !@left && $game.player.right
- end
- end
- def draw
- case @type
- when 0,2
- Img["Objects/Cog#{@type+1}"].draw_rot(@x+127,@y+129,1.3,@reversed ? -$game.time : $game.time)
- when 1,3
- Tls["Objects/Cog#{@type+1}",128,32][@reversed ? 5-$game.time/4%6 : $game.time/4%6].draw(@x,@y,2)
- end
- end
- def check(x,y,down);case @type
- when 0,2
- 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)
- when 1,3
- x.between?(@x,@x+127) and y.between?(@y,@y+31)
- end
- end
- end
- class Spikes < Enemy
- attr_reader :harmless
- def initialize(x,y,dir,supp=nil)
- @x,@y,@dir,@super=x,y,dir,supp
- @attack=(supp ? 500+$save[:level]*2 : [$save[:max_hp]/8,$save[:defence]+20].max)
- @element=1
- @setinv=(supp ? 15 : 60)
- @immortal=true
- @omnir=@super
- @unstoppable=true
- init(:enemy)
- end
- def action
- if @attacked and $save[:equip][0]==2
- Snd['BlasterCrash'].play
- Particle.new(@x,@y,3,"Objects/#{'super' if @super}Spikes",vx=-8+rand(17),-6-rand(7),:angle=>0,:rotate=>vx*4,:unstop=>true)
- @harmless=rand(4)
- end
- end
- def draw
- (@harmless ? Tls['Objects/Wreck',32][@harmless] : Img["Objects/#{'super' if @super}Spikes"]).draw_rot(@x+16,@y+16,2,@dir*90)
- end
- def size;[32,32];end
- end
- class Pendulum < Entity
- def initialize(x,y,phase)
- @x,@y=x,y
- @time=(phase ? 90 : 0)
- init(:solid)
- end
- def update
- offx=offset_x(-45+(@time%180-90).abs,160)
- offy=offset_y(-45+(@time%180-90).abs,128)
- @time+=1
- if @player
- $game.player.x+=offx-offset_x(-45+(@time%180-90).abs,160)
- $game.player.y+=offy-offset_y(-45+(@time%180-90).abs,128)
- @player=nil
- end
- end
- def draw
- angle=-45+(@time%180-90).abs
- Tls['Objects/Pendulum',64,214][0].draw_rot(@x,@y,2,0,0.5,0)
- Tls['Objects/Pendulum',64,214][1].draw_rot(@x,@y+32,1,angle,0.5,0)
- Tls['Objects/Pendulum',64,214][2].draw(@x-32-offset_x(angle,160),@y-112-offset_y(angle,128),2)
- end
- def check(x,y,down)
- angle=-45+(@time%180-90).abs
- 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))
- @player=true if $down==$game.player
- true
- end
- end
- end
- class Portal < Entity
- def initialize(x,y,target,area)
- @x,@y,@target,@area=x,y,target,area
- init
- end
- def update
- if !@portal and distance($game.player.x,$game.player.y,@x+64,@y+64)<64
- Snd['Portal'].play
- $game.player.portal(@x+64,@y+64)
- @portal=0
- end
- if @portal
- @portal+=1
- Snd['Portal FX'].play if @portal==60
- $game.flash(0xffffffff,16) if @portal>60 and @portal%15==0
- if @portal==180
- Snd['Portal FX'].play
- $save[:dimension]=false
- $game.reset(@target)
- $save[:area]=@area
- $game.map.music(@area)
- $game.came=[$game.player.x,$game.player.y]
- init
- end
- if @portal==240
- remove
- $game.player.deportal
- end
- end
- end
- def draw
- scale=((@portal and @portal>180) ? 240.0/(@portal*2+60) : 1)
- Img['Objects/Portal'].draw_rot(@x+64,@y+64,1,rand(360),0.5,0.5,scale,scale)
- end
- end
- class QuickSave < Entity
- def initialize(x,y)
- save=Marshal.load(f=File.open("data/save#{$save[:id]}",'r'))
- f.close
- @obsolete=true if save[:session] and save[:session][1][:id]==$game.map.data[:id]
- @x,@y=x,y
- @pow=0
- splice if !@obsolete
- init(:powable)
- end
- def update
- remove if @obsolete
- @pow+=1 if @pow<0
- end
- def draw
- Img['Objects/Quicksave'].draw(@x,@y,2)
- end
- def pow(x,y,width,pound)
- if x<@x+64 and x+width>@x and y<@y+70 and y>@y
- Snd['Save'].play
- save=Marshal.load(f=File.open("data/save#{$save[:id]}",'r'))
- f.close
- save[:session]=[$game.came]+[$game.map.data]+[true]
- Marshal.dump(save,f=File.open("data/save#{$save[:id]}",'w'))
- f.close
- Marshal.dump($save,f=File.open("data/save#{$save[:id]}s",'w'))
- f.close
- remove
- $game.map.modify_mask(@x,@y,:splice,'Objects/Quicksave-demask')
- $game.save=0
- end
- end
- def splice
- $game.map.modify_mask(@x,@y,:splice,'Objects/Quicksave-mask')
- end
- def tp
- $game.player.x=x+32
- $game.player.y=y+96
- end
- end
- class TheDoor < Entity
- attr_writer :open
- def initialize(x,y)
- @x,@y=x,y
- init(:solid)
- end
- def update
- 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)
- @openning=1
- Snd['Door'].play
- elsif @openning
- @openning+=1
- @open=true if @openning==24
- end
- end
- def draw
- Tls["Objects/The Door",32,64][@open ? 4 : @openning ? 1+@openning/8 : 0].draw(@x,@y,1)
- end
- def check(x,y,down);!@openning and x.between?(@x,@x+31) and y.between?(@y,@y+63);end
- end
- class Sprite < Entity
- attr_writer :angle
- def initialize(x,y,gfx,w,h,top=false)
- @x,@y,@gfx,@width,@height,@top=x,y,gfx,w,h,top
- @time=@frame=0
- init
- end
- def update
- @time+=1
- if @animation and @time% @delay==0
- @sequence+=1
- @sequence=0 if @sequence==@animation.length
- @frame=@animation[@sequence]
- end
- end
- def draw
- if @angle
- Tls[@gfx, @width, @height][@frame].draw_rot(@x, @y, 1.4, @angle, @mirror_x ? -1 : 1)
- else
- Tls[@gfx, @width, @height][@frame].draw(@x + (@mirror_x ? @width : 0), @y, @top ? 2.3 : 1.4, @mirror_x ? -1 : 1)
- end
- end
- def animation(delay,*sequence)
- @time=@sequence=0
- @delay=delay
- @animation=sequence
- @frame=@animation.first
- end
- def mirror_x
- @mirror_x=!@mirror_x
- end
- def frame=(value)
- @frame=value
- @animation=nil
- end
- end
- class Donut < Entity
- def initialize(x,y)
- @x,@y=x,y
- @y1=y
- @stand=0
- init(:solid)
- end
- def update
- @stand-=1 if @stand>0
- @fall=true if @stand>90
- @y+=8 if @fall
- if @y>$game.scy+480 and !@invisible
- @fall=nil
- @invisible=300
- elsif @invisible
- @stand=0
- @invisible-=1
- if @invisible==0
- @invisible=nil
- @y=@y1
- end
- end
- end
- def draw
- v=((@stand>0 and !@fall) ? -2+rand(5) : 0)
- Img["Objects/Donut"].draw(@x+v,@y+v,2)
- end
- def check(x,y,down)
- if !@invisible and down and x.between?(@x,@x+31) and y==@y
- @stand+=2
- end
- end
- end
Add Comment
Please, Sign In to add comment