static void draw_player() { bool* sprite; if(game.player_y_vel > 0) { sprite = PLAYER_SPRITE_DOWN; } else { sprite = PLAYER_SPRITE_UP; } for(int x = 0; x < PLAYER_SPRITE_WIDTH; x++) { for(int y = 0; y < PLAYER_SPRITE_HEIGHT; y++) { int py = game.player_y + y - PLAYER_SPRITE_HEIGHT; if(sprite[x + y*PLAYER_SPRITE_WIDTH] && py >= 0 && py < RESY) { lcdSetPixel( (game.player_x + x)%RESX, py, 1); } } } if(game.player_y < 0) { int player_x_center = game.player_x + PLAYER_SPRITE_WIDTH/2; for(int y = 0; y < 2; y++) { for(int x = player_x_center-2; x <= player_x_center+2; x++) { if(x >= 0 && x < RESX && y >= 0 && y < RESY) { lcdSetPixel(x, y, 1); } } } } }
void draw_paddles(void) { for(int8_t i = 0; i < PADDLE_HEIGHT; i++) { for(int8_t j = 0; j < PADDLE_WIDTH; j++) { lcdSetPixel(OFFSET_L - j, i+player1.paddle_pos, 1); lcdSetPixel(OFFSET_R - j, i+player2.paddle_pos, 1); } } }
static void draw_area() { for(uchar x=0; x<RESX; ++x) { for(uchar y=0; y<RESY; ++y) { // lcdSetPixel(x,y,lcdGetPixel(x,y)^bitset_get2(life,x+1,y+1)); if((lcdGetPixel(x,y)==0) ^ bitset_get2(life,x+1,y+1)) { lcdSetPixel(x,y,0xff); } else { lcdSetPixel(x,y,0); } } } }
void draw_block(int x, int y, int b) { lcdSetPixel(0 + x, 0 + y, b); lcdSetPixel(1 + x, 0 + y, b); lcdSetPixel(2 + x, 0 + y, b); lcdSetPixel(0 + x, 1 + y, b); lcdSetPixel(1 + x, 1 + y, b); lcdSetPixel(2 + x, 1 + y, b); lcdSetPixel(0 + x, 2 + y, b); lcdSetPixel(1 + x, 2 + y, b); lcdSetPixel(2 + x, 2 + y, b); }
void drawLine(int x1, int y1, int x2, int y2, uint8_t color) { if(x1==x2) { drawVLine(x1, y1, y2, color); return; } if(y1==y2) { drawHLine(y1, x1, x2, color); return; } bool xSwap = x1 > x2; bool ySwap = y1 > y2; if(xSwap){ x1 = -x1; x2 = -x2; } if(ySwap){ y1 = -y1; y2 = -y2; } bool mSwap = ABS(x2-x1) < ABS(y2-y1); if(mSwap) { SWAP(x1,y1); SWAP(x2,y2); } int dx = x2-x1; int dy = y2-y1; int D = 2*dy - dx; lcdSetPixel(x1, y1, color); int y = y1; for(int x = x1+1; x < x2; x++) { if(D > 0) { y++; D += 2 * dy - 2 * dx; } else { D += 2 * dy; } int px = mSwap ? y : x; if(xSwap) { px = -px; } int py = mSwap ? x : y; if(ySwap) { py = -py; } lcdSetPixel(px, py, color); } }
void drawBricks(int bricks[FIELD_HEIGHT][FIELD_WIDTH]) { for (int x = 0; x < FIELD_WIDTH; x++) for (int y = 0; y < FIELD_HEIGHT; y++) for (int i = 0; i < BRICK_WIDTH; i++) for (int j = 0; j < BRICK_HEIGHT; j++) lcdSetPixel(x * (BRICK_WIDTH + BRICK_SPACING) + i, y * (BRICK_HEIGHT + BRICK_SPACING) + j, bricks[y][x]?GLOBAL(nickfg):GLOBAL(nickbg)); }
void mandelPixel(int x, int y) { long r0,i0,rn, p,q; long rs,is; int iteration; rs=(mandel.rmax-mandel.rmin)/RESY; is=(mandel.imax-mandel.imin)/RESX; //p=fixpt(mandel.rmin+y*rs); //q=fixpt(mandel.imin+x*is); p=mandel.rmin+y*rs; q=mandel.imin+x*is; rn=0; r0=0; i0=0; iteration=0; while ((mul(rn,rn)+mul(i0,i0))<fixpt(4) && ++iteration<ITERATION_MAX) { rn=mul((r0+i0),(r0-i0)) +p; i0=mul(fixpt(2),mul(r0,i0)) +q; r0=rn; } if (iteration==ITERATION_MAX) iteration=ITERATION_MAX; bool pixel = ( iteration>1); lcdSetPixel(x, y, 255-iteration*2); }
void drawHLine(int y, int x1, int x2, uint8_t color) { if(x1>x2) { SWAP(x1, x2); } for (int i=x1; i<=x2; ++i) { lcdSetPixel(i, y, color); } }
void drawVLine(int x, int y1, int y2, uint8_t color) { if(y1>y2) { SWAP(y1,y2); } for (int i=y1; i<=y2; ++i) { lcdSetPixel(x, i, color); } }
static void draw_shot(int shot) { if(game.shots_x[shot] != 255){ for (int length=0; length<=4; length++) { lcdSetPixel(game.shots_x[shot]+length, game.shots_y[shot], true); } game.shots_x[shot] += 1; } }
void just_draw_ball(void){ for(int8_t i = 0; i < BALL_SIZE; i++) { for(int8_t j = 0; j < BALL_SIZE; j++) { lcdSetPixel(ball1.x + j, ball1.y + i, 1); } } }
static void draw_block(int x, int y, int set) { x *= SNAKE_DIM; y *= SNAKE_DIM; lcdSetPixel(x, y, set); lcdSetPixel(x+1, y, set); lcdSetPixel(x+2, y, set); lcdSetPixel(x, y+1, set); lcdSetPixel(x+1, y+1, set); lcdSetPixel(x+2, y+1, set); lcdSetPixel(x, y+2, set); lcdSetPixel(x+1, y+2, set); lcdSetPixel(x+2, y+2, set); }
static void reset() { int i; // setup the screen lcdClear(); for (i=MIN_X; i<MAX_X; i++) { lcdSetPixel(i,MIN_Y,0b000101011); lcdSetPixel(i,MAX_Y,0b000101011); } for (i=MIN_Y; i<MAX_Y; i++) { lcdSetPixel(MIN_X,i,0b000101011); lcdSetPixel(MAX_X,i,0b000101011); } snake.speed = MIN_SPEED; snake.len = 3; snake.dir = 0; snake.t_start = 2; points = 0; food = getFood(); // create snake in the middle of the field snake.tail[0].x = SIZE_X/2; snake.tail[0].y = SIZE_Y/2; snake.tail[1].x = SIZE_X/2 +1; snake.tail[1].y = SIZE_Y/2; snake.tail[2].x = SIZE_X/2 +2; snake.tail[2].y = SIZE_Y/2; // print initail tail draw_block(snake.tail[0].x, snake.tail[0].y, 0b00011000); draw_block(snake.tail[1].x, snake.tail[1].y, 0b00011000); draw_block(snake.tail[2].x, snake.tail[2].y, 0b00011000); // switch to level one render_level(); }
static void draw_platforms() { for(int i = 0; i < NUM_PLATFORMS; i++) { if(game.platforms_y[i] <= RESY) { for(int x = game.platforms_x1[i]; x <= game.platforms_x2[i]; x++) { for(int y = game.platforms_y[i]; y < game.platforms_y[i]+PLATFORM_HEIGHT; y++) { if(y >= 0 && y <= RESY) { lcdSetPixel(x, y, 1); } } } } } }
static void draw_ship(void) { if(game.ship_safe > 0){ game.ship_safe--; } if(game.ship_safe > 0 && game.ship_blinker == 0 && game.ship_safe%40 == 0){ game.ship_blinker = 20; } if(game.ship_blinker > 0){ game.ship_blinker--; } int ct = 0; for (int i = 0; i < SHIP_HEIGHT; i++){ for(int d = 0; d < SHIP_WIDTH; d++){ if(game.ship_blinker > 0){ } else { lcdSetPixel((game.ship_x+d)%RESX,(game.ship_y+i)%RESY,SHIP[ct]); } ct++; } } }
static void draw_asteroid(int as){ if(game.asteroids_t[as] > 0){ int x = game.asteroids_x[as]; int y = game.asteroids_y[as]; if(game.asteroids_t[as] == 1){ int ct = 0; for (int i = 0; i < ASTEROID_1_HEIGHT; i++){ for(int d = 0; d < ASTEROID_1_WIDTH; d++){ if(ASTEROID_1[ct] == 1){ lcdSetPixel(x+d,y+i,1 && game.asteroids_h[as] == 0); } ct++; } } } else if(game.asteroids_t[as] == 2){ int ct = 0; for (int i = 0; i < ASTEROID_2_HEIGHT; i++){ for(int d = 0; d < ASTEROID_2_WIDTH; d++){ if(ASTEROID_2[ct] == 1 && game.asteroids_h[as] == 0){ lcdSetPixel(x+d,y+i,1); } if(ASTEROID_2[ct] == 1 && game.asteroids_h[as] == 1 && getRandom()%2 == 0){ lcdSetPixel(x+d,y+i,1); } ct++; } } } else if(game.asteroids_t[as] == 3){ int ct = 0; for (int i = 0; i < ASTEROID_3_HEIGHT; i++){ for(int d = 0; d < ASTEROID_3_WIDTH; d++){ if(ASTEROID_3[ct] == 1 && game.asteroids_h[as] == 0){ lcdSetPixel(x+d,y+i,1); } if(ASTEROID_3[ct] == 1 && game.asteroids_h[as] == 1 && getRandom()%2 == 0){ lcdSetPixel(x+d,y+i,1); } if(ASTEROID_3[ct] == 1 && game.asteroids_h[as] == 2 && getRandom()%4 == 0){ lcdSetPixel(x+d,y+i,1); } ct++; } } } } }
void line(int x0, int y0, int x1, int y1, uint8_t color) { // Check if line is connected with a dot behind the // camera if (x0 == VERTEX_BEHIND_CAMERA || x1 == VERTEX_BEHIND_CAMERA) return; if (!isInViewport(x0, y0)) { if (!isInViewport(x1, y1)) return; int dummy = x0; x0 = x1; x1 = dummy; dummy = y0; y0 = y1; y1 = dummy; } // Bresenham int dx = abs(x1 - x0), sx = x0<x1 ? 1 : -1; int dy = abs(y1 - y0), sy = y0<y1 ? 1 : -1; int err = (dx>dy? dx : -dy) / 2, e2; while(true) { // Optimize me: For now, we just ignore pixels outside the screen. We might // want to clip those, though. if (!isInViewport(x0, y0)) break; lcdSetPixel(x0, y0, color); if (x0==x1 && y0==y1) break; e2 = err; if (e2 >-dx) { err -= dy; x0 += sx; } if (e2 < dy) { err += dx; y0 += sy; } } }
void spectrum_callback(uint8_t* buf, int bufLen) { TOGGLE(LED2); if (displayMode == MODE_SPECTRUM) lcdClear(); else if (displayMode == MODE_WATERFALL) lcdShift(0,1,0); for(int i = 0; i < 128; i++) // display 128 FFT magnitude points { // FFT unwrap: uint8_t v; if(i < 64) // negative frequencies v = buf[(bufLen/2)+64+i]; else // positive frequencies v = buf[i-64]; // fill display if (displayMode == MODE_SPECTRUM) { for(int j = 0; j < (v/2); j++) lcdBuffer[i+RESX*(RESY-j)] = 0x00; } else if (displayMode == MODE_WATERFALL) { lcdSetPixel(i,RESY-1,v); } } // text info lcdSetCrsr(0,0); lcdPrint("f="); lcdPrint(IntToStr(freq/1000000,4,F_LONG)); lcdPrintln("MHz "); lcdPrintln("-5MHz 0 +5MHz"); lcdDisplay(); }
static void mainloop(void) { int dx=0; int dy=0; setExtFont(GLOBAL(nickfont)); dx=DoString(0,0,GLOBAL(nickname)); dx=(RESX-dx)/2; if(dx<0) dx=0; dy=(RESY-getFontHeight())/2; lcdClear(); lcdSetPixel(1,1,1); DoString(dx,dy,GLOBAL(nickname)); lcdRefresh(); lk_ticks = 0; lk_button_mode = 0x00; lk_ls0 = 0x00; lk_ls1 = 0x00; lk_ls2 = 0x00; lk_ls3 = 0x00; lk_in0 = 0x00; lk_in1 = 0x00; lk_ticks = 0x0000; lk_piezo_toggle = 0x00; while(getInputRaw()==BTN_NONE){ tick_lilakit(); melody_play(); //delayms_queue(10); //XXX: this hangs the badge. delayms(10); } return; }
static bool screen_intro(void) { char key=0; while(key==0) { getInputWaitRelease(); lcdFill(0); int ct = 0; for (int i = 0; i < SHIP_HEIGHT; i++){ for(int d = 0; d < SHIP_WIDTH; d++){ lcdSetPixel((40+d)%RESX,(10+i)%RESY,SHIP[ct]); ct++; } } DoString (13,25,"R0KET TYPE"); uint32_t highscore; char highnick[20]; highscore = highscore_get(highnick); DoInt(13, 40, highscore); DoString (13, 50, highnick); lcdDisplay(); key=getInputWaitTimeout(1000); } //getInputWaitRelease(); return !(key==BTN_LEFT); }
int selectFile(char *filename, char *extension) { int skip = 0; int selected = 0; char pwd[FLEN]; memset(pwd, 0, FLEN); font=&Font_7x8; while(1) { int total; char files[PERPAGE][FLEN+2]; int count = retrieve_files(files, PERPAGE, skip, extension, pwd, &total); if (selected >= count) { selected = count - 1; } /* optimization: don't reload filelist if only redraw needed */ redraw: lcdClear(); lcdPrint("["); lcdPrint(pwd); lcdPrintln("]"); for (int i = 0; i < 98; i++) { lcdSetPixel(i, 9, 1); } lcdSetCrsr(0, 12); if (!count) { lcdPrintln("- empty"); } else { for (int i = 0; i < count; i++) { if (selected == i) { lcdPrint("*"); } else { lcdPrint(" "); } lcdSetCrsrX(14); lcdPrintln(files[i]); } } lcdRefresh(); char key = getInputWaitRepeat(); switch (key) { case BTN_DOWN: if (selected < count - 1) { selected++; goto redraw; } else { if (skip < total - PERPAGE) { skip++; } else { skip = 0; selected = 0; continue; } } break; case BTN_UP: if (selected > 0) { selected--; goto redraw; } else { if (skip > 0) { skip--; } else { skip = total - PERPAGE; if (skip < 0) { skip = 0; } selected = PERPAGE - 1; continue; } } break; case BTN_LEFT: if (pwd[0] == 0) { return -1; } else { pwd[0] = 0; continue; } case BTN_ENTER: case BTN_RIGHT: if (count) { if (files[selected][strlen(files[selected]) - 1] == '/') { /* directory selected */ strcpy(pwd, files[selected]); continue; } else { strcpy(filename, pwd); strcpy(filename + strlen(pwd), files[selected]); getInputWaitRelease(); /* ?! */ return 0; } } } } }
void drawVLine(int x, int y1, int y2, uint8_t color) { for (int i=y1; i<=y2; ++i) { lcdSetPixel(x, i, color); } }
void drawHLine(int y, int x1, int x2, uint8_t color) { for (int i=x1; i<=x2; ++i) { lcdSetPixel(i, y, color); } }
void ram(void) { short centerx = RESX >> 1; short centery = RESY >> 1; short i; uint8_t key = 0; for (i = 0; i < NUM_STARS; i++) { init_star(stars + i, i + 1); } static uint8_t count = 0; while(1) { count++; count%=256; key = getInputRaw(); if (key == BTN_ENTER) { break; } else if ( count%4 == 0 ) { if (key == BTN_UP && ship.speed < SPEED_MAX) { ship.speed++; } else if (key == BTN_DOWN && ship.speed > SPEED_STOP) { ship.speed--; } else if (key == BTN_NONE && count % 12 == 0) { /* converge towards default speed */ if (ship.speed < SPEED_DEFAULT) ship.speed++; else if (ship.speed > SPEED_DEFAULT) ship.speed--; } } if (ship.speed > SPEED_WARP) { set_warp_lights(1); } else { set_warp_lights(0); } if (count % 3 == 0) OFF(LED4); if (ship.speed == 0 && count%6==0) drift_ship(); int dx=0; int dy=0; setExtFont(GLOBAL(nickfont)); setTextColor(0x00,0xFF); dx=DoString(0,0,GLOBAL(nickname)); dx=(RESX-dx)/2; if(dx<0) dx=0; dy=(RESY-getFontHeight())/2; lcdFill(0x00); DoString(dx,dy,GLOBAL(nickname)); for (i = 0; i < NUM_STARS; i++) { stars[i].z -= ship.speed; if (ship.speed > 0 && stars[i].z <= 0) init_star(stars + i, i + 1); short tempx = ((stars[i].x * 30) / stars[i].z) + centerx; short tempy = ((stars[i].y * 30) / stars[i].z) + centery; if (tempx < 0 || tempx > RESX - 1 || tempy < 0 || tempy > RESY - 1) { if (ship.speed > 0) { /* if we are flying, generate new stars in front */ init_star(stars + i, i + 1); } else { /* if we are drifting, simply move those stars to the other end */ stars[i].x = (((tempx%RESX)-centerx)*stars[i].z)/30; stars[i].y = (((tempy%RESY)-centery)*stars[i].z)/30; } continue; } lcdSetPixel(tempx, tempy, 0xFF); if (stars[i].z < 50) { lcdSetPixel(tempx + 1, tempy, 0xFF); } if (stars[i].z < 20) { lcdSetPixel(tempx, tempy + 1, 0xFF); lcdSetPixel(tempx + 1, tempy + 1, 0xFF); } } lcdDisplay(); delayms_queue_plus(50,0); } set_warp_lights(0); }
void ram() { int raw_key, key; int i, j; int score, lastlvl, linec; new_stone(); new_stone(); // epmty grid for(i = 0; i < GRID_HEIGHT; i++) for(j = 0; j < GRID_WIDTH; j++) grid[i][j] = 0; // prepare screen lcdClear(); for(i = 0; i < 96; i++) { lcdSetPixel(i, 2, 1); lcdSetPixel(i, 65, 1); } for(i = 3; i < 65; i++) { lcdSetPixel(2, i, 1); lcdSetPixel(35, i, 1); lcdSetPixel(93, i, 1); } score = 0; lastlvl=0; linec = 0; lcdSetCrsr(37,25); lcdPrint("level: 0"); lcdSetCrsr(37,40); lcdPrint("score:"); lcdSetCrsr(37,50); lcdPrintInt(0); for(;;) { // handle input raw_key = getInputRaw(); key = 0; for(i = 0; i < 5; i++) { if(raw_key & (1 << i)) { if(!key_rep[i] || key_rep[i] == KEY_REPEAT_DELEAY) key |= 1 << i; key_rep[i] += key_rep[i] < KEY_REPEAT_DELEAY; } else key_rep[i] = 0; } // rotate if(key & BTN_UP) { i = rot; rot = (rot << 1) % 15; if(collision(0)) rot = i; } // horizontal movement i = x_pos; x_pos += !!(key & BTN_RIGHT) - !!(key & BTN_LEFT); if(i != x_pos && collision(0)) x_pos = i; // vertical movement ticks++; if(key & BTN_DOWN || ticks >= ticks_per_drop) { ticks = 0; y_pos++; if(collision(0)) { y_pos--; // check for game over if(collision(1)) return; // copy stone to grid int x, y; for(y = 0; y < 4; y++) { for(x = 0; x < 4; x++) { if(stones[stone][(x << 2) + y] & rot) grid[y + y_pos][x + x_pos] = 1; } } // check for complete lines for(y = 0; y < GRID_HEIGHT; y++) { for(x = 0; x < GRID_WIDTH; x++) if(!grid[y][x]) break; if(x == GRID_WIDTH) { lines++; linec++; // temporary line counter ticks_per_drop = STARTING_SPEED - lines / 10; if(ticks_per_drop < 1) ticks_per_drop = 1; for(i = y; i > 0; i--) for(x = 0; x < GRID_WIDTH; x++) grid[i][x] = grid[i - 1][x]; switch(linec){ case 1: score += 40*(lines/10+1); break; case 2: score += 100*(lines/10+1); break; case 3: score += 300*(lines/10+1); break; case 4: score += 1200*(lines/10+1); break; } } } if (lines/10>lastlvl){ lcdSetCrsr(37,25); lcdPrint("level: "); lcdPrintInt(lines/10); } if (linec > 0){ lcdSetCrsr(37,40); lcdPrint("score:"); lcdSetCrsr(37,50); lcdPrintInt(score); } lastlvl=lines/10; linec = 0; // get a new stone new_stone(); } } draw_grid(); lcdDisplay(); delayms(TICK_LENGTH); } return; }
void ram(void) { int inpt,dirc,c,grows = 0,dx,dy,points,point_s=1; size_t n = 0, snake_size = 5, speed=MIN_SPEED; struct elem snake[MAX_SNAKE_LEN], food; char test[512]; /* scratch space */ o_init (test, sizeof(test)); reset(snake,&snake_size,&dirc,&speed,&points,&point_s); food = rnd(); while (1) { head: if(!(++c % speed)) { inpt = getInputRaw(); dx=DoString(0,0,IntToStrX(points,2)); dx=(SIZE_X-dx)/2; if(dx<0) dx=0; dy=(SIZE_Y-getFontHeight())/2; lcdFill(255); o_rectangle(1,0,SIZE_X-2,SIZE_Y-2); o_set_gray (0); o_fill (); //o_identity (); /* reset tranforms */ o_set_gray (50); setExtFont("UBUNTU29"); lcdSetPixel(1,1,1); DoString(dx,dy,IntToStrX(points,2)); o_set_gray (255); for(n=0;n<snake_size;++n) { o_rectangle (snake[n].x*SNAKE_DEM,snake[n].y*SNAKE_DEM,SNAKE_DEM,SNAKE_DEM); /* fill background with black */ o_fill (); /* fill with 50% { reset(snake,&snake_size); goto head; }gray */ } o_rectangle (food.x*SNAKE_DEM,food.y*SNAKE_DEM,SNAKE_DEM,SNAKE_DEM); /* fill background with black */ o_fill (); lcdDisplay(); if (inpt == BTN_UP && dirc != 1) { dirc = 3; } else if (inpt == BTN_DOWN && dirc != 3) { dirc = 1; } else if (inpt == BTN_LEFT && dirc != 0) { dirc = 2; } else if (inpt == BTN_RIGHT && dirc !=2) { dirc = 0; } // struct elem t = snake[snake_size-1]; if(dirc == 0) ++t.x; else if(dirc == 1) ++t.y; else if(dirc == 2) --t.x; else if(dirc == 3) --t.y; if(t.x < 0 || t.y < 0 || t.y > SIZE_Y/SNAKE_DEM-1 || t.x > SIZE_X/SNAKE_DEM) { reset(snake,&snake_size,&dirc,&speed,&points,&point_s); goto head; } for(n=0;n<snake_size-1;++n) { if(snake[n].x == t.x && snake[n].y == t.y) { reset(snake,&snake_size,&dirc,&speed,&points,&point_s); goto head; } else if(snake[n].x == food.x && snake[n].y == food.y) { grows = 1; ++snake_size; ++points; if(speed > MAX_SPEED) --speed; food = rnd(); } } if(!grows) { for(n=0;n<snake_size-1;++n) { snake[n] = snake[n+1]; } } else grows = 0; snake[snake_size-1] = t; } else delayms(3); } }
void ram(void) { int key; int score; int x=42-5; int y=23; //############################ lcdClear(); for(int i=0;i<68;i++) lcdSetPixel(0,i,1); for(int i=0;i<68;i++) lcdSetPixel(95,i,1); for(int i=0;i<96;i++) lcdSetPixel(i,0,1); for(int i=0;i<96;i++) lcdSetPixel(i,67,1); score=0; //############################ while (1) { if(getInputRaw()!=key&&getInputRaw()!=BTN_NONE) key=getInputRaw(); if(lcdGetPixel(x,y)){ //################################### if(key!=BTN_NONE){ lcdClear(); for(int i=0;i<68;i++) lcdSetPixel(0,i,1); for(int i=0;i<68;i++) lcdSetPixel(95,i,1); for(int i=0;i<96;i++) lcdSetPixel(i,0,1); for(int i=0;i<96;i++) lcdSetPixel(i,67,1); score=0; } //####################### x=42-5; y=23; } else{ DoInt(2,2,score); DoString(42,58,"@ CTHN"); lcdSetPixel(x,y,1); if(key==BTN_LEFT) x--; if(key==BTN_RIGHT) x++; if(key==BTN_UP) y--; if(key==BTN_DOWN) y++; if(key==BTN_ENTER){ lcdClear(); break; } score++; } lcdRefresh(); delayms(23*5-42); } }
void ram() { int raw_key, key; int i, j; new_stone(); new_stone(); // epmty grid for(i = 0; i < GRID_HEIGHT; i++) for(j = 0; j < GRID_WIDTH; j++) grid[i][j] = 0; // prepare screen lcdClear(); for(i = 0; i < 96; i++) { lcdSetPixel(i, 2, 1); lcdSetPixel(i, 65, 1); } for(i = 3; i < 65; i++) { lcdSetPixel(2, i, 1); lcdSetPixel(35, i, 1); lcdSetPixel(93, i, 1); } for(;;) { // handle input raw_key = getInputRaw(); key = 0; for(i = 0; i < 5; i++) { if(raw_key & (1 << i)) { if(!key_rep[i] || key_rep[i] == KEY_REPEAT_DELEAY) key |= 1 << i; key_rep[i] += key_rep[i] < KEY_REPEAT_DELEAY; } else key_rep[i] = 0; } // rotate if(key & BTN_UP) { i = rot; rot = (rot << 1) % 15; if(collision(0)) rot = i; } // horizontal movement i = x_pos; x_pos += !!(key & BTN_RIGHT) - !!(key & BTN_LEFT); if(i != x_pos && collision(0)) x_pos = i; // vertical movement ticks++; if(key & BTN_DOWN || ticks >= ticks_per_drop) { ticks = 0; y_pos++; if(collision(0)) { y_pos--; // check for game over if(collision(1)) return; // copy stone to grid int x, y; for(y = 0; y < 4; y++) { for(x = 0; x < 4; x++) { if(stones[stone][(x << 2) + y] & rot) grid[y + y_pos][x + x_pos] = 1; } } // check for complete lines for(y = 0; y < GRID_HEIGHT; y++) { for(x = 0; x < GRID_WIDTH; x++) if(!grid[y][x]) break; if(x == GRID_WIDTH) { lines++; ticks_per_drop = STARTING_SPEED - lines / 10; if(ticks_per_drop < 1) ticks_per_drop = 1; for(i = y; i > 0; i--) for(x = 0; x < GRID_WIDTH; x++) grid[i][x] = grid[i - 1][x]; } } // get a new stone new_stone(); } } draw_grid(); lcdDisplay(); delayms(TICK_LENGTH); } return; }
void drawPxChk(int x, int y, int color) { if (x < 0 || x >= SCREEN_WIDTH || y < 0 || y >= SCREEN_HEIGHT) return; lcdSetPixel(x, y, color); }
void drawPaddle(int paddleX, int color) { for (int x = 0; x < PADDLE_WIDTH; x++) { lcdSetPixel(paddleX + x, PADDLE_Y, color); lcdSetPixel(paddleX + x, PADDLE_Y + 1, color); } }