Changeset 36

Show
Ignore:
Timestamp:
01/22/08 21:47:44 (11 months ago)
Author:
charlie137
Message:

Added Rotating font

Files:

Legend:

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

    r26 r36  
    11 
    2 GUISTERAX 0.3 
     2GUISTERAX 0.4 
    33 
    44Code, graphics and sound by Guillaume 'Charlie' Chereau (charlie137@gmail.com) 
  • trunk/guisterax/src/display.d

    r33 r36  
    172172        int h = (src)?src.h : surf.h; 
    173173        dest.y = screen.h - cast(int)round(pos.y + h); 
    174         dest.w = surf.surf.w; 
    175         dest.h = surf.surf.h; 
     174        dest.w = (src)? src.w : surf.surf.w; 
     175        dest.h = (src)? src.h : surf.surf.h; 
    176176        SDL_BlitSurface(surf.surf, src, screen, &dest); 
    177177    } 
  • trunk/guisterax/src/font.d

    r32 r36  
    3232import std.string; 
    3333 
     34import std.math : PI; 
     35 
    3436class Font 
    3537{ 
    36 private: 
    37     Surface m_surf; 
    38     uint[char] m_letters; 
    39     uint m_w, m_h; 
    40      
    41      
     38public: 
     39    Surface surf; 
     40    uint[char] letters; 
     41    uint w, h; 
     42    uint nb_angles; // used for rotating font : number of different font angles 
    4243public: 
    4344 
    4445    static Font font; 
    4546    static Font font_grey; 
     47    static Font font_moving; 
    4648     
    4749public: 
    4850    static void s_init() { 
    4951        font = new Font("data/font/font.png", "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .:/$_=", 16, 25); 
     52        font_moving = new Font("data/font/font_moving.png", "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .:/$_=", 16, 25, 32); 
    5053        font_grey = new Font("data/font/font_grey.png", "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .:/$_=", 16, 25); 
    5154    } 
    52     this(in char[] file, in char[] letters, uint w, uint h) { 
    53         m_surf = new Surface(file); 
     55    this(in char[] file, in char[] letters, uint w, uint h, uint nb = 1) { 
     56        surf = new Surface(file); 
    5457        foreach(i,l; letters) { 
    55             m_letters[l] = i; 
     58            this.letters[l] = i; 
    5659        } 
    57         m_w = w; 
    58         m_h = h; 
     60        this.w = w; 
     61        this.h = h; 
     62        this.nb_angles = nb; 
     63         
     64        assert(nb == surf.h / h); 
    5965    } 
    6066     
    61     void draw(Display disp, in char[] text, Vect pos, bool centered = false) { 
     67    void draw(Display disp, in char[] text, Vect pos, bool centered = false, float angle = 0) { 
    6268        char[][] lines = split(text, "\n"); 
    6369        if (centered) { 
    64             pos += Vect(0, (lines.length - 1) * m_h / 2);  
     70            pos += Vect(0, (lines.length - 1) * h / 2);  
    6571        } 
    6672        foreach(line; lines) { 
    67             draw_line(disp, line, pos, centered); 
    68             pos -= Vect(0, m_h);  
     73            draw_line(disp, line, pos, centered, angle); 
     74            pos -= Vect(0, h);  
    6975        } 
    7076    } 
    7177     
    72     void draw_line(Display disp, in char[] line, Vect pos, bool centered = false) { 
    73         pos -= Vect(0, m_h / 2); 
     78    void draw_line(Display disp, in char[] line, Vect pos, bool centered = false, float angle = 0) { 
     79        pos -= Vect(0, h / 2); 
    7480        if (centered) { 
    75             pos -= Vect(line.length * m_w / 2, 0);  
     81            pos -= Vect(line.length * w / 2, 0);  
    7682        } 
     83        assert(angle >= 0 && angle < 2 * PI); 
     84        uint a_index = cast(int)(angle / (2 * PI) * nb_angles); 
     85         
    7786        foreach(i, l; line) { 
    7887            disp.blit( 
    79                 m_surf, 
    80                 pos + Vect(m_w,0) * i, 
    81                 m_letters[l] * m_w, 0, m_w, m_
     88                surf, 
     89                pos + Vect(w,0) * i, 
     90                letters[l] * w, a_index * h, w,
    8291            );   
    8392        } 
  • trunk/guisterax/src/game.d

    r33 r36  
    8686        // Add the help text 
    8787        append(new Text( 
    88 "GUISTERAX 0.3 
     88"GUISTERAX 0.4 
    8989 
    9090BY GUILLAUME CHEREAU 
  • trunk/guisterax/src/menu.d

    r33 r36  
    3535public: 
    3636    Vect pos = Vect(); 
     37    bool selected = false; 
     38 
     39public: 
    3740    void draw(Display disp, in Vect pos, bool selected = false) {} 
    3841    void on_activate() {} 
     
    4649} 
    4750 
     51/** 
     52     
     53*/ 
    4854class TextEntry : Entry 
    4955{ 
     
    5258    char[] text; 
    5359    void delegate() func; 
     60    float angle = 0; /// This angle is used to make the text rotating 
     61    float rot_speed = 0.075; 
    5462     
    5563    static void s_init() { 
     
    6270        this.func = func; 
    6371    } 
    64     override void draw(Display disp, in Vect pos, bool selected = false) { 
     72    override void draw(Display disp, in Vect pos) { 
    6573        if (selected) { 
    6674            selected_surf.draw(disp, pos + this.pos); 
     75            Font.font_moving.draw(disp, text, pos + this.pos, true, angle); 
    6776        } 
    68         Font.font.draw(disp, text, pos + this.pos, true); 
     77        else { 
     78            Font.font.draw(disp, text, pos + this.pos, true); 
     79        } 
    6980    } 
     81     
     82    override void iter(float dt) { 
     83        if (selected) { 
     84            angle += dt * rot_speed; 
     85            angle = modulo(angle, 2*PI); 
     86        } 
     87        else { 
     88            angle = 0; 
     89        } 
     90    } 
     91             
    7092     
    7193    override void on_activate() { 
     
    94116    Entry selected() {return cast(Entry)children[index];} 
    95117     
     118    override void draw(Display disp, in Vect pos = Vect()) { 
     119        super.draw(disp, pos + this.pos); 
     120    } 
     121     
    96122    void up() { 
     123        selected.selected = false; 
    97124        do { 
    98125            index = modulo(index - 1, children.length); 
    99126        } while (!selected.selectable()) 
     127        selected.selected = true; 
    100128    } 
    101129     
    102130    void down() { 
     131        selected.selected = false; 
    103132        do { 
    104133            index = modulo(index + 1, children.length); 
    105134        } while (!selected.selectable()) 
     135        selected.selected = true; 
    106136    } 
    107137     
    108138    override void iter(float dt) { 
    109139        super.iter(dt); 
     140         
     141        selected.selected = true; // we update the selected entry 
     142         
    110143        if (universe.pressed_key(SDLK_UP)) { 
    111144            up(); 
     
    120153    }  
    121154     
    122     override void draw(Display disp, in Vect pos = Vect()) { 
    123         foreach(i, c; children) { 
    124             Entry e = cast(Entry)c; 
    125             assert(e); 
    126             e.draw(disp, pos + this.pos, i == index); 
    127         } 
    128     } 
    129      
    130155}; 
    131156 
  • trunk/guisterax/src/scores.d

    r33 r36  
    7171    bool is_high(int score) { 
    7272        if (scores.length < nb_scores) {return true;} 
    73         if (score > scores[$].score) {return true;} 
     73        if (score > scores[length - 1].score) {return true;} 
    7474        return false; 
    7575    } 
  • trunk/guisterax/src/shop.d

    r33 r36  
    6464    } 
    6565     
    66     override void draw(Display disp, in Vect pos, bool selected = false) { 
     66    override void draw(Display disp, in Vect pos) { 
    6767        if (selected) {m_selected_surf.draw(disp, pos + this.pos);} 
    6868        Font font = selectable() ? Font.font : Font.font_grey; 
     
    153153        m_ship = ship; 
    154154         
    155         Menu menu = new Menu(Vect(0,96)); 
     155        append(new Text("SHOPPING", Vect(0, 200), true)); 
     156         
     157        Menu menu = new Menu(Vect(0,128)); 
    156158         
    157159        float dist = 32;