source: 2010/30/alsiseoi/WorldOfBallcraft/Peli.cs @ 1411

Revision 1411, 5.9 KB checked in by alsiseoi, 13 years ago (diff)

Talent toimii ja efekti työn alla.

Line 
1using System;
2using Jypeli;
3using Jypeli.Widgets;
4using Jypeli.Assets;
5using Jypeli.Effects;
6
7public class Peli : PhysicsGame
8{
9    PhysicsObject Player1;
10    PhysicsObject Player2;
11
12    PhysicsObject Vihollinen;
13
14    PhysicsObject VasenReuna;
15    PhysicsObject OikeaReuna;
16    PhysicsObject YlaReuna;
17    PhysicsObject AlaReuna;
18
19    Vector NopeusYlos = new Vector(0, 200);
20    Vector NopeusAlas = new Vector(0, -200);
21    Vector NopeusOikealle = new Vector(200, 0);
22    Vector NopeusVasemmalle = new Vector(-200, 0);
23
24    Image olionKuva = LoadImage("nuotio");
25    Image Karistaja = LoadImage("tulitest");
26    Image Talentti0 = LoadImage("Talent0");
27
28    protected override void Begin()
29    {
30        LuoKentta();
31        AsetaOhjaimet();
32        LuoEfekti();
33    }
34
35    PhysicsObject LuoPelaaja(double x, double y, double koko, Color vari)
36    {
37        PhysicsObject pelaaja = new PhysicsObject(koko, koko, Shapes.Circle);
38        pelaaja.Color = vari;
39        pelaaja.X = x;
40        pelaaja.Y = y;
41        Add(pelaaja);
42        AddCollisionHandler(pelaaja, KasittelePelaajanTormays);
43        return pelaaja;
44    }
45
46    void LuoKentta()
47    {
48        Level.BackgroundColor = new Color (62, 102, 55);
49
50        Player1 = LuoPelaaja(300, 100, 40, new Color (1, 14, 105));
51
52        Player2 = LuoPelaaja(300, 200, 40, new Color (64, 0, 0));
53       
54        Camera.ZoomToLevel();
55        //Camera.ZoomFactor = 1.5;
56
57        VasenReuna = Level.CreateLeftBorder();
58        VasenReuna.Restitution = 0.0;
59        VasenReuna.IsVisible = true;
60
61        OikeaReuna = Level.CreateRightBorder();
62        OikeaReuna.Restitution = 0.0;
63        OikeaReuna.IsVisible = true;
64
65        YlaReuna = Level.CreateTopBorder();
66        YlaReuna.Restitution = 0.0;
67        YlaReuna.IsVisible = true;
68
69        AlaReuna = Level.CreateBottomBorder();
70        AlaReuna.Restitution = 0.0;
71        AlaReuna.IsVisible = true;
72
73        Vihollinen = new PhysicsObject(30.0, 20.0);
74        Vihollinen.Color = Color.GreenYellow;
75        Vihollinen.X = 100;
76        Vihollinen.Y = 150;
77        Vihollinen.Tag = "Osuma";
78        Add(Vihollinen);
79
80        RandomMoverBrain satunnaisAivot = new RandomMoverBrain();
81        Vihollinen.Brain = satunnaisAivot;
82
83        PhysicsObject nuotio = PhysicsObject.CreateStaticObject(70.0, 70.0);
84        nuotio.X = 300;
85        nuotio.Y = -200;
86        nuotio.Image = olionKuva;
87        Add(nuotio);
88
89        PhysicsObject tulitest = new PhysicsObject(1.0, 1.0);
90        tulitest.Image = Karistaja;
91
92    }
93
94    void AsetaOhjaimet()
95    {
96        Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Player1: Liikuta pelaajaa ylös", Player1, NopeusYlos);
97        Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, Player1, Vector.Zero);
98        Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Player1: Liikuta pelaajaa alas", Player1, NopeusAlas);
99        Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, Player1, Vector.Zero);
100        Keyboard.Listen(Key.Right, ButtonState.Down, AsetaNopeus, "Player1: Liikuta pelaajaa oikealle", Player1, NopeusOikealle);
101        Keyboard.Listen(Key.Right, ButtonState.Released, AsetaNopeus, null, Player1, Vector.Zero);
102        Keyboard.Listen(Key.Left, ButtonState.Down, AsetaNopeus, "Player1: Liikuta pelaajaa vasemmalle", Player1, NopeusVasemmalle);
103        Keyboard.Listen(Key.Left, ButtonState.Released, AsetaNopeus, null, Player1, Vector.Zero);
104
105        Keyboard.Listen(Key.W, ButtonState.Down, AsetaNopeus, "Player2: Liikuta pelaajaa ylös", Player2, NopeusYlos);
106        Keyboard.Listen(Key.W, ButtonState.Released, AsetaNopeus, null, Player2, Vector.Zero);
107        Keyboard.Listen(Key.S, ButtonState.Down, AsetaNopeus, "Player2: Liikuta pelaajaa alas", Player2, NopeusAlas);
108        Keyboard.Listen(Key.S, ButtonState.Released, AsetaNopeus, null, Player2, Vector.Zero);
109        Keyboard.Listen(Key.D, ButtonState.Down, AsetaNopeus, "Player2: Liikuta pelaajaa oikealle", Player2, NopeusOikealle);
110        Keyboard.Listen(Key.D, ButtonState.Released, AsetaNopeus, null, Player2, Vector.Zero);
111        Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Player1: Liikuta pelaajaa vasemmalle", Player2, NopeusVasemmalle);
112        Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, Player2, Vector.Zero);
113
114        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu");
115        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");
116
117        Keyboard.Listen(Key.NumPad0, ButtonState.Down, LuoTalentit, "Player1: Talent0", Player1 );
118        //Keyboard.Listen(Key.NumPad0, ButtonState.Released, null, Player1,
119
120    }
121
122    void AsetaNopeus(PhysicsObject pelaaja, Vector suunta)
123    {
124        pelaaja.Velocity = suunta;
125        //pelaaja.Push(suunta);
126    }
127
128    void KasittelePelaajanTormays(PhysicsObject pelaaja, PhysicsObject kohde )
129    {
130        if (pelaaja == Player1)
131        {
132            if (kohde.Tag.ToString() == "Osuma")
133            {
134                Player1.Destroy();
135            }
136        }
137
138        if (pelaaja == Player2)
139        {
140            if (kohde.Tag.ToString() == "Osuma")
141            {
142                Player2.Destroy();
143            }
144        }
145    }
146
147    void LuoEfekti()
148    {
149
150        Flames liekki = new Flames(Karistaja, 25, Angle.Degrees(270));
151        liekki.Position = new Vector(300, -200);
152        Add(liekki);
153
154        int pMaxMaara = 1;
155        ExplosionSystem rajahdys = new ExplosionSystem(LoadImage("Talent0"), pMaxMaara);
156        Add(rajahdys);
157        double x = 0;
158        double y = 0;
159        int pMaara = 1;
160        rajahdys.AddEffect(x, y, pMaara); 
161    }
162
163    void LuoTalentit(PhysicsObject pelaaja)
164    {
165        Vector etaisyys = new Vector(pelaaja.X - Vihollinen.X, pelaaja.Y - Vihollinen.Y);
166        if (etaisyys.Magnitude < 100)
167        {
168            Vihollinen.Destroy();
169        }
170       
171    }
172}
173
Note: See TracBrowser for help on using the repository browser.