int main(void) { int fd; int ret; char *fbp; fd = open("/dev/fb0", O_RDWR); if (-1 == fd) { perror("open"); exit(1); } /* get fb_var_screeninfo */ ret = ioctl(fd, FBIOGET_VSCREENINFO, &var); if (-1 == ret) { perror("ioctl(var)"); close(fd); exit(1); } bpp = var.bits_per_pixel / 8; /* get fb_fix_screeninfo */ ioctl(fd, FBIOGET_FSCREENINFO, &fix); if (-1 == ret) { perror("ioctl(var)"); close(fd); exit(1); } /* get framebuffer start address */ fbp = mmap(NULL, fix.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if ((void *)-1 == fbp) { perror("mmap"); close(fd); exit(1); } /* set background */ memset(fbp, 0, fix.smem_len); /* set a pixel */ //memset(fbp + 9000, 0xff, bpp); memset(fbp, 0xff, fix.smem_len); set_square(fbp, 400, 300, 500, 400, 0); ret = munmap(fbp, fix.smem_len); if (-1 == ret) { perror("munmap"); close(fd); exit(1); } close(fd); return 0; }
/* loads the map text file into a new map structure */ struct map *load_map(char *fname) { struct map *map = NULL; struct square *sq; FILE *fp; int width, height; int n; char c; /* You should not need to have to alter this function. */ if ((fp = fopen(fname, "r")) == NULL) { fprintf(stderr,"Error: cannot open file %s.\n", fname); exit(EXIT_FAILURE); } /* first pass: calcuate width and height of map */ width = height = n = 0; while ((c = getc(fp)) != EOF) { if (c == '\n') { height++; if (n > width) { width = n; } n = 0; } else { n++; } } /* rewind file */ if (fseek(fp, SEEK_SET, 0)) { return NULL; } /* pad out the map to make a sentinel border around the edge */ width += 2; height += 2; /* now we can allocate memory to the map structure */ map = map_init(width, height); if (!map) { fprintf(stderr, "Cannot allocate memory for map structure.\n"); exit(EXIT_FAILURE); } /* second pass: load in the data */ sq = map->grid + width + 1; /* skip first row as a border */ while ((c = getc(fp)) != EOF) { if (c == '\n') { sq += 2; } else { set_square(sq, c); sq++; } } fclose(fp); return map; }
square(const sf::Vector2f& windims, const sf::Vector2f& start_rel, const sf::Color& color) : m_windims(windims), m_posit(start_rel.x*m_windims.x, start_rel.y*m_windims.y), m_side(m_windims.y/m_divis), m_radius(0.5f*m_side), m_sides(m_side, m_side), m_speed_right(m_speed_mult*m_windims.x, 0.0f), m_speed_left(-m_speed_mult*m_windims.y, 0.0f), m_jump_up(0.0f, -m_speed_mult*m_windims.y), m_accel(0.0f, m_accel_mult*m_windims.y), m_color(color), m_square() { set_square(); }
square(const sf::Vector2f& windims, const wing& winger, const sf::Color& color) : m_windims(windims), m_winger(winger), m_side(m_windims.y/m_divis), m_radius(0.5f*m_side), m_sides(m_side, m_side), m_speed_right(m_speed_mult*m_windims.x, 0.0f), m_speed_left(-m_speed_mult*m_windims.x, 0.0f), m_jump_up(0.0f, -m_jump_mult*m_windims.y), m_accel(0.0f, m_accel_mult*m_windims.y), m_color(color), m_square(), m_shots() { set_wing(); set_square(); }
/* initialises the map structure */ struct map *map_init(int width, int height) { struct map *new_map; struct square *sq; int i; new_map = malloc(sizeof(struct map)); if (!new_map) { return NULL; } new_map->grid = malloc(sizeof(struct square) * width * height); if (!new_map->grid) {return NULL;} new_map->width = width; new_map->height = height; sq = new_map->grid; for (i = 0; i < width * height; i++) { set_square(sq, '#'); /* impassable by default */ sq++; } return new_map; }
shot(const float squide, const sf::Vector2f& posit, const sf::Vector2f& speed, const sf::Color& color) : m_squide(squide), m_posit(posit), m_speed(speed), m_side(0.25f*m_squide), m_sides(m_side, m_side), m_radius(0.5f*m_side), m_color(color + m_dark), m_square() { set_square(); }