indexing description: "[ A sprite composition acts like an EM_SPRITE, but itself contains multiple EM_SPRITEs. All contained EM_SPRITEs are positioned relatively to the x and y positoins of EM_SPRITE_COMPOSITION ]" date: "$Date$" revision: "$Revision$" class EM_SPRITE_COMPOSITION inherit EM_SPRITE export {NONE} make, make_from_drawable, make_from_animation redefine stop, pause, start, draw, draw_part, set_do_loop, process_change end create make_composition feature -- Initialization make_composition (a_sprite: EM_SPRITE; an_x, a_y: INTEGER) is -- creates a composition of sprites with positions x and y. -- Be aware, that the positions of the EM_SPRITEs will be added -- to x and y, so if `a_sprite' has the position (100, 100) -- and a new composition is created with `an_x'=30 and `a_y'=40 -- the position of the first sprite would be (130, 140) do x := an_x y := a_y create animations.make a_sprite.set_x_y (x + a_sprite.x, y + a_sprite.y) animations.force_last (a_sprite) process_change set_visible (True) end feature -- Draw draw (surface: EM_SURFACE) is -- draws all items in list to screen. local cursor: DS_LINKED_LIST_CURSOR [EM_SPRITE] sprite: EM_SPRITE do if is_visible then create cursor.make (animations) from cursor.start until cursor.off loop sprite := cursor.item sprite.draw (surface) cursor.forth end end end draw_part (rect: EM_RECT; a_surface: EM_SURFACE) is -- Draws rectangular part of `current' defined by `rect' to `a_surface' local cursor: DS_LINKED_LIST_CURSOR [EM_SPRITE] do if is_visible then create cursor.make (animations) from cursor.start until cursor.off loop cursor.item.draw_part (rect, a_surface) cursor.forth end end end feature -- Element Change force (a_sprite: EM_SPRITE) is -- adds a sprite to the `animations' do a_sprite.set_x_y (x + a_sprite.x, y + a_sprite.y) animations.force_last (a_sprite) process_change end start is -- starts all animations in list local cursor: DS_LINKED_LIST_CURSOR [EM_SPRITE] do create cursor.make (animations) from cursor.start until cursor.off loop cursor.item.start cursor.forth end end pause is -- starts all animations in list local cursor: DS_LINKED_LIST_CURSOR [EM_SPRITE] do create cursor.make (animations) from cursor.start until cursor.off loop cursor.item.pause cursor.forth end end stop is -- stops all animations local cursor: DS_LINKED_LIST_CURSOR [EM_SPRITE] do create cursor.make (animations) from cursor.start until cursor.off loop cursor.item.stop cursor.forth end end set_do_loop (b:BOOLEAN) is -- sets do_loop (if we want to loop the animation) local cursor: DS_LINKED_LIST_CURSOR [EM_SPRITE] do do_loop := True create cursor.make (animations) from cursor.start until cursor.off loop cursor.item.set_do_loop (True) cursor.forth end end feature {NONE} -- Implementation animations: DS_LINKED_LIST [EM_SPRITE] -- a list of EM_SPRITES process_change is -- updates the maximum width and height. local cursor: DS_LINKED_LIST_CURSOR [EM_SPRITE] left, upper, right, lower, t: INTEGER do create cursor.make (animations) -- loop through all sprites and find the bounding box of all elements from cursor.start until cursor.off loop cursor.item.process_change if cursor.item.x < left then left := cursor.item.x end t := cursor.item.x + cursor.item.width if t > right then right := t end if cursor.item.y < upper then upper := cursor.item.y end t := cursor.item.y + cursor.item.height if t > lower then lower := t end cursor.forth end -- update height and width width := right - left height := lower - upper end end