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 TheUnknowProject : PhysicsGame |
---|
10 | { |
---|
11 | Image startScreen = LoadImage("startScreen"); |
---|
12 | PlatformCharacter player; |
---|
13 | double walkSpeed = 100; |
---|
14 | double jumpSpeed = 500; |
---|
15 | |
---|
16 | //Gamedata |
---|
17 | Image playerImg; |
---|
18 | |
---|
19 | |
---|
20 | public override void Begin() |
---|
21 | { |
---|
22 | //Create game menu |
---|
23 | IsMouseVisible = true; |
---|
24 | Level.Background.Image = startScreen; |
---|
25 | |
---|
26 | PushButton button = new PushButton("Start game"); |
---|
27 | button.Position = new Vector(0, Level.Bottom * 0.9); |
---|
28 | button.Clicked += new Action(startGame); |
---|
29 | Add(button); |
---|
30 | } |
---|
31 | |
---|
32 | void loadContent() |
---|
33 | { |
---|
34 | //Load content here! |
---|
35 | playerImg = LoadImage("player"); |
---|
36 | } |
---|
37 | |
---|
38 | void setControls() |
---|
39 | { |
---|
40 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
41 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
42 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
43 | |
---|
44 | //Keyboard.Listen(Key.W, ButtonState.Down, move, "not set yet", pelaaja1, -nopeus); |
---|
45 | Keyboard.Listen(Key.A, ButtonState.Down, move, "Liikkuu vasemmalle", player, -walkSpeed); |
---|
46 | Keyboard.Listen(Key.D, ButtonState.Down, move, "Liikkuu vasemmalle", player, walkSpeed); |
---|
47 | Keyboard.Listen(Key.Space, ButtonState.Pressed, jump, "Pelaaja hyppää", player, jumpSpeed); |
---|
48 | } |
---|
49 | |
---|
50 | void move(PlatformCharacter character, double speed) |
---|
51 | { |
---|
52 | character.Walk(speed); |
---|
53 | } |
---|
54 | |
---|
55 | void jump(PlatformCharacter character, double speed) |
---|
56 | { |
---|
57 | character.Jump(speed); |
---|
58 | } |
---|
59 | |
---|
60 | void startGame() |
---|
61 | { |
---|
62 | //Start game here! |
---|
63 | ClearAll(); |
---|
64 | loadContent(); |
---|
65 | Level.CreateBorders(); |
---|
66 | Gravity = new Vector(0, -1000); |
---|
67 | Camera.ZoomToLevel(); |
---|
68 | |
---|
69 | player = new PlatformCharacter(120, 120); |
---|
70 | player.Position = new Vector(0, 0); |
---|
71 | player.Mass = 4; |
---|
72 | player.Image = playerImg; |
---|
73 | Add(player); |
---|
74 | |
---|
75 | setControls(); |
---|
76 | } |
---|
77 | } |
---|