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 | |
---|
21 | |
---|
22 | Keyboard.Listen(Key.Up, ButtonState.Down, player.thrusterStart, "Lento", 1.0); |
---|
23 | Keyboard.Listen(Key.Up, ButtonState.Up, player.thrusterEnd, "Lento"); |
---|
24 | Keyboard.Listen(Key.Down, ButtonState.Down, player.thrusterStart, "Lento", -0.2); |
---|
25 | Keyboard.Listen(Key.Down, ButtonState.Up, player.thrusterEnd, "Lento"); |
---|
26 | Keyboard.Listen(Key.Left, ButtonState.Down, player.rotate, "Lento", 4.0); |
---|
27 | Keyboard.Listen(Key.Right, ButtonState.Down, player.rotate, "Lento", -4.0); |
---|
28 | } |
---|
29 | void LoadAllImages() |
---|
30 | { |
---|
31 | images["background0"] = LoadImage("graphics/backgrounds/space_background"); |
---|
32 | images["player"] = LoadImage("graphics/ships/player"); |
---|
33 | images["tile0"] = LoadImage("graphics/tiles/tile0.png"); |
---|
34 | images["background0"] = LoadImage("graphics/backgrounds/space_background"); |
---|
35 | images["player"] = LoadImage("graphics/ships/player"); |
---|
36 | images["player_thruster"] = LoadImage("graphics/effects/thrusters/thruster0.1"); |
---|
37 | images["tile0"] = LoadImage("graphics/tiles/tile0.png"); |
---|
38 | } |
---|
39 | void LoadLevel(int level) |
---|
40 | void LoadLevel(string level) |
---|
41 | { |
---|
42 | ClearAll(); |
---|
43 | Add(this.player); |
---|
44 | Camera.Follow(this.player); |
---|
45 | AssignKeys(); |
---|
46 | LevelFromImage("graphics/levels/" + level); |
---|
47 | } |
---|
48 | void LevelFromImage(string levelName) |
---|
49 | { |
---|
50 | ColorTileMap tileMap = ColorTileMap.FromLevelAsset(levelName); |
---|
51 | tileMap.SetTileMethod(Color.FromHexCode("000000"), createTile, ""); |
---|
52 | tileMap.SetTileMethod(Color.FromHexCode("ff0000"), spawnPlayer); |
---|
53 | tileMap.Execute(20,20); |
---|
54 | tileMap.Execute(40,40); |
---|
55 | } |
---|
56 | void createTile(Vector position, double w, double h, string id) |
---|
57 | { |
---|
58 | MikonPhysicsObject tile = new MikonPhysicsObject(this, w, h); |
---|
59 | tile.MakeStatic(); |
---|
60 | tile.Position = position; |
---|
61 | if (id != "") |
---|
62 | { |
---|
63 | tile.Image = images[id]; |
---|
64 | } |
---|
65 | Add(tile); |
---|
66 | } |
---|
67 | void spawnPlayer(Vector position, double w, double h) |
---|
68 | { |
---|
69 | player.Position = position; |
---|
70 | } |
---|
71 | public override void Begin() |
---|
72 | { |
---|
73 | // TODO: Kirjoita peli tähän |
---|
74 | LoadAllImages(); |
---|
75 | this.player = new Player(); |
---|
76 | LoadLevel(0); |
---|
77 | LoadLevel("test"); |
---|
78 | } |
---|
79 | } |
---|