An open API service indexing awesome lists of open source software.

https://github.com/tahsinzidane/sky-attack

air strike game in tarminal
https://github.com/tahsinzidane/sky-attack

Last synced: 3 months ago
JSON representation

air strike game in tarminal

Awesome Lists containing this project

README

        

Alien Invasion: Terminal Defender" is built entirely in Node.js using the readline module for real-time keyboard input. The game features a fighter plane controlled by the 'A' and 'D' keys to move left and right, and Spacebar to fire bullets. Alien spaceships drop from the top of the screen, and the goal is to shoot them down before they reach the bottom. The code handles real-time updates, movement, bullet tracking, and collision detection—all in a simple terminal environment. It’s a retro-style game that brings a classic arcade experience to r console! 🎮🚀

# explanation of code
### 1. **Setting Up the Game Area and Constants**
start by setting up some basic rules for the game, like how big the game area is and what symbols will represent different things.
- create a grid of 20 columns (width) and 20 rows (height).
- The plane, bullets, and aliens are represented by specific characters: `^` for the plane, `|` for the bullets, and `W` for aliens.

### 2. **Positioning the Plane, Bullets, and Aliens**
- The plane starts in the middle of the screen.
- also set up a list of bullets (which are fired) and aliens (which appear randomly at the top).

### 3. **Listening for Keyboard Input**
use Node's built-in tools to listen for key presses while the game is running. So when press:
- **'A'**: The plane moves left.
- **'D'**: The plane moves right.
- **Space**: The plane shoots a bullet.
- **Ctrl+C**: The game exits.

### 4. **Drawing the Game Screen**
Each time the game updates:
- clear the screen and create a new grid.
- The game places the plane, bullets, and aliens in their current positions on the grid.
- Then it displays the updated grid on r terminal.

### 5. **Game Updates (Moving Things Around)**
- Every time the game updates, the bullets move up (towards the top of the screen).
- The aliens move down towards the bottom of the screen.
- If a bullet hits an alien, both the bullet and the alien disappear.
- If any alien reaches the bottom, the game ends.

### 6. **Adding New Aliens**
At random intervals, new aliens appear at the top of the screen to keep the challenge going!

### 7. **Game Loop**
This loop runs constantly, updating the positions of the bullets and aliens, checking for collisions, and redrawing the screen every few milliseconds.

---

### How it all works:
- controlling a plane that can move left or right and shoot upwards to destroy incoming aliens.
- The goal is to shoot down as many aliens as possible before they reach the bottom of the screen.
- Each time an alien is hit, it disappears along with the bullet.
- The game ends when an alien reaches the bottom of the screen.

---

This game is like a super simple version of **Space Invaders**, but all inside r terminal, and control everything using just a few keys! 🎮💻