From 4fd56dc84f1913bdd8a30d2618605ad3a16d8c51 Mon Sep 17 00:00:00 2001 From: Xory Date: Fri, 2 Aug 2024 16:08:36 +0300 Subject: [PATCH] init: add basic code --- README.md | 12 +++++++++++ index.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 README.md create mode 100644 index.cpp diff --git a/README.md b/README.md new file mode 100644 index 0000000..65d5de4 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# MGS +## Missile Guidance System (C++) +This is a small simplified missile guidance system in C++, I hope to improve it and make it more realistic in the future. + +## Installation instructions +Requirements: G++, Git and a Linux OS. +``` +git clone https://git.xorycode.dev/xory/mgs.git +cd mgs +g++ index.c +./a.out +``` diff --git a/index.cpp b/index.cpp new file mode 100644 index 0000000..0096002 --- /dev/null +++ b/index.cpp @@ -0,0 +1,63 @@ +#include +#include + +struct Missile { + int x; + int y; + int x_velocity; + int y_velocity; +}; + +struct Point { + int x; + int y; +}; + +int main() { + Point target; + target.x = 1000; + target.y = 0; + + Missile missile; + missile.x = 0; + missile.y = 0; + missile.x_velocity = 0; + missile.y_velocity = 0; + + while (target.x > missile.x || target.y > missile.y) { + missile.x += missile.x_velocity; + missile.y += missile.y_velocity; + + int x_distance = target.x - missile.x; + int y_distance = target.y - missile.y; + + if (x_distance > 0 && missile.x_velocity < 913) { + missile.x_velocity += 1; + } else { + missile.x_velocity = 0; + } + if (y_distance > 0 && missile.x_velocity < 913) { + missile.y_velocity += 1; + } else { + missile.y_velocity = 0; + } + + printf("\x1b[2J\n"); + printf("\x1b[H"); + printf("-----------------------------\n"); + printf("- Missile info\n"); + printf("X: %d\n", missile.x); + printf("Y: %d\n", missile.y); + printf("X Velocity: %d\n", missile.x_velocity); + printf("Y Velocity: %d\n", missile.y_velocity); + printf("- Target Info\n"); + printf("X: %d\n", target.x); + printf("Y: %d\n", target.y); + printf("X Distance: %d\n", x_distance); + printf("Y Distance: %d\n", y_distance); + printf("-----------------------------"); + + usleep(50000); + + } +}