Advertisement
Guest User

Untitled

a guest
Mar 18th, 2015
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;      // Required to use XNA features.
  6. using XNAMachinationisRatio;        // Required to use the XNA Machinationis Ratio Engine.
  7. using XNAMachinationisRatio.AI;     // Required to use the XNA Machinationis Ratio general AI features
  8.  
  9. /* LERNING PILL: XNAMachinationisRatio Engine
  10.  * XNAMachinationisRatio is an engine that allows implementing
  11.  * simulations and games based on XNA, simplifying the use of XNA
  12.  * and adding features not directly available in XNA.
  13.  * XNAMachinationisRatio is a work in progress.
  14.  * The engine works "under the hood", taking care of many features
  15.  * of an interactive simulation automatically, thus minimizing
  16.  * the amount of code that developers have to write.
  17.  *
  18.  * In order to use the engine, the application main class (Kernel, in the
  19.  * case of FishO'Rama) creates, initializes and stores
  20.  * an instance of class Engine in one of its data members.
  21.  *
  22.  * The classes comprised in the  XNA Machinationis Ratio engine and the
  23.  * related functionalities can be accessed from any of your XNA project
  24.  * source code files by adding appropriate 'using' statements at the beginning of
  25.  * the file.
  26.  *
  27.  */
  28.  
  29. /*LEARNING PILL: Game Tokens in the XNA Machinationis Ratio Engine.
  30.  * The XNA Machinationis Ratio engine models games as systems
  31.  * comprising entities called tokens. Tokens have a visual representation
  32.  * and interactive behaviors. Tokens are implemented in C# as instances
  33.  * of the class Token or one of its derived classes.
  34.  *
  35.  * Tokens have attributes that allow implementing simulation features.
  36.  * Tokens can be associated to a 'mind' object, in order to implement their behaviors.
  37.  */
  38.  
  39. /* LEARNING PILL: virtual world space and graphics in FishORama
  40.  * In the Machinationis Ratio engine every object has graphic a position in the
  41.  * virtual world expressed through a 3D vector (represented via a Vector3 object).
  42.  * In 2D simulations the first coordinate of the vector is the horizontal (X)
  43.  * position, the second coordinate (Y) represents the vertical position, and
  44.  * the third coordinate (Z) represents the depth. All simulation features are
  45.  * based on world coordinates.
  46.  *
  47.  * At any time, a portion of the scene is visible through a camera object (in FishO'Rama
  48.  * this is created, initialized and referenced through the Kernel class). For the purpose
  49.  * of visualization, coordinates may also be expressed relative to the camera
  50.  * origin (i.e. the center of the camera). In FishO'Rama the camera is centered on the
  51.  * origin of the world, which makes camera coordinates coinciding with world coordinates.
  52.  * This greatly simplifies all the operations.
  53.  *
  54.  * The third coordinate of the world position of an object represents the depth, i.e.
  55.  * how close an object is to the camera. This defines which objects are in front of others
  56.  * (for instance, an object with Z=3 will always be drawn in front of an object with
  57.  * Z=2).
  58.  */
  59.  
  60. /* LEARNING PILL: placing tokens in a scene.
  61.  * In order to be managed by the Machinationis Ratio engine, tokens must be placed
  62.  * in a scene.
  63.  *
  64.  * In FishORama the procedure for the creation and placement of tokens that must be
  65.  * placed in the scene at startup is carried out byn the method LoadContent of
  66.  * class Kernel.
  67.  *
  68.  * Tokens can also be created in runtime by any method of any class, provided that
  69.  * the method has access to the simulation scene object encapsulated in class Kernel.
  70.  * This object can be accessed through the property Scene of class Kernel.
  71.  */
  72.  
  73. namespace FishORama
  74. {
  75.     /// <summary>
  76.     /// Abstraction to represent the orange fish which moves peacefully in the aquarium.
  77.     ///
  78.     /// This class is derived from class X2DToken. In the XNA Machinationis Ratio engine
  79.     /// class X2DToken is a base class for all classes representing objects which
  80.     /// have a visual representation and interactive behaviors in a 2D simulation.
  81.     /// X2DToken implements a number of functionalities that make it easy for developers
  82.     /// to add interactivity to objects minimizing the amount of coded required.
  83.     ///
  84.     /// Hence, whenever we want to create a new type of object, we must create a new
  85.     /// class derived from X2DToken.
  86.     /// </summary>
  87.     ///
  88.     class OrangeFishToken: X2DToken
  89.     {
  90.         #region Data members
  91.  
  92.         // This token needs to interact with the aquarium to swim in it (it needs information
  93.         // regarding the aquarium's boundaries). Hence, it needs a "link" to the aquarium,
  94.         // which is why it stores in an instance variable a reference to its aquarium.
  95.         private AquariumToken mAquarium;    // Reference to the aquarium in which the creature lives.
  96.  
  97.         private OrangeFishMind mMind;       // Explicit reference to the mind the token is using to enact its behaviors.
  98.  
  99.         #endregion
  100.  
  101.         #region Properties
  102.  
  103.         /// <summary>
  104.         /// Get aquarium in which the creature lives.
  105.         /// </summary>
  106.         public AquariumToken Aquarium
  107.         {
  108.             get { return mAquarium; }
  109.         }
  110.  
  111.         #endregion
  112.  
  113.         #region Constructors
  114.  
  115.         /// Constructor for the orange fish.
  116.         /// Uses base class to initialize the token name, and adds code to
  117.         /// initialize custom members.
  118.         /// <param name="pTokenName">Name of the token.</param>
  119.         /// <param name="pAquarium">Reference to the aquarium in which the token lives.</param>
  120.         public OrangeFishToken(String pTokenName, AquariumToken pAquarium)
  121.             : base(pTokenName) {
  122.                 mAquarium = pAquarium;          // Store reference to aquarium in which the creature is living.
  123.                 mMind.Aquarium = mAquarium;     // Provide to the mind a reference to the aquarium, required to swim appropriately.
  124.         }
  125.  
  126.         #endregion
  127.  
  128.         #region Methods
  129.  
  130.         /* LEARNING PILL: XNA Machinationis Ration token properties.
  131.          * All tokens created through the XNA Machinationis Ratio engine have standard
  132.          * attributes that define their behavior in a simulation. These standard
  133.          * attributes can be initialized in a very efficient and simple way using
  134.          * the DeafultProperties() method.
  135.          */
  136.  
  137.         /// <summary>
  138.         /// Setup default properties of the token.
  139.         /// </summary>
  140.         protected override void DefaultProperties() {
  141.  
  142.             // Specify which image should be associated to this token, assigning
  143.             // the name of the graphic asset to be used ("OrangeFishVisuals" in this case)
  144.             // to the property 'GraphicProperties.AssetID' of the token.
  145.             this.GraphicProperties.AssetID = "OrangeFishVisuals";
  146.  
  147.             // Specify mass of the fish. This can be used by
  148.             // physics-based behaviors (work in progress, not functional yet).
  149.             this.PhysicsProperties.Mass = 3;
  150.  
  151.             /* LEARNING PILL: Token behaviors in the XNA Machinationis Ratio engine
  152.              * Some simulation tokens may need to enact specific behaviors in order to
  153.              * participate in the simulation. The XNA Machinationis Ratio engine
  154.              * allows a token to enact a behavior by associating an artificial intelligence
  155.              * mind to it. Mind objects are created from subclasses of the class AIPlayer
  156.              * included in the engine. In order to associate a mind to a token, a new
  157.              * mind object must be created, passing to the constructor of the mind a reference
  158.              * of the object that must be associated with the mind. This must be done in
  159.              * the DefaultProperties method of the token. Upon creation of the mind, XNA
  160.              * Machinationis Ratio automatically "injects" its into the token, establishing
  161.              * a link which is not visible to the programmer (but it there!)
  162.              *
  163.              * In this case, instances of the class OrangeFishToken can enact a simple swimming
  164.              * behavior. The behavior is implemented through the class SimpleSwimMind.
  165.              */
  166.  
  167.             OrangeFishMind myMind = new OrangeFishMind(this);   // Create mind, implicitly associating it to the token.
  168.            
  169.  
  170.             mMind = myMind;     // Store explicit reference to mind being used.
  171.             mMind.Aquarium = mAquarium;   // Provide to mind explicit reference to Aquarium.
  172.         }
  173.  
  174.         #endregion
  175.  
  176.     }
  177.  
  178.     public void Update(int mouseX, int mouseY){}
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement