source: 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/Player.cs @ 6619

Revision 6619, 2.3 KB checked in by sieerinn, 8 years ago (diff)

Aktiivisen kaman vaihto toimii.

Line 
1using System.Collections.Generic;
2using Jypeli;
3
4class Player : Creature
5{
6    public Dictionary<Direction, Animation> SwingAnimations { get; set; }
7
8    public Dictionary<Direction, Animation> ShootAnimations { get; set; }
9
10    public Item Sword { get; set; }
11
12    public Item ActiveItem
13    {
14        get
15        {
16            if (activeItemIndex < Inventory.Count)
17            {
18                return Inventory[activeItemIndex];
19            }
20            return null;
21        }
22    }
23
24    public Item NextItem
25    {
26        get
27        {
28            return Inventory.Count > 1 ? GetItem(activeItemIndex + 1) : null;
29        }
30    }
31
32    public Item PrevItem
33    {
34        get
35        {
36            return Inventory.Count > 1 ? GetItem(activeItemIndex - 1) : null;
37        }
38    }
39
40    private int activeItemIndex = 0;
41
42    public List<Item> Inventory { get; private set; }
43
44    public Player()
45        : base(TheLegendOfGabriel.TILE_SIZE, TheLegendOfGabriel.TILE_SIZE)
46    {
47        Inventory = new List<Item>();
48        SwingAnimations = new Dictionary<Direction, Animation>();
49        ShootAnimations = new Dictionary<Direction, Animation>();
50        CollisionIgnoreGroup = 1;
51    }
52
53    public void CycleItems()
54    {
55        activeItemIndex++;
56        if (activeItemIndex >= Inventory.Count)
57        {
58            activeItemIndex = 0;
59        }
60    }
61
62    private Item GetItem(int index)
63    {
64        if (index < 0)
65        {
66            index += Inventory.Count;
67        }
68        if (index >= Inventory.Count)
69        {
70            index -= Inventory.Count;
71        }
72        return Inventory[index];
73    }
74
75    protected override void UpdateAnimations()
76    {
77        bool itemBlocksAnimation = ActiveItem != null && ActiveItem.OverrideAnimation;
78        bool swordBlocksAnimation = Sword != null && Sword.OverrideAnimation;
79        if (!(itemBlocksAnimation || swordBlocksAnimation))
80        {
81            base.UpdateAnimations();
82        }
83    }
84
85    public override void UpdateCreature(Time time)
86    {
87        if (ActiveItem != null)
88        {
89            ActiveItem.UpdateItem(time);   
90        }
91        if (Sword != null)
92        {
93            Sword.UpdateItem(time);
94        }
95        base.UpdateCreature(time);
96    }
97}
Note: See TracBrowser for help on using the repository browser.