source: 2010/30/samipunn/Pong/Peli.cs @ 1274

Revision 1274, 1.8 KB checked in by samipunn, 13 years ago (diff)

Pong

Line 
1using System;
2using Jypeli;
3using Jypeli.Widgets;
4using Jypeli.Assets;
5
6public class Peli : PhysicsGame
7{
8    Vector nopeusYlos = new Vector(0, 200);
9    Vector nopeusAlas = new Vector(0, -200);
10
11    PhysicsObject pallo;
12    PhysicsObject maila1;
13    PhysicsObject maila2;
14
15    protected override void Begin()
16    {
17
18
19
20
21        Level.CreateBorders(1.0, false);
22
23
24        Camera.ZoomToLevel();
25
26        luokentta();
27        AsetaOhjaimet();
28        AloitaPeli();
29
30
31
32
33
34    }
35
36
37
38
39    void luokentta()
40    {
41        Level.BackgroundColor = Color.Black;
42        pallo = new PhysicsObject(40.0, 40.0);
43        pallo.Shape = Shapes.Circle;
44        Add(pallo);
45
46        pallo.X = -0.0;
47        pallo.Y = 0.0;
48
49        maila1 = LuoMaila(Level.Left + 20.0, 0.0);
50        maila2 = LuoMaila(Level.Right - 20.0, 0.0);
51        pallo.Restitution = 1.0;
52
53        Camera.ZoomToLevel();
54        Vector impulssi = new Vector(500.0, 0.0);
55        pallo.Hit(impulssi);
56
57    }
58   
59    void AloitaPeli()
60    {
61    }
62
63
64
65    PhysicsObject LuoMaila(double x, double y)
66    {
67        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0);
68        maila.Shape = Shapes.Rectangle;
69        maila.X = x;
70        maila.Y = y;
71        maila.Restitution = 1.0;
72        Add(maila);
73
74        return maila;
75
76    }
77
78
79    void AsetaOhjaimet()
80    {
81        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos);
82        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero);
83
84
85
86        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu");
87    }
88    void AsetaNopeus(PhysicsObject maila, Vector nopeus)
89    {
90        maila.Velocity = nopeus;
91    }
92
93
94}
95
96
Note: See TracBrowser for help on using the repository browser.