source: 2010/30/jyniinin/SeppoPeli/Peli.cs @ 1402

Revision 1402, 3.9 KB checked in by jyniinin, 13 years ago (diff)

jotakin taaaaaas

Line 
1using System;
2using Jypeli;
3using Jypeli.Widgets;
4using Jypeli.Assets;
5
6
7class Tasohyppely : PhysicsGame
8{
9
10    Image paikallaanVasemmalle = LoadImage("Seppo 2");
11    Image paikallaanOikealle;
12
13    Image[] kavelyVasemmalle = LoadImages("seppo 4");
14    Image[] kavelyOikealle;
15
16
17
18
19    const double nopeus = 200;
20    const double hyppyVoima = 4000;
21
22    PlatformCharacter Seppo;
23    PlatformCharacter norsu;
24    PlatformCharacter tahti;
25    PlatformCharacter maali;
26
27
28
29
30
31    protected override void Begin()
32
33    {
34        Gravity = new Vector(0, -1000);
35
36        Image paikallaanVasemmalle = LoadImage("heppu1");
37        Image paikallaanOikealle;
38
39        Image[] kavelyVasemmalle = LoadImages("heppu1", "heppu2", "heppu3");
40        Image[] kavelyOikealle;
41
42
43
44
45        luoKentta();
46        lisaaNappaimet();
47
48        Camera.Follow(Seppo);
49        Camera.ZoomFactor = 2.0;
50        Camera.StayInLevel = true;
51       
52    }
53
54    void luoKentta()
55    {
56        Level.Background.CreateGradient(Color.White, Color.SkyBlue);
57        PhysicsObject vasenReuna = Level.CreateLeftBorder();
58        vasenReuna.StaticFriction = 0;
59        PhysicsObject OikeaReuna = Level.CreateRightBorder();
60        OikeaReuna.StaticFriction = 0;
61        PhysicsObject Pohja = Level.CreateBottomBorder();
62        Pohja.StaticFriction = 0;
63
64
65
66
67        lisaaTaso(-200, -350);
68        lisaaTaso(0, -200);
69 
70
71        lisaaPelaajat();
72        LisaaViholliset();
73 
74    }
75
76
77    void lisaaTaso(double x, double y)
78    {
79        PhysicsObject taso = PhysicsObject.CreateStaticObject(100, 30);
80        taso.Color = Color.Green;
81        taso.X = x;
82        taso.Y = y;
83        Add(taso);
84    }
85
86    void lisaaPelaajat()
87    {
88        Seppo = new PlatformCharacter(30,50);
89        Seppo.Mass = 4.0;
90        Seppo.Image = LoadImage("Seppo");
91        Seppo.X = 0;
92        Seppo.Y = Level.Bottom + 120;
93
94        Add(Seppo);
95
96        maali = new PlatformCharacter(120, 130);
97        maali.Mass = 4.0;
98        maali.Image = LoadImage("Koti Maali");
99        maali.X = 200;
100        maali.Y = Level.Bottom + 120;
101
102        Add(maali);
103    }
104    void LisaaViholliset()
105    {
106        norsu = new PlatformCharacter(80, 80);
107        norsu.Mass = 8.0;
108        norsu.Image = LoadImage("norsu");
109        norsu.X = 40;
110        norsu.Y = Level.Bottom + 420;
111       
112
113       
114        Add(norsu);
115
116       tahti = new PlatformCharacter(40, 40);
117       tahti.Mass = 10.0;
118       tahti.Image = LoadImage("tahti");
119       tahti.X = 100;
120       tahti.Y = Level.Bottom + 320;
121       tahti.AngularVelocity = 5.0;
122
123       Add(tahti);
124       
125    }
126
127
128    void lisaaNappaimet()
129    {
130        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");
131        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä");
132
133        Keyboard.Listen(Key.Left, ButtonState.Down, liikuta, "Liikkuu vasemmalle", Seppo, -nopeus);
134        Keyboard.Listen(Key.Right, ButtonState.Down, liikuta, "Liikkuu oikealle", Seppo, nopeus);
135        Keyboard.Listen(Key.Up, ButtonState.Pressed, hyppaa, "Hyppää", Seppo, hyppyVoima);
136
137        ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä");
138
139        ControllerOne.Listen(Button.DPadLeft, ButtonState.Down, liikuta, "Pelaaja liikkuu vasemmalle", Seppo, -nopeus);
140        ControllerOne.Listen(Button.DPadRight, ButtonState.Down, liikuta, "Pelaaja liikkuu oikealle", Seppo, nopeus);
141        ControllerOne.Listen(Button.A, ButtonState.Pressed, hyppaa, "Pelaaja hyppää", Seppo, hyppyVoima);
142        ControllerOne.Listen(Button.Start, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");
143
144    }
145
146    void liikuta(PlatformCharacter hahmo, double nopeus)
147    {
148        hahmo.Walk(nopeus);
149    }
150
151    void hyppaa(PlatformCharacter hahmo, double voima)
152    {
153        hahmo.Jump(voima  ); 
154    }
155
156   
157}
158
159   
160
161
162
Note: See TracBrowser for help on using the repository browser.