source: 2011/26/OttoS/Space Race/Space Race/Space Race/Peli.cs @ 2311

Revision 2311, 4.7 KB checked in by oteeansa, 12 years ago (diff)

Talletus.

Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class Peli : PhysicsGame
10{
11    PhysicsObject UFO;
12    Image olionKuva = LoadImage("ufo");
13    Image taustaKuva = LoadImage("m101");
14    int nopeutus = 0;
15    Timer aikaLaskuri;
16    DoubleMeter alaspainLaskuri;
17
18    List<Label> valikonKohdat;
19    Timer ajastin;
20
21
22    public override void Begin()
23    {
24        Valikko();
25        //ValikossaLiikkuminen();
26        //AsetaOhjaimet();
27        //LuoAikaLaskuri();
28    }
29
30    void LuoSatunnainenEste(Timer sender)
31    {
32        double y = RandomGen.NextDouble(Level.Bottom, Level.Top);
33        PhysicsObject Este = PhysicsObject.CreateStaticObject(35.0, 300.0);
34        Add(Este);
35        Este.Tag = "este";
36        Este.X = Level.Left + RandomGen.NextDouble(800, 1200);
37        Este.Y = y;
38        Este.Color = Color.Black;
39        Este.Velocity = new Vector(-250 - (RandomGen.NextDouble(nopeutus/2, nopeutus)), 0.0);
40
41        nopeutus += 9;
42    }
43
44    void AsetaOhjaimet()
45    {
46        Keyboard.Listen(Key.Escape, ButtonState.Released, Exit, null);
47        Keyboard.Listen(Key.Up, ButtonState.Down,
48          LiikutaUFO, null, new Vector(0, 1000));
49        Keyboard.Listen(Key.Down, ButtonState.Down,
50          LiikutaUFO, null, new Vector(0, -1000));
51
52    }
53
54    void LiikutaUFO(Vector vektori)
55    {
56        UFO.Push(vektori);
57
58    }
59    void LuoRajahdys()
60    {
61        ExplosionSystem rajahdys =
62        new ExplosionSystem(LoadImage("123"), 200);
63        rajahdys.Color = Color.Transparent;
64        Add(rajahdys);
65        double x = 0;
66        double y = 0;
67        int pMaara = 50;
68        rajahdys.AddEffect(UFO.X, UFO.Y, pMaara);
69        UFO.Destroy();
70       
71    }
72
73    void KasitteleUfonTormays(PhysicsObject UFO, PhysicsObject kohde)
74    {
75            LuoRajahdys();
76    }
77
78    void LuoAikaLaskuri()
79    {
80        alaspainLaskuri = new DoubleMeter(0);
81
82        Timer aikaLaskuri = new Timer();
83        aikaLaskuri.Interval = 0.1;
84        aikaLaskuri.Trigger += LaskeAlaspain;
85        aikaLaskuri.Start();
86
87        Label aikaNaytto = new Label();
88        aikaNaytto.TextColor = Color.White;
89        aikaNaytto.DecimalPlaces = 1;
90        aikaNaytto.BindTo(alaspainLaskuri);
91        Add(aikaNaytto);
92        aikaNaytto.X = 500;
93        aikaNaytto.Y = 450;
94    }
95
96    void LaskeAlaspain(Timer timer)
97    {
98        alaspainLaskuri.Value += 2;
99
100    }
101
102    void AloitaPeli()
103    {
104        //ajastin.Stop();
105        ClearAll();
106        // Tähän tulee kaikki kentän luomiset ym. alustukset...
107        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Valikko, "Palaa valikkoon");
108        AsetaOhjaimet();
109
110        UFO = new PhysicsObject(30.0, 30.0);
111        Add(UFO);
112        UFO.Image = olionKuva;
113        UFO.X = Level.Left + 250;
114        UFO.Y = 0.0;
115        UFO.IgnoresCollisionResponse = true;
116
117        Vector impulssi = new Vector(500.0, 0.0);
118        UFO.Restitution = 1.0;
119        Level.BackgroundColor = Color.White;
120        Camera.ZoomToLevel();
121        Level.Background.Image = taustaKuva;
122        Level.CreateBorders(true);
123
124        ajastin = new Timer();
125        ajastin.Interval = 1.5;
126        ajastin.Trigger += LuoSatunnainenEste;
127        ajastin.Start();
128        AddCollisionHandler(UFO, KasitteleUfonTormays);
129
130        PhysicsObject ylareuna = Level.CreateTopBorder();
131 
132    }
133
134    void Valikko()
135    {
136        ClearAll();
137        valikonKohdat = new List<Label>();
138
139        Label kohta1 = new Label("Aloita uusi peli");
140        kohta1.Position = new Vector(0, 40);
141        valikonKohdat.Add(kohta1);
142
143        Label kohta2 = new Label("Lopeta");
144        kohta2.Position = new Vector(0, -40);
145        valikonKohdat.Add(kohta2);
146
147        foreach (Label valikonKohta in valikonKohdat)
148        {
149            Add(valikonKohta);
150        }
151
152        Mouse.ListenOn(kohta1, MouseButton.Left, ButtonState.Pressed, AloitaPeli, null);
153        Mouse.ListenOn(kohta2, MouseButton.Left, ButtonState.Pressed, Exit, null);
154
155        Mouse.IsCursorVisible = true;
156        //Mouse.ListenMovement(1.0, ValikossaLiikkuminen, null);
157        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "");
158    }
159
160    /*
161    void ValikossaLiikkuminen(AnalogState hiirenTila)
162    {
163        foreach (Label kohta in valikonKohdat)
164        {
165            if (Mouse.IsCursorOn(kohta))
166            {
167                kohta.TextColor = Color.Red;
168            }
169            else
170            {
171                kohta.TextColor = Color.Black;
172            }
173
174        }
175    }
176     * */
177
178   
179
180
181
182
183
184}
185
Note: See TracBrowser for help on using the repository browser.