// 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; Image sprite_img = LoadImage("img/player.png"); p->spritesheet = LoadTextureFromImage(sprite_img); UnloadImage(sprite_img); } 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) { DrawTextureRec(p->spritesheet, (Rectangle) { 128, 128, 128, 128 }, p->position, WHITE); } 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; }