Get the App
SLTechnology News&Howtos  ›  Development  › 

How to write the code for python to make Mini Game?

Shulou Source: shulou.com Published: 2022-06-01 20:49:12 09月26日 Update

This article mainly introduces "how to write the code for python to make Mini Game". In daily operation, I believe many people have doubts about how to write the code for python to make Mini Game. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to write the code for Mini Game by python". Next, please follow the editor to study!

Step1: Hello, Rabbit

Effect:

Step2: adding background

First, load the desired picture; secondly, loop through x and y in turn, and draw the grass effect according to the values of x and y in the loop; the next few lines are to draw the castle on the screen.

Effect:

Step3: let the rabbit move

Next you need to add some real game elements, such as allowing the rabbit to move along with the button.

Effect (can move rabbits):

Step4: turn the rabbit around

OK, now your rabbit can move when you press the button, but wouldn't it be cooler if you could use the mouse to point the rabbit in the direction you chose? So it doesn't always face in one direction.

Effect:

Step5: shoot! Rabbit

Getting rabbits to shoot arrows at their enemies is a bit complicated because you need to track all the arrows, update them, rotate them, and delete them as they run off the screen.

Effect:

Step6: badger, get your weapons!

Well, now there's a castle, and you have a hero who can move and shoot arrows. What else is missing? The enemy who attacked the castle, of course.

In this step, you will randomly create some badgers to rush to the castle. More and more badgers will emerge in the course of the game.

Effect:

Step7: the collision between Badger and Arrow

Badgers rush to your castle, but your arrows have no effect on them! How does this make the rabbit defend its home?

It's time for the arrowhead to kill the badger and the rabbit to protect its castle and win the game.

Effect:

Step8: add the display of health values and time

The game runs pretty well, with attackers and defenders. Now, all you need is a way to show the rabbit's score.

The easiest way is to add a HUD to show the health of the current castle. You can also add a timing to record how long the castle has survived.

Effect:

Step9: win or lose

If you play long enough, even if your health has become 0, the game will continue! Not only that, you can still shoot at these badgers with arrows. This can't be right. You need to add some winning or losing situations to make your game worth playing.

Then let's add the conditions of victory or defeat. You can do this by terminating the main loop and entering the victory / defeat cycle. You need to indicate whether the player wins or not and display it on the screen.

Effect:

Step10: free music and sound effects

The game is pretty good now, but there is no sound. It's a little too quiet. Add a little sound effect to make you feel the game better.

Effect:

Of course, there are all kinds of sound effects. ~ ~ the picture probably can't express emm.

This is the end of the study on "how to write the code for making Mini Game by python". I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Effects Rabbit Castle Arrow Mobile Code Mini Game production Learning Loop next Sound that is screen method time time Victory good Picture Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple macOS Xiaomi Huawei Shulou Technology