1local ns = {}
2setmetatable(ns, {__index = _G})
3mt_elbrus_background_anim = ns;
4setfenv(1, ns);
5
6-- Animated image members
7local background = {};
8
9-- Scrolling offsets
10local offset_y = 0;
11-- Must be > 768.0
12local image_height = 1024;
13local first_update_done = false;
14
15-- c++ objects instances
16local Map = nil
17local Script = nil
18local Effects = nil
19
20function Initialize(map_instance)
21    Map = map_instance;
22    Script = Map:GetScriptSupervisor();
23    Effects = Map:GetEffectSupervisor();
24    -- Load the creatures animated background
25    background = Script:CreateImage("data/visuals/backgrounds/cliff_background.png");
26    background:SetDimensions(1024.0, image_height);
27
28    first_update_done = false;
29end
30
31
32function Update()
33
34    if (first_update_done == false) then
35        first_update_done = true;
36        -- 24.0 is the number of tiles on the y axis in the map mode.
37        -- 768 is the area that is always shown on screen.
38        if (Map:GetMapYOffset() >= ((Map:GetMapHeight() * 2.0) - 24.0)) then
39            offset_y = 0;
40        else
41            offset_y = ((Map:GetMapHeight() * 2.0) - Map:GetMapYOffset() - 24.0) / (2.0 * Map:GetMapHeight() * (image_height - 768));
42        end
43    end
44
45    offset_y = offset_y + Effects:GetCameraYMovement() * Map:GetMapHeight() / image_height
46    -- Trouble-Shooting: This prevents certain ugly edge-cases.
47    if (offset_y < 0.0) then
48        offset_y = 0.0;
49    end
50
51    --print(offset_y,  Map:GetMapYOffset(), Map:GetMapHeight())
52
53end
54
55local white_color = vt_video.Color(1.0, 1.0, 1.0, 1.0);
56
57function DrawBackground()
58    -- Draw background animation
59    VideoManager:Move(512.0, 768.0 + offset_y);
60    background:Draw(white_color);
61end
62