source: 2012/JAO/Tero/Pong/Pong/Pong/Pong.cs @ 2694

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