source: 2010/23/Kavaisan/Pong/Peli.cs @ 512

Revision 512, 2.7 KB checked in by kavaisan, 13 years ago (diff)

TEin pong pelin.

Line 
1using System;
2using Jypeli;
3using Jypeli.ScreenObjects;
4using Jypeli.Assets;
5
6namespace Pong
7{
8    public class Peli : PhysicsGame
9    {
10        PhysicsObject Pallo;
11        PhysicsObject maila1;
12        PhysicsObject maila2;
13
14
15
16
17
18        protected override void Begin()
19        {
20            LuoKentta();
21            AsetaOhjaimet();
22            Aloitapeli();
23
24
25
26        }
27        void LuoKentta()
28        {
29            Pallo = new PhysicsObject(40.0, 40.0);
30            Pallo.Shape = Shapes.Circle;
31            Pallo.X = -200.0;
32            Pallo.Y = 0.0;
33            Pallo.Restitution = 1.0;
34            Add(Pallo);
35
36            maila1 = LuoMaila(Level.Left + 20.0, 0.0);
37            maila2 = LuoMaila(Level.Right - 20.0, 0.0);
38
39            Level.CreateBorders(1.0, false);
40            Level.BackgroundColor = Color.Black;
41
42            Camera.ZoomToLevel();
43
44
45            Level.CreateBorders();
46            Pallo.Restitution = 1.0;
47        }
48        void Aloitapeli()
49        {
50            Vector impulssi = new Vector(500.0, 0.0);
51            Pallo.Hit(impulssi);
52        }
53
54
55        PhysicsObject LuoMaila(double x, double y)
56        {
57            PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0);
58            maila.Shape = Shapes.Rectangle;
59            maila.X = x;
60            maila.Y = y;
61            maila.Restitution = 1.0;
62            Add(maila);
63            return maila;
64        }
65        void AsetaOhjaimet()
66        {
67            Keyboard.Listen(Key.A, ButtonState.Pressed, LiikutaMailaaYlos, "Pelaaja 1: Liikuta mailaa ylös", maila1);
68            Keyboard.Listen(Key.A, ButtonState.Released, PysaytaMaila, null, maila1);
69            Keyboard.Listen( Key.Z, ButtonState.Pressed, LiikutaMailaaAlas, "Pelaaja 1: Liikuta mailaa alas", maila1 );
70            Keyboard.Listen( Key.Z, ButtonState.Released, PysaytaMaila, null, maila1 );
71
72            Keyboard.Listen( Key.Up, ButtonState.Pressed, LiikutaMailaaYlos, "Pelaaja 2: Liikuta mailaa ylös", maila2 );
73            Keyboard.Listen( Key.Up, ButtonState.Released, PysaytaMaila, null, maila2 );
74            Keyboard.Listen( Key.Down, ButtonState.Pressed, LiikutaMailaaAlas, "Pelaaja 2: Liikuta mailaa alas", maila2 );
75            Keyboard.Listen( Key.Down, ButtonState.Released, PysaytaMaila, null, maila2 );
76
77
78            Keyboard.Listen( Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet" );
79            Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu");
80        }
81
82            void LiikutaMailaaYös( PhysicsObject maila ) 
83            {
84                Vector nopeus = new Vector(0, 200);
85                maila.Velocity = nopeus;
86            }
87           
88
89        }
90    }
91}
Note: See TracBrowser for help on using the repository browser.