Spaceship game controlled by ESP32 card

ESP32 22-01-25
31 0

Tutorial plan

1- Presentation of the Spaceship game

2- Objective of the Spaceship project

3- Required Components

4- Component Wiring

5- Programming ESP32 with Micropython

 

 

Presentation of the Spaceship game

The Spaceship Game is an interactive and fast-paced arcade game where players control a spaceship to navigate through a field of obstacles, dodge enemies, and earn points by surviving as long as possible or destroying targets. The game combines simple mechanics, immersive sound effects, and a compact setup to deliver an engaging experience.

1. Objective:

The primary goal is to steer the spaceship safely, avoiding collisions while collecting points. Players aim to survive for as long as possible while increasing their score.

2. Controls:

The spaceship is controlled using a joystick.

Players can move up, down, left, or right and use the joystick button for additional actions, such as firing projectiles.

3. Visuals:

The game is displayed on an LCD screen, showcasing the spaceship, obstacles, and current score in a simplified graphical style.

4. Audio Feedback:

A buzzer provides sound effects for key events such as firing, collisions, or level-ups, enhancing the gameplay experience.

5. Gameplay Mechanics:

Obstacles or enemies appear randomly and move toward the spaceship.

Difficulty increases as the game progresses, with faster or more frequent obstacles.

 

Objective of the Spaceship Project

The Spaceship Game is an arcade-style game designed for an ESP32 microcontroller platform, utilizing a joystick for control, an LCD I2C display for visualization, and a buzzer for sound effects. It provides an engaging gameplay experience by combining simple mechanics with interactive feedback.

The game revolves around controlling a spaceship to navigate a field of moving obstacles while attempting to survive as long as possible and achieve a high score. The spaceship can dodge obstacles and shoot projectiles at targets. The LCD screen displays the game environment, while the buzzer adds sound effects for various actions like shooting, collisions, and level progressions.

1. Spaceship Movement:

Controlled using the joystick, allowing movement in two directions (left, right).

Boundaries prevent the spaceship from moving off-screen.

2. Shooting Mechanic:

Players can shoot projectiles by pressing the joystick button.

Successfully hitting an enemy and clears the enemy.

3. Sound Effects:

A quick beep sound plays when :

- the ship is moving

- Shooting:  the joystick button is pressed

 

Required Components

ESP32 board

Executes game logic, handles inputs from the joystick, and manages output to the LCD and buzzer.

Joystick Module

X-axis and Y-axis: Controls the movement of the spaceship.

Button: Triggers specific actions, such as firing projectiles.

LCD Screen (16x2 or 20x4)

Pinouts of 1602 LCD display with I2C

Displays the game environment, including the spaceship and enemies.

Jumper Wires

Jumper wires

Jumper wires will be used to make connections between the components.

Breadboard:

Breadboard

A breadboard can be used to create a temporary circuit for testing and prototyping.

 

Component Wiring

1- Joystick to ESP32 :

GND → GND

VCC → 3V3

X-axis (VRx pin ) → GPIO34

Y-axis (VRy pin) → GPIO35

Button (SW pin) → GPIO33

LCD Screen (I2C-based) to ESP32 :

SDA → GPIO21 (I2C Data).

SCL → GPIO22 (I2C Clock).

VCC → 5V

GND → GND

 

Programming ESP32 with Micropython

1- Ensure MicroPython is installed on your ESP32

2- Flash your ESP32 with MicroPython using this file esp32-20210902-v1.17.bin

3- Import this two libraries : i2c_lcd and lcd_api for I2C LCD screen

4- Initialize peripherals (LCD, joystick) and game variables (ship position, etc.).

5- Continuously read joystick input and Update the ship’s position.

6- If we press the joystick, we launch the rocket

7- Refresh the display with updated graphics.

 

Here is the full program :

The Spaceship Game is not just a fun and challenging arcade game. it’s also an excellent project for learning MicroPython, embedded systems, and game design!

0 comment

Leave a comment

Veuillez noter s'il vous plaît*

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Purpose of this website

Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.

Contact details

Zaouiet Kontech-Jemmel-Monastir-Tunisia

+216 92 886 231

medaliprof@gmail.com

Pictures of the articles

Robotic site created by MedAli-Teacher info