indexing description: "[ An rotatable EM_GOOF_OBJECT like a car or ship. ]" date: "$Date$" revision: "$Revision$" class EM_GOOF_ROTATABLE inherit EM_GOOF_OBJECT redefine draw, make end DOUBLE_MATH create make, make_multiple_picture feature -- Initialization make(img: EM_BITMAP x: DOUBLE y: DOUBLE phs: EM_GOOF_PHYSICS) is -- Make goof_object do physics := phs create position.make(x,y) visible := true image := img create image_position.make(image.width/2,image.height/2) has_multiple_pictures := false premade := false end make_multiple_picture(imgs: DS_LINKED_LIST[EM_BITMAP] x: DOUBLE y: DOUBLE phs: EM_GOOF_PHYSICS) is -- Make with multiple picture for rotation require has_images: imgs /= void and then imgs.count > 0 phs_not_void: phs /= void do physics := phs create position.make(x,y) visible := true image := imgs.item(1) images := imgs create image_position.make(image.width/2,image.height/2) has_multiple_pictures := true premade := false end feature -- Properties arc: DOUBLE -- Current arc set_arc(a_arc: DOUBLE) is -- Set arc do arc := a_arc ensure arc_set: arc = a_arc end has_multiple_pictures: BOOLEAN -- Are there multiple pictures for rotation images: DS_LINKED_LIST[EM_DRAWABLE] -- Multiple images for rotation feature {EM_GOOF_OBJECT, EM_GOOF_PHYSICS} -- Drawing draw(screen: EM_VIDEO_SURFACE at: EM_VECTOR_2D at_angle: DOUBLE) is -- draw the object local pos_copy: EM_VECTOR_2D current_image: EM_DRAWABLE iamge_number: INTEGER do if arc > Pi*2 then arc := arc - Pi*2 elseif arc < 0 then arc := arc + Pi*2 end if has_multiple_pictures then iamge_number := (arc/(Pi*2)*(images.count-1)).rounded+1 current_image := images.item(iamge_number) pos_copy := position.rotation_around_zero(at_angle) -- pos_copy := position.rotation(position.zero, at_angle) current_image.set_x_y((pos_copy.x+at.x-image_position.x).rounded, (pos_copy.y+at.y-image_position.y).rounded) screen.draw_object(current_image) else pos_copy := position.rotation_around_zero(at_angle) image.set_x_y((pos_copy.x+at.x-image_position.x).rounded, (pos_copy.y+at.y-image_position.y).rounded) image.set_x((image.x + image.width / 2).rounded) image.set_y((image.y + image.height / 2).rounded) image.rotate(arc/Pi*180) image.set_x((image.x - image.width / 2).rounded) image.set_y((image.y - image.height / 2).rounded) screen.draw_object(image) image.rotate(-arc/Pi*180) end end invariant has_images: has_multiple_pictures implies (images /= void and then images.count > 0) end