Menu

How games are made for the phone. The best software for creating games for IOS, Android, PC

Ornamental crops for the garden

Many people, when downloading games for mobile platforms, think: "Why not make a dream come true? Why not make your product that will be better and more interesting than what the interactive entertainment industry already offers?" If you do not know how to create games on Android, but want to learn, this article will tell you about some of the pitfalls that await novice developers.

Idea

The first thing that is required to create a game is an idea. At the first stage, it can be written in any form. It is desirable that it "catch" and be understandable. Most likely, in the process of incarnation, it will be changed. Something will have to be added, and something will have to be completely removed or redone. There is nothing strange in this - with further elaboration of the details, the functionality will not only have to be thoroughly described, but also checked for suitability.

You shouldn't completely abandon the initial description of the idea and start creating Russian games on Android, skipping this stage. The collection of thoughts is the main starting point from which it is easiest to start moving. In addition, the ideas set out on paper will allow you to look at your plans more objectively, perhaps mark and correct weaknesses in advance.

Feature List

Since it is impossible to create games on "Android" without their detailed study, at this stage you will have to continue working on and describe the features that will be in the game. For example, the God of War series is a slasher. The main character's weapon is a whip. During the battle, you can make long beautiful combo attacks. Each level ends with a boss fight.

This list is rather stingy and only reflects the main features, that is, those that set the game apart from others. In fact, there are many more, but other features are secondary. When describing, the first should go those without which your future creation cannot exist, and the last - less important ones, which can be sacrificed for the sake of the speed of development.

Dizdok

So how to create new game without this document it is almost impossible, you will have to work on it too. Dizdok is an abbreviation for "design document", it includes the most detailed descriptions:

  • Object model and entity functionality.
  • Functional specifications.
  • Game content.
  • Interface.
  • A knowledge base can be added as needed.
  • Object model.

Object Model

The object model contains information about each game entity: weapons, armor, NPCs, spells, player. It is unique to each game.

Functionality should be understood as:

  • Can I put on / take off / buy / sell / improve.
  • Will it remain in the inventory after death.
  • Will it lose strength over time or with some kind of action.
  • Whether it increases the characteristics of a character or a group.
  • Whether the set has special properties.

The points described above are optional, their number can be reduced or increased for each individual group of entities.

Functional specifications

Continuing the answer to the question of how to create games for Android, you should talk about the next section of the design doc. The functional specifications describe the gameplay piece by piece. Here you need to tell as accurately as possible what the main character can do and how it is implemented. The same must be done for each NPC separately. In addition to the playable characters, first-aid kits, weapons, armor, and environmental elements should be touched upon.

In fact, this section is a set of rules that affects all game moments, from the menu to how damage from a hit will be calculated. The more you work out each individual point, the easier it will be to implement your project.

Content

Before you create a good game, you need to think about what exactly will be in it. When describing the specifications, you can specify that the characters will shoot from firearms, which are loaded with ammunition with a fixed damage. When hitting an NPC, the power of the armor will be deducted from this parameter. You will also need to indicate the name of each individual sample of weapons, armor, NPCs. And, of course, it is necessary to describe the Content - these are the bricks from which the whole game will subsequently be built.

Interface

The interface is a set of functions and buttons with which the user will interact with the program. The main thing to consider when creating it is convenience. To understand exactly how to organize all the elements, you can run and analyze the best examples of the genre, transferring the most appropriate solutions to your project.

Choosing an engine or constructor

One more step that will have to be completed before creating games on Android is to choose. Long gone are the days when everything had to be done from scratch. Today, taking a ready-made constructor, you can do all the work by writing a minimum of code.

The choice of the engine should be made based on some of its features:

  • Terms of Use.
  • Possibilities.
  • Price.
  • Developer support.
  • Documentation.
  • Community size.
  • Simplicity.
  • Extensibility.

Terms of Use: it is possible that having bought a constructor once, you will not become its full owner. It happens that with the commercial success of the game, you have to pay a percentage of the profits to the engine developers. The main thing is that before creating games on Android, familiarize yourself with the product chosen for implementation.

Possibilities: they must completely cover the needs of the developer. If the product offers more than it needs, the game can be easily expanded and new features of the design dock can be used. But think about balance too! Using the Unreal Engine for Tetris is silly.

Support: First of all, it is important to find out whether the product has development? Are bugs fixed from version to version? Is it acquiring new functionality and tools? An engine that is rapidly evolving has an edge over an engine that was frozen a few years ago.

Community: how many people use the constructor? If users a large number of, finding documentation, lessons, master classes, examples is not a problem. If there are relatively few users, this information may not be available to the extent that will allow you to do something competitive.

Extensibility: Before creating your own game, take the trouble to find out if it is possible to connect external modules to the selected engine. They are usually used to export or import 3D models, sounds, scripts, sprites. If there is support for such tools, the constructor is not limited only to internal utilities for creating content.

UDK

Unreal Development Kit is not the easiest to learn game engine, but one of the most powerful. It is used not only by novice developers, but also by large corporations. If you are looking for an answer to the question: "How to create a 3D game and which engine to choose for this?" - you should explore the possibilities of the UDK.

