source: 2013/30/MiskaK/MW2(My Warfare 2)/Paranneltu Jypeli/GameObjects/GameObject/GameObject.cs @ 4507

Revision 4507, 5.0 KB checked in by anlakane, 10 years ago (diff)

Talletus.

Line 
1#region MIT License
2/*
3 * Copyright (c) 2009 University of Jyväskylä, Department of Mathematical
4 * Information Technology.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24#endregion
25
26/*
27 * Authors: Tero Jäntti, Tomi Karppinen, Janne Nikkanen.
28 */
29
30using System;
31using System.Collections.Generic;
32using System.ComponentModel;
33using Jypeli.Controls;
34using Jypeli.GameObjects;
35
36
37namespace Jypeli
38{
39    /// <summary>
40    /// Pelialueella liikkuva olio.
41    /// Käytä fysiikkapeleissä <c>PhysicsObject</c>-olioita.
42    /// </summary>
43#if !XBOX && !WINDOWS_PHONE
44    [Serializable]
45#endif
46    [Save]
47    public partial class GameObject : GameObjects.GameObjectBase, IGameObjectInternal
48    {
49        public List<Listener> AssociatedListeners { get; private set; }
50
51        #region Destroyable
52
53        /// <summary>
54        /// Tuhoaa olion. Tuhottu olio poistuu pelistä.
55        /// </summary>
56        public override void Destroy()
57        {
58            this.MaximumLifetime = TimeSpan.Zero;
59
60            DestroyChildren();
61
62            if ( AssociatedListeners != null )
63            {
64                foreach ( Listener listener in AssociatedListeners )
65                {
66                    listener.Destroy();
67                }
68            }
69
70            base.Destroy();
71        }
72
73        #endregion
74
75        /// <summary>
76        /// Alustaa uuden peliolion.
77        /// </summary>
78        /// <param name="width">Leveys.</param>
79        /// <param name="height">Korkeus.</param>
80        public GameObject( double width, double height )
81            : this( width, height, Shape.Rectangle )
82        {
83        }
84
85        /// <summary>
86        /// Alustaa uuden peliolion.
87        /// </summary>
88        /// <param name="width">Leveys.</param>
89        /// <param name="height">Korkeus.</param>
90        /// <param name="shape">Muoto.</param>
91        public GameObject( double width, double height, Shape shape )
92            : base()
93        {
94            InitDimensions( width, height, shape );
95            InitAppearance();
96            InitListeners();
97            InitLayout( width, height );
98        }
99
100        /// <summary>
101        /// Alustaa uuden peliolion.
102        /// Kappaleen koko ja ulkonäkö ladataan parametrina annetusta kuvasta.
103        /// </summary>
104        /// <param name="animation">Kuva</param>
105        public GameObject( Animation animation )
106            : base()
107        {
108            InitDimensions( animation.Width, animation.Height, Shape.Rectangle );
109            InitAppearance( animation );
110            InitListeners();
111            InitLayout( animation.Width, animation.Height );
112        }
113
114        /// <summary>
115        /// Alustaa widgetin.
116        /// </summary>
117        public GameObject( ILayout layout )
118            : base()
119        {
120            Vector defaultSize = new Vector( 100, 100 );
121            InitDimensions( defaultSize.X, defaultSize.Y, Shape.Rectangle );
122            InitAppearance();
123            InitListeners();
124            InitLayout( defaultSize.X, defaultSize.Y, layout );
125        }
126
127        private void InitListeners()
128        {
129            this.AssociatedListeners = new List<Listener>();
130        }
131
132        /// <summary>
133        /// Peliolion päivitys. Tätä kutsutaan, kun <c>IsUpdated</c>-ominaisuuden
134        /// arvoksi on asetettu <c>true</c> ja olio on lisätty peliin.
135        /// <see cref="IsUpdated"/>
136        /// </summary>
137        /// <param name="time">Peliaika.</param>
138        [EditorBrowsable( EditorBrowsableState.Never )]
139        public override void Update( Time time )
140        {
141            base.Update( time );
142            UpdateChildren( time );
143            if ( _layoutNeedsRefreshing )
144            {
145                RefreshLayout();
146                _layoutNeedsRefreshing = false;
147            }
148            if ( oscillators != null )
149                oscillators.Update( time );
150        }
151    }
152}
Note: See TracBrowser for help on using the repository browser.