source: 2013/26/ChristianS/PinkkiPonkki/PinkkiPonkki/PinkkiPonkki/PinkkiPonkki.cs @ 4188

Revision 4188, 3.7 KB checked in by chsarre, 10 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 PinkkiPonkki : PhysicsGame
10{
11    Vector nopeusYlos = new Vector(0, 750);
12    Vector nopeusAlas = new Vector(0, -750);
13
14    PhysicsObject pallo;
15
16    PhysicsObject maila1;
17    PhysicsObject maila2;
18
19
20    public override void Begin()
21    {
22       
23        MessageDisplay.Add("Peli alkaa! Ole valmiina!");
24        MessageDisplay.TextColor = Color.White;
25        MessageDisplay.MessageTime = new TimeSpan(0, 0, 10);
26        LuoKentta();
27        Asetaohjaimet();
28        AloitaPeli();
29        LisaaLaskurit();
30
31        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli");
32       
33    }
34    void LuoKentta()
35    {
36        pallo = new PhysicsObject(40.0, 40.0);
37        pallo.Shape = Shape.Circle;
38        Add(pallo);
39        pallo.X = -200.0;
40        pallo.Y = 0.0;
41
42        maila1 = LuoMaila(Level.Left + 20.0, 0.0);
43        maila2 = LuoMaila(Level.Right - 20.0, 0.0);
44
45        Level.CreateBorders(1.0, false);
46        pallo.Restitution = 1.0;
47        Level.BackgroundColor = Color.DarkRed;
48        Camera.ZoomToLevel();
49    }
50    PhysicsObject LuoMaila(double x, double y)
51    {
52        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0);
53        maila.Shape = Shape.Rectangle;
54        maila.X = x;
55        maila.Y = y;
56        maila.Restitution = 1.0;
57        Add(maila);
58        return maila;
59    }
60
61    void AloitaPeli()
62    {
63        Vector impulssi = new Vector(590, 0.0);
64        pallo.Hit(impulssi);
65    }
66    void Asetaohjaimet()
67    {
68        Keyboard.Listen(Key.W, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös",maila1, nopeusYlos);
69        Keyboard.Listen(Key.W, ButtonState.Released,AsetaNopeus, null, maila1, Vector.Zero);
70        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
71        Keyboard.Listen(Key.S,      ButtonState.Down,     AsetaNopeus,     "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas);
72        Keyboard.Listen(Key.S,      ButtonState.Released, AsetaNopeus,     null,                             maila1, Vector.Zero);
73
74        Keyboard.Listen(Key.Up,     ButtonState.Down,     AsetaNopeus,     "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos);
75        Keyboard.Listen(Key.Up,     ButtonState.Released, AsetaNopeus,     null,                             maila2, Vector.Zero);
76        Keyboard.Listen(Key.Down,   ButtonState.Down,     AsetaNopeus,     "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas);
77        Keyboard.Listen(Key.Down,   ButtonState.Released, AsetaNopeus,     null,                             maila2, Vector.Zero);
78
79        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");
80    }
81    void AsetaNopeus(PhysicsObject maila, Vector nopeus)
82    {
83        if ((nopeus.Y > 0) && (maila.Top > Level.Top))
84        {
85            maila.Velocity = Vector.Zero;
86            return;
87        }
88        if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom))
89        {
90            maila.Velocity = Vector.Zero;
91            return;
92        }
93
94        maila.Velocity = nopeus;
95    }
96    void LisaaLaskurit()
97    {
98        // ...
99    }
100   IntMeter LuoPisteLaskuri(double x, double y)
101{
102    IntMeter laskuri = new IntMeter(0);
103    laskuri.MaxValue = 10;
104
105    Label naytto = new Label();
106    naytto.BindTo(laskuri);
107    naytto.X = x;
108    naytto.Y = y;
109    naytto.TextColor = Color.White;
110    naytto.BorderColor = Level.BackgroundColor;
111    naytto.Color = Level.BackgroundColor;
112    Add(naytto);
113
114    return laskuri;
115}
116
117
118}
Note: See TracBrowser for help on using the repository browser.