Changeset 17

Show
Ignore:
Timestamp:
12/09/07 07:23:24 (1 year ago)
Author:
charlie137
Message:

Added help enrty in the main menu

Files:

Legend:

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

    r5 r17  
    22 
    33- Design : 
    4     - remove all m_xxx when possible  
    5     - DOC !!! 
     4    - add doc 
    65 
    76- Score 
    8 - Help entry in the main menu 
    97- Best score 
    108 
  • trunk/guisterax/src/font.d

    r10 r17  
    2727import display; 
    2828import utils; 
     29import actor; 
     30import display; 
     31 
     32import std.string; 
    2933 
    3034class Font 
     
    5660     
    5761    void draw(Display disp, in char[] text, Vect pos, bool centered = false) { 
     62        char[][] lines = split(text, "\n"); 
     63        if (centered) { 
     64            pos += Vect(0, (lines.length - 1) * m_h / 2);  
     65        } 
     66        foreach(line; lines) { 
     67            draw_line(disp, line, pos, centered); 
     68            pos -= Vect(0, m_h);  
     69        } 
     70    } 
     71     
     72    void draw_line(Display disp, in char[] line, Vect pos, bool centered = false) { 
    5873        pos -= Vect(0, m_h / 2); 
    5974        if (centered) { 
    60             pos -= Vect(text.length * m_w / 2);  
     75            pos -= Vect(line.length * m_w / 2, 0);  
    6176        } 
    62         foreach(i, l; text) { 
     77        foreach(i, l; line) { 
    6378            disp.blit( 
    6479                m_surf, 
     
    6984    } 
    7085}; 
     86 
     87class Text : Actor 
     88{ 
     89public: 
     90    Font font = null; 
     91    Vect pos; 
     92    char[] text; 
     93    bool centered; 
     94     
     95    this(Font font, in char[] text, in Vect pos, bool centered = false) { 
     96        this.font = font; 
     97        this.text = text.dup; 
     98        this.pos = pos; 
     99        this.centered = centered;       
     100    } 
     101     
     102    this(in char[] text, in Vect pos, bool centered = false) { 
     103        this(Font.font, text, pos, centered); 
     104    } 
     105 
     106    override void draw(Display disp, in Vect pos = Vect()) { 
     107          font.draw(disp, text, pos + this.pos, centered); 
     108    } 
     109 
     110}; 
  • trunk/guisterax/src/game.d

    r16 r17  
    7171        super(pos); 
    7272        append(new Entry("NEW GAME", &new_game, Vect(0,0))); 
    73         append(new Entry("QUIT", &quit, Vect(0,-32))); 
     73        append(new Entry("HELP", &help, Vect(0, -32))); 
     74        append(new Entry("QUIT", &quit, Vect(0,-64))); 
    7475    } 
    7576     
     
    7980    } 
    8081     
     82    void help() { 
     83        Game g = new Game(); 
     84        g.help(); 
     85    } 
     86     
    8187    void quit() { 
    8288        throw new Quit(); 
     89    } 
     90}; 
     91 
     92class Help : Universe 
     93{ 
     94    this() { 
     95        super(); 
     96        // Add the help text 
     97        append(new Text( 
     98"GUISTERAX 0.3 
     99 
     100BY GUILLAUME CHEREAU 
     101 
     102CONTROL : 
     103 UP ARROW    : THRUST FORWARD 
     104 LEFT ARROW  : TURN LEFT      
     105 RIGHT ARROW : TURN RIGHT     
     106 SPACE BAR   : FIRE           
     107", 
     108        Vect(0, 0), true)); 
     109         
     110    } 
     111    override void iter(float dt) { 
     112        super.iter(); 
     113        if (pressed_key(SDLK_RETURN)) { 
     114            kill(); 
     115        } 
    83116    } 
    84117}; 
     
    112145    } 
    113146     
     147    void help() { 
     148        Help h = new Help(); 
     149        run(h); 
     150    } 
     151     
    114152    void play() { 
    115          
    116153        m_ship = new Ship(Vect(10,0)); 
    117154        uint level = 1; 
  • trunk/guisterax/src/menu.d

    r10 r17  
    8484        } 
    8585             
    86         if (universe.pressed_key(SDLK_SPACE)) { 
     86        if (universe.pressed_key(SDLK_RETURN)) { 
    8787            selected.on_activate(); 
    8888        } 
  • trunk/guisterax/src/universe.d

    r10 r17  
    4646        // I am not sure this is the most efficient way it depends on the way SDL 
    4747        // handle blitting surfaces that are not included in the visible screen 
    48         for(int i = -1; i <= 1; ++i) { 
    49             for(int j = -1; j <= 1; ++j) { 
     48        for(int i = 0; i <= 0; ++i) { 
     49            for(int j = 0; j <= 0; ++j) { 
    5050                disp.blit(surf, pos + Vect(i*u.width, j*u.height), x, y, w, h); 
    5151            } 
  • trunk/guisterax/src/vect.d

    r15 r17  
    3131    string toString() {return format("%f,%f", x, y);} 
    3232     
    33     static Vect opCall(float x = 0, float y = 0) { 
     33    static Vect opCall(float x, float y) { 
    3434        Vect ret; 
    3535        ret.x = x; ret.y = y; 
    3636        return ret; 
     37    } 
     38     
     39    static Vect opCall() { 
     40        return Vect(0,0); 
    3741    } 
    3842