1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using Jypeli; |
---|
4 | using Jypeli.Assets; |
---|
5 | using Jypeli.Controls; |
---|
6 | using Jypeli.Effects; |
---|
7 | using Jypeli.Widgets; |
---|
8 | |
---|
9 | |
---|
10 | |
---|
11 | public class Proto236b : PhysicsGame //true survivor |
---|
12 | { |
---|
13 | Player player; |
---|
14 | static public Dictionary<string, Image> images = new Dictionary<string, Image>(); |
---|
15 | void AssignKeys() |
---|
16 | { |
---|
17 | Keyboard.Listen(Key.Escape, ButtonState.Down, Exit, "Lopeta Peli"); |
---|
18 | Keyboard.Listen(Key.Up, ButtonState.Down, player.throttle, "Lento"); |
---|
19 | } |
---|
20 | void LoadAllImages() |
---|
21 | { |
---|
22 | images["background0"] = LoadImage("graphics/backgrounds/space_background"); |
---|
23 | images["player"] = LoadImage("graphics/ships/player"); |
---|
24 | images["tile0"] = LoadImage("graphics/tiles/tile0.png"); |
---|
25 | } |
---|
26 | void LoadLevel(int level) |
---|
27 | { |
---|
28 | ClearAll(); |
---|
29 | Add(this.player); |
---|
30 | AssignKeys(); |
---|
31 | LevelFromImage("graphics/levels/" + level); |
---|
32 | } |
---|
33 | void LevelFromImage(string levelName) |
---|
34 | { |
---|
35 | ColorTileMap tileMap = ColorTileMap.FromLevelAsset(levelName); |
---|
36 | tileMap.SetTileMethod(Color.FromHexCode("000000"), createTile, ""); |
---|
37 | tileMap.SetTileMethod(Color.FromHexCode("ff0000"), spawnPlayer); |
---|
38 | tileMap.Execute(20,20); |
---|
39 | } |
---|
40 | void createTile(Vector position, double w, double h, string id) |
---|
41 | { |
---|
42 | MikonPhysicsObject tile = new MikonPhysicsObject(this, w, h); |
---|
43 | tile.MakeStatic(); |
---|
44 | tile.Position = position; |
---|
45 | if (id != "") |
---|
46 | { |
---|
47 | tile.Image = images[id]; |
---|
48 | } |
---|
49 | Add(tile); |
---|
50 | } |
---|
51 | void spawnPlayer(Vector position, double w, double h) |
---|
52 | { |
---|
53 | player.Position = position; |
---|
54 | } |
---|
55 | public override void Begin() |
---|
56 | { |
---|
57 | // TODO: Kirjoita peli tähän |
---|
58 | LoadAllImages(); |
---|
59 | this.player = new Player(); |
---|
60 | LoadLevel(0); |
---|
61 | } |
---|
62 | } |
---|