#include "antifaShip.h" #include "game.h" // TODO: Get rid of some magic numbers. void initAntifaShip(Entity * entity, Game * game) { entity->model = &game->assets.models[ANTIFA_SHIP_ASSET]; // Acceleration stuff. entity->useAcceleration = true; entity->acceleration = (EntityAcceleration){ .speedUp = 30.0, .speedDown = 15, .rotation = (Vector3){2.0, 2.0, 2.0} }; // Set Data pointer. entity->data = KF_MALLOC(sizeof(AntifaShip)); if (entity->data == NULL) { ALLOCATION_ERROR; return; } AntifaShip * data = (AntifaShip*)entity->data; data->lastMouse = Vector2Zero(); data->forwardSpeed = 0.0; } void closeAntifaShip(Entity * entity) { if (entity->data != NULL) KF_FREE(entity->data); } void controlAntifaShipJoystick(Game * game, Entity * entity) { Vector3 stick = (Vector3){ GetGamepadAxisMovement(0, 1), -GetGamepadAxisMovement(0, 0), GetGamepadAxisMovement(0, 2) * 0.25 }; stick = Vector3Scale(stick, 0.5); entityJoystickControl(entity, stick, fabs(GetGamepadAxisMovement(0, 3) * 300.0)); } void controlAntifaShipKeyboardAndMouse(Game * game, Entity * entity) { AntifaShip * data = (AntifaShip*)entity->data; // Get mouse values. Vector2 mouse = GetMousePosition(); float speed = GetMouseWheelMove(); data->forwardSpeed += (speed * game->settings.scrollBarSpeed); if (data->forwardSpeed < 0.0) data->forwardSpeed = 0.0; Vector2 v = Vector2Subtract(mouse, data->lastMouse); data->lastMouse = mouse; // Using mouse as a joystick. Vector3 mouseStick = (Vector3){ (v.y / GetScreenHeight()) * game->settings.mouseSensitivity, (-v.x / GetScreenWidth()) * game->settings.mouseSensitivity, 0.0, }; // Swap axis for more movement with mouse. if (IsMouseButtonDown(MOUSE_BUTTON_MIDDLE)) { mouseStick.z = -mouseStick.y; mouseStick.y = 0.0; } entityJoystickControl(entity, mouseStick, data->forwardSpeed); } void updateAntifaShip(Game * game, Entity * entity) { switch (game->settings.controlMode) { case JOYSTICK_CONTROL: controlAntifaShipJoystick(game, entity); break; case KEYBOARD_AND_MOUSE_CONTROL: controlAntifaShipKeyboardAndMouse(game, entity); break; default: break; } } void drawAntifaShip(Game * game, Entity * entity) { entityDraw(entity); }