Jypeli 10
The simple game programming library
GameObject.cs
Siirry tämän tiedoston dokumentaatioon.
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;
34
35
36namespace Jypeli
37{
42 [Save]
43 public partial class GameObject : GameObjects.GameObjectBase, IGameObjectInternal
44 {
48 public List<Listener> AssociatedListeners { get; private set; }
49
50 #region Destroyable
51
55 public override void Destroy()
56 {
57 this.MaximumLifetime = TimeSpan.Zero;
58
60
61 if ( AssociatedListeners != null )
62 {
63 foreach ( Listener listener in AssociatedListeners )
64 {
65 listener.Destroy();
66 }
67 }
68
69 base.Destroy();
70 }
71
72 #endregion
73
79 public GameObject(double width, double height)
80 : this(width, height, Shape.Rectangle, 0.0, 0.0)
81 {
82 }
83
91 public GameObject(double width, double height, double x, double y)
92 : this(width, height, Shape.Rectangle, x, y)
93 {
94 }
95
104 public GameObject(double width, double height, Shape shape, double x, double y)
105 : this(width, height, shape)
106 {
107 Position = new Vector(x, y);
108 }
109
116 public GameObject(double width, double height, Shape shape)
117 : base()
118 {
119 InitDimensions(width, height, shape);
122 InitLayout(width, height);
123 }
124
130 public GameObject( Animation animation )
131 : base()
132 {
133 InitDimensions( animation.Width, animation.Height, Shape.Rectangle );
134 InitAppearance( animation );
136 InitLayout( animation.Width, animation.Height );
137 }
138
142 public GameObject( ILayout layout )
143 : base()
144 {
145 Vector defaultSize = new Vector( 100, 100 );
146 InitDimensions( defaultSize.X, defaultSize.Y, Shape.Rectangle );
149 InitLayout( defaultSize.X, defaultSize.Y, layout );
150 }
151
152 private void InitListeners()
153 {
154 this.AssociatedListeners = new List<Listener>();
155 }
156
163 [EditorBrowsable( EditorBrowsableState.Never )]
164 public override void Update( Time time )
165 {
166 base.Update( time );
167 UpdateChildren( time );
169 {
172 }
173 if ( oscillators != null )
174 oscillators.Update( time );
175 }
176 }
177}
Sarja kuvia, jotka vaihtuvat halutulla nopeudella. Yksi animaatio koostuu yhdestä tai useammasta kuva...
Definition: Animation.cs:62
double? Height
Animaation korkeus. Nolla, jos animaatiossa ei ole yhtään ruutua.
Definition: Animation.cs:161
double? Width
Animaation leveys. Nolla, jos animaatiossa ei ole yhtään ruutua.
Definition: Animation.cs:153
SynchronousList< Oscillator > oscillators
Definition: Movement.cs:37
override Vector?? Position
Definition: Dimensions.cs:72
void UpdateChildren(Time time)
GameObject(ILayout layout)
Alustaa widgetin.
Definition: GameObject.cs:142
void InitListeners()
Definition: GameObject.cs:152
void InitAppearance()
Definition: Appearance.cs:92
GameObject(double width, double height, double x, double y)
Alustaa uuden peliolion.
Definition: GameObject.cs:91
override void Update(Time time)
Peliolion päivitys. Tätä kutsutaan, kun IsUpdated-ominaisuuden arvoksi on asetettu true ja olio on li...
Definition: GameObject.cs:164
void InitLayout(double width, double height)
Alustaa asettelijan käyttöön
Definition: Layout.cs:122
List< Listener > AssociatedListeners
Tähän peliolioon liitetyt kuuntelijat
Definition: GameObject.cs:48
GameObject(double width, double height)
Alustaa uuden peliolion.
Definition: GameObject.cs:79
GameObject(double width, double height, Shape shape, double x, double y)
Alustaa uuden peliolion.
Definition: GameObject.cs:104
void InitDimensions(double width, double height, Shape shape)
Definition: Dimensions.cs:146
override void Destroy()
Tuhoaa olion. Tuhottu olio poistuu pelistä.
Definition: GameObject.cs:55
GameObject(double width, double height, Shape shape)
Alustaa uuden peliolion.
Definition: GameObject.cs:116
void RefreshLayout()
Päivittää lapsiolioiden paikat ja koot, jos widgetille on asetettu asettelija. Tätä metodia EI yleens...
Definition: Layout.cs:149
GameObject(Animation animation)
Alustaa uuden peliolion. Kappaleen koko ja ulkonäkö ladataan parametrina annetusta kuvasta.
Definition: GameObject.cs:130
bool _layoutNeedsRefreshing
Definition: Layout.cs:11
Kaikille peliolioille yhteinen kantaluokka
TimeSpan MaximumLifetime
Olion suurin mahdollinen elinaika. Kun Lifetime on suurempi kuin tämä, olio kuolee.
Suorakulmio.
Definition: Shapes.cs:322
Kuvio.
Definition: Shapes.cs:47
static readonly Rectangle Rectangle
Suorakulmio.
Definition: Shapes.cs:73
Rajapinta asettelijalle. Asettelija asettelee widgetin lapsioliot siten, että ne mahtuvat widgetin si...
Definition: ILayout.cs:95
Ohjaintapahtumien kuuntelija.
Definition: Listener.cs:72
void Destroy()
Tuhoaa kuuntelijan
Definition: Listener.cs:203
Sisältää tiedon ajasta, joka on kulunut pelin alusta ja viime päivityksestä.
Definition: Time.cs:14
2D-vektori.
Definition: Vector.cs:67
double Y
Vektorin Y-komponentti
Definition: Vector.cs:339
double X
Vektorin X-komponentti.
Definition: Vector.cs:334