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 Peli : PhysicsGame |
---|
10 | { |
---|
11 | Image hahmonKuva = LoadImage("hahmo"); |
---|
12 | Shape hahmonMuoto; |
---|
13 | |
---|
14 | PlatformCharacter hahmo; |
---|
15 | |
---|
16 | public override void Begin() |
---|
17 | { |
---|
18 | // TODO: Kirjoita ohjelmakoodisi tähän |
---|
19 | hahmonMuoto = Shape.FromImage(hahmonKuva); |
---|
20 | LuoKenttä(); |
---|
21 | AloitaPeli(); |
---|
22 | AsetaOhjaimet(); |
---|
23 | |
---|
24 | |
---|
25 | } |
---|
26 | void LuoAloitusruutu() |
---|
27 | { |
---|
28 | } |
---|
29 | void LuoKenttä() |
---|
30 | { |
---|
31 | TileMap kentta = TileMap.FromFile("kentta.txt"); |
---|
32 | kentta['%'] = lisaaTaso; |
---|
33 | kentta['#'] = lisaaTaso; |
---|
34 | kentta['/'] = lisaaTaso; |
---|
35 | kentta['='] = lisaaTaso; |
---|
36 | kentta['+'] = lisaaTaso; |
---|
37 | kentta.Insert(40.0, 40.0); |
---|
38 | |
---|
39 | hahmo = new PlatformCharacter(50, 50, hahmonMuoto); |
---|
40 | hahmo.Image = hahmonKuva; |
---|
41 | hahmo.X = -2300.0; |
---|
42 | hahmo.Y = -225.0; |
---|
43 | |
---|
44 | Add(hahmo); |
---|
45 | |
---|
46 | //PhysicsObject alaReuna = Level.CreateBottomBorder(1.0, true); |
---|
47 | Gravity = new Vector(0.0, -800.0); |
---|
48 | //Level.CreateBorders(); |
---|
49 | Camera.Follow(hahmo); |
---|
50 | Camera.StayInLevel = true; |
---|
51 | //Timer ajastin = new Timer(); |
---|
52 | //ajastin.Interval = 0.01; |
---|
53 | //ajastin.Trigger += liikutaHahmoa; |
---|
54 | //ajastin.Start(); |
---|
55 | } |
---|
56 | PhysicsObject lisaaTaso() |
---|
57 | { |
---|
58 | PhysicsObject taso = PhysicsObject.CreateStaticObject(40.0, 40.0); |
---|
59 | taso.Color = Color.Green; |
---|
60 | return taso; |
---|
61 | } |
---|
62 | void AloitaPeli() |
---|
63 | { |
---|
64 | Vector impulssi = new Vector(300.0, 0.0); |
---|
65 | hahmo.Hit(impulssi); |
---|
66 | } |
---|
67 | void AsetaOhjaimet() |
---|
68 | { |
---|
69 | Keyboard.Listen(Key.Right, ButtonState.Down, AsetaNopeus, "Paina oikealle nuolta niin hahmo liikkuu oikealle", new Vector(10000.0, 0.0)); |
---|
70 | Keyboard.Listen(Key.Left, ButtonState.Down, AsetaNopeus, "Paina nuolta oikealle niin hahmo liikkuu oikealle", new Vector(-10000.0, 0.0)); |
---|
71 | Keyboard.Listen(Key.Space, ButtonState.Pressed, LiikutaPelaajaa, "Paina SPACE niin hahmo hyppää"); |
---|
72 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
73 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); |
---|
74 | |
---|
75 | } |
---|
76 | void AsetaNopeus(Vector vektori) |
---|
77 | { |
---|
78 | hahmo.Push(vektori); |
---|
79 | } |
---|
80 | |
---|
81 | void LiikutaPelaajaa() |
---|
82 | { |
---|
83 | hahmo.Jump(1000.0); |
---|
84 | } |
---|
85 | //void liikutaHahmoa(Timer Sender) |
---|
86 | //{ |
---|
87 | //hahmo.Velocity = new Vector(100.0, hahmo.Velocity.Y); |
---|
88 | //} |
---|
89 | |
---|
90 | } |
---|