init: add basic code

This commit is contained in:
Xory 2024-08-02 16:08:36 +03:00
commit 4fd56dc84f
2 changed files with 75 additions and 0 deletions

12
README.md Normal file
View file

@ -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
```

63
index.cpp Normal file
View file

@ -0,0 +1,63 @@
#include <cstdio>
#include <unistd.h>
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);
}
}