/* * Copyright (C) 2018,2026 Ortega Froysa, Nicolás * Author: Ortega Froysa, Nicolás * * This program 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. * * This program 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 this program. If not, see . */ #pragma once #include "vec.h" #include class Ship { private: /// Position of the ship in pixels. Vec pos; /// Velocity of the ship in pixels per frame. Vec vel; /** * The direction that the ship is facing in radians, where * 0 is right facing. */ float direction; public: /** * @brief Initialize ship. * * @param x Initial X position. * @param y Initial Y position. */ Ship(const float x, const float y); /** * @brief Updates the ship's variables according to keyboard * input and gravitational forces. * * @param grav Vector of gravitational acceleration in pixels per frame squared. */ void update(const Vec &grav); /** * @brief Reset ship to position. * * @param x X position to reset to. * @param y Y position to reset to. */ inline void reset(float x, float y) { this->pos.set(x, y); this->vel.set(0, 0); this->direction = 0; } /** * @brief Draw the ship. */ void draw() const; inline Vec getPos() const { return pos; } inline Vec getVel() const { return vel; } inline float getDirection() const { return direction; } };