void SetPlayerStatusInfo(int score, int shields, int charge) { char buf[3]; Uint8 *pixels; int i; /* Set the score counter. */ sprintf(buf, "%2i", score); DrawChar5x5(player_score.led_surface, buf[0], 1, 0, 0); DrawChar5x5(player_score.led_surface, buf[1], 1, 6, 0); /* Set the shield bar. */ SDL_LockSurface(player_shields.led_surface); pixels = (Uint8 *)player_shields.led_surface->pixels; for (i = 0; i < 12; i++) { if (i < shields * 12 / 100) pixels[i] = 1; else pixels[i] = 0; } SDL_UnlockSurface(player_shields.led_surface); /* Set the phaser charge bar. */ SDL_LockSurface(player_charge.led_surface); pixels = (Uint8 *)player_charge.led_surface->pixels; for (i = 0; i < 80; i++) { if (i < charge * 80 / PHASER_CHARGE_MAX) pixels[i] = 1; else pixels[i] = 0; } SDL_UnlockSurface(player_charge.led_surface); }
void SetOpponentStatusInfo(int score, int shields) { char buf[3]; Uint8 *pixels; int i; /* Set the score counter. */ sprintf(buf, "%2i", score); DrawChar5x5(opponent_score.led_surface, buf[0], 1, 0, 0); DrawChar5x5(opponent_score.led_surface, buf[1], 1, 6, 0); /* Set the shield bar. */ SDL_LockSurface(opponent_shields.led_surface); pixels = (Uint8 *)opponent_shields.led_surface->pixels; for (i = 0; i < 12; i++) { if (i < shields * 12 / 100) pixels[i] = 1; else pixels[i] = 0; } SDL_UnlockSurface(opponent_shields.led_surface); }
unsigned int Puts(u8 x, u8 y, const char *s, u8 font, u16 color, u16 bgcolor) { char c; while(*s) { c = *s++; if(c >= 0x20) { if ( font == FONT5x5 ) { x = DrawChar5x5(x, y, c, color, bgcolor); } else if ( font == FONT5x7 ) { x = DrawChar5x7(x, y, c, color, bgcolor); } if(x > LCD_WIDTH) { break; } } } return x; }
void UpdateStatusDisplay(SDL_Surface *screen) { int i; /* Update the scroller. This is not linked to the global time_scale, since speed really doesn't matter. The only effect of a high framerate would be that the scrolling message would move faster. */ if ((scroller_ticks % 6) == 0) { char ch; for (i = 0; i < SCROLLER_BUF_SIZE-1; i++) { scroller_buf[i] = scroller_buf[i+1]; } if (scroller_msg[scroller_pos] == '\0') { ch = ' '; scroller_pos--; } else { ch = scroller_msg[scroller_pos]; } scroller_pos++; scroller_buf[i] = ch; status_msg.virt_x = 0; for (i = 0; i < SCROLLER_BUF_SIZE; i++) { DrawChar5x5(status_msg.led_surface, scroller_buf[i], 1, 6 * i, 0); } } else { status_msg.virt_x++; } scroller_ticks++; LED_DrawDisplay(&player_score, screen, 0, 0); LED_DrawDisplay(&player_shields, screen, 0, 48); LED_DrawDisplay(&status_msg, screen, 96 + (SCREEN_WIDTH - 2 * 96 - 448) / 2 , 0); LED_DrawDisplay(&opponent_score, screen, SCREEN_WIDTH - 96, 0); LED_DrawDisplay(&opponent_shields, screen, SCREEN_WIDTH - 96, 48); /// LED_DrawDisplay(&player_charge, screen, 0, SCREEN_HEIGHT - 9); }
void PutLinebr(u8 x, u8 y, const char *s, u16 color, u16 bgcolor) { unsigned int i, start_x=x, font_height, wlen, llen; char c; const char *wstart; font_height = 5; FillRect(0, y, x-1, (y+font_height), bgcolor); //clear before text llen = (LCD_WIDTH-x)/8; wstart = s; while(*s) { c = *s++; if(c == '\n') {//new line FillRect(x, y, (LCD_WIDTH-1), (y+font_height), bgcolor); //clear after text x = start_x; y += font_height+1; FillRect(0, y, x-1, (y+font_height), bgcolor); //clear before text continue; } if(c == ' ') {//start of a new word wstart = s; } if((c == ' ') && (x == start_x)) { //do nothing } else if(c >= 0x20) { i = DrawChar5x5(x, y, c, color, bgcolor); if(i > LCD_WIDTH) {//new line if(c == ' ') {//do not start with space FillRect(x, y, (LCD_WIDTH-1), (y+font_height), bgcolor); //clear after text x = start_x; y += font_height+1; FillRect(0, y, x-1, (y+font_height), bgcolor); //clear before text } else { wlen = (s-wstart); if(wlen > llen) {//word too long FillRect(x, y, (LCD_WIDTH-1), (y+font_height), bgcolor); //clear after text x = start_x; y += font_height+1; FillRect(0, y, x-1, (y+font_height), bgcolor); //clear before text x = DrawChar5x5(x, y, c, color, bgcolor); } else { FillRect(x-(wlen*8), y, (LCD_WIDTH-1), (y+font_height), bgcolor); //clear after text x = start_x; y += font_height+1; FillRect(0, y, x-1, (y+font_height), bgcolor); //clear before text s = wstart; } } } else { x = i; } } } FillRect(x, y, (LCD_WIDTH-1), (y+font_height), bgcolor); //clear after text }