source: 2013/26/LeeviK/Pong/Pong/Pong/Pong.cs @ 4202

Revision 4202, 1.7 KB checked in by juiitamm, 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 Pong : PhysicsGame
10{
11    Vector nopeusYlös = new Vector(0, 200);
12    Vector nopeusAlas = new Vector(0, 200);
13
14    PhysicsObject maila1;
15    PhysicsObject maila2;
16    PhysicsObject pallo;
17    public override void Begin()
18    { 
19        LuoKentta();
20        AsetaOhjaimet();
21        AloitaPeli();
22        // TODO: Kirjoita ohjelmakoodisi tähän
23
24
25       
26    }
27    void LuoKentta()
28    {
29        pallo = new PhysicsObject(40.0, 40.0);
30        pallo.Shape = Shape.Circle;
31        pallo.X = -200;
32        pallo.Restitution = 1.0;
33        Add(pallo);
34        LuoMaila(Level.Left + 20.0, 0.0);
35        LuoMaila(Level.Right - 20.0, 0.0);
36
37        Level.CreateBorders(1.0, false);
38        Level.BackgroundColor = Color.Black;
39        Camera.ZoomToLevel();
40
41    }void AloitaPeli()
42    {  Vector impulssi = new Vector(500.0, 200.0);
43        pallo.Hit(impulssi);
44    }
45    void LuoMaila(double x, double y)
46    {
47        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0);
48        maila.Shape = Shape.Rectangle;
49        maila.X = x;
50        maila.Y = y;
51        maila.Restitution = 1.0;
52        Add(maila);
53    }
54    void AsetaOhjaimet()
55    {
56        Keyboard.Listen(Key.A, ButtonState.Down, LiikutaMaila1Ylos, Pelaaja1: "Liikuta mailaa ylös");
57        Keyboard.Listen(Key.A, ButtonState.Released, PysaytaMaila1, null);
58
59        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
60 
61    }
62    void Asetanopeus(PhysicsObject maila, Vector nopeus)
63    {
64        maila.Velocity = nopeus;
65    }
66}
Note: See TracBrowser for help on using the repository browser.