Shell::Shell(position startPos) // Constructor { pos.set(startPos.getX(), startPos.getY(), startPos.getTh()); seeTank = false; seeAi = false; float x,y; x = pos.getX(); y = pos.getY(); updateBb(); }
void Tank::resetTank(float newX, float newY, float newTh, float newTurretTh) { pos.set(newX,newY,newTh); turretTh = newTurretTh; body.setPosition(newX,newY); body.setRotation(newTh); turret.setPosition(newX,newY); turret.setRotation(newTh); updateBb(); }
void Shell::move() // Move Shell { float x,y,th; x = pos.getX(); y = pos.getY(); th = pos.getTh(); float thRad = DEG2RAD(th); // Heading in radians float dx = cos(thRad) * shellMoveConst; float dy = sin(thRad) * shellMoveConst; pos.set(x + dx, y + dy, th); updateBb(); }
Shell::Shell(Position startPos, bool isNPC) // Constructor { pos = startPos; firingPosition = pos; npc = isNPC; float x,y; x = pos.getX(); y = pos.getY(); box.setFillColor(sf::Color(90,90,90)); box.setSize(sf::Vector2f(6.0f,12.0f)); box.setOrigin(2,6); updateBb(); debugMode = false; visible = false; }
void Tank::implementMove() { float x,y,th; x = pos.getX(); y = pos.getY(); th = pos.getTh(); float thRad = DEG2RAD(th); // Heading in radians float dx = cos(thRad) * moveConst; float dy = sin(thRad) * moveConst; if(forward) { pos.set(x + dx, y + dy, th); } if(backward) { pos.set(x - dx, y - dy, th); } if(left) { float newTh = th-rotMoveConst; if(newTh < 0){newTh += 360.0;} pos.set(x, y, newTh); newTh = turretTh-rotMoveConst; if(newTh < 0){newTh += 360.0;} turretTh = newTh; } if(right) { float newTh = th+rotMoveConst; if(newTh > 360.0){newTh -= 360.0;} pos.set(x, y, newTh); newTh = turretTh+rotMoveConst; if(newTh > 360.0){newTh -= 360.0;} turretTh = newTh; } if(turretLeft) { float newTh = turretTh - turRotMoveConst; if(newTh < 0.0){newTh += 360.0;} turretTh = newTh; } if(turretRight) { float newTh = turretTh + turRotMoveConst; if(newTh > 360.0){newTh -= 360.0;} turretTh = newTh; } body.setPosition(pos.getX(),pos.getY()); body.setRotation(pos.getTh()); turret.setPosition(pos.getX(),pos.getY()); turret.setRotation(turretTh); updateBb(); // Update the bounding box // Decrement fire counter if(fireCounter > 0) fireCounter--; }