source: 2014/27/JouniP_esimerkki/Pongpeli/Pongpeli/Pongpeli/Pongpeli.cs @ 5193

Revision 5193, 1.8 KB checked in by jotapoti, 9 years ago (diff)

luennolla tehdyt esimerkit: ohjelman jakaminen aliohjelmiin, usean mailan tekeminen

Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class Pongpeli : PhysicsGame
10{
11    PhysicsObject pallo;
12
13    public override void Begin()
14    {
15        LuoKentta();
16
17        Camera.ZoomToLevel(); // zoomataan kamera niin, että koko kenttä näkyy
18
19        // lyödään pallo liikkeelle:
20        Vector impulssi = new Vector(500.0, 0.0);
21        pallo.Hit(impulssi);
22
23
24        LisaaOhjaimet();
25
26
27    }
28
29    void LuoMaila(double x, double y)
30    {
31        PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0);
32        maila.Shape = Shape.Rectangle;
33        maila.X = x;
34        maila.Y = y;
35        maila.Restitution = 1.0;
36        Add(maila);
37    }                                                       
38                                                           
39    void LuoKentta()                                       
40    {                                                       
41        // luodaan peliin pallo:                           
42        pallo = new PhysicsObject(40.0, 40.0);             
43        pallo.Shape = Shape.Circle;                         
44        pallo.X = -200.0;                                   
45        pallo.Y = 0.0;
46        pallo.Restitution = 1.0;
47        Add(pallo);
48
49        // luodaan peliin mailat:
50        LuoMaila(Level.Left + 20.0, 0.0);
51        LuoMaila(Level.Right - 20.0, 0.0);
52
53        // luodaan peliin reunat:
54        Level.CreateBorders(1.0, false);
55        Level.Background.Color = Color.Black;
56
57    }
58
59    void LisaaOhjaimet()
60    {
61        // lisätään peliin ohjaimet:
62        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
63    }
64}
Note: See TracBrowser for help on using the repository browser.