void HumanConsole::restart() { timeCount = 0; lastMove = 0; lastSpeedup = -1000; running = false; keyUp = keyDown = keyLeft = keyRight = false; keyShift = keyZ = keyX = false; gameInfo.gameStatus = INIT; gameInfo.score = gameInfo.round = 0; gameInfo.planeX = PLANE_INIT_X; gameInfo.planeY = PLANE_INIT_Y; gameInfo.planeSkillsNum = 0; string bossName; init(bossName); emit setBossName(QString(bossName.c_str())); emit setPlayerName(QString("Human")); emit setTime(0); emit setScore(0); emit setValue1(0); emit setValue2(0); gameCenter->init(QPointF(gameInfo.planeX, gameInfo.planeY), QPointF(BULLET_X, BULLET_Y)); }
void ofxBKDoubleSlider::mouseDragged(ofMouseEventArgs &e) { float targetVal = getValueForPosition(getMousePosition().x)-mouseDragOffset; if(currentDraggingValue == 1) setValue(targetVal); else if(currentDraggingValue == 2) setValue2(targetVal); }
ofxBKDoubleSlider::ofxBKDoubleSlider(string _label, float _x, float _y, float _width,float _height) { init(_label, _x, _y, _width,_height); setValue2(.75); setValue(.25); }
void ofxBKDoubleSlider::setValues(float _value, float _value2,bool notify) { setValue(_value,false); setValue2(_value2,notify); }
void HumanConsole::onTimer() { if (gameInfo.gameStatus != BATTLE) return; /* Boss bullets */ timeCount ++; if (timeCount % 5 == 0) { vector<NewBullet> nb; string msg; gameInfo.round ++; getAction(gameInfo, nb, msg); gameInfo.round --; for (int i = 0; i < nb.size(); i ++) if (isValidNewBullet(nb[i])) newBullets[nb[i].initTime][getBulletType(nb[i].vx, nb[i].vy)].push_back(nb[i]); nb.clear(); update(nb); for (int i = 0; i < nb.size(); i ++) { double vx = nb[i].vx, vy = nb[i].vy; vx *= 10; vy *= 10; gameCenter->addBullet(QPointF(BULLET_X, BULLET_Y), QPointF(vx, vy)); } gameInfo.round ++; if (gameInfo.round % 100 == 0) gameInfo.planeSkillsNum ++; emit setTime(gameInfo.round); emit setValue1(gameInfo.planeSkillsNum); emit setValue2(gameInfo.planeSkillsNum); } /* Use skill */ if (keyX) { if (gameInfo.planeSkillsNum < 5) goto fail; gameInfo.planeSkillsNum -= 5; emit setValue1(gameInfo.planeSkillsNum); emit setValue2(gameInfo.planeSkillsNum); gameInfo.bullets.clear(); gameCenter->Bomb(QPointF(gameInfo.planeX, gameInfo.planeY)); } else if (keyZ) { if (gameInfo.planeSkillsNum < 2) goto fail; gameInfo.planeSkillsNum -= 2; emit setValue1(gameInfo.planeSkillsNum); emit setValue2(gameInfo.planeSkillsNum); lastSpeedup = timeCount; gameCenter->SpeedUP(QPointF(gameInfo.planeX, gameInfo.planeY)); } fail: /* Judge hit */ vector<QPointF> bp; gameCenter->getBulletsPos(bp); for (int i = 0; i < bp.size(); i ++) { double x = bp[i].x(), y = bp[i].y(); if (SQR(gameInfo.planeX - x) + SQR(gameInfo.planeY - y) <= SQR(BULLET_R[0] + EPSILON)) { gameInfo.gameStatus = BOSS_WIN; emit gameOver(); break; } } /* Game score */ if (!keyUp && !keyDown && !keyRight && !keyLeft) { if (timeCount - lastMove == 5) { gameInfo.score ++; gameCenter->addPlaneBullet(QPointF(gameInfo.planeX, gameInfo.planeY), QPointF(BULLET_X, BULLET_Y)); emit setScore(gameInfo.score); lastMove = timeCount; } } else lastMove = timeCount; /* Plane move */ if (keyShift) cntSpeed = 4.0; else cntSpeed = 8.0; if (timeCount - lastSpeedup <= 150) cntSpeed *= 2; double dx = 0, dy = 0; if (keyUp) dy += cntSpeed; if (keyDown) dy -= cntSpeed; if (keyRight) dx += cntSpeed; if (keyLeft) dx -= cntSpeed; gameInfo.planeX += dx; gameInfo.planeY += dy; if (gameInfo.planeX < 0) gameInfo.planeX = 0; if (gameInfo.planeY < 0) gameInfo.planeY = 0; if (gameInfo.planeX > 1000) gameInfo.planeX = 1000; if (gameInfo.planeY > 1000) gameInfo.planeY = 1000; gameCenter->ElementMoveTo(1, QPointF(gameInfo.planeX, gameInfo.planeY), 1.0/50.0); }