The internal scripting language, UnrealScript, is used to describe the program logic. The developer's site provides many lessons, both filmed on video and described in text. At the same time, they cover the maximum functionality - from the editor to writing your own scripts.

Torque 2D / 3D

Torque is one of the most popular game builders for mobile platforms. Has all the necessary set of editors and debugging tools. During development, programmers paid great attention to convenience and tried to make all utilities as simple and accessible as possible.

The constructor comes with documentation that describes most of the features. On the official site you can find tutorials and source codes for several ready-made games.

For writing scripts, Torque has a built-in Torque Script language. The properties of each object can be predefined. Also, the constructor has a built-in Box2D set, which deals with physical calculations.

If you are trying to find an answer to the question: "How to create and which engine to choose for this?" - you can safely say that Torque will allow you to make a multiplayer project in a short time. All the necessary functionality is built in in advance, and the examples on the official website will show you how to use it most efficiently.

The study

After choosing a game engine, it is still unclear how you can create a game. You will have to spend a lot of time on your training. Since there is no team yet, you will need to do everything yourself: write scripts, create textures, sprites, models (if the game is three-dimensional), write a script, test. It is easy to guess that a novice developer will have to grasp the basics of many writers, tester, artist, and designer at once.

It is best to learn by doing, that is, while working on your project. Another way to learn everything you need to do is work for a game development company. At the same time, you should not immediately target the position of the chief programmer: even if you are asked to do routine things, do not refuse the opportunity to look at gamedev from the inside.

Work in any company starts at the bottom, that's okay. And the skills of a scriptwriter, level designer, balancer, tester will be very useful, and these are exactly the industries in which most of the juniors work. After a few years of such classes, it will be possible to learn how to create design documents and technical tasks, learn about bug trackers and form a contact base. After the work done, in order to create Russian games for Android, you will need to spend much less effort, because you will stock up on all the necessary skills and abilities.

It is quite possible that, having proved your competence in development issues, you will not have to leave the old team, moreover, in it you will take a leading position with your project.

There is hardly a person who has never played at least one computer game at least once in his life, no matter if it is on a laptop or a mobile device. Well, who of you, dear reader of our blog, has not dreamed of creating your own game and, if you do not become a millionaire thanks to your project, then become famous at least among your friends?

But how to create a game on Android from scratch without having special knowledge and not even knowing the basics of programming? It turns out that trying yourself as a game developer is not such a difficult task. This will be the topic of our today's material.

  1. Idea or scenario.
  2. Desire and patience.
  3. Game constructor.

And if everything is more or less clear with the first two components of success, then we need to dwell on the third component in more detail.

What is Game Constructor

We are talking about a program that greatly simplifies the development of games, making it accessible to people who do not have programming skills. The game designer combines an integrated development environment, a game engine and a level editor that works as a visual editor ( WYSIWYG- English. abbreviation "what you see is what you get").

Some constructors may be limited to the genre (for example, RPG, arcade, quests). Others, while providing the ability to design games of different genres, at the same time limit the imagination of a novice developer to 2D games.

Even after reading only what has already been written, it becomes clear that for a beginner developer who has decided to write a game for any operating system, including the Android OS, the choice of a suitable constructor is the main task, because the fate of the future project depends on the functionality and capabilities of this tool.

How to choose the right constructor

You need to start by assessing your own level of knowledge in the field of programming. If it tends to zero or is absent at all, then it is better to try the simplest options. And even if you do not have the necessary knowledge of the English language, then in this case you can find a program that suits you.

And the second important point when choosing a constructor is functionality. Here you need to very accurately analyze the scenario of your project, because the more complex the game is, the more various tools you will need to create it, respectively, and the constructor will need a more powerful one.

To help with the choice, below we will present to your attention the best design programs, which, in general, does not exclude the fact that you, having thoroughly rummaged through forums or specialized sites, will choose something else for yourself, since the range of this range of programs quite wide.

Top 5 best game builders

Construct 2

This app consistently ranks at the top of the rankings of game constructors. With Construct 2, you can create 2D games of almost any genre for various platforms, including Android, as well as animation games aimed at browsers that support HTML5.

Taking into account the huge number of auxiliary tools, even novice users will be able to master the program.

To master working with Construct 2, there is no need to buy a license, the free Free version offers ample tools and the ability to export finished project to some platforms. However, coding the finished product for mobile platforms and access to the full range of functionality will give you a Personal license for $ 129. If your skill in creating games has reached its climax, and you have already begun to receive more than $ 5,000 in income from your project, you will have to fork out for the Business option, which will cost $ 429.

Now, check out some hands-on video tutorials on building gaming applications with Construct 2:

Clickteam fusion

Clickteam Fusion is another example of an excellent full-fledged game constructor that helps even a beginner to create a full-fledged game. The program provides the ability to export created applications completely free of charge in HTML5 format, which means that it will be possible to publish browser games and, in addition, convert them for publication in various mobile markets, for example, Google play.

