Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Keypress
- def Keypress.[](id,repeat=true)
- @@keys = [] unless defined?(@@keys)
- key=(id.class==Symbol ? $config[1][id] : id)
- if repeat
- $screen.button_down?(key)
- elsif !$pressing[0].include?(key) and $screen.button_down?(key)
- $pressing[1] << key
- return true
- end
- end
- end
- class Img
- def Img.[](name,tileable=false)
- @@images = Hash.new unless defined?(@@images)
- if @@images[name.downcase]
- @@images[name.downcase]
- else
- dir=((Dir.exists?(file="data/gfx/#{name.downcase.split('/')[0]}") or File.exists?(file+'.png')) ? '/gfx' : '')
- @@images[name.downcase] = Image.new($screen, "data#{dir}/#{name.downcase}.png", tileable)
- end
- end
- def Img.reset
- @@images.clear
- end
- end
- class Tls
- def Tls.[](name,width,height=width,tileable=false)
- size=[width,height]
- @@tiles = Hash.new unless defined?(@@tiles)
- if @@tiles[[name.downcase,size]]
- @@tiles[[name.downcase,size]]
- else
- @@tiles[[name.downcase,size]] = Image.load_tiles($screen, Img[name], width, height, tileable)
- end
- end
- def Tls.reset
- @@tiles.clear
- end
- end
- def Sub
- def Sub.[](name,srcx,srcy,w,h)
- if name.class==String
- img=Img[name]
- else
- img=Tls[name[0],name[1],name[2]]
- end
- img.subimage(srcx,srcy,w,h)
- end
- end
- class Snd
- def Snd.[](name)
- @@sounds = Hash.new unless defined?(@@sounds)
- if @@sounds[name.downcase]
- @@sounds[name.downcase]
- else
- dir=((Dir.exists?(file="data/sfx/#{name.downcase.split('/')[0]}") or File.exists?(file+'.ogg')) ? '/sfx' : '')
- @@sounds[name.downcase] = Sample.new($screen, "data#{dir}/#{name.downcase}.ogg")
- end
- end
- def Snd.reset
- @@sounds.clear
- end
- end
- class Msc
- def Msc.[](name,pre=nil)
- @@music = Hash.new unless defined?(@@music)
- if pre==:auto
- dir=((Dir.exists?(file="data/music/#{name.split('/')[0]}") or File.exists?(file+'.ogg')) ? '/music' : '')
- pre=File.exists?("data#{dir}/#{name.downcase}-pre.ogg")
- end
- name+='-pre' if pre
- if !@@music[name.downcase]
- dir=((Dir.exists?(file="data/music/#{name.downcase.split('/')[0]}") or File.exists?(file+'.ogg')) ? '/music' : '')
- @@music[name.downcase] = Song.new($screen, "data#{dir}/#{name.downcase}.ogg")
- end
- $premusic=nil
- $premusic=[@@music[name.downcase],name.chomp('-pre')] if pre
- @@music[name.downcase]
- end
- def Msc.reset
- @@music.clear
- end
- end
- class Fnt
- def Fnt.[](name,size=[])
- @@fonts = Hash.new unless defined?(@@fonts)
- if name.class==Array
- name[0].downcase!
- if @@fonts[name]
- @@fonts[name]
- else
- @@fonts[name] = BitmapFont.new(name,size)
- end
- else
- if @@fonts[[name.downcase,size]]
- @@fonts[[name.downcase,size]]
- else
- @@fonts[[name.downcase,size]] = Font.new($screen, name.downcase, size)
- end
- end
- end
- def Fnt.reset
- @@fonts.clear
- end
- end
- class BitmapFont
- NEW_LINE='^'
- DFACTOR=0.7
- def initialize(images,characters)
- @images,@characters=images,characters
- end
- def draw(text,x,y,z,args={})
- posx=posy=0
- scalex=(args[:scalex] ? args[:scalex] : 1)
- scaley=(args[:scaley] ? args[:scaley] : 1)
- xspacing=(args[:xspacing] ? args[:xspacing] : @images[1]*scalex)
- yspacing=(args[:yspacing] ? args[:yspacing] : @images[1]*scaley)
- max=args[:max]
- align=args[:align]
- text=text.to_s
- text.each_char{|char| index=@characters.index(char.upcase)
- scalex1=(char.upcase==char ? scalex : scalex*DFACTOR)
- scaley1=(char.upcase==char ? scaley : scaley*DFACTOR)
- Tls[*@images][index].draw(x+posx-(align==:right ? (text.length*xspacing) : align==:center ? (text.length*xspacing)/2 : 0),y+posy+(scaley1 != scaley ? yspacing*(1-DFACTOR) : 1),z,scalex1,scaley1,args[:color] ? args[:color] : 0xffffffff) if index
- posx+=xspacing
- (posy+=yspacing ; posx=0) if char==NEW_LINE or max && posx+xspacing>max}
- end
- end
- class Entity
- attr_accessor :x,:y,:stop,:invisible,:active,:unstoppable,:removed
- def init(*types)
- $game.entities[0] << self
- $game.entities[1] << self if types.include?(:enemy)
- $game.entities[2] << self if types.include?(:powable)
- $game.entities[3] << self if types.include?(:solid)
- $game.entities[4] << self if types.include?(:hittable)
- $game.entities[5] << self if types.include?(:stompable)
- end
- def remove
- $game.remove(self)
- @removed=true
- end
- def gravity(width,height=width,gravity=1,down=true)
- @vy||=0
- @offx||=0
- @vy+=gravity
- if @vy.to_i>0
- @vy.to_i.times{if !$game.solid?(@x+@offx,@y+height,down) and !$game.solid?(@x+@offx+width/2,@y+height,down) and !$game.solid?(@x+@offx+width-1,@y+height,down) ; @y+=1 else @vy=0 ; break end}
- elsif @vy.to_i<0
- (-@vy).to_i.times{if !$game.solid?(@x+@offx,@y) and !$game.solid?(@x+@offx+width/2,@y) and !$game.solid?(@x+@offx+width-1,@y) ; @y-=1 else @vy=0 ; break end}
- end
- if !@water && $game.map.water?(@x+width/2,@y+height) or @water && !$game.map.water?(@x+width/2,@y+height)
- Snd['Swim'].play
- @water=!@water
- tr=Trail.new(@x+width/2-16,@y+height-32,2,['Effects/Splash',32,32],[0,1,2,3],4)
- 64.times{if !$game.map.water?(tr.x+16,tr.y+32) then tr.y+=1 else break end}
- 64.times{if $game.map.water?(tr.x+16,tr.y+31) then tr.y-=1 else break end}
- end
- end
- def dead?;@dead;end
- end
- class NilClass
- def stop;end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement