void Submarine::move(GameLevel& context) { if(context.isGameover()) { return; } // control static const int SPD = 1 << 7; static const int R2 = 90; // 0.5/sqrt(2) / (1/256) if(context.core.pressed(BTN_U) && context.core.pressed(BTN_L)) { x -= R2; y -= R2; } else if(context.core.pressed(BTN_U) && context.core.pressed(BTN_R)) { x += R2; y -= R2; } else if(context.core.pressed(BTN_D) && context.core.pressed(BTN_L)) { x -= R2; y += R2; } else if(context.core.pressed(BTN_D) && context.core.pressed(BTN_R)) { x += R2; y += R2; } else if(context.core.pressed(BTN_U)) { y -= SPD; } else if(context.core.pressed(BTN_L)) { x -= SPD; } else if(context.core.pressed(BTN_R)) { x += SPD; } else if(context.core.pressed(BTN_D)) { y += SPD; } // clamping into field static const fixed MARGIN = 6; x = Clamp(x, 0, (SCREEN_WIDTH - MARGIN) << 8); y = Clamp(y, (MARGIN - H) << 8, (SCREEN_HEIGHT - MARGIN) << 8); // launching torpedo if(extraLives >= 0 && (context.core.pushed(BTN_A) || context.core.pushed(BTN_B))) { context.launchTorpedo((int)fieldX() + 10, fieldY() + 1); } //firing auto shot #ifdef LOW_FLASH_MEMORY if(context.frameCount() % 5 == 0) { context.fireAutoShot(fieldX() + 3, fieldY() - 3); } #else if(context.lookForEnemy() && context.frameCount() % 5 == 0) { context.fireAutoShot(fieldX() + 3, fieldY() - 3); } #endif // updating armor timer if(armor > 0) { --armor; } }
void Submarine::draw(GameLevel& context) const { if(armor == 0 || (extraLives >= 0 && context.frameCount() / 3 % 2 == 0)) { context.core.drawBitmap(fieldX() - 1, fieldY() - 2, bitmapSubmarine, 2); if(context.frameCount() % ECHO_CYCLE > 30) { // sustain: 30 frames context.core.drawPixel(fieldX() + 6, fieldY() - 1, 1); } } //context.getArduboy().drawRect(x, y, W, H, 0); }
void Bullet::move() { x += vx; y += vy; // frame out static const char MARGIN = 4; if( fieldX() < -MARGIN || (byte)fieldX() > SCREEN_WIDTH + MARGIN || fieldY() < -MARGIN || (byte)fieldY() > SCREEN_HEIGHT + MARGIN ) { inactivate(); } }
void Bullet::draw(GameLevel& context) const { // ToDo: async animation (if there are enough memories) const byte frame = context.frameCount() / 3 % 2; if(type % 2 == 0) { const byte* bitmaps[] = {bitmapMbullet0, bitmapMbullet1}; context.core.drawBitmap(fieldX() - bitmapMbullet0[0]/2, fieldY() - bitmapMbullet0[1]/2, bitmaps[frame], 2); } else { const byte* bitmaps[] = {bitmapSbullet0, bitmapSbullet1}; context.core.drawBitmap(fieldX() - bitmapSbullet0[0]/2, fieldY() - bitmapSbullet0[1]/2, bitmaps[frame], 2); } //arduboy.drawPixel(x, y, 0); }
void SolvedElectrostaticSystem::findField() { fieldX = doubleGrid::Zero(iMax-iMin+1, jMax-jMin+1); // X components of field fieldY = doubleGrid::Zero(iMax-iMin+1, jMax-jMin+1); // Y components of field field = doubleGrid::Zero(iMax-iMin+1, jMax-jMin+1); // Magnitude of field for(int i=iMin; i<=iMax; i++) { for(int j=jMin; j<=jMax; j++) { // Components in i direction if(i==iMax) fieldX(i-iMin, j-jMin) = getPotentialIJ(i,j) - getPotentialIJ(i-1,j); else if(i==iMin) fieldX(i-iMin, j-jMin) = getPotentialIJ(i+1,j) -getPotentialIJ(i,j); else fieldX(i-iMin, j-jMin) = (getPotentialIJ(i+1,j)-getPotentialIJ(i-1,j))/2; // Components in j direction if(j==jMax) fieldY(i-iMin, j-jMin) = getPotentialIJ(i,j) - getPotentialIJ(i,j-1); else if(j==jMin) fieldY(i-iMin, j-jMin) = getPotentialIJ(i,j+1) -getPotentialIJ(i,j); else fieldY(i-iMin, j-jMin) = (getPotentialIJ(i,j+1)-getPotentialIJ(i,j-1))/2; // Full field field(i-iMin, j-jMin) = sqrt( pow(fieldX(i-iMin, j-jMin), 2) + pow(fieldY(i-iMin, j-jMin), 2) ); } } fieldFound = true; }
void Submarine::onHit(GameLevel& context) { if(armor <= 0) { if(extraLives >= 0) { context.spawnParticle(fieldX() - 2, fieldY() - 4, PARTICLE_EXPLOSION); context.core.tone(185, 250); } --extraLives; if(extraLives < 0) { context.setGameover(); // ToDo: add gameover sfx inactivate(); } armor = ARMOR_FRAMES; } }
void Bullet::onHit(GameLevel& context) { #ifndef LOW_FLASH_MEMORY context.core.drawBitmap(fieldX() - bitmapCircle[0]/2, fieldY() - bitmapCircle[1]/2, bitmapCircle, 2); #endif inactivate(); }