source: 2013/24/OnniV/pong/pong/pong/pong.cs @ 4070

Revision 4070, 1.9 KB checked in by onosvevi, 10 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    Vector nopeusYlös = new Vector(0, 200);
12    Vector nopeusAlas = new Vector(0, -200);
13
14    PhysicsObject pallo;
15
16    PhysicsObject maila1;
17    PhysicsObject maila2;
18
19    public override void Begin()
20    {
21        LuoKentta();
22        asetaohjaimet();
23        aloitapeli();
24       
25       
26    }
27
28    void LuoKentta()
29    {
30        pallo = new PhysicsObject(70.0, 70.0);
31        Add(pallo);
32        pallo.Shape = Shape.Circle;
33        pallo.Color = Color.Lime;
34        pallo.X = 0.0;
35        pallo.Y = 0.0;
36        Level.CreateBorders(1.0, false);
37        pallo.Restitution = 0.8;
38        Level.BackgroundColor = Color.Black;
39        maila1 = luomaila(Level.Left + 20.0, 0.0);
40        maila2 = luomaila(Level.Right - 20.0, 0.0);
41        Camera.ZoomToLevel();
42
43
44
45
46    }
47
48    void aloitapeli()
49    {
50        Vector impulssi = new Vector(700.0, 0.0);
51        pallo.Hit(impulssi);
52    }
53    PhysicsObject luomaila(double X, double Y)
54    {
55        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0);
56        maila.Shape = Shape.Rectangle;
57        maila.X = X;
58        maila.Y = Y;
59        maila.Restitution = 1.0;
60        Add(maila);
61        return maila;
62    }
63
64    void asetaohjaimet()
65    {
66        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, LiikutaMaila1Ylös, "pelaaja1: liikuta mailaa ylös", maila1, nopeusYlös);
67        Keyboard.listen(Key.A, ButtonState.Released, AsetaNopeus, PysäytäMaila1, null, maila1, Vector.Zero);
68        Keyboard.Listen(Key.Escape, ButtonState.Pressed);
69       
70
71
72
73
74    }
75    void AsetaNopeus()
76    {
77        maila1.Velocity = nopeus;
78        maila2.Velocity = nopeus;
79    }
80     
81
82
83
84    }
85}
86   
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102   
103   
104
105   
106
Note: See TracBrowser for help on using the repository browser.