1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using Jypeli; |
---|
4 | using Jypeli.Assets; |
---|
5 | using Jypeli.Controls; |
---|
6 | using Jypeli.Effects; |
---|
7 | using Jypeli.Widgets; |
---|
8 | |
---|
9 | public 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 | } |
---|