source: 2015/koodauskerho/SanteriK/FastestGunInTown/FastestGunInTown/FastestGunInTown/FastestGunInTown.cs @ 7973

Revision 7973, 2.4 KB checked in by otosjahn, 7 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 FastestGunInTown : PhysicsGame
10
11{
12   
13    Image hahmonkuva = LoadImage("hahmo");
14    Image hahmon2kuva = LoadImage("hahmo2");
15    Image ammuskuva = LoadImage("ammus");
16
17    PlatformCharacter[] pelaajat = new PlatformCharacter[2];
18    public override void Begin()
19    {
20        LuoKentta();
21
22        asetaohjaimet();
23
24
25    }
26    void LuoKentta()
27    {
28        ColorTileMap ruudut = ColorTileMap.FromLevelAsset("PelinKentta");
29        ruudut.SetTileMethod(Color.FromHexCode("#FF4CFF00"), LuoPelaaja, 1);
30        ruudut.SetTileMethod(Color.Red, LuoPelaaja, 0);
31        ruudut.SetTileMethod(Color.Black, LuoTaso);
32        ruudut.Execute(40, 40);
33       
34    }
35
36    void LuoTaso(Vector paikka, double korkeus, double leveys)
37    {
38        PhysicsObject taso =  PhysicsObject.CreateStaticObject(leveys, korkeus);
39        taso.Position = paikka;
40        Add(taso);
41        taso.Color = Color.Black;
42    }
43
44    void LuoPelaaja(Vector paikka, double korkeus, double leveys, int indeksi)
45    {
46        PlatformCharacter hahmo = new PlatformCharacter(200, 200);
47        hahmo.Shape = Shape.Rectangle;
48        Add(hahmo);
49        hahmo.Image = hahmonkuva;
50        hahmo.Position = paikka;
51        if(indeksi == 1) hahmo.Turn(Direction.Left);
52
53         AssaultRifle pelaajan1Ase = new AssaultRifle(30, 10);
54        pelaajan1Ase.Ammo.Value = 6;
55        pelaajan1Ase.ProjectileCollision = AmmusOsui;
56        hahmo.Weapon = pelaajan1Ase;
57        pelaajat[indeksi] = hahmo;
58    }
59    void AmmusOsui(PhysicsObject ammus, PhysicsObject kohde)
60    {
61        //ammus.Destroy();
62    }
63    void AmmuAseella(AssaultRifle ase)
64    {
65        PhysicsObject ammus = ase.Shoot();
66
67        if (ammus != null)
68        {
69
70            ammus.Size *= 3;
71            ammus.Image = ammuskuva;
72            ammus.MaximumLifetime = TimeSpan.FromSeconds(2.0);
73        }
74    }
75    void asetaohjaimet()
76    {
77        Keyboard.Listen(Key.Space, ButtonState.Down, AmmuAseella, "Ammu", (AssaultRifle)pelaajat[0].Weapon);
78        Keyboard.Listen(Key.LeftShift, ButtonState.Down, AmmuAseella, "Ammu", (AssaultRifle)pelaajat[1].Weapon);
79        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
80    }
81
82}
83
Note: See TracBrowser for help on using the repository browser.