source: 2010/30/jojumuho/Pong/Peli.cs @ 1279

Revision 1279, 2.7 KB checked in by jojumuho, 13 years ago (diff)

pongi vielä kesken kohta valmis
hahaha

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