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 | private ColorTileMap map; |
---|
15 | public ColorTileMap Map { get { return map; } set { map = value; } } |
---|
16 | private Dictionary<string, Image> images = new Dictionary<string, Image>(); |
---|
17 | public Dictionary<string, Image> Images { get { return images; } set { images = value; } } |
---|
18 | private Dictionary<string, Image[]> imageLists = new Dictionary<string, Image[]>(); |
---|
19 | public Dictionary<string, Image[]> ImageLists { get { return imageLists; } set { imageLists = value; } } |
---|
20 | |
---|
21 | |
---|
22 | void AssignKeys() |
---|
23 | { |
---|
24 | Keyboard.Listen(Key.Escape, ButtonState.Down, Exit, "Lopeta Peli"); |
---|
25 | Keyboard.Listen(Key.Up, ButtonState.Down, player.thrusterStart, "Lento", 1.0); |
---|
26 | Keyboard.Listen(Key.Up, ButtonState.Released, player.thrusterEnd, "Lento"); |
---|
27 | Keyboard.Listen(Key.Down, ButtonState.Down, player.thrusterStart, "Lento", -0.2); |
---|
28 | Keyboard.Listen(Key.Down, ButtonState.Released, player.thrusterEnd, "Lento"); |
---|
29 | Keyboard.Listen(Key.Left, ButtonState.Down, player.rotate, "Lento", 4.0); |
---|
30 | Keyboard.Listen(Key.Right, ButtonState.Down, player.rotate, "Lento", -4.0); |
---|
31 | } |
---|
32 | void LoadAllImages() |
---|
33 | { |
---|
34 | images["background0"] = LoadImage("graphics/backgrounds/space_background"); |
---|
35 | images["player"] = LoadImage("graphics/ships/player"); |
---|
36 | imageLists["player_thruster"] = LoadImages("graphics/effects/thrusters/thruster0.1", "graphics/effects/thrusters/thruster0.2"); |
---|
37 | images["tile0"] = LoadImage("graphics/tiles/tile0"); |
---|
38 | } |
---|
39 | void LoadLevel(string level) |
---|
40 | { |
---|
41 | ClearAll(); |
---|
42 | Add(this.player); |
---|
43 | Camera.Follow(this.player); |
---|
44 | AssignKeys(); |
---|
45 | LevelFromImage("graphics/levels/" + level); |
---|
46 | } |
---|
47 | void LevelFromImage(string levelName) |
---|
48 | { |
---|
49 | Dictionary<String, String> convert = new Dictionary<String, String>(); |
---|
50 | convert.Add("000000","tile0"); |
---|
51 | ColorTileMap tileMap = ColorTileMap.FromLevelAsset(levelName); |
---|
52 | tileMap.SetTileMethod(Color.FromHexCode("000000"), createTile, convert["000000"]); |
---|
53 | tileMap.SetTileMethod(Color.FromHexCode("ff0000"), spawnPlayer); |
---|
54 | double w=40, h=40; |
---|
55 | tileMap.Execute(w, h); |
---|
56 | map = tileMap; |
---|
57 | for (int x = 0; x < tileMap.RowCount; x++) |
---|
58 | { |
---|
59 | for (int y = 0; y < tileMap.ColumnCount; y++) |
---|
60 | { |
---|
61 | String hexColor=tileMap.GetTile(x,y).ToString().Substring(0,6); |
---|
62 | int lask = 0; |
---|
63 | if (hexColor == "FFFFFF"||hexColor=="FF00FF") { continue; } |
---|
64 | if (hexColor == "FF0000") { lask++; continue; } |
---|
65 | if (convert.ContainsKey(hexColor)) |
---|
66 | { |
---|
67 | createTile(new Vector((x * w)+20, y * h+20), w, h, convert[hexColor]); |
---|
68 | } |
---|
69 | } |
---|
70 | } |
---|
71 | } |
---|
72 | void createTile(Vector position, double w, double h, string id) |
---|
73 | { |
---|
74 | if (id == "") { return; } |
---|
75 | MikonPhysicsObject tile = new MikonPhysicsObject(this, w, h); |
---|
76 | tile.MakeStatic(); |
---|
77 | tile.Position = position; |
---|
78 | tile.Image = images[id]; |
---|
79 | Add(tile); |
---|
80 | } |
---|
81 | void spawnPlayer(Vector position, double w, double h) |
---|
82 | { |
---|
83 | player.Position = position; |
---|
84 | } |
---|
85 | public override void Begin() |
---|
86 | { |
---|
87 | // TODO: Kirjoita peli tähän |
---|
88 | LoadAllImages(); |
---|
89 | this.player = new Player(this); |
---|
90 | this.player.IsUpdated = true; |
---|
91 | LoadLevel("0"); |
---|
92 | } |
---|
93 | } |
---|