// try to recycle a hidden dot or make a new one void Cube::newDot(const Float2 p, const Float2 v) { bool noRecycle = true; // can a hidden dot be recycled? for (uint8_t d=0; d<dot_n && noRecycle; d++) { if ( vid.sprites[d].isHidden() ) { initDot(d, p, v); noRecycle = false; } } if (noRecycle && dot_n<maxDots) { initDot(dot_n, p, v); ++dot_n; } }
void update() { if (KEY_DOWN_NOW(BUTTON_SELECT)) main(); sprintf(string, "Score = %d", score); for (int i = 0; i < NUMDOTS; i++) { if (rectCollides(dots[i].rect, pacman) || dots[i].rect.col<=0) { if (dots[i].isGhost && dots[i].rect.col > 0) drawEnd(); else { initDot(i); score++; } } dots[i].rect.col -= dots[i].del; } // Move Pacman if (KEY_DOWN_NOW(BUTTON_DOWN) && pacman.row < SCREENHEIGHT - pacman.height - TEXT_HEIGHT) pacman.row++; if (KEY_DOWN_NOW(BUTTON_UP) && pacman.row > 0) pacman.row--; if (KEY_DOWN_NOW(BUTTON_LEFT) && pacman.col > 0) pacman.col--; if (KEY_DOWN_NOW(BUTTON_RIGHT) && pacman.col < SCREENWIDTH - pacman.width) pacman.col++; }
void initialize() { drawTitle(); setPalette(Pacman_palette, PACMAN_PALETTE_SIZE, PACMAN_PALETTE_OFFSET); setPalette(ghost_palette, PACMAN_PALETTE_SIZE, GHOST_PALETTE_OFFSET); DOT emptyDot; emptyDot.rect.row = 0; emptyDot.rect.col = 0; emptyDot.rect.height = 0; emptyDot.rect.width = 0; emptyDot.del = 0; emptyDot.isGhost = 0; for (int i = 0; i < NUMDOTS; i++) dots[i] = oldDots[i] = emptyDot; ghostFrequency = 32; score = 0; // Make Pacman and his shadow pacman.height = pacman.width = 16; pacman.row = (SCREENHEIGHT-pacman.height-TEXT_HEIGHT)/2; pacman.col = 0; // Make dots for (int i = 0; i < NUMDOTS; i++) { initDot(i); drawDot(i); } oldPacman = pacman; for (int i = 0; i < NUMDOTS; i++) oldDots[i] = dots[i]; }