source: 2012/30/ArttuP/pong/pong/pong/pong.cs @ 3704

Revision 3704, 2.6 KB checked in by sieerinn, 11 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    Vector nopeusYlos = new Vector(0, 200);
12    Vector nopeusAlas = new Vector(0, -200);
13    PhysicsObject maila1;
14    PhysicsObject maila2;
15
16    IPhysicsObject pallo;
17
18    public override void Begin()
19    {
20        LuoKentta();
21        AloitaPeli();
22        asetaohjaimet();
23    }
24    void LuoKentta()
25    {
26        pallo = new PhysicsObject(100, 100);
27        Add(pallo);
28
29
30
31        maila1 = LuoMaila(Level.Left + 20.0, 0.0);
32        maila2 = LuoMaila(Level.Right - 20.0, 0.0);
33
34
35        pallo.Color = Color.Black;
36        Level.CreateBorders(1.0, false);
37
38
39
40
41        pallo.Shape = Shape.Circle;
42        pallo.X = -200;
43        pallo.Y = 50;
44        pallo.Restitution = 1.0;
45        Level.BackgroundColor = Color.Pink;
46        Camera.ZoomToLevel();
47    }
48    void AloitaPeli()
49    {
50        Vector impulssi = new Vector(600.0, 0.0);
51        pallo.Hit(impulssi);
52    }
53
54    PhysicsObject LuoMaila(double x, double y)
55    {
56        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0);
57        maila.Shape = Shape.Rectangle;
58        maila.X = x;
59        maila.Y = y;
60        maila.Restitution = 1.0;
61        Add(maila);
62        return maila;
63    }
64    void asetaohjaimet()
65    {
66        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli");
67        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
68        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos);
69        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero);
70        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas);
71        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero);
72
73        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos);
74        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero);
75        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas);
76        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero);
77
78        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");
79    }
80    void AsetaNopeus(PhysicsObject maila, Vector nopeus)
81    {
82        maila.Velocity = nopeus;
83    }
84
85}
Note: See TracBrowser for help on using the repository browser.