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

Revision 5224, 1.8 KB checked in by mijoilmo, 9 years ago (diff)

vähän kaikkea
player omassa luokassansa

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    void LoadAllImages()
21    {
22        images["background0"] = LoadImage("graphics/backgrounds/space_background");
23        images["player"] = LoadImage("graphics/ships/player");
24        images["tile0"] = LoadImage("graphics/tiles/tile0.png");
25    }
26    void LoadLevel(int level)
27    {
28        ClearAll();
29        Add(this.player);
30        AssignKeys();
31        LevelFromImage("graphics/levels/" + level);
32    }
33    void LevelFromImage(string levelName)
34    {
35        ColorTileMap tileMap = ColorTileMap.FromLevelAsset(levelName);
36        tileMap.SetTileMethod(Color.FromHexCode("000000"), createTile, "");
37        tileMap.SetTileMethod(Color.FromHexCode("ff0000"), spawnPlayer);
38        tileMap.Execute(20,20);
39    }
40    void createTile(Vector position, double w, double h, string id)
41    {
42        MikonPhysicsObject tile = new MikonPhysicsObject(this, w, h);
43        tile.MakeStatic();
44        tile.Position = position;
45        if (id != "")
46        {
47            tile.Image = images[id];
48        }
49        Add(tile);
50    }
51    void spawnPlayer(Vector position, double w, double h)
52    {
53        player.Position = position;
54    }
55    public override void Begin()
56    {
57        // TODO: Kirjoita peli tähän
58        LoadAllImages();
59        this.player = new Player();
60        LoadLevel(0);
61    }
62}
Note: See TracBrowser for help on using the repository browser.