void ram(void) { int c=0, pos=0,del=0; struct pos_s tail[MAX_SNAKE_LEN]; snake.tail = tail; // load the highscore highscore = highscore_get(); // initially reset everything reset(); while (1) { if(!(++c % snake.speed)) { handle_input(); pos = (snake.t_start+1) % MAX_SNAKE_LEN; snake.tail[pos].x = snake.tail[snake.t_start].x; snake.tail[pos].y = snake.tail[snake.t_start].y; if(snake.dir == 0) snake.tail[pos].x++; else if(snake.dir == 1) snake.tail[pos].y++; else if(snake.dir == 2) snake.tail[pos].x--; else if(snake.dir == 3) snake.tail[pos].y--; snake.t_start = pos; if (pos < snake.len) { del = MAX_SNAKE_LEN - (snake.len - pos); } else del = pos - snake.len; // remove last, add first line draw_block(snake.tail[del].x, snake.tail[del].y, 0xFF); draw_block(snake.tail[pos].x, snake.tail[pos].y, 0b00011000); // check for obstacle hit.. if (hitWall() || hitSelf()) { death_anim(); if (showHighscore()) break; reset(); } else if (hitFood()) next_level(); lcdDisplay(); } #ifdef SIMULATOR delayms(50); #else delayms(3); #endif } }
void render(SDL_Renderer *rend, State &s) { SDL_SetRenderDrawColor(rend, 50, 50, 50, 255); SDL_RenderClear(rend); // Enemies for(int i = 0; i < s.N; i++) { if (s.enemies[i].alive) { if (s.enemies[i].shotdown) draw_block(rend, s.enemies[i].b, 160, 30, 30, 180); else draw_block(rend, s.enemies[i].b, 170, 0, 10, 255); } } // Player draw_block(rend, s.player.b, 255, 0, 0, 255); // Bullet draw_block(rend, s.bullet, 255, 0, 0, 255); // Stage number for (int i = 0; i < s.stage+1; i++) { SDL_Rect r = {(i+1)*10, 10, 5, 5}; SDL_SetRenderDrawColor(rend, 240, 170, 0, 200); SDL_RenderFillRect(rend, &r); } // Update the screen SDL_RenderPresent(rend); }
static void draw_stairs_internal(ModeInfo * mi) { GLfloat X; mi->polygon_count = 0; glPushMatrix(); glPushMatrix(); glTranslatef(-3.0, 0.1, 2.0); for (X = 0; X < 2; X++) { mi->polygon_count += draw_block(0.5, 2.7 + 0.1 * X, 0.5); glTranslatef(0.0, 0.1, -1.0); } glPopMatrix(); glTranslatef(-3.0, 0.0, 3.0); glPushMatrix(); for (X = 0; X < 6; X++) { mi->polygon_count += draw_block(0.5, 2.6 - 0.1 * X, 0.5); glTranslatef(1.0, -0.1, 0.0); } glTranslatef(-1.0, -0.9, -1.0); for (X = 0; X < 5; X++) { mi->polygon_count += draw_block(0.5, 3.0 - 0.1 * X, 0.5); glTranslatef(0.0, 0.0, -1.0); } glTranslatef(-1.0, -1.1, 1.0); for (X = 0; X < 3; X++) { mi->polygon_count += draw_block(0.5, 3.5 - 0.1 * X, 0.5); glTranslatef(-1.0, -0.1, 0.0); } glPopMatrix(); glPopMatrix(); }
int menu_execentry(struct MENU_ENTRY *entry) { unsigned int *val; struct MENU *m; draw_block(0, 100, 128, 8, 3, DRAW_ERASE); switch(entry->type) { case INTENTRY: val = (unsigned int*)entry->data; draw_block(0, 50, 128, 8, 3, DRAW_ERASE); draw_hexW(0,50,*val, 3, DRAW_PUT); break; case FUNCENTRY: entry->exec(); return 1; break; case MENUENTRY: m = (MENU*)entry->data; if(m->num_entries != 0) { menu_exec((MENU*)entry->data); return 1; } break; default: break; } return 0; }
void draw_shape (shape_t shape, int col, int row, struct color_t color) { int pos; pos = col + row * BOARD_COLS; draw_block (pos, color); draw_block (pos + shape[1], color); draw_block (pos + shape[2], color); draw_block (pos + shape[3], color); }
void game_show_next_block(GtkMenuItem *menuitem, gpointer user_data) { options.shw_nxt = !options.shw_nxt; if(!game_over) { if(!options.shw_nxt) draw_block(0,0,next_block,next_frame,TRUE,TRUE); else draw_block(0,0,next_block,next_frame,FALSE,TRUE); } }
static void render_level() { char highscore_string[20]; char points_string[20]; draw_block( food.x, food.y, 0b11101000); strcpy (points_string,"Points: "); strcat (points_string,IntToStr(points,6,0)); strcpy (highscore_string,"HI: "); strcat (highscore_string,IntToStr(highscore,6,0)); // Display point color based on compare with highscore if (points<highscore || (points==0 && highscore==0)) { // Black setTextColor(0xff,0x00); } else if (points==highscore) { // Dark Yellow setTextColor(0xff,0b11011000); } else if (points>highscore) { // Dark Green setTextColor(0xff,0b00011000); } DoString(0,0,points_string); setTextColor(0xff,0b00000011); DoString(MAX_X-44,0,highscore_string); }
std::shared_ptr<gge::texture> piece_pattern::make_texture() const { const int width = MAX_PIECE_COLS*BLOCK_SIZE; const int height = MAX_PIECE_ROWS*BLOCK_SIZE; gge::pixmap<gge::pixel_type::GRAY> pm(width, height); uint8_t *bits = &pm.data[0]; for (int r = 0; r < MAX_PIECE_ROWS; r++) { for (int c = 0; c < MAX_PIECE_COLS; c++) { if (pattern[r][c] != '#') continue; bool left = c > 0 && pattern[r][c - 1] == '#'; bool right = c < MAX_PIECE_COLS - 1 && pattern[r][c + 1] == '#'; bool up = r > 0 && pattern[r - 1][c] == '#'; bool down = r < MAX_PIECE_ROWS - 1 && pattern[r + 1][c] == '#'; draw_block(&bits[BLOCK_SIZE*(r*width + c)], width, left, right, up, down); } } std::shared_ptr<gge::texture> tex(new gge::texture); tex->load(pm); return tex; }
void blocks_update_callback(Layer *layer, GContext *ctx) { (void)layer; (void)ctx; GRect block_rect[2]; GRect layer_bounds = layer_get_bounds(layer); GRect layer_frame = layer_get_frame(layer); block_rect[0] = GRect(layer_bounds.origin.x, layer_bounds.origin.y + BLOCK_LAYER_EXTRA, BLOCK_SIZE, layer_frame.size.h - BLOCK_LAYER_EXTRA); block_rect[1] = GRect(layer_bounds.origin.x + BLOCK_SIZE + BLOCK_SPACING, layer_bounds.origin.y + BLOCK_LAYER_EXTRA, BLOCK_SIZE, layer_frame.size.h - BLOCK_LAYER_EXTRA); for (uint8_t i = 0; i < 2; ++i) { GRect *rect = block_rect + i; draw_block(ctx, *rect, 4); } }
void draw(){ clear(); draw_base(); draw_world(); draw_block(); refresh(); }
/* crea un bitmap con la pieza actual */ BITMAP *create_piece_bitmap(PLAYER *player, int *xout, int *yout) { BITMAP *bmp; int c, x, y, w, h; get_piece_blocks(player); get_piece_metrics(player, &x, &y, &w, &h); /* crear el bitmap */ bmp = create_bitmap(w, h); if (!bmp) return NULL; /* limpiar el bitmap con el color máscara actual */ clear_to_color(bmp, bitmap_mask_color(bmp)); /* dibujar cada bloque de la pieza en el bitmap */ for (c=0; c<4; c++) draw_block(bmp, player->piece.bx[c]-x, player->piece.by[c]-y, player->piece.block[c], FALSE); /* posiciones absolutas de la pieza; si se usa draw_sprite() con estas posiciones, el bitmap se dibujará en el mismo sitio donde está la pieza actual */ if (xout) *xout = player->px+x; if (yout) *yout = player->py+y; return bmp; }
static void glut_display_callback() { glClear(GL_COLOR_BUFFER_BIT); for (int x=0; x<GRID_WIDTH; x++) { for (int y=0; y<GRID_HEIGHT; y++) { if (grid_fill[x][y]) { draw_block(x, y, grid_fill[x][y]); } } } if (!game_over) { draw_shape(); } glColor3f(0.2f, 0.2f, 0.2f); glBegin(GL_LINES); for (int x=1; x<GRID_WIDTH; x++) { glVertex2f(x * GRID_SIZE, 0.0f); glVertex2f(x * GRID_SIZE, GRID_HEIGHT * GRID_SIZE); } for (int y=1; y<GRID_HEIGHT; y++) { glVertex2f(0.0f, y * GRID_SIZE); glVertex2f(GRID_HEIGHT * GRID_SIZE, y * GRID_SIZE); } glEnd(); glFlush(); glutSwapBuffers(); }
void remove_complete_lines(void) { char s[8]; byte row, x, y, complete; for (row = curr_y - 1; row < curr_y + 3 && row < PLAYF_HEIGHT; row++) { complete = 1; for (x = 0; x < PLAYF_WIDTH && complete; x++) { if (!is_block_set(x, row)) complete = 0; } if (complete) { for (y = row; y > 0; y--) { for (x = 0; x < PLAYF_WIDTH; x++) { if (is_block_set(x, y - 1)) draw_block(x, y); else clear_block(x, y); } } lines++; buf2screen(); } } itoa(lines, s); vputs(100, 80, "LINES "); vputs(135, 80, s); }
/* "Load" a plaayfield and set the game to that one */ static int goto_level(game_t *p_game) { int i,j; if (p_game->level >= p_game->levels) return -1; rand_nr = 0; p_game->nr_blocks=0; fe_load_data(p_game->p_levels, p_game->level*((FIELD_WIDTH+1)*(FIELD_HEIGHT-4)+1)+6, (FIELD_WIDTH+1)*FIELD_HEIGHT, "Zarkanoid"); /* Set the data for the level */ for(j=0; j<FIELD_HEIGHT-4; j++) { for(i=0; i<FIELD_WIDTH; i++) { uint8_t curr = p_game->p_levels[j*(FIELD_WIDTH+1)+i]-'0'; block_t *p_block = &p_game->p_field[j*FIELD_WIDTH+i]; /* If field[x,y] is not empty */ if (curr && !((curr & TYPE_IMPOSSIBLE) == TYPE_IMPOSSIBLE)) p_game->nr_blocks++; init_block(p_block, curr); draw_block(p_block, i, j); } } return 0; }
void draw_cube(gdImagePtr g, struct cube *c, int x, int y, int edge, int yellow, int gray, int black) { int size, color; size = edge / 3; /* Ecken zeichnen */ draw_block(g, x, y, size, gray); draw_block(g, x + 2 * size, y, size, gray); draw_block(g, x, y + 2 * size, size, gray); draw_block(g, x + 2 * size, y + 2 * size, size, gray); color = yellow; /* Mitte zeichnen */ if (c->type == LEER) color = gray; draw_block(g, x + size, y + size, size, color); color = gray; if (c->north) color = yellow; draw_block(g, x + size, y, size, color); color = gray; if (c->east) color = yellow; draw_block(g, x + 2 * size, y + size, size, color); color = gray; if (c->south) color = yellow; draw_block(g, x + size, y + 2 * size, size, color); color = gray; if (c->west) color = yellow; draw_block(g, x, y + size, size, color); /* Raender zeichnen */ gdImageRectangle(g, x, y, x + edge, y + edge, black); }
void cc1100IRQ (void) { if (cc1100_read1(0x3B | READ | BURST) > 0) { RF_getfifo(RFbuf); cc1100_strobe(SIDLE); cc1100_strobe(SFRX); struct cc1100frame_ *RXframe; RXframe = (struct cc1100frame_ *)&RFbuf[0]; if ((RXframe->len == 1) && ((RXframe->destAddr == cc1100Addr) || (RXframe->destAddr == 0x00))) { switch_WOR_RX(); } if(RFstatus & WORenabled) cc1100_strobe(SWOR); else cc1100_strobe(SRX); if (RXframe->len > 3) { setCBIntervall(WORrx_cb,WORrx_time); switch ( RXframe->packetType) { case 0x01: draw_block(0,50,128,10,3,DRAW_ERASE); draw_string(0, 50, (char*)&RFbuf[headerLen], 3, DRAW_PUT); break; case 0x02: if (RXframe->data[0] == 0x01) { RXframe->destAddr = RXframe->srcAddr; RXframe->srcAddr = cc1100Addr; RXframe->data[0] = 0x02; RXframe->len = 0x04; switch_to_idle(); RF_send(RFbuf); } else if (RFbuf[headerLen] == 0x02) { RFstatus |= Received; } break; case 0x03: if ((RXframe->data[0] == 0x01) && (timeInfo & time_accurate)) { send_time(RXframe->srcAddr); } else if (RFbuf[headerLen] == 0x02) { memcpy((unsigned char *)&time,(unsigned char *)&RXframe->data[1],3); memcpy((unsigned char *)&date,(unsigned char *)&RXframe->data[4],4); timeInfo |=0x02; VICSoftInt = INT_EINT2; } } } } waitTX(); EXTINT = 0x01; }
static void draw_shape() { for (int x=0; x<4; x++) { for (int y=0; y<4; y++) { if (cur_shape[x][y]) { draw_block(cur_x+x, cur_y-y, cur_shape[x][y]); } } } }
static void draw_playgrd(void) { int l,c; for(l=0; l<LINES; ++l) { for(c=0; c<COLS; ++c) { cursor_to(PGRD_LEFT+c*2, PGRD_TOP+l); draw_block(0, GAME->playgrd[l][c]); } } }
void draw_curr_part(void) { byte i; char x, y; for (i = 0; i < 4; i++) { x = curr_part.x[i]; y = curr_part.y[i]; draw_block(x + curr_x, y + curr_y); } }
void RAW_learn(struct RAWset_* RAWset) { unsigned char cmd; unsigned char mode; lcd_fill(0); draw_block(0,10,128,2,3,DRAW_PUT); mode = 1; while(KEY_A) {}; while(!KEY_A) { draw_block(0,0,100,9,3,DRAW_ERASE); set_font(BOLDFONT); if (mode) draw_string(0, 0, "Tasten anlernen", 3, DRAW_PUT); else draw_string(0, 0, "Tasten testen", 3, DRAW_PUT); set_font(SMALLFONT); draw_string(0, 20, "Gewuenschte Taste auf der\nBetty druecken.\nDie Tasten A, B, C und D\nkoennen nicht angelernt\nwerden", 3, DRAW_PUT); draw_string(0, 90, "A - Exit\nB - Anlernen/Testen\n", 3, DRAW_PUT); waitKeyUpDown(); draw_block(0,20,128,45,3,DRAW_ERASE); draw_block(0,90,128,45,3,DRAW_ERASE); if(KEY_A || KEY_B || KEY_C || KEY_D) { if(KEY_B) mode = 1-mode; } else { cmd=getKeynum() -4; if(mode) { getIR(&(RAWset->RAWcmd[cmd])); } else { RAW_Send((unsigned long)&(RAWset->RAWcmd[cmd])); while(ANYKEY) RAW_Repeat(); RAW_Stop(); } } } }
static void draw_cur(void) { int i; for(i=0; i<4; ++i) { if(GAME->cur[i].line < 0) continue; cursor_to(PGRD_LEFT+GAME->cur[i].col*2, PGRD_TOP+GAME->cur[i].line); draw_block(0, GAME->curtype); } }
void draw_grid() { int b, y, x; for(y = 0; y < GRID_HEIGHT; y++) { for(x = 0; x < GRID_WIDTH; x++) { b = grid[y][x] || (x >= x_pos && x < x_pos + 4 && y >= y_pos && y < y_pos + 4 && stones[stone][((x - x_pos) << 2) + (y - y_pos)] & rot); draw_block(4 + x * 3, 4 + y * 3, b); } } // look adhead for(y = 0; y < 4; y++) for(x = 0; x < 4; x++) draw_block(40 + x * 3, 7 + y * 3, !!(stones[next_stone][(x << 2) + y] & next_rot)); }
/* Clears visible content of window to background color. Normally this means to set the window to the background color. But if window type is WINFLG_FRAME and WINFLG_HIDE is set, the foreground color is used to clear the window. If clr_border is 1, the border (if any) will also be cleared. */ void win_clear(struct Window *win, int clr_border){ int border = clr_border ? 0 : win->border; int frame = (win->flags & WINFLG_FRAME) ? 1 : 0; int color = ((win->flags & WINFLG_FRAME) && (win->flags & WINFLG_HIDE)) ? win->fg_color : win->bg_color; if (! (win->flags & WINFLG_VISIBLE)) return; draw_block(win->start_row+border+frame, win->start_col+border+frame, win->width-2*border-2*frame, win->height-2*border-2*frame, color); };
void draw_map_with_buff_offset(min_block_type *map, int buff_off_x, int buff_off_y, int buffer_w, int buffer_h, int vx, int vy) { #define GET_BLOCK_FROM_THIS(x, y) GET_BLOCK_FROM_BUFFER(map, x, y, buff_off_x, buff_off_y, buffer_w, buffer_h) update_sky(); SDL_FillRect(surface, NULL, 0xFFFFFFFF); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { min_block_type cb = GET_BLOCK_FROM_THIS(j, i); if (cb == BLCK_AIR) { int pu = GET_BLOCK_FROM_THIS(j - 1, i) != BLCK_AIR; int pl = GET_BLOCK_FROM_THIS(j, i - 1) != BLCK_AIR; int plu = GET_BLOCK_FROM_THIS(j - 1, i - 1) != BLCK_AIR; draw_block(cb, j, i, vx + j, vy + i, w, h, s_b_shadows[pu][plu][pl]); } else { draw_block(cb, j, i, vx + j, vy + i); } } } for(int i = 0; i < FLASHBACK_MAX; i++) { if((flashbacks[i].frames_left > 0) && (flashbacks[i].x >= vx) && (flashbacks[i].x < (vx + w)) && (flashbacks[i].y >= vy) && (flashbacks[i].y < (vy + h))) { if (flashbacks[i].inf == BLCK_AIR) { int pu = GET_BLOCK_FROM_THIS(flashbacks[i].x - vx - 1, flashbacks[i].y - vy) != BLCK_AIR; int pl = GET_BLOCK_FROM_THIS(flashbacks[i].x - vx, flashbacks[i].y - vy - 1) != BLCK_AIR; int plu = GET_BLOCK_FROM_THIS(flashbacks[i].x - vx - 1, flashbacks[i].y - vy - 1) != BLCK_AIR; draw_block(flashbacks[i].inf, flashbacks[i].x - vx, flashbacks[i].y - vy, flashbacks[i].x, flashbacks[i].y, w, h, s_b_shadows[pu][plu][pl]); } else { draw_block(flashbacks[i].inf, flashbacks[i].x - vx, flashbacks[i].y - vy, flashbacks[i].x, flashbacks[i].y); } // flashbacks[i].frames_left--; } } ui_redraw_needed = false; #undef GET_BLOCK_FROM_THIS }
void draw_b(unsigned char x, unsigned char y) { unsigned char w; if(!(is_drawing)) { if(bat_state & BAT_DEBUG) { draw_block(4,0,108,24,3,DRAW_ERASE); draw_numU(4,0,bat_min>>2,0,3,DRAW_PUT); draw_numU(32,0,bat_max>>2,0,3,DRAW_PUT); draw_numU(4,8,(bat_max>>2)-(bat_min>>2),0,3,DRAW_PUT); draw_numU(60,0,bat_min,0,3,DRAW_PUT); draw_numU(88,0,bat_max,0,3,DRAW_PUT); draw_numU(60,8,bat_max-bat_min,0,3,DRAW_PUT); if((bat_state & BAT_NORMAL)) draw_string(4,16,"Bat.Operation",3,DRAW_PUT); if((bat_state & BAT_CHARGE)) draw_string(4,16,"Charging",3,DRAW_PUT); if((bat_state & BAT_CHARGE_DONE)) draw_string(4,16,"Done Charging",3,DRAW_PUT); } if (bat_min<0x320) w = 0; else if (bat_min>0x380) w = 12; else w = (bat_min-0x320)/8; draw_block(x+1,y+1,12,5,3,DRAW_ERASE); draw_rect(x,y,14,7,1,3,DRAW_PUT); draw_vline(x+14,y+2,3,3,DRAW_PUT); if(w>0) draw_block(x+1,y+1,w,5,2,DRAW_PUT); if(w<12) draw_block(x+1+w,y+1,12-w,5,0,DRAW_PUT); }
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(); }
void draw_map(min_block_type *map, int vx, int vy) { update_sky(); SDL_FillRect(surface, NULL, 0xFFFFFFFF); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { draw_block(map[i * w + j], j, i, vx + j, vy + i); } } for(int i = 0; i < FLASHBACK_MAX; i++) { if(flashbacks[i].frames_left > 0) { draw_block(flashbacks[i].inf, flashbacks[i].x, flashbacks[i].y, vx + flashbacks[i].x, vy + flashbacks[i].y); flashbacks[i].frames_left--; } } ui_redraw_needed = false; }
void draw_bm(struct canvas_t* cvs, const struct blockmap_t* bm, int x, int y, int sz, unsigned long outline, int alpha) { int i, j; for (i = 0; i != bm->w; ++i) { for (j = 0; j != bm->h; ++j) { if (bm->buf[j*bm->w+i].occupied) { draw_block(cvs, &(bm->buf[j*bm->w+i]), x+i*sz, y+j*sz, sz, outline, alpha); } } } }
static void next_level() { food = getFood(); draw_block( food.x, food.y, 0b11101000); if(snake.len < MAX_SNAKE_LEN-2) snake.len++; if(snake.speed >= MAX_SPEED) snake.speed--; setTextColor(0xff,0b11100000); DoString(0,0,IntToStr(++points,6,0)); }
/*- * draw_point Draw the current point in a swirl pattern onto the XImage * * - swirl is the swirl * - win is the window to update */ static void draw_point(ModeInfo * mi, swirlstruct *sp) { int r; int x, y; /* get current point coordinates and resolution */ x = sp->x; y = sp->y; r = sp->r; /* check we are within the window */ if ((x < 0) || (x > sp->width - r) || (y < 0) || (y > sp->height - r)) return; /* what style are we drawing? */ if (sp->two_plane) { int r2; /* halve the block size */ r2 = r / 2; /* interleave blocks at half r */ draw_block(sp->ximage, x, y, r2, do_point(sp, x, y)); draw_block(sp->ximage, x + r2, y, r2, do_point(sp, x + r2, y)); draw_block(sp->ximage, x + r2, y + r2, r2, do_point(sp, x + r2, y + r2)); draw_block(sp->ximage, x, y + r2, r2, do_point(sp, x, y + r2)); } else draw_block(sp->ximage, x, y, r, do_point(sp, x, y)); /* update the screen */ /*- * PURIFY 4.0.1 on SunOS4 and on Solaris 2 reports a 256 byte memory leak on * the next line. */ (void) XPutImage(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), sp->ximage, x, y, x, y, r, r); }