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

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