source: 2010/30/pyryl/pong/Peli.cs @ 1276

Revision 1276, 1.9 KB checked in by paaaanro, 13 years ago (diff)

Pyryn Pongi

Line 
1using System;
2using Jypeli;
3using Jypeli.Widgets;
4using Jypeli.Assets;
5
6public class Peli : PhysicsGame
7{
8    Vector NopeusYlos = new Vector (200.0);
9    Vector NopeusAlas = new Vector (-200.0);
10
11    PhysicsObject pallo;
12
13    protected override void Begin()
14    {
15        LuoKentta();
16        AsetaOhjaimet();
17        AloitaPeli();
18        //TODO: Alusta peli tässä
19       // LuoKentta();
20       
21       
22
23    }
24    void LuoKentta()
25    {
26        pallo = new PhysicsObject(40.0, 40.0);
27
28        pallo.Shape = Shapes.Circle;
29        Add(pallo);
30        pallo.X = 0.0;
31        pallo.Y = 0.0;
32
33        Level.CreateBorders(1.0, false);
34        pallo.Restitution = 1.0;
35        pallo.KineticFriction = 0;
36        Level.BackgroundColor = Color.Black;
37        Camera.ZoomToLevel();
38        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0);
39        maila.Shape = Shapes.Rectangle;
40        maila.X = Level.Left + 20.0;
41        maila.Y = 0.0;
42        maila.Restitution = 1.0;
43        Add(maila);
44        maila1 = LuoMaila (Level.Left + 20.0, 0.0);
45        maila2 = LuoMaila(Level.Right - 20.0, 0.0);
46    }
47    void AloitaPeli()
48    {
49        Vector impulssi = new Vector(500.0, 0.0);
50        pallo.Hit(impulssi);
51    }
52    PhysicsObject LuoMaila (double x, double y )
53    {
54        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0);
55        maila.Shape = Shapes.Rectangle;
56        maila.X = x;
57        maila.Y = y;
58        maila.Restitution = 1.0;
59        Add(maila);
60        return maila;
61}
62    void AsetaOhjaimet()
63    {
64        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu");
65        Keyboard.Listen (Key.A ButtonState.Down, LiikutaMailaaYlos, "Pelaaja 1: Liikuta Mailaa Ylos");
66        Keyboard.Listen (Key.A ButtonState.Released PysaytaMaila, Null);
67    }
68{void AsetaNopeus ( PhysicsObject maila, Vector nopeus )
69{
70   maila.Velocity = nopeus;
71
72}
73}
Note: See TracBrowser for help on using the repository browser.