Class: Xibe::Scene

Inherits:
Object
  • Object
show all
Includes:
Event
Defined in:
lib/xibe.rb

Constant Summary

Constants included from Event

Event::QUIT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Event

#keydown?, #keyup?

Constructor Details

#initialize(width, height, fill = 0x00) ⇒ Scene

Returns a new instance of Scene.



384
385
386
387
388
389
390
391
392
# File 'lib/xibe.rb', line 384

def initialize(width, height,fill = 0x00)
  @width = width
  @height = height
  @fill = fill
  @camera = Layer.new
  @camera.width = @@window.width
  @camera.height = @@window.height
  @objects = []
end

Instance Attribute Details

#cameraObject

Returns the value of attribute camera.



382
383
384
# File 'lib/xibe.rb', line 382

def camera
  @camera
end

#fillObject

Returns the value of attribute fill.



382
383
384
# File 'lib/xibe.rb', line 382

def fill
  @fill
end

#heightObject (readonly)

Returns the value of attribute height.



383
384
385
# File 'lib/xibe.rb', line 383

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



383
384
385
# File 'lib/xibe.rb', line 383

def width
  @width
end

Instance Method Details

#add(object) ⇒ Object

Add the object to scene



429
430
431
432
# File 'lib/xibe.rb', line 429

def add(object)
  @objects << object
  @objects = @objects.uniq
end

#center_camera_relative_to(object) ⇒ Object

Center camera relative to object



445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
# File 'lib/xibe.rb', line 445

def center_camera_relative_to(object)
  @camera.x = ( object.x + object.width / 2 ) - @camera.width / 2;
  @camera.y = ( object.y + object.height / 2 ) - @camera.height / 2;

  if @camera.left < 0
    @camera.x = 0
  end

  if @camera.top < 0
    @camera.y = 0
  end

  if @camera.right > @width
    @camera.x = @width - @camera.width
  end

  if @camera.bottom > @height
    @camera.y = @height - @camera.height
  end
end

#delete(object) ⇒ Object

Delete the object from scene



435
436
437
# File 'lib/xibe.rb', line 435

def delete(object)
  @objects.delete(object)
end

#display(scene) ⇒ Object

Sets the scene to display



418
419
420
421
422
# File 'lib/xibe.rb', line 418

def display(scene)
  finalize
  @@window.scene = scene
  SDL.get_video_surface.set_clip_rect(0,0,@width,@height)
end

#drawObject

Draw scene



467
468
469
470
471
472
# File 'lib/xibe.rb', line 467

def draw
  objs = @objects.sort_by { |obj| [obj.z] }
  objs.each do |obj|
    obj.draw
  end
end

#finalizeObject



394
395
396
# File 'lib/xibe.rb', line 394

def finalize

end

#inputObject

Keyboard, Joystick or Mouse



440
441
442
# File 'lib/xibe.rb', line 440

def input
  
end

#load_map(filename) ⇒ Object

Load map from file



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# File 'lib/xibe.rb', line 399

def load_map(filename)
  lines = File.open(filename).readlines.join
  map = eval(lines)
  map[:tilesets].each do |tileset|
    self.instance_variable_set("@#{tileset[:name]}", Image.to_tiles(tileset[:filename], tileset[:width], tileset[:height], tileset[:transparent], tileset[:margin]))
  end

  map[:tilemaps].each do |tilemap|
    tiles =  self.instance_variable_get("@#{tilemap[:tileset]}")
    tlmap = self.instance_variable_set("@#{tilemap[:name]}", Tilemap.new(tiles, tilemap[:obstacle]))
    tlmap.x = tilemap[:x]
    tlmap.y = tilemap[:y]
    tlmap.z = tilemap[:z]
    tlmap.load_map tilemap[:map], tilemap[:width], tilemap[:height]
    add(tlmap)
  end
end

#updateObject



424
425
426
# File 'lib/xibe.rb', line 424

def update
  
end