source: 2015/27/MiroS/Raiskintapeli/Raiskintapeli/Raiskintapeli/TankkiPeli.cs @ 6687

Revision 6687, 2.9 KB checked in by miausilj, 8 years ago (diff)

tankki liikkuu ja kääntyy hiiren asoittamaansuuntaan.
jättää myös pommeja ja ampuu

Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class TankkiPeli : PhysicsGame
10{
11    Image tankkikuva = LoadImage("Tankki");
12    Image Vihulainen = LoadImage("Vihulainen");
13
14    PhysicsObject tankki;
15
16    public override void Begin()
17    {
18   
19        //IsFullScreen = true;
20       
21        Level.Width = Screen.Width;
22        Level.Height = Screen.Height;
23        Camera.ZoomToLevel();
24
25        Level.CreateBorders();
26        LisaaPelaaja();
27        LisaaOhjaimet();
28        LuoMappi(1);
29    }
30    void LisaaPelaaja()
31    {
32
33        tankki = new PhysicsObject(50.0, 50.0);
34        tankki.X = -1.0;
35        tankki.Y = -300.0;
36        tankki.Image = tankkikuva;
37        tankki.LinearDamping = 0.1;
38        tankki.AngularDamping = 0.1;
39        Add(tankki);
40
41    }
42     
43    void LuoVihulainen()
44    {
45        PhysicsObject vihu = new PhysicsObject(Vihulainen);
46        vihu.Size = vihu.Size * 0.1;
47        vihu.Position = new Vector(RandomGen.NextDouble(Level.Left, Level.Right), RandomGen.NextDouble(Level.Bottom, Level.Top));
48        vihu.CanRotate = false;
49        Add(vihu);
50       
51    }
52
53    void JättääPommin(PhysicsObject tankki)
54    {
55        PhysicsObject pommi = new PhysicsObject(15.0, 15.0);
56        pommi.Position = tankki.Position;
57        Add(pommi);
58        pommi.Color = Color.Black;
59        pommi.CanRotate=false;
60        Timer.SingleShot(2.0, delegate
61        {
62            pommi.Destroy();
63            Explosion räjähdys = new Explosion(100.0);
64            räjähdys.Position = pommi.Position;
65            Add(räjähdys);
66        });
67
68    }
69    void Ampuu(PhysicsObject tankki)
70    {
71        PhysicsObject ammus = new PhysicsObject(5.0, 5.0);
72        ammus.Position = tankki.Position;
73            Add(ammus);
74            ammus.Color = Color.Yellow;
75            ammus.Hit(tankki.Angle.GetVector()*1000);
76            Timer.SingleShot(2.0, delegate
77            {
78                ammus.Destroy();
79            });
80
81    }
82    void LuoMappi(int vaikeusaste)
83    {
84        for (int i = 0; i < 3*vaikeusaste; i++)
85        {
86            LuoVihulainen();
87        }
88    }
89    void LisaaOhjaimet()
90    {
91       
92        Keyboard.Listen(Key.X, ButtonState.Pressed, JättääPommin, "Jättää pommin", tankki);
93        Keyboard.Listen(Key.Z, ButtonState.Pressed, Ampuu, "Ampuu tykillä", tankki);
94        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
95
96        Mouse.ListenMovement(0.0, Tahtaa, "");
97        Mouse.IsCursorVisible = true;
98        Keyboard.Listen(Key.W, ButtonState.Down, LiikuWASD, "LiikutaYlos");
99    }
100    void Tahtaa(AnalogState hiirenTila)
101    {
102        tankki.Angle = (Mouse.PositionOnWorld - tankki.Position).Angle;
103
104
105    }
106    void LiikuWASD()
107    {
108        tankki.Push(Vector.FromLengthAndAngle(8000, tankki.Angle));
109    }
110}
Note: See TracBrowser for help on using the repository browser.