The main characteristics include the simplicity of the interface, support for shader effects and hardware acceleration, the presence of a full-fledged event editor, saving projects in formats compatible with various platforms, including Android.

The paid Developer version of the program is not available for residents of the Russian Federation, but its licensed disc can be ordered from the same Amazon, lightening the personal budget by an average of $ 100. It is possible to Russify the menu through a third-party crack.

How to work with the application, watch a special video course:

Stencyl

Stencyl is another great tool that allows you to develop simple 2D computer games without special knowledge of codes, as well as programming languages ​​for all popular platforms. Here you have to work with scenarios and diagrams, which are presented in the form of blocks, and you can drag objects or characteristics with the mouse, which is very convenient.

The developer of the program also offers the opportunity to write his own code in blocks, but this, of course, will require knowledge in the field of programming.

The presence of an excellent graphic editor Scene Designer allows the user to apply their imagination to drawing game worlds.

The optimal set of functions will help to create high-quality games of different genres, but the most tiled (tiled) Stencyl graphics will be relevant for "shooters" or "adventure games".

The program is distributed free of charge, but export to desktop formats requires a subscription, which will cost $ 99 for a year, and a license for mobile games- $ 199 per year.

Watching a crash course on working with Stencyl:

Game maker

The program exists in paid and free version. A budget option allows you to create solid two-dimensional games for the desktop. While the paid version makes it possible to write rather "fancy" 3D toys for Windows, iOS and Android. For now, we are interested in a free opportunity to learn how to realize ourselves in the gaming industry, and Game Maker is the very option that will allow you to create games with your own script without restrictions on the choice of genre.

The program offers a selection of ready-made templates for locations, objects, as well as characters, sounds and backgrounds. So, all creative work comes down to dragging and dropping selected elements into the work area and choosing conditions - location and interaction with other objects. Although knowledge of the programming language is not required, but users who are "in the subject" will be able to use GML, something similar to JS and C ++.

Game Maker is distributed in English, so those who do not know it sufficiently will need to download the localization file.

Who is interested in this program, we suggest watching the training video:

Unity 3D

Unity 3D is perhaps the best thing to offer for creating a quality 3D project. Completely ready-made models, as well as textures and scripts are integrated into the program. In addition, it is possible to add your own content - sound, images and videos.

Games created with Unity are compatible with all popular platforms from iOS or Android mobile devices to SMART TVs.

The program features high compilation speed, easy-to-use interface, flexible and multifunctional editor.

All game actions and behavior of characters are based on a solid physics core PhysX. Each object created in this game constructor is a certain combination of events and scripts, controlled by the developer himself.

It is important to understand that although the program is positioned as a game constructor designed for beginners, a certain level of knowledge is still needed to work with this application. Well, working with 3D graphics requires a fairly modern computer equipped with a hardware video card.

A series of lessons on creating games with Unity 3D:

So, you decided to realize your dream of creating your own unique game. We have tried to provide information that can help with this. Please note that if you carefully read the material presented, and at least skimmed through the video tutorials for each program, you probably noticed that working with each game constructor is based on the same principle. Therefore, it is quite possible that you can choose something more suitable for your needs. We at least hope that at this stage the question of how to make a game on Android yourself is closed. Good luck!

This tutorial is intended primarily for beginners in Android development, but it may also be useful for more experienced developers. Here's how to create a simple 2D Android game without using any game engines. I used Android Studio for this, but any other appropriate set up development environment can be used.

Step 1. Coming up with the idea of ​​the game
Let's take a fairly simple idea as an example:

At the bottom of the screen is a spaceship. It can move left and right by pressing the corresponding buttons. Asteroids move vertically down from the top. They appear across the entire width of the screen and move at different speeds. The ship should dodge meteorites for as long as possible. If a meteorite hits it, the game is over.


Step 2. Create a project
In Android Studio, in the top menu, select File → New → New Project.

Here we enter the name of the application, domain and path. Click Next.

Here you can enter the android version. You can also choose an android watch and TV. But I'm not sure that our application will work on all this. So it's better to enter everything as in the screenshot. Click Next.

Here, be sure to select Empty Activity. And click Next.

Here we leave everything as it is and click Finish. So the project has been created. Let's move on to the third step.

Step 3. Add pictures

Step 5. Editing the MainActivity class

First of all, add implements View.OnTouchListener to the class definition. The class definition will now be like this:

