source: 2012/30/TinoS/Pong/Pong/Pong/Pong.cs @ 3690

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