Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Edit
- def initialize name
- @name = name
- @screen = Rubygame::Screen.set_mode([800,600],0, [Rubygame::HWSURFACE, Rubygame::DOUBLEBUF])
- @image = []
- @map
- @mouse = Mouse_input.new
- #@sprites = Rubygame::Sprites::Group.new()
- #Rubygame::Sprites::UpdateGroup.extend_object(@sprites)
- #@sprites.push(@mouse)
- end
- def new_file file
- save(file , @name)
- @map = read(@name)
- image
- edit_mode
- end
- def load
- @map = read(@name)
- image
- edit_mode
- end
- def read filename
- yaml_string = File.read filename; YAML:: load yaml_string
- end
- def save object , filename
- File.open filename , 'w' do |f|
- f.write(object.to_yaml)
- end
- end
- def image
- #load image files according to the strings it read in @map['file']
- @map['file'].each do |file|
- @image << Rubygame::Image.load("data/maps/#{file}")
- end
- map
- end
- def map
- x = y = time = 0
- @map['points'].each do |render|
- if render != nil
- @image[render].blit(@screen,[x,y])
- else
- #Code doesn't work for some reason.
- #Rubygame::Draw.filled_box( @screen, [50,0], [50,50], [0,0,0] )
- end
- x += 50
- time += 1
- if time == 16
- y += 50
- x = 0
- time = 0
- end
- end
- end
- def change event
- #Compare x and y until the value are greater and then map the last points.
- #Purpose is to determine the relative locations of the mouse in which squares
- max = 0
- #Start at negative 1 because @map['points'] contains array element and array start with 0
- square = -1
- while (1)
- #Deal with x position; square increase by 1
- if event.pos[0] >= max
- max +=50
- square += 1
- else
- max = 0
- break
- end
- end
- #So the square will appear where the mouse is..relatively
- square -= 16
- while (1)
- #Deal with y position; square increase by 16
- if event.pos[1] >= max
- max +=50
- square += 16
- else
- break
- end
- end
- if @map['points'][square] == nil
- @map['points'][square] = 0
- else
- @map['points'][square] += 1
- if @map['points'][square] == 7
- @map['points'][square] = 0
- end
- end
- map
- end
- def edit_mode
- q = Rubygame::Queue.instance()
- while 1
- @screen.flip
- q.get.each do |event|
- case event
- when Rubygame::MouseMotionEvent
- @mouse.pos(event)
- when Rubygame::MouseDownEvent
- case event.button
- when Rubygame::MOUSE_LEFT
- change(event)
- end
- when Rubygame::KeyDownEvent
- case event.key
- when Rubygame::K_ESCAPE
- save(@map , @name)
- exit
- end
- when Rubygame::QuitEvent
- exit
- end
- end
- #@sprites.undraw(@screen,@image)
- @mouse.update
- #@sprites.draw(@screen)
- end
- end
- end
Add Comment
Please, Sign In to add comment