source: 2010/27/frjolehm/The King of the island/The King of the island/Peli.cs @ 1125

Revision 1125, 3.3 KB checked in by frjolehm, 13 years ago (diff)
Line 
1using System;
2using Jypeli;
3using Jypeli.Widgets;
4using Jypeli.Assets;
5
6public class Peli : PhysicsGame
7{
8    PlatformCharacter pelaaja1;
9    PlatformCharacter pelaaja2;
10
11    PhysicsObject vasenreuna;
12    PhysicsObject oikeareuna;
13    PhysicsObject alareuna;
14    PhysicsObject yläreuna;
15
16    Boolean Pelaajan1JuoksuAskel;
17    Boolean Pelaajan2JuoksuAskel;
18
19    const double Juoksunopeus = 20;
20
21    protected override void Begin()
22    {
23        Aloitapikkupeli(1);
24    }
25
26    void Aloitapikkupeli(int peliMuoto)
27    {
28        //Kuoleman juoksu
29        if (peliMuoto == 1){
30            LuoKenttä(800,700);
31            AddCollisionHandler(oikeareuna, JuoksuVoitto);
32            pelaaja1 = LuoUkko(Level.Left + 30,Level.Bottom + 75,100, 100);
33            pelaaja2 = LuoUkko(Level.Left+ 30,Level.Bottom + 200, 100, 100);
34            JuoksuOhjaimet();
35        }
36
37    }
38
39    void LuoKenttä(double width, double height)
40    {
41        Level.Width = width;
42        Level.Height = height;
43
44        vasenreuna = Level.CreateLeftBorder();
45        vasenreuna.IsVisible = false;
46
47        oikeareuna = Level.CreateRightBorder();
48        oikeareuna.IsVisible = false;
49
50        yläreuna = Level.CreateTopBorder(); 
51        yläreuna.IsVisible = false;
52
53        alareuna = Level.CreateBottomBorder();
54        alareuna.IsVisible = false;
55
56
57        Camera.ZoomToLevel();
58
59    }
60
61    void JuoksuOhjaimet() 
62    {
63        Keyboard.Listen(Key.A, ButtonState.Pressed, LuoJuoksu, "Pelaaja liikkuu", pelaaja1, false, false);
64        Keyboard.Listen(Key.D, ButtonState.Pressed, LuoJuoksu, "Pelaaja liikkuu", pelaaja1, false, true);
65
66        Keyboard.Listen(Key.Left, ButtonState.Pressed, LuoJuoksu, "Pelaaja2 liikkuu", pelaaja2, true, false);
67        Keyboard.Listen(Key.Right, ButtonState.Pressed, LuoJuoksu, "Pelaaja2 liikkuu", pelaaja2, true, true);
68    }
69
70    //                   ukko          false = p1 true = p2    false = n1 true = n2
71    void LuoJuoksu(PlatformCharacter ukko, Boolean pelaaja, Boolean näppäin)
72    {
73        //Pelaaja 1
74        if (pelaaja == false)
75        {
76            if (näppäin == Pelaajan1JuoksuAskel)
77            {
78                Liikuta(ukko, Juoksunopeus);
79                if (Pelaajan1JuoksuAskel == true)
80                {
81                    Pelaajan1JuoksuAskel = false;
82                }
83
84            }
85        }
86        else
87        {
88            if (näppäin == Pelaajan2JuoksuAskel)
89            {
90                Liikuta(ukko, Juoksunopeus);
91                if (Pelaajan2JuoksuAskel == true)
92                {
93                    Pelaajan2JuoksuAskel = false;
94                }
95            }
96        }
97    }
98
99    void JuoksuVoitto(PhysicsObject maali, PlatformCharacter kohde) 
100    { 
101        if(kohde == pelaaja1)
102        {
103            ClearAll();
104        }
105        else if (kohde == pelaaja2) 
106        {
107            ClearAll();
108        }
109    }
110
111
112
113    void Liikuta(PlatformCharacter ukko, double nopeus)
114    {
115        ukko.Walk(nopeus);
116    }
117
118    PlatformCharacter LuoUkko(double x, double y, double kokoX, double kokoY)
119    {
120        PlatformCharacter ukko = new PlatformCharacter(kokoX, kokoY, Shapes.Circle);
121        ukko.Mass = 4.0;
122        ukko.X = x;
123        ukko.Y = y;
124        ukko.Image = LoadImage("Tipu1");
125        Add(ukko);
126        return ukko;
127    }
128}
Note: See TracBrowser for help on using the repository browser.