source: 2010/27/jomialja/Catch The Rainbow/Catch The Rainbow/Peli.cs @ 1222

Revision 1222, 3.4 KB checked in by jomialja, 13 years ago (diff)

ääni

Line 
1using System;
2using Jypeli;
3using Jypeli.Widgets;
4using Jypeli.Assets;
5
6public class Peli : PhysicsGame
7
8{
9    const int ruudunleveys = 50;
10    const int ruudunkorkeus = 50;
11
12    Vector NopeusEteen = new Vector(200, 0);
13
14    PhysicsObject Crossword;
15
16    PlatformCharacter Max;
17
18    protected override void Begin()
19    {
20        LuoMax();
21        AsetaOhjaimet();
22        LuoKentta();
23       
24    }
25    void LuoKentta()
26    {
27        Camera.FollowedObject = Max;
28
29        TileMap ruudut = TileMap.FromFile("Kentta 1.txt");
30        ruudut ['='] = LuoPalikka;
31        ruudut['C'] = LuoRainbow;
32        ruudut['J'] = LuoCrossword;
33        ruudut.Insert(ruudunleveys, ruudunkorkeus);
34
35        Gravity = new Vector(0.0, -800.0);
36       
37    }
38    PhysicsObject LuoPalikka()
39    {
40        PhysicsObject Palikka = PhysicsObject.CreateStaticObject(50, 50);
41        Palikka.Color = Color.Brown;
42        return Palikka;
43    }
44   PhysicsObject LuoRainbow()
45    {
46        PhysicsObject Rainbow = PhysicsObject.CreateStaticObject(25, 25);
47        Rainbow.Image = Image.FromFile("Rainbow.png");
48        AddCollisionHandler(Rainbow, KasitteleRainbownTormaus);
49        return Rainbow;
50    }
51
52    void LuoMax()
53    {
54        Max = new PlatformCharacter(35,45);
55        Max.Restitution = 0.0;
56        Max.CanRotate = false;
57        Max.X = -450;
58        Max.Y = -365;
59        Max.Image = Image.FromFile("Max Mechanic.png");
60        Max.KineticFriction = 0.0;
61        Add (Max);
62        return;
63    }
64
65    void AsetaOhjaimet()
66    {
67        Keyboard.Listen(Key.A, ButtonState.Down, PelaajaLiikuTaakse, "Liiku Taaksepäin");
68        Keyboard.Listen(Key.A, ButtonState.Released, PelaajaPysahdy, null);
69        Keyboard.Listen(Key.D, ButtonState.Down, PelaajaLiikuEteenpain, "Liiku Eteenpäin");
70        Keyboard.Listen(Key.D, ButtonState.Released, PelaajaPysahdy, null);
71        Keyboard.Listen(Key.W, ButtonState.Down, PelaajaHypaa, "Hyppää");
72
73
74        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");
75        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu");
76    }
77    void PelaajaLiikuEteenpain()
78    {
79        Max.Walk(300);
80        Max.Image = Image.FromFile("Max Mechanic.png");
81    }
82
83    void PelaajaLiikuTaakse()
84    {
85        Max.Walk (-300);
86        Max.Image = Image.FromFile("max mechanic2.png");
87    }
88
89    void PelaajaPysahdy()
90    {
91        Vector nopeus = new Vector(0.0, 0);
92    }
93
94    void PelaajaHypaa()
95    {
96        Max.Jump(1000);
97    }
98    PhysicsObject LuoCrossword()
99    {
100        Crossword = new PhysicsObject(35.0, 45.0);
101        Crossword.Image = Image.FromFile("Crossword_hand.png");
102
103        Timer ajastin = new Timer();
104        ajastin.Tag = Crossword;
105        ajastin.Interval = 1;
106        ajastin.Trigger += Tekoaly;
107        Add (ajastin);
108        ajastin.Start();
109        return Crossword;
110    }
111    void Tekoaly(Timer sender)
112    {
113        PhysicsObject vihollinen = (PhysicsObject)sender.Tag;
114        double etaisyys = vihollinen.X - Max.X;
115        if (etaisyys < 0)
116        {
117            etaisyys = etaisyys * -1;
118        }
119        if (etaisyys < 150)
120        {
121            vihollinen.Image = LoadImage("Crossword2");
122        }
123        sender.Start();
124    }
125    void KasitteleRainbownTormays( PhysicsObject Rainbow, PhysicsObject kohde)
126    {
127     
128    } 
129
130}
Note: See TracBrowser for help on using the repository browser.