source: 2011/24/EeroP/ZOMBIE RUNNER/ZOMBIE RUNNER/ZOMBIE RUNNER/Peli.cs @ 2026

Revision 2026, 3.0 KB checked in by eejoprit, 12 years ago (diff)

ukkojen liikkuminen valmis:DD

Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9
10public class Peli : PhysicsGame
11{
12    Double nopeus = 200;
13    Double katse = 100;
14   
15    Image pelaaja1kuva = LoadImage("vihreäukko");
16    Image pelaaja2kuva = LoadImage("punainenukko");
17   
18   
19    PhysicsObject pelaaja1;
20    PhysicsObject pelaaja2;
21
22
23    public override void Begin()
24    {
25        // TODO: Kirjoita ohjelmakoodisi tähän
26        luokentta();
27       
28
29        ohjaimet();
30        Camera.Zoom(2.0);
31    }
32
33   
34   
35    void luokentta()
36    {
37        Level.BackgroundColor = Color.Gray;
38       
39        //kenttä 1
40        TileMap ruudut = TileMap.FromFile ("kentta1.txt");
41        ruudut.SetTileMethod('1', luopelaaja1);
42        ruudut.SetTileMethod('2', luopelaaja2);
43
44        ruudut.Execute(64, 64);
45    }
46   
47   
48    void luopelaaja1(Vector paikka, double x, double y)
49    {
50        pelaaja1 = new PhysicsObject (64.0, 64.0);
51        pelaaja1.Image = pelaaja1kuva;
52        pelaaja1.Color = Level.BackgroundColor;
53        pelaaja2.Position = paikka;
54        pelaaja1.Shape = Shape.Circle;
55
56        Add(pelaaja1);
57       
58    }
59
60    void luopelaaja2 (Vector paikka, double x, double y)
61    {
62        pelaaja2 = new PhysicsObject (64.0, 64.0);
63        pelaaja2.Image = pelaaja2kuva;
64        pelaaja2.Color = Level.BackgroundColor;
65        pelaaja2.Position = paikka;
66        pelaaja2.Shape = Shape.Circle;
67        Add(pelaaja2);
68       
69    }
70   
71
72    void ohjaimet()
73    {
74        ControllerOne.ListenAnalog(AnalogControl.LeftStick, -1, pelaaja0liike, ("liikutelaan pelaajaa numero 1"), pelaaja1);
75        ControllerOne.ListenAnalog(AnalogControl.RightStick, 0.01, pelaaja0katse, "katsotaan pelaajalla numero 1",pelaaja1);
76        ControllerOne.Listen(Button.Back, ButtonState.Down, Exit, ("poistu pelistä"));
77
78        ControllerTwo.ListenAnalog(AnalogControl.LeftStick, -1, pelaaja0liike, ("liikutelaan pelaajaa numero 1"), pelaaja2);
79        ControllerTwo.ListenAnalog(AnalogControl.RightStick, 0.01, pelaaja0katse, "katsotaan pelaajalla numero 1", pelaaja2);
80        ControllerTwo.Listen(Button.Back, ButtonState.Down, Exit, ("poistu pelistä"));
81    }
82   
83   
84    void pelaaja0liike(AnalogState vasen_tatintila, PhysicsObject pelaaja0)
85    {
86        if (vasen_tatintila.StateVector.Magnitude < 0.1)
87        {
88            pelaaja0.Stop();
89        }
90        else
91        {
92            Vector tatinasento = vasen_tatintila.StateVector;
93            Vector pelaaja1nopeus = nopeus * tatinasento;
94            pelaaja0.Velocity = pelaaja1nopeus;
95        }
96
97
98    }
99
100    void pelaaja0katse(AnalogState oikea_tatintila, PhysicsObject pelaaja0)
101    { 
102        Vector tatin2asento = oikea_tatintila.StateVector;
103        Vector pelaaja1katse = katse * tatin2asento ;
104        pelaaja0.Angle = pelaaja1katse.Angle - Angle.RightAngle;
105    }
106
107  }
Note: See TracBrowser for help on using the repository browser.