// Copyright 2025 Bill Rossi // // This file is part of Starship Futuretime // // Starship Futuretime is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Starship Futuretime is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Starship Futuretime. If not, see . #include #include #include "player.h" void initialize_player(Player *p) { p->position = (Vector2) { 400, 300 }; p->velocity = (Vector2) { 0, 0 }; p->acceleration = (Vector2) { 0, 0 }; p->pitch = PITCH_NEUTRAL; p->roll = ROLL_NEUTRAL; } void handle_player_input(Player *p) { if (IsKeyDown(KEY_DOWN)) p->pitch = PITCH_DESCENDING; else if (IsKeyDown(KEY_UP)) p->pitch = PITCH_ASCENDING; else p->pitch = PITCH_NEUTRAL; if (IsKeyDown(KEY_LEFT)) p->roll = ROLL_LEFT; else if (IsKeyDown(KEY_RIGHT)) p->roll = ROLL_RIGHT; else p->roll = ROLL_NEUTRAL; } void draw_player(Player *p) { Vector2 nose = { p->roll == ROLL_LEFT ? p->position.x - 50 : p->roll == ROLL_RIGHT ? p->position.x + 50 : p->position.x, p->pitch == PITCH_DESCENDING ? p->position.y + 20 : p->pitch == PITCH_ASCENDING ? p->position.y - 20 : p->position.y }; Vector2 left_wing = { p->position.x - 100, p->position.y + 50 }; Vector2 right_wing = { p->position.x + 100, p->position.y + 50 }; DrawTriangle(nose, left_wing, right_wing, DARKGRAY); } void move_player(Player *p) { switch (p->roll) { case ROLL_LEFT: p->acceleration.x = -ACCEL_X; break; case ROLL_NEUTRAL: p->acceleration.x = 0; break; case ROLL_RIGHT: p->acceleration.x = ACCEL_X; break; } switch (p->pitch) { case PITCH_DESCENDING: p->acceleration.y = 4; break; case PITCH_NEUTRAL: p->acceleration.y = 0; break; case PITCH_ASCENDING: p->acceleration.y = -4; break; } p->velocity.x += p->acceleration.x; p->velocity.x = CLAMP(p->velocity.x, MAX_VEL_X); p->velocity.x *= DAMPING_X; p->velocity.y += p->acceleration.y; p->velocity.y = CLAMP(p->velocity.y, MAX_VEL_Y); p->position.x += p->velocity.x; p->position.y += p->velocity.y; }