Public class MainActivity extends AppCompatActivity implements View.OnTouchListener (
Add the required static variables (class variables) to the class:

Public static boolean isLeftPressed = false; // left button pressed public static boolean isRightPressed = false; // right button pressed
To procedure protected void onCreate (Bundle savedInstanceState) (
add the lines:

GameView gameView = new GameView (this); // create gameView LinearLayout gameLayout = (LinearLayout) findViewById (R.id.gameLayout); // find gameLayout gameLayout.addView (gameView); // and add gameView Button leftButton = (Button) findViewById (R.id.leftButton); // find buttons Button rightButton = (Button) findViewById (R.id.rightButton); leftButton.setOnTouchListener (this); // and add this class as a listener (onTouch will be triggered when clicked) rightButton.setOnTouchListener (this);
Classes LinearLayout, Button, etc. highlighted in red because they haven't been added to Import yet.
To add to Import and remove the red highlight, you need to press Alt + Enter for each.
GameView will be highlighted in red because this class does not exist yet. We'll create it later.

Now we add the procedure:

Public boolean onTouch (View button, MotionEvent motion) (switch (button.getId ()) (// define which button case R.id.leftButton: switch (motion.getAction ()) (// define pressed or released case MotionEvent. ACTION_DOWN: isLeftPressed = true; break; case MotionEvent.ACTION_UP: isLeftPressed = false; break;) break; case R.id.rightButton: switch (motion.getAction ()) (// define pressed or released case MotionEvent.ACTION_DOWN: isRightPressed = true; break; case MotionEvent.ACTION_UP: isRightPressed = false; break;) break;) return true;)
If someone is confused, this is how the MainActivity class should look like as a result:

Package com.spaceavoider.spaceavoider; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.widget.Button; import android.widget.LinearLayout; public class MainActivity extends AppCompatActivity implements View.OnTouchListener (public static boolean isLeftPressed = false; // left button pressed public static boolean isRightPressed = false; // right button pressed @Override protected void onCreate (Bundle savedInstanceState) (super.onCreate) (savedInstanceState) ; setContentView (R.layout.activity_main); GameView gameView = new GameView (this); // create gameView LinearLayout gameLayout = (LinearLayout) findViewById (R.id.gameLayout); // find gameLayout gameLayout.addView (gameView); / / and add gameView Button leftButton = (Button) findViewById (R.id.leftButton); // find Button buttons rightButton = (Button) findViewById (R.id.rightButton); leftButton.setOnTouchListener (this); // and add this class as a listener (when clicked, onTouch will be triggered) rightButton.setOnTouchListener (this);) public boolean onTouch (View button, MotionEvent motion) (switch (button.getId ()) (// define which button case R .id.leftButton: switch (motion.getAction ()) (// determine whether it is pressed or released case MotionEvent.ACTION_DOWN: isLeftPressed = true; break; case MotionEvent.ACTION_UP: isLeftPressed = false; break; ) break; case R.id.rightButton: switch (motion.getAction ()) (// define pressed or released case MotionEvent.ACTION_DOWN: isRightPressed = true; break; case MotionEvent.ACTION_UP: isRightPressed = false; break;) break; ) return true; ))
So, the MainActivity class is ready! In it, the not yet created GameView class is initiated. And when the left button is pressed - the static variable isLeftPressed = true, and when the right one - isRightPressed = true. In general, this is all that he does.

To begin with, we will make the spaceship displayed on the screen, and so that it moves by pressing the control buttons. Let's save the asteroids for later.

Step 6. Create the GameView class

Now let's finally create the missing GameView class. So let's get started. Add extends SurfaceView implements Runnable to the class definition. Mobile devices have different screen resolutions. It can be an old small phone with a resolution of 480x800, or a large 1800x2560 tablet. In order for the game to look the same on all devices, I divided the screen into 20 parts horizontally and 28 vertically. I named the resulting unit of measurement unit. Other numbers can be selected. The main thing is that the relationship between them is approximately preserved, otherwise the image will be elongated or compressed.

Public static int maxX = 20; // horizontal size public static int maxY = 28; // vertical size public static float unitW = 0; // pixels per unit horizontally public static float unitH = 0; // pixels per unit vertically
unitW and unitW will be calculated later. We also need other variables:

Private boolean firstTime = true; private boolean gameRunning = true; private Ship ship; private Thread gameThread = null; private Paint paint; private Canvas canvas; private SurfaceHolder surfaceHolder;
The constructor will be like this:

Public GameView (Context context) (super (context); // initialize objects for drawing surfaceHolder = getHolder (); paint = new Paint (); // initialize thread gameThread = new Thread (this); gameThread.start ();)
The run () method will contain an infinite loop. At the beginning of the loop, the update () method is executed
which will calculate the new coordinates of the ship. Then the draw () method draws the ship on the screen. And at the end, the control () method will pause for 17 milliseconds. After 17 milliseconds, run () will start again. And so on until the variable gameRunning == true. These methods are:

@Override public void run () (while (gameRunning) (update (); draw (); control ();)) private void update () (if (! FirstTime) (ship.update ();)) private void draw () (if (surfaceHolder.getSurface (). isValid ()) (// check if surface is valid if (firstTime) (// initialization at first start firstTime = false; unitW = surfaceHolder.getSurfaceFrame (). width () / maxX ; // calculate the number of pixels in the unit unitH = surfaceHolder.getSurfaceFrame (). height () / maxY; ship = new Ship (getContext ()); // add the ship) canvas = surfaceHolder.lockCanvas (); // close the canvas canvas .drawColor (Color.BLACK); // fill the background with black ship.drow (paint, canvas); // draw the ship surfaceHolder.unlockCanvasAndPost (canvas); // open the canvas)) private void control () (// pause for 17 milliseconds try (gameThread.sleep (17);) catch (InterruptedException e) (e.printStackTrace ();))
Pay attention to initialization on first start. There we calculate the number of pixels in the unit and add the ship. We haven't created the ship yet. But first, we will create its parent class.

Step 7. Create the SpaceBody class

It will be the parent of the Ship and Asteroid class. It will contain all the variables and methods common to these two classes. Add variables:

Protected float x; // coordinates protected float y; protected float size; // size protected float speed; // speed protected int bitmapId; // image id protected Bitmap bitmap; // picture
and methods

Void init (Context context) (// compress the image to the desired size Bitmap cBitmap = BitmapFactory.decodeResource (context.getResources (), bitmapId); bitmap = Bitmap.createScaledBitmap (cBitmap, (int) (size * GameView.unitW), ( int) (size * GameView.unitH), false); cBitmap.recycle ();) void update () (// new coordinates will be calculated here) void drow (Paint paint, Canvas canvas) (// draw a picture canvas.drawBitmap (bitmap, x * GameView.unitW, y * GameView.unitH, paint);)
Step 8. Create the Ship class

Now let's create a Ship class. It inherits the SpaceBody class, so we add extends SpaceBody to the class definition.

Let's write a constructor:

Public Ship (Context context) (bitmapId = R.drawable.ship; // define initial parameters size = 5; x = 7; y = GameView.maxY - size - 1; speed = (float) 0.2; init (context); // initialize the ship)
and override the update () method

@Override public void update () (// move the ship depending on the pressed button if (MainActivity.isLeftPressed && x> = 0) (x - = speed;) if (MainActivity.isRightPressed && x<= GameView.maxX - 5){ x += speed; } }
On this, the spaceship is ready! We compile and run everything. A spaceship should appear on the screen. When you press the buttons, it should move to the right and left. Now add the asteroids falling from above. Upon collision with a ship, the game ends.

Step 9. Create the Asteroid class

Let's add an Asteroid class. It also inherits the SpaceBody class, so we add extends SpaceBody to the class definition.

Let's add the variables we need:

Private int radius = 2; // radius private float minSpeed ​​= (float) 0.1; // minimum speed private float maxSpeed ​​= (float) 0.5; // maximum speed
The asteroid should appear at a random point at the top of the screen and fly down at a random speed. To do this, x and speed are set using a random number generator in its constructor.

Public Asteroid (Context context) (Random random = new Random (); bitmapId = R.drawable.asteroid; y = 0; x = random.nextInt (GameView.maxX) - radius; size = radius * 2; speed = minSpeed ​​+ (maxSpeed ​​- minSpeed) * random.nextFloat (); init (context);)
The asteroid must move vertically downward at a certain speed. Therefore, in the update () method, we add speed to the x coordinate.

@Override public void update () (y + = speed;)
We will also need a method to determine if the asteroid collided with the ship.

Public boolean isCollision (float shipX, float shipY, float shipSize) (return! (((X + size)< shipX)||(x >(shipX + shipSize)) || ((y + size)< shipY)||(y >(shipY + shipSize))); )
Let's consider it in more detail. For simplicity, we assume that the ship and the asteroid are squares. Here I went from the opposite. That is, I determine when the squares do NOT intersect.

((x + size)< shipX) - корабль слева от астероида.
(x> (shipX + shipSize)) - ship to the right of the asteroid.
((y + size)< shipY) - корабль сверху астероида.
(y> (shipY + shipSize)) - ship below the asteroid.

Between these four expressions is || (or). That is, if at least one expression is true (which means that the squares DO NOT intersect) - the resulting ones are also true.

I invert all this expression with a sign !. As a result, the method returns true when the squares intersect. What we need.

You can read about the definition of the intersection of more complex shapes.

Step 10. Add asteroids to GameView

Add variables to GameView:

Private ArrayList asteroids = new ArrayList<>(); // asteroids will be harassed here private final int ASTEROID_INTERVAL = 50; // time after which asteroids appear (in iterations) private int currentTime = 0;
also add 2 methods:

Private void checkCollision () (// iterate over all asteroids and check if one of them touches the ship for (Asteroid asteroid: asteroids) (if (asteroid.isCollision (ship.x, ship.y, ship.size)) (// the player has lost gameRunning = false; // stop the game // TODO add an explosion animation))) private void checkIfNewAsteroid () (// add a new asteroid every 50 iterations if (currentTime> = ASTEROID_INTERVAL) (Asteroid asteroid = new Asteroid (getContext () ); asteroids.add (asteroid); currentTime = 0;) else (currentTime ++;))
And in the run () method, add calls to these methods before calling control ().

@Override public void run () (while (gameRunning) (update (); draw (); checkCollision (); checkIfNewAsteroid (); control ();))
Next, in the update () method, add a loop that iterates over all asteroids and calls the update () method on them.

Private void update () (if (! FirstTime) (ship.update (); for (Asteroid asteroid: asteroids) (asteroid.update ();)))
Add the same loop to the draw () method.

Private void draw () (if (surfaceHolder.getSurface (). IsValid ()) (// check if surface is valid if (firstTime) (// initialization on first run firstTime = false; unitW = surfaceHolder.getSurfaceFrame (). Width ( ) / maxX; // calculate the number of pixels in the unit unitH = surfaceHolder.getSurfaceFrame (). height () / maxY; ship = new Ship (getContext ()); // add the ship) canvas = surfaceHolder.lockCanvas (); // close the canvas canvas.drawColor (Color.BLACK); // fill the background with black ship.drow (paint, canvas); // draw the ship for (Asteroid asteroid: asteroids) (// draw asteroids asteroid.drow (paint, canvas); ) surfaceHolder.unlockCanvasAndPost (canvas); // open the canvas))
That's all! The simplest 2D game is ready. We compile, run and see what happened!
If someone is confused or something does not work, you can download the source.

The game is, of course, primitive. But it can be improved by adding new functions. First of all, you should implement the removal of asteroids that flew off the screen. You can make the ship can shoot at asteroids, so that the game will gradually speed up, add a timer, a table of records, and more. If you are interested, I will write a sequel, where I will describe all this.

That's all. Write reviews, questions, topics of interest to you to continue.

How to quickly write an Android game in Unity

Nowadays, anyone can become a successful mobile game or app developer without the titanic efforts. An example of such a case is Dong Nguyen, who developed Flappy Bird. The game did not have any complex mechanics or graphics, but this did not stop it from becoming popular and bringing its creator fifty thousand dollars a day. However, there was nothing remarkable about the game. All it took to be successful was being in the right place at the right time and a little luck. This can happen today, you just need the right idea.

To demonstrate how easy it is to write something like this, today we'll write our own Flappy Bird using Unity in just 10 minutes.

Playable character

First create a new project and make sure 2D is selected.

Load your bird sprite into the scene. Don't forget to turn on your fantasy!

Then adjust the size of the sprite as you like by dragging it around the corner in the desired direction. The sprite should be visible in the hierarchy window on the left. All objects in the scene are visible in it, and at the moment there should be only two of them: a camera and a bird.

Drag the camera onto the bird and release. The camera should be under the bird, which means that the camera is now the “child” of the bird. Now the position of the camera will be fixed relative to the bird. If the bird moves forward, the camera does the same.

Select the bird again in the scene or in the hierarchy window. You will see a list of options and attributes on the right in a window called Inspector. Here you can manage various variables associated with a specific object.

Now click on Add Component. Choose Physics2D> Rigidbody2D - this is a ready-made set of instructions for applying gravity to our character. Click on Constraints in this panel and then select freeze rotation Z. This will prevent the bird from rotating with the camera in a circle.

In the same way, add a Polygon Collider that tells Unity where the character's boundaries are. Press Play and see how the sprite, along with the camera, falls down infinitely.

So far so good!

Now it's time to start flying the character, since it won't be difficult.

First you need to create a C # script. Create a folder for it (right-click somewhere in assets and create a "Scripts" folder), right-click and choose Create> C # Script.

Let's call it "Character". Double click on it to open it in your IDE, be it MonoDevelop or Visual Studio. Then add the following code:

Public class Character: MonoBehaviour (public Rigidbody2D rb; public float moveSpeed; public float flapHeight; // This is needed for initialization void Start () (rb = GetComponent ();) // Update is called once per frame void Update () (rb .velocity = new Vector2 (moveSpeed, rb.velocity.y); if (Input.GetMouseButtonDown (0)) (rb.velocity = new Vector2 (rb.velocity.x, flapHeight);) if (transform.position.y> 18 || transform.position.y< -19) { Death(); } } public void Death() { rb.velocity = Vector3.zero; transform.position = new Vector2(0, 0); } }

This code does two things. It makes the character move forward at a speed that we define in the inspector, and creates the feeling of a bird flying. The Update () method is called repeatedly throughout the game, so whatever you put here will run continuously. In this case, we are adding some speed to our object. The rb variable is the RigidBody2D script that we applied to our object earlier, so when we write rb.velocity we are referring to the object's speed.

A tap on the screen is interpreted by Unity as a mouse click if you are using a mobile device. After clicking, we make the character move up a little.

The moveSpeed ​​variable will be responsible for the movement speed, and the flapHeight variable - for the increase in the bird's flight height after each click. Since these variables are declared public, we can change them outside of the script.

The Death () method is also declared public, which means that other objects and scripts can call it. This method simply returns the character's position to the start. It will also be used every time the character flies too high or low. You will soon understand why it is declared as public. Line rb.velocity = Vector3.zero; is needed to remove the impulse - do we want the character to fall faster and faster after each death?

Now you can exit the IDE and add the script as a component to your character. To do this, select our bird and click Add Component> Scripts> Character. Now we can define moveSpeed ​​and flapHeight in the inspector (this is what public variables are for). Let's assign the variables the values ​​3 and 5, respectively.

And one more thing: in the inspector, you need to add a tag to the character. To do this, click where it says Tag: Untagged and then select Player in the drop-down list.

Obstacles

Now let's add obstacles: pipes. Someone in the pipes finds mushrooms, and someone - their death.

Drag the pipe sprite into the scene where the first obstacle should be and name it pipe_up.
Now let's create a new script called Pipe:

Public class Pipe: MonoBehaviour (private Character character; // This is needed for initialization void Start () (character = FindObjectOfType ();) // Update is called once per frame void Update () (if (character.transform.position.x - transform.position.x>

Add this script to the pipe sprite in the same way as before. Thus, the pipe will return to the screen after going beyond its left border. We haven't done anything here yet, but we'll come back to this.

The OnCollisionEnter2D () method is called every time the pipe interacts with the character. After that, the previously created Death () method is called, returning the player to the starting point.

So we have one pipe that will fade in and out from time to time at the other end of the screen. If you hit it, you will die.

Inverted pipes

Right now we only have one pipe sprite. Let's add another one. To do this, right-click in the hierarchy window, click New 2D Object> Sprite and then select the sprite you want to use. It's even easier to just drag and drop the file into the scene again.

Name this sprite pipe_down. In the inspector under the Sprite Renderer, select the Flip Y option to flip the pipe upside down. Add the same RigidBody2D.

Now let's write a new C # script called PipeD. It will contain similar code:

Public class PipeD: MonoBehaviour (private Character character; // This is needed for initialization void Start () (character = FindObjectOfType ();) // Update is called once per frame void Update () (if (character.transform.position.x - transform.position.x> 30) ()) void OnCollisionEnter2D (Collision2D other) (if (other.gameObject.tag == "Player") (character.Death ();)))

Prefabs

So, this code is enough for us to make the whole game. We could move the pipes to the right side of the screen every time they disappear, or copy and paste as many pipes as we would like to see throughout the game.

If you go the first way, then making sure that the pipes are as they should after random generation, and maintaining an honest course of things would be difficult. After the death of the character, they could appear kilometers from the first pipe!

If you go the second way, then everything will end up with unnecessary memory consumption, with the resulting slowdown of the game, and limited replayability, tk. everything is in the same place every time.

Let's use prefabs instead. To put it simply, we will turn our pipes into templates that we can then use to efficiently create more pipes as desired. If there are programmers here, then treat the Pipe script as a class and pipes as instances of this object.

To do this, create a new folder "Prefabs". Then drag pipe_up and pipe_down from the hierarchy window to the folder.

Every time you drag an object from this folder into the scene, it will have the same properties, so you don't have to constantly add components. Moreover, if you resize a component in a folder, it will affect all pipes in the game, and you do not have to change each of them separately.

As you can imagine, this will greatly save our resources. It also means that we can interact with objects from code. We can create instances of our pipes.

First, add this code to the conditional statement in the Update () method of the Pipe script, which we left blank:

Void Update () (if (character.transform.position.x - transform.position.x> 30) (float xRan = Random.Range (0, 10); float yRan = Random.Range (-5, 5); Instantiate (gameObject, new Vector2 (character.transform.position.x + 15 + xRan, -10 + yRan), transform.rotation); Destroy (gameObject);))

This is needed to create an instance of our gameObject. The result is a new identical copy. In Unity, whenever you use the word gameObject, it refers to the object to which the script is currently attached - in our case, the pipe.

We are re-generating our pipes in random variations to make it more fun.

But instead of doing the same thing in the PipeD script, we generate both objects in the same place. Thus, we can easily set the position of the second pipe relative to the first. It also means we need less code for PipeD.

Create a public gameObject named pipeDown. Then update your code like this:

If (character.transform.position.x - transform.position.x> 30) (float xRan = Random.Range (0, 10); float yRan = Random.Range (-5, 5); float gapRan = Random.Range (0, 3); Instantiate (gameObject, new Vector2 (character.transform.position.x + 15 + xRan, -11 + yRan), transform.rotation); Instantiate (pipeDown, new Vector2 (character.transform.position.x + 15 + xRan, 12 + gapRan + yRan), transform.rotation); Destroy (gameObject);)

Go back to Unity and drag the pipe_down prefab from the prefab folder (this is important!) To the place where it says "Pipe Down" (notice how our camel case is replaced by a space) on the pipe up sprite. If you remember, we defined Pipe Down as a public gameObject, which gives us the ability to determine what this object is from anywhere - in this case, through the inspector. By choosing a prefab for this object, we make sure that when the pipe is instantiated, it will include all the attributes and script that we added earlier. We are not just creating a sprite, but re-creating an object with a collider that can kill the character.

Everything that we add in the same place in the PipeD script is simply Destroy (gameObject) so that the pipe will self-destruct when it goes off the left edge of the screen.

If you start the game now, the screen will advance further automatically, and you will die if you run into any of the pipes. Fly far enough and these pipes will disappear and reappear ahead.

Unfortunately, there is a great distance between the pipes and the screen looks empty. We could fix this by adding a few prefabs to our scene to create a pipeline of constantly appearing pipes. However, it would be better to generate pipes in a script. This is important, because otherwise, after the death of the character, the pipes at the beginning of the path will be destroyed, and empty space will again form.

Thus, we can create the first few pipes during each load of the game and return everything to its place after the death of the character.

Endless flight

Now let's create public variables pipe_up and pipe_down in the Character script. This will give you the ability to reference the generated objects by dragging and dropping prefabs onto the character object, just like when we added pipe_down to the Pipe script.

We need to add these variables:

Public GameObject pipe_up; public GameObject pipe_down;

Then we'll write a method like this:

Public void BuildLevel () (Instantiate (pipe_down, new Vector3 (14, 12), transform.rotation); Instantiate (pipe_up, new Vector3 (14, -11), transform.rotation); Instantiate (pipe_down, new Vector3 (26, 14), transform.rotation); Instantiate (pipe_up, new Vector3 (26, -10), transform.rotation); Instantiate (pipe_down, new Vector3 (38, 10), transform.rotation); Instantiate (pipe_up, new Vector3 ( 38, -14), transform.rotation); Instantiate (pipe_down, new Vector3 (50, 16), transform.rotation); Instantiate (pipe_up, new Vector3 (50, -8), transform.rotation); Instantiate (pipe_down, new Vector3 (61, 11), transform.rotation); Instantiate (pipe_up, new Vector3 (61, -13), transform.rotation);)

We will call it once in the Update () method and once in the Death () method.

After the game starts, Update () is called, and our pipes are installed according to the given configuration. Due to this, the first few obstacles will always be in the same place. After the death of the player, the pipes will go to the same places.

Go back to the scene in Unity and delete the two pipes that are there now. Your "game" will just look like a blank screen with a bird. Press Play and the pipes will appear, after the first few, their position will be randomly determined.

Finally

So we made the whole game! Add a score counter, try to make it more original and increase the difficulty of the game as you progress. It will also not be superfluous to make a menu. It is also a good idea to destroy the pipes on the screen after the death of the character. Once you're done with that, consider having a Play Store-ready game in your pocket! A once similar game made another developer very rich, which proves that you don't need to be a programming genius or have a rich publisher behind you to be successful. You just need good idea and ten minutes!

Want to write Android apps but don't know where to start? Then check out our great for learning Android development.

Greetings to all readers of my blog! Today I want to talk about such an interesting business as creating games for the Android OS. Previously, creating games was a rather painstaking task that required certain knowledge and skills from programmers, artists, and designers. To write a more or less serious game, it was necessary to assemble a team, find funding, create an engine on which it would work, write thousands of lines of code, double-check the game's performance and catch errors dozens of times.

Today, the creation of games for both computers and mobile platforms has become much easier, since universal engines and development environments have appeared, or speaking simple languageprograms for creating games for Android and personal computers. About six months ago I considered, and today we will talk about tools for creating full-fledged games.

Now everyone can develop their own game and present it to the public. All that is required is a program for creating games for Android, a little patience, free time and talent. With the help of special tools, development is very easy and simple: you can create your own levels, plots, heroes and monsters, set patterns of character behavior, use physics; you can use already prepared objects, textures, models and animation sets. Basically, programs for creating games for Android make it possible to immediately try them out in simulation mode on a computer to find out how these games will work on different configurations of smartphones and tablets. Now we will look at 2 of the most famous and most functional environments for creating games for Android.

Unity 3d

The most functional tool for developing mobile games is the Unity 3d engine. It was used for such famous android games as: Dead Trigger, The Silent Age, Shattered Planet. This program for creating games for Android allows you to easily create games of any genre: shooters and action games from the first and third person, races, RPGs, strategies, platformers, puzzles - whatever. Many developers create separate libraries and toolkits for Unity, putting them in free access, so that a user who decides to download this program for creating games for Android will have access to various content (character models, levels, textures, sounds, and so on), which he can add to his games.

Example using Unity 3d:



For inexperienced users, the developers of the program for creating Android Unity games 3d have prepared a large number of video tutorials, so everyone can master this engine with proper patience. Games developed with this utility can be redistributed on the Google Play store, but subject to certain terms and conditions - you can find them out by reading the Unity and Google Play license agreement. Thus, the game creator can not only acquire useful developer skills, but also make a profit if the projects developed by him become successful. Below I will provide a video review that will help you get to know this engine better.

DX Studio

The next popular program for creating games for Android, which you can download for free, is called DX Studio. This engine allows you to develop games for Android and Windows platforms: the first uses the OpenGL ES graphics API, and the second uses DirectX.

With the help of this program for creating 3d games for Android, the user can develop sufficiently high-quality projects that contain modern shaders, a particle system, various effects, a reliable physical model, lightmapping and dynamic shadows, and surround sound. Working in this program, you can use third-party libraries (including those from AutoCAD, 3Ds MAX) and create your own objects - the possibilities for the user are extensive.
The DX Studio engine is completely free for users - provided that games developed with it are distributed free of charge. I also attach a video review to this engine, which will show exactly how you can create games:

Modern programs for creating games for Android enable even inexperienced users to develop their own game projects. Creating games is turning from a painstaking and time-consuming activity into entertainment, which means that everyone can try themselves in the gaming industry.

Do you know which ones are the best?