source: 2018/24/TOMASM/TomaksenPeli/TomaksenPeli/TomaksenPeli.cs @ 9747

Revision 9747, 2.0 KB checked in by osedcald, 15 months ago (diff)
Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Widgets;
7
8public class TomaksenPeli : PhysicsGame
9{
10
11    Image alus2 = LoadImage("avaruusalus2");
12    Image alus1 = LoadImage("avaruusalus1");
13    Image ruoho = LoadImage("grass");
14    public override void Begin()
15    {
16        Level.Background.Image = ruoho;
17        Level.Background.Size = Screen.Size;
18
19        PhysicsObject kolmio1 = new PhysicsObject(35, 35);
20        kolmio1.Image = alus1;
21        Add(kolmio1);
22
23        PhysicsObject kolmio2 = new PhysicsObject(35, 35);
24        kolmio2.Image = alus2;
25        Add(kolmio2);
26
27        Keyboard.Listen(Key.A, ButtonState.Down, Rotate, "rotate to left", kolmio1, 3.0);
28        Keyboard.Listen(Key.D, ButtonState.Down, Rotate, "rotate to right", kolmio1, -3.0);
29        Keyboard.Listen(Key.W, ButtonState.Down, Thrust, "thrust forward", kolmio1, 300.0);
30
31        Keyboard.Listen(Key.A, ButtonState.Released, Rotate, "", kolmio1, 0.0);
32        Keyboard.Listen(Key.D, ButtonState.Released, Rotate, "", kolmio1, 0.0);
33
34
35
36        Keyboard.Listen(Key.Left, ButtonState.Down, Rotate, "rotate to left", kolmio2, 3.0);
37        Keyboard.Listen(Key.Right, ButtonState.Down, Rotate, "rotate to right", kolmio2, -3.0);
38        Keyboard.Listen(Key.Up, ButtonState.Down, Thrust, "thrust forward", kolmio2, 300.0);
39
40        Keyboard.Listen(Key.Left, ButtonState.Released, Rotate, "", kolmio2, 0.0);
41        Keyboard.Listen(Key.Right, ButtonState.Released, Rotate, "", kolmio2, 0.0);
42
43       
44
45
46        Level.CreateBorders(false);
47
48
49        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
50    }
51    void Rotate(PhysicsObject pelaaja, double kiertonopeus)
52    {
53
54        pelaaja.AngularVelocity = kiertonopeus;
55       
56    }
57    void Thrust(PhysicsObject pelaaja, double acceleration)
58    {
59        Vector playerDirection = Vector.FromLengthAndAngle(acceleration, pelaaja.Angle);
60        pelaaja.Push(playerDirection);
61
62    }
63
64
65}
Note: See TracBrowser for help on using the repository browser.