source: 2016/24/HaseebS/FysiikkaPeli1/FysiikkaPeli1/FysiikkaPeli1/FysiikkaPeli1.cs @ 7279

Revision 7279, 1.5 KB checked in by empaheik, 5 years ago (diff)

I created my first game. It in middle of the work. Hopefully it would be finished tomorrow. I am creating Ping Pong

Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class FysiikkaPeli1 : PhysicsGame
10{
11    PhysicsObject ball;
12    public override void Begin()
13    {
14        CreateLevel();
15        StartGame();   
16    }
17    void CreateLevel()
18    {
19        ball = new PhysicsObject(40.0, 40.0);
20        ball.Shape = Shape.Circle;
21        ball.X = 100.0;
22        ball.Y = -0.0;
23        ball.Restitution = 1.0;
24        Add(ball);
25
26        CreatePaddle(Level.Right -20, 0.0);
27        CreatePaddle(Level.Left +20, 0.0);
28       
29           
30
31
32        Camera.ZoomToLevel();
33
34        Level.Background.Color = Color.Black;
35        Level.CreateBorders(1.0, true);
36    }
37    void StartGame()
38    {
39        Vector impulse = new Vector(-400.0, 0.0);
40        ball.Hit(impulse);
41    }
42
43    void CreatePaddle(double x, double y)
44    {
45        PhysicsObject paddle = PhysicsObject.CreateStaticObject(20.0, 100.0);
46        paddle.Shape = Shape.Rectangle;
47        paddle.X = x;
48        paddle.Y = y;
49        paddle.Restitution = 1.0;
50        Add(paddle);
51    }
52
53    void SetControls()
54    {
55        Keyboard.Listen(Key.A, ButtonState.Down, MovePaddle1Up, "Player, When you press A, Paddle goes up" );
56        Keyboard.Listen(Key.A, ButtonState.Released, StopPaddle1, "Playe When you release A, Paddle stop " )
57        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
58    }
59}
Note: See TracBrowser for help on using the repository browser.