Пример #1
0
//Handling of rotation and debug up and down movement (disabled in curse.c)
void moveShip(Ship *ship, FILE *sketch, int direction) {
    eraseShip(ship, sketch);

    switch(direction) {
    //down, left, right, up
    case DOWN:
        ship -> centerPos[0] += 0;
        ship -> centerPos[1] += 10;
        recreateShip(ship);
        break;
    case LEFT:

        rotateShip(ship, -ROT_ANGLE);
        break;
    case RIGHT:

        rotateShip(ship, ROT_ANGLE);
        break;
    case UP:
        ship -> centerPos[0] -= 0;
        ship -> centerPos[1] -= 10;
        recreateShip(ship);
        break;
    }

    drawShip(ship, sketch);
}
Пример #2
0
//Updates position of ship based on accelerations, called from timer.c critical zone
void applyAccelerations(Ship *ship, iArgs input, FILE *sketch) {
    eraseShip(ship, sketch);

    double oldX = ship -> centerPos[0];
    double oldY = ship -> centerPos[1];

    if (rotationBuffer != ship -> rotationAngle) {
        rotationBuffer = ship -> rotationAngle;
    }

    double oldxV = ship -> xspeed;
    double oldyV = ship -> yspeed;
    double deltat = 0.05;
    double thrust;
    double ar = rotationBuffer * PI / 180.0;

    if (ship -> thrustOn) {
        thrust = input.thrust;
    } else {
        thrust = 0;
    }

    ship -> xA = thrust*cos(ar);
    ship -> yA = -(input.gravity) + thrust*sin(ar);

    ship -> centerPos[0] = oldX + oldxV*deltat + (1/2)*(ship -> xA)*deltat*deltat;
    ship -> centerPos[1] = oldY + oldyV*deltat + (1/2)*(ship -> yA)*deltat*deltat;
    ship -> xspeed = oldxV - (ship -> xA)*deltat;
    ship -> yspeed = oldyV - (ship -> yA)*deltat;

    checkBoundaries(ship);
    recreateShip(ship);

    if (rotationBuffer != ship -> rotationAngle) {
        rotateShip(ship, rotationBuffer - 90);
    }


    drawShip(ship, sketch);
    //
}
Пример #3
0
void rotateRight() {
  rotateShip(&ship, 0., 0., rotSpeed);
}
Пример #4
0
void rotateLeft() {
  rotateShip(&ship, 0., 0., -rotSpeed);
}
Пример #5
0
void rotateDown() {
  rotateShip(&ship, rotSpeed, 0., 0.);
}
Пример #6
0
void rotateUp() {
  rotateShip(&ship, -rotSpeed, 0., 0.);
}