source: 2010/24/elariilo/Pong/Peli.cs @ 814

Revision 814, 1.8 KB checked in by hniemi, 13 years ago (diff)

Tein pong peliä sen verran että sain mailat valmiiksi mutta tuli virhe niiden liikuttamisessa )=

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