Jypeli  9
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 
30 using System;
31 using System.Collections.Generic;
32 using System.ComponentModel;
33 using Jypeli.GameObjects;
34 
35 
36 namespace Jypeli
37 {
42  [Save]
43  public partial class GameObject : GameObjects.GameObjectBase, IGameObjectInternal
44  {
45  public List<Listener> AssociatedListeners { get; private set; }
46 
47  #region Destroyable
48 
52  public override void Destroy()
53  {
54  this.MaximumLifetime = TimeSpan.Zero;
55 
57 
58  if ( AssociatedListeners != null )
59  {
60  foreach ( Listener listener in AssociatedListeners )
61  {
62  listener.Destroy();
63  }
64  }
65 
66  base.Destroy();
67  }
68 
69  #endregion
70 
76  public GameObject(double width, double height)
77  : this(width, height, Shape.Rectangle, 0.0, 0.0)
78  {
79  }
80 
88  public GameObject(double width, double height, double x, double y)
89  : this(width, height, Shape.Rectangle, x, y)
90  {
91  }
92 
101  public GameObject(double width, double height, Shape shape, double x, double y)
102  : this(width, height, shape)
103  {
104  Position = new Vector(x, y);
105  }
106 
113  public GameObject(double width, double height, Shape shape)
114  : base()
115  {
116  InitDimensions(width, height, shape);
117  InitAppearance();
118  InitListeners();
119  InitLayout(width, height);
120  }
121 
127  public GameObject( Animation animation )
128  : base()
129  {
130  InitDimensions( animation.Width, animation.Height, Shape.Rectangle );
131  InitAppearance( animation );
132  InitListeners();
133  InitLayout( animation.Width, animation.Height );
134  }
135 
139  public GameObject( ILayout layout )
140  : base()
141  {
142  Vector defaultSize = new Vector( 100, 100 );
143  InitDimensions( defaultSize.X, defaultSize.Y, Shape.Rectangle );
144  InitAppearance();
145  InitListeners();
146  InitLayout( defaultSize.X, defaultSize.Y, layout );
147  }
148 
149  private void InitListeners()
150  {
151  this.AssociatedListeners = new List<Listener>();
152  }
153 
160  [EditorBrowsable( EditorBrowsableState.Never )]
161  public override void Update( Time time )
162  {
163  base.Update( time );
164  UpdateChildren( time );
166  {
167  RefreshLayout();
168  _layoutNeedsRefreshing = false;
169  }
170  if ( oscillators != null )
171  oscillators.Update( time );
172  }
173  }
174 }
Jypeli.GameObject.InitListeners
void InitListeners()
Definition: GameObject.cs:149
Jypeli.Listener
Ohjaintapahtumien kuuntelija.
Definition: Listener.cs:50
Jypeli.GameObject.GameObject
GameObject(Animation animation)
Alustaa uuden peliolion. Kappaleen koko ja ulkonäkö ladataan parametrina annetusta kuvasta.
Definition: GameObject.cs:127
Jypeli.Vector.X
double X
Definition: Vector.cs:312
Jypeli.GameObject.Update
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:161
Jypeli.Animation.Width
double? Width
Animaation leveys. Nolla, jos animaatiossa ei ole yhtään ruutua.
Definition: Animation.cs:153
Jypeli.GameObject.Destroy
override void Destroy()
Tuhoaa olion. Tuhottu olio poistuu pelistä.
Definition: GameObject.cs:52
Jypeli
Definition: Automobile.cs:5
Jypeli.GameObject.oscillators
SynchronousList< Oscillator > oscillators
Definition: Movement.cs:37
Jypeli.GameObject.RefreshLayout
void RefreshLayout()
Päivittää lapsiolioiden paikat ja koot, jos widgetille on asetettu asettelija. Tätä metodia EI yleens...
Definition: Layout.cs:135
Jypeli.GameObject.AssociatedListeners
List< Listener > AssociatedListeners
Definition: GameObject.cs:45
Jypeli.Rectangle
Suorakulmio.
Definition: Shapes.cs:318
Jypeli.GameObject.InitLayout
void InitLayout(double width, double height)
Definition: Layout.cs:114
Jypeli.Shape
Kuvio.
Definition: Shapes.cs:47
Jypeli.GameObject.DestroyChildren
void DestroyChildren()
Definition: ChildObjects.cs:167
Jypeli.GameObjects
Definition: GameObjectBase.cs:5
Jypeli.GameObject.InitDimensions
void InitDimensions(double width, double height, Shape shape)
Definition: Dimensions.cs:94
Jypeli.GameObject.GameObject
GameObject(ILayout layout)
Alustaa widgetin.
Definition: GameObject.cs:139
Jypeli.Shape.Rectangle
static readonly Rectangle Rectangle
Suorakulmio.
Definition: Shapes.cs:70
Jypeli.ILayout
Rajapinta asettelijalle. Asettelija asettelee widgetin lapsioliot siten, että ne mahtuvat widgetin si...
Definition: ILayout.cs:84
Jypeli.GameObject.InitAppearance
void InitAppearance()
Definition: Appearance.cs:92
Jypeli.GameObject.GameObject
GameObject(double width, double height, double x, double y)
Alustaa uuden peliolion.
Definition: GameObject.cs:88
Jypeli.Time
Sisältää tiedon ajasta, joka on kulunut pelin alusta ja viime päivityksestä.
Definition: Time.cs:14
Jypeli.GameObject._layoutNeedsRefreshing
bool _layoutNeedsRefreshing
Definition: Layout.cs:11
Jypeli.Animation
Sarja kuvia, jotka vaihtuvat halutulla nopeudella. Yksi animaatio koostuu yhdestä tai useammasta kuva...
Definition: Animation.cs:62
Jypeli.GameObject.GameObject
GameObject(double width, double height)
Alustaa uuden peliolion.
Definition: GameObject.cs:76
Jypeli.GameObject.GameObject
GameObject(double width, double height, Shape shape)
Alustaa uuden peliolion.
Definition: GameObject.cs:113
Jypeli.Vector
2D-vektori.
Definition: Vector.cs:59
System
Definition: CFFauxAttributes.cs:29
Jypeli.GameObjects.GameObjectBase
Kaikille peliolioille yhteinen kantaluokka
Definition: GameObjectBase.cs:10
Jypeli.GameObject.GameObject
GameObject(double width, double height, Shape shape, double x, double y)
Alustaa uuden peliolion.
Definition: GameObject.cs:101
Jypeli.SynchronousList.Update
void Update(Time time)
Lisää ja poistaa jonossa olevat elementit sekä kutsuu niiden Update-metodia.
Definition: SynchronousList.cs:272
Jypeli.GameObject.UpdateChildren
void UpdateChildren(Time time)
Definition: ChildObjects.cs:177
Jypeli.Vector.Y
double Y
Definition: Vector.cs:313
Jypeli.Animation.Height
double? Height
Animaation korkeus. Nolla, jos animaatiossa ei ole yhtään ruutua.
Definition: Animation.cs:161