In the first week of August, the Chinese government branded online games electronic drugs. Considering that some young Chinese players have been known to spend more than eight hours at a stretch gaming - neglecting studies and family, and foregoing any attempt at a social life, it would be hard to say the government officials are totally wrong.
In many ways, gaming addiction mirrors drug addiction and the effects can be just as devastating.
So what does that mean for your Genshin Impact adventures? Probably nothing,
On the other hand, in keeping with China's policy of harm reduction, development might be slowed down - new weapons and battles might be fewer and farther between, but maybe only for gamers in China.
Genshin Impact is written in C++, the language for programming robots and operating a whole slew of other systems. We have to wonder, though... how hard would it be to write a game's code entirely in Python?
It turns out to be not difficult at all. Read on to find out what Superprof discovered while playing around with Python.
What Is a Computer Game?
You might be thinking 'what kind of question is that?'. Who doesn't know what a computer game is? Well, sure, we all know there are stunning graphics and engaging storylines and intriguing characters and so on. But what is a computer game, actually?
Games played on mobile devices and those driven by gaming consoles must have graphical user interfaces.
Find good python courses London here on Superprof.
These interfaces, amusingly called GUIs (pronounced 'gooeys'), are how users interact with their devices. On your smartphone, sliding your finger across the screen can result in a new menu popping up or, if you have a writing or drawing application open, you'll see a line following your finger's path.
Some phones require you to draw a pattern on the screen so that it will unlock.
All of these examples and more - like touching an icon to open an app are you, interacting with your phone. Playing a game on your phone or via a gaming console is no different: you are causing actions to take place on-screen through the moves you physically make.
Now that we understand computer games are essentially GUIs, let's take a look at some of the best programming languages to write them in.
Earlier, we mentioned that Genshin Impact is written in C++. For a lot of programmers and game code writers, that's the go-to language because it's fast and it renders complex, beautiful graphics. The downside to it, though, is this language's complexity, and that it can be unyielding.
Also, consider that it takes up to 100 people or more to write a game's code. That means each coder has to know the programming language roughly as well as the next. Considering how heavy C++'s syntax is, that's no mean feat.
C++ loses out on cross-platform coding. Even though there are libraries to help adapt the game's code to various operating systems, the language's complexity makes it difficult to use. You really have to know C++ inside and out and how to adapt it to specific platforms to write your game's code in this language.
Java is a great cross-platform language; 97% of all websites manage their pages' behaviour with Java. However, it tends to be very slow - if you know anything about Minecraft, you'll agree that it's not a very dynamic game. Also, Java is not particularly well-adapted to low-end computers unless you're also running an optimization module such as Optifine.
Programmers all aver that VB.net/C# is the gold standard to write game code with but it has a huge Achilles' heel: it does not work across all platforms. We'll get into what the means in the next section.
Python, on the other hand, does away with complex syntax and annihilates the cross-platform question.
First off, unlike C++, Python is an interpretive language. There's no need for translation from source code to machine code. Granted, you lose a bit of performance - an aspect of Python that makes it the ideal language for machine learning.
Second, Python is easily readable and negates the need for extensive coding. Also, thanks to its modular structure, it is less likely to suffer errors, as coding becomes a simple matter of retrieving the desired module from Python's extensive library and plugging it in where it's needed.
With praises thoroughly sung, now comes the downside: if you're creating an action game that demands a high number of frames-per-second (FPS) and a lot of processing power, Python might not be the only language you'll need.
Find good python tutorial here on Superprof.
The Cross-Platform Question
Do you have an iPhone or is yours powered by Android? Do you like to game on a PC or is Mac more your style? Or maybe you're deeply concerned about privacy and security so you've opted for a Linux operating system.
These operating systems and others are known as platforms. They give coders a major headache.
There's a Google Play store for Android apps, the Apple store to download iOS apps and Microsoft has their app store to download apps for their PCs. Visit any of those 'stores' and you'll find all the same apps: Facebook, Snapchat, and many of the same games. That's because they are the same, but for their code.
Game developers and coders in general must always be mindful of which platform(s) they want their applications to run on. If you're designing exclusively for Apple, you can count on losing the Android and Windows markets and, if you only design for Windows... as they have the lowest smartphone market share, you'll lose out on virtually the entire mobile device market.
Older programming languages are not adaptable across platforms; you must code separately for each platform you want your game to run on. Newer, more adaptable languages, Python among them, work well across many different platforms, making it one of the more popular languages to write in.
Granted, Python is not a new language; it's been around for over 30 years but it has recently come into its own, thanks in part to its versatility. Indeed, Python is now touted as one of the best languages for web development, alongside Vue.js and Angular.
Find good python classes here on Superprof.
How to Write Computer Games in Python
Keep in mind that, while Python is easy to work with and has many applications, performance is not one of its top characteristics so, if your game is heavy on graphics and action, you will likely run into trouble if you code only in Python.
However, if you're writing code for a 2D, low-graphics game like Noughts and Crosses or Snake and Apple, Python will more than fit the bill.
Pygame is a library of Python modules written and compiled specifically to create computer games. It includes sound libraries and computer graphics, all ready to be dropped into any Python game program. How does it work?
- get familiar with Tkinter, Python's standard GUI
- learn to draw geometric shapes with its canvas widget
- use the bind widget to identify what action mouse clicks should take
- outline your game by drawing a game flow diagram
- code your game's initialization functions
- code your game's drawing functions
- code your game's logical functions
The logical functions actually run the game. They keep track of user inputs, the state/stage the game is in and they advance the game's progress. They keep track of scores, determine if the game is over and deliver the verdict - win or lose.
Those pesky 'illegal move' messages also originate from the game's logical functions.
This, of course, is just a brief outline of how to code a game using Pygames. Naturally, you'll want to embellish a bit by using different colours and you can even add effects, all of which can be found in Python's code library.
Creating easy games is just one way you can use Python; discover some of the others...
Drawbacks to Writing Games in Python
Probably the biggest downside to writing game code in Python is low performance. Comparing some of the most popular games. like the aforementioned Genshin Impact with its lush graphics and fast action, Python simply can't measure up - either in speed or in the visuals.
As versatile as Python is, it is not suited to the mobile environment. Few mobile devices use Python because its strengths lie in server-side development rather than running power-driven applications. Smartphones and tablets being commonly used for gaming means that, due to its nature and structure, Python games won't get a foothold.
Finally, developing a game in Python can be a bit tedious. For all that its libraries are extensive, well-labelled and easy to use, the process of Python game creation is still quite convoluted. Most developers contend that the effort is not worth the simplistic yield.
Still, a few Python-based games stand out, Frets of Fire and Save the Date among them. Note that Save the Date was 2013's Indicade's finalist entry. Indicade is like the Sundance Film Festival, only for computer games.
Where Python really comes into its own is data science...
The platform that connects tutors and students