source: 2014/27/AleksanteriV/Protokolla236TrueSurvivor/Protokolla236TrueSurvivor/Protokolla236TrueSurvivor/Protokolla236TrueSurvivor.cs @ 5260

Revision 5260, 2.8 KB checked in by mijoilmo, 6 years ago (diff)
Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9
10
11public 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}
Note: See TracBrowser for help on using the repository browser.