CLICK HERE TO DOWNLOAD THE GAME FROM GOOGLE PLAY STORE
Introduction
Is it possible to use A.I. to create video games with appealing graphics, developed across multiple levels of increasing difficulty, including introductory screens, menus, and reward systems based on level completion… in short, a real game that goes beyond the classic Snake from the 1980s, all developed solely with the help of artificial intelligence?
This was the question I asked myself after watching several videos where games were developed from scratch using the ChatGPT bot. Most of these games had simple, rudimentary graphics that resembled productions from the early ’80s rather than recent creations.
So, I decided to venture into something more complex, using the paid version of ChatGPT and the Unity game engine.
Tools
ChatGPT 4o paid versiono.
Unity release 2022.3.46f1
First approach: what type of game to create
I’m not a programmer, I don’t make video games professionally, and I don’t usually play them either.
But I enjoy creating them in my free time. I find the connection between art, creativity, logic, development strategy, and the math behind algorithms fascinating.
It’s a blend of science and art in the game development process.
A few hours a week, I retreat to my corner; I could paint, do puzzles, write, or read a book plenty of activities to keep the mind sharp. But no, I open Unity (for those who don’t know, it’s a game engine, a program for making game programs) and start writing code.
Most of the time, what comes out are atrocious monstrosities that I abandon, only to start from scratch the next time.
This time, though, things were different. I thought, why not use A.I. to create video games ? I sit at my desk, searching for that creative spark for my hour of mental exercise, but I come up with nothing.
So I take the world’s most famous chatbot and type: “give me an idea for an app,” and it suggests something that I later called the Parable of the Sower: a farmer throws seeds, and the player has to direct the wind to make them fall on the soil instead of on rocks or thorns.
I think, “Did OpenAI also give this bot mystical visions?” But the idea wasn’t bad; I rework it and think that instead of seeds, I could use balloons, and rather than making them fall to the ground, I could guide them along a path—more or less complex—to reach the exit.
A.I. TO CREATE VIDEO GAMES: Writing the code
Since I was at it, I also asked ChatGPT it to write the code and graphics, and this is where the interesting experience began. The bot generated the code, but it often contained errors. Most of the time, I ended up spending more time finding and fixing these than if I had written everything from scratch.
Indeed, the more complex my requests were, the more errors it made. I also started having trouble following the flow of what it was doing and its programming logic.
So I changed my strategy: I still wanted to use A.I. to create video games, but I would decide on the program’s logic. I’d have it handle small pieces of code, essentially the groundwork of what I needed, and then I’d refine it based on what I wanted.
This worked well. It saved me a lot of time, I maintained control over the produced code, and I progressed faster than ever before.
This time, I finished my little creation.
You can find it on the Play Store by searching for ColorfulFlight; here’s the link.
Conclusions – USING A.I. TO CREATE VIDEO GAMES … Did it work ?
Today, and I mean today, November 13, 2024, at 7:30 p.m. as I write this article, we’re still far from being able to use A.I. to create video games, or more generally, to have Artificial Intelligence write a complete, complex code without errors.
Developer oversight and control are necessary to understand how the code was created, which is essential for future modifications and for understanding the results.
Tomorrow, I’m not sure; AI development is progressing so quickly that I no longer know what to expect.
However, I’m convinced that AI should remain a tool to handle the “grunt work,” allowing us to retain control over the outcome and fine-tune the details.
“Power is nothing without control,” said an old Pirelli ad, and that’s how AI should be.
So, can AI be used to create a complex video games from scratch? The answer is: not yet, at least not as I had imagined, but we’re not too far off, and the support it provides is immense.
Returning to the game development, I had a great time creating increasingly complex paths with traps, secret moves, and other surprises that you’ll have to discover to progress. Enjoy!
The CHAT with the BOT
If you’re curious, I’ll copy part of my discussion with ChatGPT below, just to give you an idea of how things went.
ME: Think of a simple yet original 2D game to create with Unity, not too complicated.
An idea for a simple yet original 2D game to make with Unity could be “Master of the Wind.”
Game Description:
In “Master of the Wind,” the player controls a character who has the power to control the wind. The goal of the game is to guide plant seeds through various levels to make them sprout in specific locations. The player uses the wind to move the seeds, avoiding obstacles and solving small environmental puzzles.
Game Mechanics:
- Wind Control: The player draws the direction and intensity of the wind with the mouse (or touch on mobile devices) to influence the seeds’ movement.
- Environmental Obstacles: Obstacles like rocks, animals, or opposing air currents that the player must navigate around.
- Interactive Elements: Objects like fans, barriers, and trampolines that can be activated or deactivated to help the seed reach its destination.
- Scoring System: The player is rewarded based on time spent and the number of wind gusts used to complete the level.
Why It’s Simple Yet Original:
- Technical Simplicity: The core mechanics can be achieved using Unity’s 2D physics, simulating the wind through forces applied to the seeds.
- Minimalist Graphics: A simple, clean art style minimizes the time needed to create visual assets.
- Originality: Combines puzzle and strategy elements with an innovative wind control mechanic based on drawing, offering a fresh experience to players.
Development Tips:
- Initial Tutorial: Include introductory levels to teach the player how to control the wind and interact with game elements.
- Difficulty Progression: Introduce new obstacles and elements as the game progresses to keep the player engaged.
- Music and Sound Effects: Relaxing background music and ambient sounds can enhance the gameplay experience.
This game strikes a good balance between development simplicity and an original concept that stands out. Plus, it lets you explore various Unity features, such as input handling, 2D physics, and game object interactions.
ME : Give me instructions and code for a first draft of the game. I’ve already installed Unity and created a new project. I’m ready to start.
Sure! I’ll guide you step by step in creating a first draft of “Master of the Wind” using Unity. This draft will include the basic mechanics: wind control and seed movement. Make sure you have a recent version of Unity installed and a new 2D project ready.
Step 1: Project Setup
Create a New 2D Project:
- Open Unity Hub and click on “New Project.”
- Select the “2D” template.
- Name the project, for example, “MaestroDelVento.”
- Click “Create.”
Set Up the Main Scene:
- Save the current scene by going to File > Save As… and name it “MainScene.”
- In the Project window, create the following folders to organize assets:
Sprites
Scripts
Prefabs
Scenes
Step 2: Creating Game Elements
1. Create the Seed
- Create a Seed:
- Go to GameObject > 2D Object > Sprite > Circle.
- Rename the object to “Seed.”
- Position it at the center of the scene (0,0,0).
- In the Sprite Renderer component, change the color if you want to differentiate it.
- Add Components to the Seed:
- With the Seed selected, click on Add Component and add:
- Rigidbody 2D: Set Gravity Scale to 0.
- Circle Collider 2D.
2. Create the Target (Germination Point)
- Create the Target:
- Go to GameObject > 2D Object > Sprite > Square.
- Rename the object to “Target.”
- Position it somewhere in the scene to represent the destination.
- Resize the object to make it distinguishable.
- Add a Collider to the Target:
- Add a Box Collider 2D to the Target.
- Check the Is Trigger box in the collider.
3. Create Obstacles
- Create an Obstacle:
- Go to GameObject > 2D Object > Sprite > Square.
- Rename the object to “Obstacle.”
- Position it between the Seed and the Target.
- Add a Box Collider 2D.
Step 3: Implementing Wind Control
1. Create the WindController Script
- Create the Script:
- In the Scripts folder, right-click and select Create > C# Script.
- Name the script “WindController.”
- Add the Script to a GameObject:
- Create a new Empty GameObject and name it “WindManager.”
- Drag the
WindController
script ontoWindManager.
2. Code for the WindController Script
Open the script WindController and insert the following code :
using UnityEngine;
public class WindController : MonoBehaviour
{
public float windForce = 5f;
private Rigidbody2D seedRigidbody;
void Start()
{
GameObject seed = GameObject.Find(“Seme”);
if (seed != null)
{
seedRigidbody = seed.GetComponent<Rigidbody2D>();
}
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
ApplyWindForce();
}
}
void ApplyWindForce()
{
Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 direction = (mousePosition – seedRigidbody.position).normalized;
seedRigidbody.AddForce(direction * windForce, ForceMode2D.Impulse);
}
}
Code Explanation:
Public Variables:
- windForce: Determines the intensity of the wind.
Private Variables:
- seedRigidbody: Reference to the Rigidbody2D component of the seed.
Start():
- Finds the Seed object in the scene and retrieves its Rigidbody2D component.
Update():
- Checks if the left mouse button has been pressed.
- Calls the
ApplyWindForce()
function.
ApplyWindForce():
- Converts the mouse position to world coordinates.
- Calculates the direction from the seed to the clicked point.
- Applies a force to the seed in that direction.
Step 4: Implementing Win Logic
1. Create the Goal Script
- Create the Script:
- In the Scripts folder, create a new script named “Goal.”
- Add the Script to the Target:
- Drag the
Goal
script onto the “Target” object.
2. Code for the Goal Script
using UnityEngine;
using UnityEngine.SceneManagement;
public class Goal : MonoBehaviour
{
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.name == "Seme")
{
Debug.Log("Livello completato!");
// Puoi aggiungere qui la logica per caricare il livello successivo
// Ad esempio: SceneManager.LoadScene("ProssimoLivello");
}
}
}
Code Explanation:
OnTriggerEnter2D(Collider2D other):
- Called when an object with a Rigidbody2D enters the trigger zone of the Target.
- Checks if the object is the Seed.
- If true, it prints a completion message.
Step 5: Adding Visual Feedback
- Particle Effect for Wind
Create a Particle System:
Go to GameObject > Effects > Particle System.
Rename the object to “WindEffect.”
Place it as a child of “WindManager.”
Configure the Particle System:
Adjust the parameters to simulate wind (speed, direction, duration).
Control Particle Emission in the WindController Script:
Modify the WindController script to activate the effect when wind is applied.
// Aggiungi in cima allo script
private ParticleSystem windEffect;
void Start()
{
// Codice esistente...
windEffect = GetComponentInChildren<ParticleSystem>();
}
void ApplyWindForce()
{
// Codice esistente...
if (windEffect != null)
{
windEffect.Play();
}
}
Step 6: Interaction Improvements
- Drawing Wind Direction
Add a Line to Show the Direction:
Create a new script called “WindVisualizer” and add it to “WindManager.”
WindVisualizer Script Code:
using UnityEngine;
public class WindVisualizer : MonoBehaviour
{
private LineRenderer lineRenderer;
private Vector2 startMousePosition;
void Start()
{
lineRenderer = gameObject.AddComponent<LineRenderer>();
lineRenderer.startWidth = 0.05f;
lineRenderer.endWidth = 0.05f;
lineRenderer.positionCount = 2;
lineRenderer.enabled = false;
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
startMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
lineRenderer.SetPosition(0, startMousePosition);
lineRenderer.enabled = true;
}
else if (Input.GetMouseButton(0))
{
Vector2 currentMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
lineRenderer.SetPosition(1, currentMousePosition);
}
else if (Input.GetMouseButtonUp(0))
{
lineRenderer.enabled = false;
}
}
}
Code Explanation:
LineRenderer:
Used to draw a line between two points.
Update():
Draws the line while the mouse is pressed.
Step 7: Adding Wind Force Limits
Modify the WindController Script:
Add a variable to limit wind usage.
public float windCooldown = 1f;
private float windTimer = 0f;
void Update()
{
windTimer += Time.deltaTime;
if (Input.GetMouseButtonDown(0) && windTimer >= windCooldown)
{
ApplyWindForce();
windTimer = 0f;
}
}
Code Explanation:
windCooldown: waiting time between each use of the wind.
windTimer: keeps track of the time elapsed since the last use.
Step 8: Adding Sounds
- Importing Sound Effects
Import the Sounds:
Drag the audio files into the “Audio” folder within Assets. - Adding AudioSource
Add an AudioSource to WindManager:
With “WindManager” selected, click on Add Component and add AudioSource.
Deselect Play On Awake. - Modify the WindController Script to Play the Sound
private AudioSource windAudio;
void Start()
{
// Codice esistente...
windAudio = GetComponent<AudioSource>();
}
void ApplyWindForce()
{
// Codice esistente...
if (windAudio != null)
{
windAudio.Play();
}
}
Step 9: Testing and Debugging
Run the Game:
Click on Play to test the implemented features.
Ensure that the seed moves correctly, visual and sound effects work, and the win logic is active.
Debugging:
Use the Unity console to monitor any errors or log messages.
Step 10: Next Steps
Creating Additional Levels:
Design new levels with increasing obstacles and challenges.
Implementing a Scoring System:
Create a UI to display the score based on time or efficiency.
Graphic Improvements:
Import custom graphic assets to enhance the visual appearance.
Gameplay Optimization:
Adjust parameters to balance difficulty and make the game more engaging.
Conclusion
You now have a working draft of “Wind Master”! This foundation allows you to expand the game by adding new mechanics, levels, and aesthetic improvements. Remember to save your work frequently and experiment to find the gameplay that satisfies you the most.
If you encounter difficulties or have specific questions about any step, I’m here to help. Happy developing!
From here on, I proceeded step by step, introducing something new each time.
At the moment, in my opinion, this is the winning strategy: maintaining control and understanding of the code to be able to correct the bot where it makes mistakes and potentially improve it.