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 | public class Proto236b : PhysicsGame //true survivor |
---|
10 | { |
---|
11 | Player player; |
---|
12 | private ColorTileMap map; |
---|
13 | public ColorTileMap Map { get { return map; } set { map = value; } } |
---|
14 | private Dictionary<string, Image> images = new Dictionary<string, Image>(); |
---|
15 | public Dictionary<string, Image> Images { get { return images; } set { images = value; } } |
---|
16 | private Dictionary<string, Image[]> imageLists = new Dictionary<string, Image[]>(); |
---|
17 | public Dictionary<string, Image[]> ImageLists { get { return imageLists; } set { imageLists = value; } } |
---|
18 | private ProtoLevel currentLevel; |
---|
19 | public ProtoLevel CurrentLevel { get { return currentLevel; } set { currentLevel = value; } } |
---|
20 | |
---|
21 | void AssignKeys() |
---|
22 | { |
---|
23 | Keyboard.Listen(Key.Escape, ButtonState.Down, Exit, "Lopeta Peli"); |
---|
24 | Keyboard.Listen(Key.Up, ButtonState.Down, player.thrusterStart, "Lento", 1.0); |
---|
25 | Keyboard.Listen(Key.Up, ButtonState.Released, player.thrusterEnd, "Lento"); |
---|
26 | Keyboard.Listen(Key.Down, ButtonState.Down, player.thrusterStart, "Lento", -0.2); |
---|
27 | Keyboard.Listen(Key.Down, ButtonState.Released, player.thrusterEnd, "Lento"); |
---|
28 | Keyboard.Listen(Key.Left, ButtonState.Down, player.rotate, "Lento", 4.0); |
---|
29 | Keyboard.Listen(Key.Right, ButtonState.Down, player.rotate, "Lento", -4.0); |
---|
30 | } |
---|
31 | void LoadAllImages() |
---|
32 | { |
---|
33 | images["background0"] = LoadImage("graphics/backgrounds/space_background"); |
---|
34 | images["player"] = LoadImage("graphics/ships/player"); |
---|
35 | imageLists["player_thruster"] = LoadImages("graphics/effects/thrusters/thruster0.1", "graphics/effects/thrusters/thruster0.2"); |
---|
36 | images["tile0"] = LoadImage("graphics/tiles/tile0"); |
---|
37 | } |
---|
38 | void LoadLevel(ProtoLevel level) |
---|
39 | { |
---|
40 | ClearAll(); |
---|
41 | currentLevel = level; |
---|
42 | Add(this.player); |
---|
43 | Camera.Follow(this.player); |
---|
44 | AssignKeys(); |
---|
45 | LevelFromImage("graphics/levels/" + level.TileMapSrc); |
---|
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 | tileMap.SetTileMethod(Color.FromHexCode("00ff00"), spawnEnemy); |
---|
55 | |
---|
56 | double w=40, h=40; |
---|
57 | tileMap.Execute(w, h); |
---|
58 | map = tileMap; |
---|
59 | //int laskValk = 0; |
---|
60 | //int laskPun = 0; |
---|
61 | //int lask = 0; |
---|
62 | for (int y = 0; y < tileMap.RowCount; y++) |
---|
63 | { |
---|
64 | for (int x = 0; x < tileMap.ColumnCount; x++) |
---|
65 | { |
---|
66 | String hexColor=tileMap.GetTile(y,x).ToString().Substring(2,6); |
---|
67 | |
---|
68 | //if (hexColor == "FFFFFF") { laskValk++; continue; } |
---|
69 | //if (hexColor == "FF00FF") { laskPun++; continue; } |
---|
70 | //if (hexColor == "FF0000") { lask++; continue; } |
---|
71 | //if (hexColor == "FF0000") { lask++; continue; } |
---|
72 | if (convert.ContainsKey(hexColor)) |
---|
73 | { |
---|
74 | createTile(new Vector(x * w + w / 2 - Level.Width / 2 - Level.Width, (tileMap.RowCount - y - 1) * h + h / 2 - Level.Height / 2), w, h, convert[hexColor]); |
---|
75 | createTile(new Vector(x * w + w / 2 - Level.Width / 2 + Level.Width, (tileMap.RowCount - y - 1) * h + h / 2 - Level.Height / 2), w, h, convert[hexColor]); |
---|
76 | } |
---|
77 | } |
---|
78 | } |
---|
79 | } |
---|
80 | void createTile(Vector position, double w, double h, string id) |
---|
81 | { |
---|
82 | if (id == "") { return; } |
---|
83 | MikonPhysicsObject tile = new MikonPhysicsObject(this, w, h); |
---|
84 | tile.MakeStatic(); |
---|
85 | tile.AbsolutePosition = position; |
---|
86 | tile.Image = images[id]; |
---|
87 | Add(tile); |
---|
88 | } |
---|
89 | void spawnPlayer(Vector position, double w, double h) |
---|
90 | { |
---|
91 | player.Position = position; |
---|
92 | } |
---|
93 | void spawnEnemy(Vector position, double w, double h) |
---|
94 | { |
---|
95 | new Enemy1(this,w,h,position); |
---|
96 | } |
---|
97 | public override void Begin() |
---|
98 | { |
---|
99 | // TODO: Kirjoita peli tähän |
---|
100 | LoadAllImages(); |
---|
101 | this.player = new Player(this); |
---|
102 | this.player.IsUpdated = true; |
---|
103 | |
---|
104 | LoadLevel(new ProtoLevel("0",true));//tää on huono metodi, TODO: luo level-classit ennen lataamista |
---|
105 | } |
---|
106 | } |
---|