source: 2013/26/RoopeR/Pong/Pong/Pong/Pong.cs @ 4197

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