//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); }
void explode(Ship *ship, FILE *sketch) { int i, j, k; for (k = 0; k < 5; k++) { for (i = 0; i < 2; i++) for (j = 0; j < 3; j++) ship -> structure[i][j] += (rand() % 40) - 20; eraseShip(ship, sketch); drawShip(ship, sketch); } }
//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); // }
inline void moveShip(POSITION oldPos, POSITION newPos, int map_x_location) { eraseShip(oldPos, map_x_location); drawShip(newPos, map_x_location); }