source: 2010/24/Vilvaini/Pongi/Peli.cs @ 804

Revision 804, 1.8 KB checked in by vilvaini, 13 years ago (diff)

Kaikki valmiina paitsi toisen mailan liikuttaminen, pisteet ja toisen mailan alasliikuttaminen.

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