Class: Kawaii::SceneManager

Inherits:
Object
  • Object
show all
Defined in:
lib/kawaii/scene_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(game, scene = nil) ⇒ SceneManager

Returns a new instance of SceneManager.



5
6
7
8
9
10
11
12
13
# File 'lib/kawaii/scene_manager.rb', line 5

def initialize game, scene = nil
	@game = game
	@scene = scene
	@old_scene = nil
	@current_transition = 0.0
	@state = :none
	@state = :transition if @scene != nil
	@on_scene_activated = []
end

Instance Attribute Details

#gameObject

Returns the value of attribute game.



3
4
5
# File 'lib/kawaii/scene_manager.rb', line 3

def game
  @game
end

#sceneObject

Returns the value of attribute scene.



3
4
5
# File 'lib/kawaii/scene_manager.rb', line 3

def scene
  @scene
end

Instance Method Details

#drawObject



65
66
67
68
69
70
71
72
# File 'lib/kawaii/scene_manager.rb', line 65

def draw
	if @old_scene != nil
		@old_scene.draw
	end
	if @scene != nil
		@scene.draw
	end
end

#on_scene_activated(lmbda) ⇒ Object



31
32
33
# File 'lib/kawaii/scene_manager.rb', line 31

def on_scene_activated(lmbda)
	@on_scene_activated << lmbda
end

#pop_sceneObject

removes the current scene



25
26
27
28
29
# File 'lib/kawaii/scene_manager.rb', line 25

def pop_scene
	@state = :none
	@old_scene = nil
	@scene = nil
end

#push_scene(scene) ⇒ Object

switches to a new scene and loads it



16
17
18
19
20
21
22
# File 'lib/kawaii/scene_manager.rb', line 16

def push_scene scene
	@old_scene = @scene
	@scene = scene		
	@scene.load
	@current_transition = 0.0
	@state = :transition
end

#update(dt) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/kawaii/scene_manager.rb', line 35

def update dt
	case @state
		when :none
			@scene.update dt
		when :transition
			if @scene != nil
				@scene.transition_in @current_transition, @scene.transition_duration
			end
			if @old_scene != nil
				@old_scene.transition_out @current_transition, @old_scene.transition_duration
			end

			@current_transition += dt
			if @current_transition > @scene.transition_duration
				@state = :transition_done
				@current_transition = 0.0
				@on_scene_activated.each do |l|
					l.call()
				end
				# remove jobs
				@on_scene_activated.clear
			end
		when :transition_done
			@current_transition = 0.0
			@old_scene = nil
			@state = :none
		else
	end
end