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

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