Changeset 1111 for cacatris


Ignore:
Timestamp:
Sep 26, 2006, 11:41:10 PM (14 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • Added preliminary score counting system (ok it sucks), and down key (ok, it sucks as well) (but I'm drunk AHAH)
Location:
cacatris/trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cacatris/trunk/src/cacatris.h

    r1108 r1111  
    5050
    5151
    52 void infos_populate(cucul_canvas_t *);
     52void infos_populate(cucul_canvas_t *, unsigned int score);
    5353void playfield_draw(cucul_canvas_t *);
    5454void put_piece(unsigned int, unsigned int, unsigned int, unsigned int);
  • cacatris/trunk/src/main.c

    r1108 r1111  
    2121    unsigned int speed = 32;
    2222    unsigned int fixed_y = 0;
    23 
     23    unsigned char lost = 0;
     24    unsigned int  score = 0;
     25    unsigned int lines = 0;
    2426
    2527    field = cucul_create_canvas(0, 0);
     
    8082        }
    8183
     84        if(lost) continue;
     85
     86
     87        if(y==0 && has_landed(current_piece, x ,y, rotation)) {
     88            lost = 1;
     89            continue;
     90        }
     91
    8292        if(left)
    8393        {
     
    8999            if(movable(current_piece, x+1, y, rotation))
    90100                x++;
     101        }
     102        if(down)
     103        {
     104            while((movable(current_piece, x-1, y, rotation)) && (!has_landed(current_piece, x-1, y, rotation)))
     105            {
     106                fixed_y+=speed;
     107                y = fixed_y>>8;
     108            }
    91109        }
    92110
     
    111129
    112130        /* Populate info canvas */
    113         infos_populate(infos);
     131        infos_populate(infos, score);
    114132        /* Draw everything on playfield */
    115133        put_piece(current_piece, x ,y, rotation);
     
    137155        }
    138156
    139 
    140         maybe_remove_line();
     157        lines = maybe_remove_line();
     158        if(lines)
     159        {
     160            score += (lines*40);
     161
     162        }
    141163
    142164        if(!baseTime)
     
    154176
    155177
    156 void infos_populate(cucul_canvas_t *inf)
     178void infos_populate(cucul_canvas_t *inf, unsigned int score)
    157179{
    158180    unsigned int i;
     181    char scoreline[1024];
     182
     183    sprintf(scoreline, " Score    :   %05d ", score);
     184
    159185    cucul_set_color(inf, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
    160186    cucul_putstr(inf, 0, 0,"      =Cacatris=    ");
     
    163189    cucul_putstr(inf, 0, 3," __________________ ");
    164190    cucul_putstr(inf, 0, 4,"                    ");
    165     cucul_putstr(inf, 0, 5," Score    :   NXXXX ");
     191    cucul_putstr(inf, 0, 5,scoreline);
    166192    cucul_putstr(inf, 0, 6," Time     :   XX:XX ");
    167193
     
    287313    int x, v=0;
    288314    unsigned char *p = &playfield[(FIELD_HEIGHT-1)*FIELD_WIDTH];
     315    int ret = 0;
    289316    for(x = 0; x < FIELD_WIDTH ; x++)
    290317        if(*p++)
     
    293320    if(v==FIELD_WIDTH) {
    294321        memmove(&playfield[FIELD_WIDTH], playfield, (FIELD_HEIGHT-1)*FIELD_WIDTH);
    295         return 1;
     322        ret += maybe_remove_line();
     323        return ret;
    296324    }
    297325    return 0;
Note: See TracChangeset for help on using the changeset viewer.