3 BitmapResource knightGfx { ":knight.png" };
4 BitmapResource dragonGfx { ":dragon.png" };
5 BitmapResource mageGfx { ":mage.png" };
6 BitmapResource archerGfx { ":archer.png" };
7 BitmapResource castleGfx { ":castle.png" };
9 Array<BitmapResource> gfxResources { [ knightGfx, dragonGfx, mageGfx, archerGfx, castleGfx ] };
16 void Render(Surface surface)
18 Bitmap bmp = res ? res.bitmap : null;
21 surface.Blit(bmp, x, y, 0,0, bmp.width, bmp.height);
24 surface.foreground = lime;
25 surface.Rectangle(x-1, y-1, x + bmp.width, y + bmp.height);
26 surface.foreground = white;
27 surface.Rectangle(x-2, y-2, x + bmp.width+1, y + bmp.height+1);
36 class Knight : WorldObject { res = knightGfx; selectable = true; }
37 class Dragon : WorldObject { res = dragonGfx; }
38 class Mage : WorldObject { res = mageGfx; selectable = true; }
39 class Archer : WorldObject { res = archerGfx; selectable = true; }
40 class Castle : WorldObject { res = castleGfx; }
42 Array<WorldObject> objects
54 class WorldObjectController : WindowController<WorldObject>
56 bool OnKeyHit(WorldObjectController controller, Key key, unichar ch)
62 Iterator<WorldObject> it { objects };
69 } while(!selected.selectable);
70 controller.controlled = selected;
73 case left: x -= 5; break;
74 case right: x += 5; break;
75 case up: y -= 5; break;
76 case down: y += 5; break;
78 controller.window.Update(null);
83 class MainWindow : Window
85 text = "Keyboard Input Using Controllers";
87 borderStyle = sizable;
93 controller = WorldObjectController { this };
97 selected = objects[1];
98 ((WorldObjectController)controller).controlled = selected;
102 bool OnLoadGraphics()
104 for(r : gfxResources)
109 void OnUnloadGraphics()
111 for(r : gfxResources)
121 void OnRedraw(Surface surface)
128 MainWindow mainWindow {};