Changeset 23

Show
Ignore:
Timestamp:
12/11/07 05:19:20 (1 year ago)
Author:
charlie137
Message:

Added comment in the code

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/guisterax/Makefile

    r20 r23  
    1313    gdc -fdebug -g -o guisterax src/*.d src/derelict/util/*.d src/derelict/sdl/*.d -Isrc/ -Isrc/derelict -lm 
    1414     
     15dmd: src/*.d 
     16    dmd -op -ofguisterax src/*.d src/derelict/util/*.d src/derelict/sdl/*.d -Isrc/ -Isrc/derelict -L-ldl 
     17 
    1518clean: 
    16     rm -rf build guisterax *.o *.bp *.greg 
     19    rm -f guisterax 
     20    find -name '*.o' | xargs rm -f 
  • trunk/guisterax/src/actor.d

    r10 r23  
    2828import display; 
    2929 
     30/** 
     31    Base class for everything in the game. 
     32     
     33    An actor has a parent actor and a list of children actor, so that all the actors of the game are in a tree-like structure. 
     34    Every actors have an iter, move and update methods. They are called in that order at each iteration of the game. 
     35*/ 
    3036class Actor 
    3137{ 
     
    3541     
    3642public: 
     43    /// The parent of this actor. 
    3744    Actor parent; 
     45    /// All the children of this actor. 
    3846    Actor[] children; 
     47    /// Defines if the actor has to be deleted or not. 
    3948    bool alive = true; 
    4049     
    4150public: 
     51    /// Return all the children that are of type T. 
    4252    T[] children_as(T)() { 
    4353        bool is_t(in Actor a) {return cast(T)a !is null;} 
     
    4555    } 
    4656     
     57    /// Return the first ancestor of type T. 
    4758    T parent_as(T)() { 
    4859        T casted = cast(T)parent; 
     
    5263    } 
    5364     
     65    /// Return the fist ancestor of type Universe. 
    5466    Universe universe() {return parent_as!(Universe)();} 
    5567     
     68    /// Kill the actor (the parent will delete it in the next iteration step). 
    5669    void kill() {alive = false;} 
    5770     
    5871    this() {} 
    5972     
     73    /// Indicate how much the actor contribute to the global danger of the game. 
    6074    float danger() {return 0;} 
    6175     
     76    /** Append a children actor. 
     77        Params: 
     78            a =     the actor to add 
     79            end =   add the actor at the end of the children list 
     80    */ 
    6281    void append(Actor a, bool end = true) { 
    6382        if (end) { 
     
    6887        a.parent = this; 
    6988    } 
     89     
     90    /** Append a children actor. 
     91        Params: 
     92            a =     the actor to add 
     93            pos =   add the actor just before this 
     94    */ 
    7095    void append(Actor a, Actor pos) { 
    7196        m_next_children = insert(m_next_children, a, pos); 
     
    7398    } 
    7499 
    75     void iter(float dt = 1) { 
     100    /// Iter the actor of a given time 
     101    void iter(float dt) { 
    76102        foreach(a; children) { 
    77103            a.iter(dt); 
     
    79105    } 
    80106     
    81     void move(float dt = 1) { 
     107    /// Move the actor of a given time 
     108    void move(float dt) { 
    82109        foreach(a; children) { 
    83110            a.move(dt); 
     
    85112    } 
    86113     
     114    /// Update the actor 
    87115    void update() { 
    88116        // update actor list 
     
    95123    } 
    96124     
     125    /** 
     126        Draw the actor on a display 
     127        Params: 
     128            disp =  the display to draw on 
     129            pos =   the pos where to draw 
     130    */ 
    97131    void draw(Display disp, in Vect pos = Vect()) { 
    98132        foreach(a; children) { 
  • trunk/guisterax/src/element.d

    r22 r23  
    3636import std.stdio; 
    3737 
     38/** 
     39    Special Actor that represents a circular object in a Universe 
     40     
     41    Elements have some additional attributes, like pos, speed, radius...  
     42*/ 
    3843class Element : Actor 
    3944{ 
     
    4247     
    4348public: 
    44     bool stay_inside_universe = true; 
    45     Vect pos = Vect(0,0); 
    46     Vect speed = Vect(0,0); 
    47     Vect force; 
    48     float mass = 1; 
    49     Sprite sprite; 
    50     float max_speed = float.infinity; 
    51     float radius = 0; 
    52     float friction = 0; 
     49    Vect pos = Vect();      /// The pos of the element in the universe 
     50    Vect speed = Vect();    /// The speed of the element in the universe 
     51    Vect force;             /// The force currently applied on the element  
     52    float mass = 1;         /// The mass of the element 
     53    Sprite sprite;          /// The sprite 
     54    float max_speed = float.infinity;   /// The element can't go faster than that 
     55    float radius = 0;                   /// Used to compute the collisions 
     56    float friction = 0;                 /// Used to slow down the element 
    5357 
    5458public: 
    55  
     59    /**  
     60        Set the angle of the element 
     61     
     62        It also set the sprite image, because the sprite images represent the element under angles from 0 to 2 * PI  
     63    */ 
    5664    void angle(float a) { 
    5765        m_angle = a; 
     
    6169    float angle() {return m_angle;} 
    6270 
     71    /// Deprecated: use e.force += x instead 
    6372    void add_force(in Vect f) {force += f;} 
    6473 
     74    /// Use if the element can be hitten (like the ship for example) 
    6575    void hit(float v) {} 
    6676 
     77    /** 
     78        Constructor 
     79        Params: 
     80            sprite =    every image of the sprite represent a given angle 
     81            pos =       the initial position of the element  
     82    */ 
    6783    this(Sprite sprite = null, in Vect pos = Vect()) { 
    6884        super(); 
     
    7187    } 
    7288     
     89    /** 
     90        Add an attraction force in a given direction 
     91        Params: 
     92            pos =       the direction of attraction 
     93            strenght =  the strenght of the force 
     94            direct =    define if the force should be applied proportionally to the time or not 
     95                        if direct = true, the force is directly added to the speed 
     96    */ 
    7397    void attract(in Vect pos, float strenght, bool direct = true) { 
    7498        Vect normal = (pos - this.pos).normal(); 
     
    79103        } 
    80104    } 
     105    /// ditto 
    81106    void repeal(in Vect pos, float strenght, bool direct = true) { 
    82107        attract(pos, -strenght, direct); 
     
    84109         
    85110 
    86      
     111    /// Return true if the element can collide into an other given element 
    87112    bool can_collide(in Element e) {return false;} 
     113    /// Compute the result of the collision with an other element 
    88114    void collide(Element e) {} 
    89115     
  • trunk/guisterax/src/game.d

    r17 r23  
    110110    } 
    111111    override void iter(float dt) { 
    112         super.iter(); 
     112        super.iter(dt); 
    113113        if (pressed_key(SDLK_RETURN)) { 
    114114            kill(); 
  • trunk/guisterax/src/surface.d

    r16 r23  
    3232public import display; 
    3333 
     34/** 
     35    Represent a drawable surface. 
     36*/ 
    3437class Surface 
    3538{ 
     
    6972}; 
    7073 
     74/** 
     75    Represent a rectangular part of a surface 
     76*/ 
    7177class SubSurface : Surface 
    7278{ 
  • trunk/guisterax/src/timer.d

    r10 r23  
    2626import utils; 
    2727 
     28/** 
     29    Trigger a function after a given time 
     30*/ 
    2831class Timer: Actor 
    2932{ 
     
    5558}; 
    5659 
     60/** 
     61    Trigger a function after a given random time 
     62*/ 
    5763class RandTimer : Timer 
    5864{ 
    5965    float p; 
     66    /** 
     67        Constructor 
     68        Params: 
     69            e =     probability that the event append in a unity time 
     70            func =  function to call 
     71            loop =  if true reinit the timer after each events 
     72    */ 
    6073    this(float e, void delegate() func, bool loop = false){ 
    6174        p = 1/e; 
  • trunk/guisterax/src/universe.d

    r21 r23  
    3232import surface; 
    3333 
     34/** 
     35    Special Display that display the element several time if they touch the universe border 
     36*/ 
    3437class UniverseDisplay : Display 
    3538{ 
     
    6164}; 
    6265 
     66/** 
     67    Special Actor in which the element children can collide into each other  
     68*/ 
    6369class Universe : Actor 
    6470{ 
     
    7985    float bottom() {return -m_height / 2;} 
    8086     
     87    /// Return all the elements in the universe 
    8188    Element[] elements() {return m_elements;} 
    8289     
     
    8693    } 
    8794     
    88     override void iter(float dt = 1) { 
    89         /// Get the keys 
     95    override void iter(float dt) { 
     96        // Get the keys 
    9097        bool[] n_keys = MainDisplay().getKeys(); 
    9198        m_pressed_keys.length = m_keys.length; 
     
    113120    } 
    114121     
     122    /// Check if a key is currently down. 
    115123    bool key(in SDLKey key) { 
    116124        if (key >= m_keys.length) {return false;} 
     
    118126    } 
    119127     
     128    /// Check if a key has been pressed. 
    120129    bool pressed_key(in SDLKey key) { 
    121130        if (key >= m_pressed_keys.length) {return false;} 
     
    123132    } 
    124133     
     134    /// Check if two elements collide. 
    125135    static bool collide(in Element e1, in Element e2) { 
    126136        return (e1.pos - e2.pos).norm <= e1.radius + e2.radius; 
    127137    } 
    128138     
     139    /// Compute the all collisions  
    129140    void compute_collisions() { 
    130141        for(int i = 0; i < m_elements.length; ++i) {