indexing description: "[ NEVER_ENDING_BACKGROUND demo for EiffelMedia. This demonstrates how you can combine an EM_NEVER_ENDING_BACKGROUND_HORIZONTAL with an EM_NEVER_ENDING_BACKGROUND_VERTICAL to build a background that is never ending. ]" date: "$Date$" revision: "$Revision$" class NEVER_ENDING_BACKGROUND inherit EM_APPLICATION EM_CONSTANTS export {NONE} all end create make feature {NONE} -- Initialization make is -- Create the main application. local keyboard: EM_KEYBOARD do -- Initiliase subsystems Video_subsystem.set_video_surface_width (Window_width) Video_subsystem.set_video_surface_height (Window_height) Video_subsystem.set_video_bpp (Screen_resolution) Video_subsystem.set_fullscreen (Is_fullscreen_enabled) Video_subsystem.enable initialize_screen -- Check subsystem initialisation if Video_subsystem.is_enabled then -- Set global options set_window_title ("EiffelMedia never ending background") set_window_icon ("icon.png") set_application_id ("never_ending_background") create keyboard.make_snapshot keyboard.enable_repeating_key_down_events (50, 50) -- Setup first scene create first_scene.make_scene initialize_scene -- Set first scene and launch it set_scene (first_scene) launch -- Disable subsystems Video_subsystem.disable else io.error.put_string ("Failed to initialise video subsystem.%N") end end initialize_scene is -- Create objects the scene is constructed of and put them into `scene'. local background_viewport: EM_ZOOMABLE_CONTAINER do -- Create viewport for only showing part of the background. create background_viewport.make (screen.width - 200, screen.height - 200) background_viewport.set_x_y (100, 100) first_scene.main_container.extend (background_viewport) -- Create endless background inside viewport. bitmap_factory.create_bitmap_from_image ("back1.gif") create endless_background_horizontal.make (bitmap_factory.last_bitmap) first_scene.start_animating (endless_background_horizontal) create endless_background_vertical.make (endless_background_horizontal) first_scene.start_animating (endless_background_vertical) endless_background_vertical.set_x_y (-100, -100) background_viewport.extend (endless_background_vertical) -- Create endless text in front of background. create endless_text_horizontal.make (create {DEMO_TEXT}.make) first_scene.start_animating (endless_text_horizontal) create endless_text_vertical.make (endless_text_horizontal) first_scene.start_animating (endless_text_vertical) first_scene.main_container.extend (endless_text_vertical) -- Subscribe event handlers first_scene.event_loop.key_down_event.subscribe (agent handle_key_down_event (?)) end feature {NONE} -- Keyboard management handle_key_down_event (a_keyboard_event: EM_KEYBOARD_EVENT) is -- Handle keyboard events. require a_keyboard_event_not_void: a_keyboard_event /= Void local vspeed_diff: INTEGER hspeed_diff: INTEGER do if a_keyboard_event.key = a_keyboard_event.sdlk_escape then first_scene.quit end if a_keyboard_event.key = a_keyboard_event.sdlk_up then vspeed_diff := 5 end if a_keyboard_event.key = a_keyboard_event.sdlk_down then vspeed_diff := -5 end if a_keyboard_event.key = a_keyboard_event.sdlk_left then hspeed_diff := 5 end if a_keyboard_event.key = a_keyboard_event.sdlk_right then hspeed_diff := -5 end endless_text_vertical.set_speed (endless_text_vertical.speed + vspeed_diff) endless_background_vertical.set_speed (endless_background_vertical.speed + 2 * vspeed_diff) endless_text_horizontal.set_speed (endless_text_horizontal.speed + hspeed_diff) endless_background_horizontal.set_speed (endless_background_horizontal.speed + 2 * hspeed_diff) end feature {NONE} -- Implementation first_scene: EM_DRAWABLE_SCENE -- The scene used to run the never ending backgrounds in. endless_text_horizontal: EM_NEVER_ENDING_BACKGROUND_HORIZONTAL -- The horizontal background for the demo text endless_text_vertical: EM_NEVER_ENDING_BACKGROUND_VERTICAL -- The vertical background for the demo text endless_background_horizontal: EM_NEVER_ENDING_BACKGROUND_HORIZONTAL -- The horizontal background for the back image endless_background_vertical: EM_NEVER_ENDING_BACKGROUND_VERTICAL -- The vertical background for the back image Window_width: INTEGER is 1024 -- Window width Window_height: INTEGER is 768 -- Window height Screen_resolution: INTEGER is 16 -- Screen resolution Is_fullscreen_enabled: BOOLEAN is False -- Is fullscreen enabled? end