source: 2010/23/ekeimaja/Labyrinth/Labyrinth/Peli.cs @ 633

Revision 633, 4.9 KB checked in by ekeimaja, 13 years ago (diff)

eipä mitään uutta...

Line 
1using System;
2using Jypeli;
3using Jypeli.ScreenObjects;
4using Jypeli.Assets;
5using System.Collections.Generic;
6
7
8namespace Labyrinth // © Eki Majankallio 2010
9{ //wanderedbrainilla hirviöt
10    public class Peli : PhysicsGame
11    {
12        PhysicsObject Pelaaja1;
13        PhysicsObject Pelaaja2;
14
15        const int RuudunLeveys = 50;
16        const int RuudunKorkeus = 50;
17
18        protected override void Begin()
19        {
20           
21
22
23            var merkit = new Dictionary<char, ObjectCreator>();
24            merkit['x'] = LuoSeina;
25            merkit['D'] = LuoHirvio;
26            merkit['0'] = LuoRuoka;
27            merkit['1'] = LuoPelaaja1;
28            merkit['2'] = LuoPelaaja2;
29            merkit['F'] = LuoMaali;
30
31            char[,] ruudut = Tiles.ReadFromFile("kentta1.txt");
32
33            Tiles.Insert(this, ruudut, merkit, RuudunLeveys, RuudunKorkeus);
34
35            LuoOhjain();
36
37            Camera.ZoomToLevel();
38        }
39
40        PhysicsObject LuoPelaaja1()
41        {
42            Pelaaja1 = new PhysicsObject(40.0,40.0);
43            Pelaaja1.IgnoresPhysicsLogics = true;
44            Pelaaja1.CanRotate = false; 
45            Pelaaja1.Image = LoadImage("player1");
46            Add(Pelaaja1);
47            return Pelaaja1;
48
49        }
50
51        PhysicsObject LuoPelaaja2()
52        {
53            Pelaaja2 = new PhysicsObject(40.0, 40.0);
54            Pelaaja2.IgnoresPhysicsLogics = true;
55            Pelaaja2.CanRotate = false;
56            Pelaaja2.Image = LoadImage("player2");
57            Add(Pelaaja2);
58            return Pelaaja2;
59        }
60
61        GameObject LuoHirvio()
62        {
63            GameObject Hirvio = new GameObject(50.0, 50.0);
64            Hirvio.Image = LoadImage("monster");
65            Add(Hirvio);
66            return Hirvio;
67        }
68
69        GameObject LuoRuoka()
70        {
71            GameObject Ruoka = new GameObject(50.0, 50.0);
72            Ruoka.Image = LoadImage("food");
73            Add(Ruoka);
74            return Ruoka;
75        }
76
77        GameObject LuoMaali()
78        { 
79            GameObject Maali = new GameObject(50.0, 50.0);
80            Maali.Image = LoadImage("goal");
81            Add(Maali);
82            return Maali;
83        }
84
85        PhysicsObject LuoSeina()
86        {
87            PhysicsObject seina = PhysicsObject.CreateStaticObject(50.0, 50.0);
88            seina.Shape = Shapes.Rectangle;
89            seina.Restitution = 0.0;
90            seina.Color = Color.Black;
91            return seina;
92
93        }
94        void LuoOhjain()
95        {
96            //näppäin alhaalla
97            Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaPelaajaaVasemmalle, null);
98            Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelaajaaOikealle, null);
99            Keyboard.Listen(Key.Up, ButtonState.Down, LiikutaPelaajaaYlos, null);
100            Keyboard.Listen(Key.Down, ButtonState.Down, LiikutaPelaajaaAlas, null);
101            Keyboard.Listen(Key.A, ButtonState.Down, LiikutaPelaaja2Vasemmalle, null);
102            Keyboard.Listen(Key.D, ButtonState.Down, LiikutaPelaaja2Oikealle, null);
103            Keyboard.Listen(Key.W, ButtonState.Down, LiikutaPelaaja2Ylos, null);
104            Keyboard.Listen(Key.S, ButtonState.Down, LiikutaPelaaja2Alas, null);
105            //näppäin ylhäällä
106            Keyboard.Listen(Key.Left, ButtonState.Released, Pelaaja1.StopHorizontal, null);
107            Keyboard.Listen(Key.Right, ButtonState.Released, Pelaaja1.StopHorizontal, null);
108            Keyboard.Listen(Key.Up, ButtonState.Released, Pelaaja1.StopVertical, null);
109            Keyboard.Listen(Key.Down, ButtonState.Released, Pelaaja1.StopVertical, null);
110            Keyboard.Listen(Key.A, ButtonState.Released, Pelaaja2.StopHorizontal, null);
111            Keyboard.Listen(Key.D, ButtonState.Released, Pelaaja2.StopHorizontal, null);
112            Keyboard.Listen(Key.W, ButtonState.Released, Pelaaja2.StopVertical, null);
113            Keyboard.Listen(Key.S, ButtonState.Released, Pelaaja2.StopVertical, null);
114           
115        }
116
117        //pelaaja1
118        void LiikutaPelaajaaVasemmalle()
119        {
120            Pelaaja1.Hit(new Vector(-10, 0));
121        }
122
123        void LiikutaPelaajaaOikealle()
124        {
125            Pelaaja1.Hit(new Vector(20, 0));
126        }
127
128        void LiikutaPelaajaaYlos()
129        {
130            Pelaaja1.Hit(new Vector(0, 10));
131        }
132
133        void LiikutaPelaajaaAlas()
134        {
135            Pelaaja1.Hit(new Vector(0, -10));
136       }
137        //Pelaaja2
138        void LiikutaPelaaja2Vasemmalle()
139        {
140            Pelaaja2.Hit(new Vector(-10, 0));
141        }
142
143        void LiikutaPelaaja2Oikealle()
144        {
145            Pelaaja2.Hit(new Vector(20, 0));
146        }
147
148        void LiikutaPelaaja2Ylos()
149        {
150            Pelaaja2.Hit(new Vector(0, 10));
151        }
152
153        void LiikutaPelaaja2Alas()
154        {
155            Pelaaja2.Hit(new Vector(0, -10));
156        }
157
158    }
159}
Note: See TracBrowser for help on using the repository browser.