Jypeli  5
The simple game programming library
Direction.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 /*
31  * Directions
32  *
33  * 14.4.2009 (Tomi Karppinen)
34  * - Class is now serializable
35  * 14.4.2009 (Tomi Karppinen)
36  * - Added the Direction enumeration
37  * 14.4.2009 Initial version (Tomi Karppinen)
38  */
39 
40 using System;
41 using System.Collections.Generic;
42 using AdvanceMath;
43 using Physics2DDotNet;
44 
45 namespace Jypeli
46 {
50  public struct Direction
51  {
55  public static Direction None = new Direction( "None", 0, 0 );
56 
60  public static Direction Up = new Direction( "Up", 0, 1 );
61 
65  public static Direction Down = new Direction( "Down", 0, -1 );
66 
70  public static Direction Left = new Direction( "Left", -1, 0 );
71 
75  public static Direction Right = new Direction( "Right", 1, 0 );
76 
80  private Vector Vector;
81 
85  public Angle Angle
86  {
87  get { return Vector.Angle; }
88  }
89 
93  public string Name;
94 
95  private Direction( string name, int x, int y )
96  {
97  Name = name;
98  Vector = new Vector(x, y);
99  }
100 
106  public static Direction Inverse( Direction d )
107  {
108  if ( d == Direction.Up ) return Direction.Down;
109  if ( d == Direction.Down ) return Direction.Up;
110  if ( d == Direction.Left ) return Direction.Right;
111  if ( d == Direction.Right ) return Direction.Left;
112 
113  return Direction.None;
114  }
115 
116  public Vector GetVector()
117  {
118  return Vector;
119  }
120 
121  public override bool Equals( object obj )
122  {
123  if ( !( obj is Direction ) ) return false;
124  return this == ( (Direction)obj );
125  }
126 
127  public static bool operator ==(Direction left, Direction right)
128  {
129  return (left.Vector == right.Vector && left.Name == right.Name);
130  }
131 
132  public static bool operator !=(Direction left, Direction right)
133  {
134  return (left.Vector != right.Vector || left.Name != right.Name);
135  }
136  }
137 }
static Direction Down
Suunta alas.
Definition: Direction.cs:65
Angle Angle
Kulma radiaaneina.
Definition: Vector.cs:308
static bool operator!=(Direction left, Direction right)
Definition: Direction.cs:132
Suuntakulma (rajoitettu -180 ja 180 asteen välille) asteina ja radiaaneina. Tietoja kulmasta: http://...
Definition: Angle.cs:40
static Direction Left
Suunta vasemmalle.
Definition: Direction.cs:70
static Direction None
Ei suuntaa.
Definition: Direction.cs:55
override bool Equals(object obj)
Definition: Direction.cs:121
Perussuunta tasossa.
Definition: Direction.cs:50
Vector GetVector()
Definition: Direction.cs:116
static Direction Inverse(Direction d)
Palauttaa vastakkaisen suunnan annetulle suunnalle.
Definition: Direction.cs:106
static Direction Right
Suunta oikealle.
Definition: Direction.cs:75
string Name
Suunnan nimi.
Definition: Direction.cs:93
static Direction Up
Suunta ylös.
Definition: Direction.cs:60
2D-vektori.
Definition: Vector.cs:56
static bool operator==(Direction left, Direction right)
Definition: Direction.cs:127