From 7c099db49271683060d42a3924005f5a1e84963a Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 27 Aug 2008 15:37:58 +0100 Subject: [PATCH] Remove Mechanics stuff --- src/Makefile.am | 2 +- src/Mechanics.cpp | 60 ----------------------------------------------- src/Mechanics.hpp | 52 ---------------------------------------- src/Menu.cpp | 31 ++++++++++++------------ src/Menu.hpp | 4 +--- 5 files changed, 18 insertions(+), 131 deletions(-) delete mode 100644 src/Mechanics.cpp delete mode 100644 src/Mechanics.hpp diff --git a/src/Makefile.am b/src/Makefile.am index c190f90..7eceb33 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,7 +12,7 @@ lander_SOURCES = Main.cpp Game.hpp Game.cpp \ Ship.hpp Ship.cpp Viewport.hpp Viewport.cpp LandingPad.hpp \ LandingPad.cpp Surface.hpp Surface.cpp Mine.hpp Mine.cpp \ ElectricGate.hpp ElectricGate.cpp Key.hpp Key.cpp \ - Mechanics.hpp Mechanics.cpp Geometry.hpp Image.hpp \ + Geometry.hpp Image.hpp \ Image.cpp AnimatedImage.hpp AnimatedImage.cpp \ Texture.hpp Texture.cpp Options.hpp Options.cpp \ ConfigFile.hpp ConfigFile.cpp SoundEffect.hpp \ diff --git a/src/Mechanics.cpp b/src/Mechanics.cpp deleted file mode 100644 index bdf9df0..0000000 --- a/src/Mechanics.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* Mechanics.cpp -- Frame-rate independent movemoment. - * Copyright (C) 2008 Nick Gasson - * - * 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 . - */ - -#include -#include "Mechanics.hpp" - -Position::Position(float x, float y) - : x(x), y(y) -{ - -} - -Position Position::operator+(Velocity &v) const -{ - return Position(x + v.GetXSpeed(), y + v.GetYSpeed()); -} - -Position Position::operator-(Velocity &v) const -{ - return Position(x - v.GetXSpeed(), y - v.GetYSpeed()); -} - -void Position::operator+=(Velocity &v) -{ - x += v.GetXSpeed(); - y += v.GetYSpeed(); -} - - -void Position::operator-=(Velocity &v) -{ - x -= v.GetXSpeed(); - y -= v.GetYSpeed(); -} - -Velocity::Velocity(float xspeed, float yspeed) - : xspeed(xspeed), yspeed(yspeed) -{ - -} - -Velocity Velocity::Project(float speed, float angle) -{ - return Velocity(speed * cosf(angle), speed * sinf(angle)); -} - diff --git a/src/Mechanics.hpp b/src/Mechanics.hpp deleted file mode 100644 index 5716f8c..0000000 --- a/src/Mechanics.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* Mechanics.hpp -- Frame-rate independent movemoment. - * Copyright (C) 2008 Nick Gasson - * - * 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 . - */ - -#ifndef INC_MECHANICS_HPP -#define INC_MECHANICS_HPP - -class Velocity { -public: - Velocity(float xspeed, float yspeed); - Velocity() { Velocity(0.0f, 0.0f); } - - static Velocity Project(float speed, float angle); - - float GetXSpeed() const { return xspeed; } - float GetYSpeed() const { return yspeed; } - -private: - float xspeed, yspeed; -}; - -class Position { -public: - Position(float x, float y); - Position() { Position(0, 0); } - - float GetX() const { return x; } - float GetY() const { return y; } - - Position operator+(Velocity &v) const; - Position operator-(Velocity &v) const; - void operator+=(Velocity &v); - void operator-=(Velocity &v); - -private: - float x, y; -}; - -#endif diff --git a/src/Menu.cpp b/src/Menu.cpp index 737a6a9..f23998e 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -274,38 +274,39 @@ MenuStar::MenuStar() const int screenWidth = OpenGL::GetInstance().GetWidth(); const int screenHeight = OpenGL::GetInstance().GetHeight(); - double x, y; do { x = (double)(rand()%(screenWidth/2) + screenWidth/4); y = (double)(rand()%(screenHeight/2) + screenHeight/4); - } while (y == 0); - pos = Position(x, y); + } while (y == screenHeight/2 || x == screenWidth/2); - double ratio = (pos.GetY() - screenHeight/2) / (pos.GetX() - screenWidth/2); - double angle = atan(ratio); - vel = Velocity::Project(SPEED, angle); + double ratio = (y - screenHeight/2) / (x - screenWidth/2); + angle = atan(ratio); } void MenuStar::Display(double fade) { - starImage->Draw(pos.GetX(), pos.GetY(), starRotate, scale); + starImage->Draw(x, y, starRotate, scale); starRotate += ROTATE_SPEED; } bool MenuStar::Move() { - if (pos.GetX() > OpenGL::GetInstance().GetWidth() / 2) - pos += vel; - else - pos -= vel; + if (x > OpenGL::GetInstance().GetWidth() / 2) { + x += SPEED * cos(angle); + y += SPEED * sin(angle); + } + else { + x -= SPEED * cos(angle); + y -= SPEED * sin(angle); + } scale += ENLARGE_RATE; // Has it left the screen? - return (pos.GetX() > OpenGL::GetInstance().GetWidth() - || pos.GetY() > OpenGL::GetInstance().GetHeight() - || pos.GetX() + starImage->GetWidth() < 0 - || pos.GetY() + starImage->GetWidth() < 0); + return (x > OpenGL::GetInstance().GetWidth() + || y > OpenGL::GetInstance().GetHeight() + || x + starImage->GetWidth() < 0 + || y + starImage->GetWidth() < 0); } MenuOption::MenuOption(const char *imgFile, int off, int order) diff --git a/src/Menu.hpp b/src/Menu.hpp index 42b233c..5eecc20 100644 --- a/src/Menu.hpp +++ b/src/Menu.hpp @@ -21,7 +21,6 @@ #define INC_MENU_HPP #include "ScreenManager.hpp" -#include "Mechanics.hpp" #include "Image.hpp" #include "Font.hpp" @@ -38,8 +37,7 @@ private: double scale; bool active; - Position pos; - Velocity vel; + double x, y, angle; static double starRotate; static Image *starImage; -- 2.39.2