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

Revision 5256, 2.4 KB checked in by mijoilmo, 8 years ago (diff)

Tein liikkumisen uudestaan. Outo bugi että lieska ei näy kun peruuttaa vaikka pitäisi periaatteessa koodin mukaan näkyä.

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["player_thruster"] =             LoadImage("graphics/effects/thrusters/thruster0.1");
30        images["tile0"] =                       LoadImage("graphics/tiles/tile0.png");
31    }
32    void LoadLevel(string level)
33    {
34        ClearAll();
35        Add(this.player);
36        Camera.Follow(this.player);
37        AssignKeys();
38        LevelFromImage("graphics/levels/" + level);
39    }
40    void LevelFromImage(string levelName)
41    {
42        ColorTileMap tileMap = ColorTileMap.FromLevelAsset(levelName);
43        tileMap.SetTileMethod(Color.FromHexCode("000000"), createTile, "");
44        tileMap.SetTileMethod(Color.FromHexCode("ff0000"), spawnPlayer);
45        tileMap.Execute(40,40);
46    }
47    void createTile(Vector position, double w, double h, string id)
48    {
49        MikonPhysicsObject tile = new MikonPhysicsObject(this, w, h);
50        tile.MakeStatic();
51        tile.Position = position;
52        if (id != "")
53        {
54            tile.Image = images[id];
55        }
56        Add(tile);
57    }
58    void spawnPlayer(Vector position, double w, double h)
59    {
60        player.Position = position;
61    }
62    public override void Begin()
63    {
64        // TODO: Kirjoita peli tähän
65        LoadAllImages();
66        this.player = new Player();
67        LoadLevel("test");
68    }
69}
Note: See TracBrowser for help on using the repository browser.