source: 2017/24/ViljamiM/Zombodroid/Zombodroid/Zombodroid/Zombodroid.cs @ 8641

Revision 8641, 4.4 KB checked in by npo17_18, 6 years ago (diff)
Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class Zombodroid : PhysicsGame
10{
11    PhysicsObject matti;
12    SoundEffect Aani = LoadSoundEffect("pyssyaani");
13    bool vasenPyssy = true;
14
15    public override void Begin()
16    {
17        AsetaOhjaimet();
18        AsetaHenkilot();
19
20        Mappi();
21
22        Camera.Follow(matti);
23
24        Mouse.ListenMovement(0.1, Tahtaa, "Tähtää aseella");
25
26        IsMouseVisible = true;
27
28        YksVihu();
29
30
31
32    }
33    void AsetaOhjaimet()
34    {
35        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
36
37        Keyboard.Listen(Key.A, ButtonState.Down,
38   LiikutaPelaajaa, null, new Vector(-220, 0));
39        Keyboard.Listen(Key.D, ButtonState.Down,
40          LiikutaPelaajaa, null, new Vector(220, 0));
41        Keyboard.Listen(Key.W, ButtonState.Down,
42          LiikuEteen, null);
43        Keyboard.Listen(Key.S, ButtonState.Down,
44          LiikutaPelaajaa, null, new Vector(0, -220));
45
46        Keyboard.Listen(Key.A, ButtonState.Released,
47   LiikutaPelaajaa, null, Vector.Zero);
48        Keyboard.Listen(Key.D, ButtonState.Released,
49         LiikutaPelaajaa, null, Vector.Zero);
50        Keyboard.Listen(Key.W, ButtonState.Released,
51          LiikutaPelaajaa, null, Vector.Zero);
52        Keyboard.Listen(Key.S, ButtonState.Released,
53          LiikutaPelaajaa, null, Vector.Zero);
54
55        Mouse.Listen(MouseButton.Left, ButtonState.Pressed, Ammu, null);
56
57
58    }
59    void AsetaHenkilot()
60    {
61        matti = new PhysicsObject(75, 75);
62        matti.Image = LoadImage("oikeeukkeli");
63       
64        matti.X = 100;
65        Add(matti, 3);
66        matti.CanRotate = false;
67        double laserinpituus = 1000;
68        GameObject laser = new  GameObject(2, laserinpituus);
69        laser.Y = matti.Y + laserinpituus/2+16;
70        laser.Color = new Color(Color.Red, 30);
71        matti.Add(laser);
72    }
73
74    void LiikutaPelaajaa(Vector vektori)
75    {
76        matti.Move(vektori);
77    }
78    void Tahtaa(AnalogState hiirenLiike)
79    {
80        Vector suunta = (Mouse.PositionOnWorld - matti.AbsolutePosition).Normalize();
81        matti.Angle = suunta.Angle - Angle.RightAngle;
82    }
83    void Ammu()
84    {
85        Aani.Play();
86        PhysicsObject panos = new PhysicsObject(5.0, 5.0);
87        if (vasenPyssy)
88        {
89            panos.Position = matti.Position + ((Mouse.PositionOnWorld - matti.AbsolutePosition).Normalize()) * 32 + (((Mouse.PositionOnWorld - matti.AbsolutePosition).Normalize()) * 22).RightNormal;
90            vasenPyssy = false;
91        }
92        else
93        {
94            panos.Position = matti.Position + ((Mouse.PositionOnWorld - matti.AbsolutePosition).Normalize()) * 32 + (((Mouse.PositionOnWorld - matti.AbsolutePosition).Normalize()) * -22).RightNormal;
95            vasenPyssy = true;
96        }
97        panos.IgnoresCollisionWith(matti);
98        panos.MaximumLifetime = new TimeSpan(0, 0, 2);
99        Add(panos);
100        panos.Velocity = ((Mouse.PositionOnWorld - matti.AbsolutePosition).Normalize())*2000;
101
102       
103    }
104    void Mappi()
105    {
106        Level.Background.Image = LoadImage("mappi");
107       
108    }
109    void LiikuEteen()
110    {
111        matti.Move(((Mouse.PositionOnWorld - matti.AbsolutePosition).Normalize()) * 220);
112    }
113    void YksVihu()
114    {
115        PhysicsObject vihu = new PhysicsObject(100.0, 100.0);
116        RandomMoverBrain satunnaisAivot = new RandomMoverBrain(50);
117        satunnaisAivot.ChangeMovementSeconds = 3;
118        vihu.Brain = satunnaisAivot;
119        FollowerBrain suraajanAivot = new FollowerBrain(matti);
120       
121
122        double nakokentanpituus = 300;
123        PhysicsObject nakokentta = new PhysicsObject(300, nakokentanpituus);
124        nakokentta.Tag = "nakoalue";
125        nakokentta.Y = vihu.Y + nakokentanpituus / 2 + 16;
126        nakokentta.Angle = Angle.StraightAngle;
127        nakokentta.Shape = Shape.Triangle;
128        vihu.CanRotate = false;
129        nakokentta.CanRotate = false;
130
131
132       // AddCollisionHandler(matti, nakokentta, delegate { VihuNakeeMatin(vihu); });
133
134
135        Add(vihu);
136        Add(nakokentta);
137        PhysicsStructure kokoVihu = new PhysicsStructure(vihu, nakokentta);
138        nakokentta.IgnoresCollisionResponse = true;
139    }
140    void VihuNakeeMatin(PhysicsObject vihu)
141    {
142        MessageDisplay.Add("vihunakeepelaajan");
143
144    }
145
146
147}
Note: See TracBrowser for help on using the repository browser.