source: 2015/26/Tuisku/pong/pong/pong/pong.cs @ 6125

Revision 6125, 3.4 KB checked in by jotapoti, 8 years ago (diff)
Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class pong : PhysicsGame
10{
11    PhysicsObject pallo; 
12    PhysicsObject maila1;
13    PhysicsObject maila2;
14
15    public override void Begin()
16    {
17        luokenttä();
18        AsetaOhjaimet();
19        AloitaPeli();
20
21        Vector nopeusYlös = new Vector(0.0, 200.0);
22        Vector nopeusAlas = new Vector(0.0, -200.0);
23
24        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli");
25        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
26    }
27    void luokenttä()
28    {
29        pallo = new PhysicsObject(40.0, 40.0);
30        pallo.Shape = Shape.Circle;
31        Add(pallo);
32        pallo.X = -200.0;
33        pallo.Y = 0.0;
34        Level.CreateBorders(1.0, false);
35        pallo.Restitution = 1.0;
36
37        maila1 = LuoMaila(Level.Left + 20.0, 0.0);
38        maila2 = LuoMaila(Level.Right + 20.0, 0.0);
39
40         Level.BackgroundColor = Color.Black;
41   
42
43
44
45    }
46
47
48    void AloitaPeli()
49    {
50        Vector impulssi = new Vector(500.0, 0.0);
51        pallo.Hit(impulssi);
52        LuoMaila(Level.Left + 20.0, 0.0);
53        LuoMaila(Level.Right + 20.0, 0.0);
54
55    }
56
57
58
59    PhysicsObject LuoMaila(double x, double y)
60    {
61        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0);
62        maila.Shape = Shape.Rectangle;
63        maila.X = x;
64        maila.Y = y;
65        maila.Restitution = 1.0;
66        Add(maila);
67        return maila;
68
69        PhysicsObject maila2 = PhysicsObject.CreateStaticObject(20.0, 100.0);
70        maila2.Shape = Shape.Rectangle;
71        maila2.X = x;
72        maila2.Y = y;
73        maila2.Restitution = 1.0;
74        Add(maila2);
75        return maila2;
76    }
77
78     
79         void AsetaOhjaimet()
80         { 
81            Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
82
83            Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös",maila1);
84
85            Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero);
86
87
88         }
89
90       
91       void AsetaNopeus(PhysicsObject maila, Vector 20)
92    {
93        maila.Velocity = 20;
94    }
95
96  void AsetaNopeus(PhysicsObject maila, Vector nopeus)
97 {
98   maila.Velocity = nopeus;
99 }
100
101         {
102        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos);
103        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero);
104        Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas);
105        Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero);
106
107        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos);
108        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero);
109        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas);
110        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero);
111
112        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");
113        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
114    }
115
116}
Note: See TracBrowser for help on using the repository browser.