Changeset 1108
- Timestamp:
- Sep 26, 2006, 11:16:35 PM (17 years ago)
- Location:
- cacatris/trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cacatris/trunk/src/cacatris.h
r1097 r1108 1 1 /* 2 2 * $Id: cacatris.h 1 2006-09-22 16:56:18Z jylam $ 3 *4 * This program is free software; you can redistribute it and/or modify5 * it under the terms of the GNU General Public License as published by6 * the Free Software Foundation; either version 2 of the License, or7 * (at your option) any later version.8 3 * 9 4 * This program is free software; you can redistribute it and/or … … 31 26 #define INFO_WIDTH 20 32 27 #define FIELD_WIDTH 20 33 #define FIELD_HEIGHT 3 528 #define FIELD_HEIGHT 32 34 29 #define FIELD_CANVAS_WIDTH 40 35 #define FIELD_CANVAS_HEIGHT 3 530 #define FIELD_CANVAS_HEIGHT 32 36 31 37 32 unsigned char playfield[FIELD_WIDTH*FIELD_HEIGHT]; … … 55 50 56 51 57 58 59 52 void infos_populate(cucul_canvas_t *); 60 53 void playfield_draw(cucul_canvas_t *); … … 62 55 void remove_piece(unsigned int id, unsigned int x, unsigned int y, unsigned int rot); 63 56 unsigned char movable(unsigned int id, int x, int y, unsigned int rot); 64 57 unsigned char has_landed(unsigned int id, unsigned int x, unsigned int y, unsigned int rot); 58 unsigned char maybe_remove_line(void); 65 59 66 60 piece_t pieces[] = { -
cacatris/trunk/src/main.c
r1096 r1108 1 1 /* 2 2 * $Id$ 3 *4 * This program is free software; you can redistribute it and/or modify5 * it under the terms of the GNU General Public License as published by6 * the Free Software Foundation; either version 2 of the License, or7 * (at your option) any later version.8 3 * 9 4 * This program is free software; you can redistribute it and/or … … 21 16 signed int x=(FIELD_WIDTH/2)-1, y=0, rotation=0, old_x=0, old_y=0, old_rotation=0; 22 17 unsigned int current_piece, next_piece, baseTime = 0; 23 unsigned char last_has_landed = 0;18 unsigned char last_has_landed = 1; 24 19 unsigned char left = 0, right = 0, down = 0; 25 20 unsigned long long int curTime = 0; … … 55 50 left = 0; right = 0; down = 0; 56 51 57 printf("%llu\n", curTime);58 59 52 /* Handle events */ 60 61 53 while(caca_get_event(dp, CACA_EVENT_KEY_PRESS 62 54 | CACA_EVENT_QUIT, &ev, 0)) … … 64 56 if(ev.type == CACA_EVENT_QUIT) 65 57 goto end; 66 58 switch(ev.data.key.ch) 67 59 { 68 60 case CACA_KEY_ESCAPE: … … 70 62 break; 71 63 case CACA_KEY_UP: 72 rotation++; 73 rotation = rotation&0x03; 64 if(movable(current_piece, x, y, (rotation+1)&0x03)) 65 { 66 rotation++; 67 rotation = rotation&0x03; 68 } 74 69 break; 75 70 case CACA_KEY_DOWN: … … 88 83 { 89 84 if(movable(current_piece, x-1, y, rotation)) 90 x--;85 x--; 91 86 } 92 87 if(right) 93 88 { 94 89 if(movable(current_piece, x+1, y, rotation)) 95 x++;90 x++; 96 91 } 97 92 98 93 if(!last_has_landed) 99 94 { 100 remove_piece(current_piece, old_x ,old_y, old_rotation);95 last_has_landed = 0; 101 96 } 102 97 else … … 105 100 } 106 101 107 put_piece(current_piece, x ,y, rotation);108 102 109 103 old_x = x; … … 115 109 116 110 117 if(y==(FIELD_HEIGHT-4)) 118 { 111 112 /* Populate info canvas */ 113 infos_populate(infos); 114 /* Draw everything on playfield */ 115 put_piece(current_piece, x ,y, rotation); 116 playfield_draw(field); 117 remove_piece(current_piece, x ,y, rotation); 118 /* blit infos canvas into general one */ 119 cucul_blit(screen, (cucul_get_canvas_width(screen)) - INFO_WIDTH, 0, infos, NULL); 120 /* blit playfield canvas into general one */ 121 cucul_blit(screen, 18, 0, field, NULL); 122 123 caca_refresh_display(dp); 124 125 126 if(has_landed(current_piece, x ,y, rotation)) 127 { 128 put_piece(current_piece, x ,y, rotation); 119 129 fixed_y = 0; 120 130 x = (FIELD_WIDTH/2)-1; … … 127 137 } 128 138 129 /* Populate info canvas */ 130 infos_populate(infos); 131 /* Draw everything on playfield */ 132 playfield_draw(field); 133 /* blit infos canvas into general one */ 134 cucul_blit(screen, (cucul_get_canvas_width(screen)) - INFO_WIDTH, 0, infos, NULL); 135 /* blit playfield canvas into general one */ 136 cucul_blit(screen, 18, 0, field, NULL); 137 138 caca_refresh_display(dp); 139 139 140 maybe_remove_line(); 140 141 141 142 if(!baseTime) … … 144 145 } 145 146 curTime+=caca_get_display_time(dp); 146 147 147 } 148 148 … … 206 206 { 207 207 unsigned int ix, iy; 208 printf("rotation %d\n", rot);209 208 piece_t *p = &pieces[(id*4)+rot]; 210 209 … … 218 217 { 219 218 unsigned int ix, iy; 220 printf("rotation %d\n", rot);221 219 piece_t *p = &pieces[(id*4)+rot]; 222 220 … … 224 222 for(ix = 0; ix < p->w; ix++) 225 223 if(ix<p->w && iy<p->h) 226 if(p->data[ix+iy*4])227 playfield[(ix+x)+(iy+y)*FIELD_WIDTH] = 0;224 if(p->data[ix+iy*4]) 225 playfield[(ix+x)+(iy+y)*FIELD_WIDTH] = 0; 228 226 } 229 227 … … 231 229 { 232 230 piece_t *p = &pieces[(id*4)+rot]; 231 unsigned int ix, iy; 233 232 int w, h; 234 233 … … 237 236 238 237 238 if(y>=(signed)(FIELD_HEIGHT-p->h)) { 239 return 0; 240 } 241 242 239 243 if(x>=0 && (x+w<=FIELD_WIDTH) && y<(FIELD_HEIGHT-(signed)h)) 240 244 { 245 for(iy = 0; iy < p->h; iy++) 246 for(ix = 0; ix < p->w; ix++) 247 if((p->data[ix+iy*4]!=0) && (playfield[(ix+x)+(iy+y)*FIELD_WIDTH]!=0)) { 248 return 0; 249 } 250 241 251 return 1; 242 252 } … … 244 254 return 0; 245 255 } 256 257 unsigned char has_landed(unsigned int id, unsigned int x, unsigned int y, unsigned int rot) 258 { 259 piece_t *p = &pieces[(id*4)+rot]; 260 unsigned int ix, iy; 261 unsigned int w, h; 262 263 w = p->w; 264 h = p->h; 265 266 if(y>=(FIELD_HEIGHT-p->h)) { 267 return 1; 268 } 269 y++; 270 if(x>=0 && (x+w<=FIELD_WIDTH) && y<=(FIELD_HEIGHT-h)) 271 { 272 for(iy = 0; iy < p->h && (iy+y<FIELD_HEIGHT) ; iy++) 273 for(ix = 0; (ix < p->w) && (ix+x<FIELD_WIDTH); ix++) 274 if((p->data[ix+iy*4]!=0) && (playfield[(ix+x)+(iy+y)*FIELD_WIDTH]!=0)) { 275 return 1; 276 } 277 278 return 0; 279 } 280 281 return 1; 282 } 283 284 285 unsigned char maybe_remove_line(void) 286 { 287 int x, v=0; 288 unsigned char *p = &playfield[(FIELD_HEIGHT-1)*FIELD_WIDTH]; 289 for(x = 0; x < FIELD_WIDTH ; x++) 290 if(*p++) 291 v++; 292 293 if(v==FIELD_WIDTH) { 294 memmove(&playfield[FIELD_WIDTH], playfield, (FIELD_HEIGHT-1)*FIELD_WIDTH); 295 return 1; 296 } 297 return 0; 298 }
Note: See TracChangeset
for help on using the changeset viewer.