cleaned all trailing white space from source files.
[sdk] / samples / guiAndGfx / bitmapsAndKB / Objects / objects.ec
1 import "ecere"
2
3 BitmapResource peasantGfx { ":peasant.png" };
4 BitmapResource dragonGfx { ":dragon.png" };
5 BitmapResource mageGfx { ":mage.png" };
6 BitmapResource archerGfx { ":archer.png" };
7 BitmapResource castleGfx { ":castle.png" };
8
9 Array<BitmapResource> gfxResources { [ peasantGfx, dragonGfx, mageGfx, archerGfx, castleGfx ] };
10
11 class WorldObject
12 {
13    BitmapResource res;
14
15    void Render(Surface surface)
16    {
17       Bitmap bmp = res ? res.bitmap : null;
18       if(bmp)
19          surface.Blit(bmp, x, y, 0,0, bmp.width, bmp.height);
20    }
21
22 public:
23    int x, y;
24 }
25
26 class Peasant : WorldObject { res = peasantGfx; }
27 class Dragon : WorldObject { res = dragonGfx; }
28 class Mage : WorldObject { res = mageGfx; }
29 class Archer : WorldObject { res = archerGfx; }
30 class Castle : WorldObject { res = castleGfx; }
31
32 Array<WorldObject> objects
33 { [
34    Castle { 180, 150 },
35    Mage { 50, 50 },
36    Archer { 150, 250 },
37    Peasant { 380, 290 },
38    Peasant { 120, 150 },
39    Dragon { 320, 50 }
40 ] };
41
42 class MainWindow : Window
43 {
44    text = "A World of Objects";
45    background = black;
46    borderStyle = sizable;
47    hasMaximize = true;
48    hasMinimize = true;
49    hasClose = true;
50    size = { 576, 432 };
51
52    bool OnLoadGraphics()
53    {
54       for(r : gfxResources)
55          AddResource(r);
56       return true;
57    }
58
59    void OnUnloadGraphics()
60    {
61       for(r : gfxResources)
62          RemoveResource(r);
63    }
64
65    void OnDestroy()
66    {
67       objects.Free();
68    }
69
70    void OnRedraw(Surface surface)
71    {
72       for(o : objects)
73          o.Render(surface);
74    }
75 }
76
77 MainWindow mainWindow {};