📜 ⬆️ ⬇️

My own game. Part 1

Disclaimer


Here is an article about how my friends and I wrote the game. We finished it and sell it, but it does not bring us money. However, it was very interesting and fun for us to do it, and I decided to share my memories. The article will have a minimum of technical details, I will not lay out the code, since it makes no sense to learn from it. This is the code of amateurs, not professionals, there is an error on a mistake. None of us has IT education and no one has ever been professionally engaged in programming. I will sometimes lay out the technical details, as without it, nowhere. I ask readers also not to post comments about what we are fuckers, as it is a shame to read. Though true.

Other parts of the article
Part 2
Part 3

Chapter 1. Prehistoric events


A lot of time passed and I don’t remember very well the small details, however I remember exactly that I came home later than usual and was rather tired when I saw the call of Fyodor Mikhalych. Missed

I'll call you back tomorrow, I thought.

Fedor Mikhalych has always been the heart of our project. And it was like a brain, though, it was not quite true either. I was hands, I guess. Navra, I was rather a back office. And Fedor Mikhalych - the front. Therefore, he always gushing ideas. And I always rudely cut off the flight of his thoughts:

- Fedor Mikhalych, this is impossible, for this you will need to redo everything in the engine, and change half of the Essetes. And this is not to mention the fact that the idea itself is idiotic, I don’t like it - so I’ll then answer Fyodor Mikhalych’s calls to put his ideas in code in a few weeks, call him, and say what I’ve come up with and wrote a cool Thing ... But it will be later.

Before that, there was still about a year. In the meantime, we thought we were writing an MMORPG.

MMORPG we started writing somehow suddenly. Neither I, nor Fedor Mikhalych, nor Dimon, have ever in their life been engaged in professional programming at all, not to mention the development of games. We all worked in the bank, Dimon traded currencies, I - in debt, and Fyodor Mikhalych was involved in supporting trades. And Dimon and Fedor Mikhalych worked in the same bank, and I - in the other. But we were gamers. We wanted to write games. I "dabbled" programming from school, once upon a time I, with the help of Andre Lamotte's book "Programming Games Under Windows", wrote a Wolfenstein game on C, wrote clearly on the book, but my compiler did not know how to build an assembler in C code, so, unlike the book version, my engine worked very slowly. Then I didn’t do programming for a long time at all, until, one day, in one bookstore, my mind didn’t fall on the book “Programming 3D Games under Windows” by Andre Lamotte.

Deja Vu, I thought in French. Since I worked in a French bank, I sometimes had to do that.

But it was a completely different book. I looked through it and realized that this is what is needed. I wanted her. I wanted to do what it said. I called Fedor Mikhalych and asked him to write a 3D game. And he agreed.

My wife prepared a very tasty dinner, but I was very tired and silently picked around the plate. I was thinking about why the code is not going to. It was summer and at work it was boring. I even missed the laptop with me to play in my spare time. In the summer there is no one on the market, and there is plenty of free time at work. And the code was not collected because my global variables were declared in the .h file, and it was included in several .c files. And the compiler cursed redepension.

#ifndef file_h #define file_h 

Will come later. In the meantime, I invented my own bicycle. I invented a lot of them. After reading the Lamotte book, it seemed to me that I could do anything. I started studying OpenGL and it turned out that, in general, I don’t even have to write anything (it was a fixed pipeline, yes. I know a lot about how shaders work, and that I need to write a lot, later). I quickly made a clumsy walker on the surface in the 2D world from the first person (the world is visible in 3D, but the engine did not know how to handle displacements in height, that is, in fact, everything was 2D, as in Wolf). In the book there was a detailed analysis of the Fomata md2 and obj, and I pulled the buttons from the 2nd Quake and from the Internet. Everything was fine, but due to errors like the one above, the code could suddenly stop gathering after small changes. And could not stop. I often puzzled over this at the time, and often invented bicycles.

And yes, I wrote the engine for our MMORPG. And Fedor Mikhalych and Dimon were responsible for almost everything else. I felt like John Carmack. I was fine. But progress was slow. And Fedor Mikhalych constantly called. Here and now. We should call him back.

I thanked my spouse for dinner and poured myself some wine. We need to talk to Fedor Mikhalych. My wife looked at me like a wolf. In her opinion, I had to talk to her. But duty is paramount.

- Hi, Fedor Mikhalych, called?
- Pate, throw this crap, which you write, we are engaged in garbage!
- ???, - Of course, I answered wrong.
- It is necessary to write games for iPhone. The future is mobile gaming.

I must say, Fedor Mikhalych was not the first to come up with this idea. Appstor actively grew. Large projects began to appear, but there was a lot of space on the market. And all there sought.

- Okay. Let's think about it.
- Nehru think. Let's do the game. Just something simpler, not MMORPG, otherwise we will not add anything to retirement. And you have to release it now, before the train leaves.
- Well, I want to write in 3D. How to play iPhone in 3D?
- Hammer, - Fedor Mikhalych was very persistent. - Let's write is not 3D. Let's think about the genre.
- Think. Okay, let me see what's up there. I will put Ikskod and look. When I bought a MacBook myself, I saw that on the disk with it I went for free Ixcode. Like norms Wednesday.
- Well. I threw you a post on the links to sites with tutorials on programming for iPhone. I especially liked some Ray Venderlich. Take a look.
- Good.

Something like this, I plunged into the world of mobile development. Without specialized education, without knowledge of the PLO, without an idea of ​​what to develop. And my first thought when I opened an iPhone programming tutorial was “what an idiotic syntax”. About these words I still describe Objective C.

Then it was more fun. It turns out my usual

 GLBegin(GL_TRIANGLES); GLVertex3f(…); GLend(); 

On the iPhone did not work. GLTranslatef, etc. did not work either. stupidity

- Okay. I knowingly read Lamota, I know how it works, - I thought. And he wrote.

Somewhere, a couple of days, I figured out Vertex Array Objects and how to work with them in the shader. It took me a week to create a project where I could move a cube with an animated texture across the screen. Most of the time it took to draw a series of texts for animation. Sprites After about two weeks I had a little platformer ready. I called him Agent Ivan, in honor of my future Hebrew teacher.



All this time, Fedor Mikhalych thought hard. The fact is that, in his opinion, the platformer did not make sense to write. It was primitive.

“This is primitive,” he said. - That would be more serious. By the way, have you heard that they are going to republish the UFO on a computer?
- X-Com?
- Yes.
- It is high time. Cool game was. By the way, would perfectly fit the touch interface. Will it be released on an iPhone?

Fedor Mikhalych thought.

- Come on.

Now I thought.

- Let's do X-com? We have no rights.
- Well, clone. Not himself X-com. They will release on the computer, and we are on the sly on the iPhone.

It was interesting. We both really liked X-com. Then it seemed to me that creating a clone of X-com was not difficult. Harder platformer, of course, but not much. For half a year should cope. If you're lucky, relax on the iPhone before the remake is released on PC. Will be cool. It will be fun. And, most importantly, this is not a big project. If I made a platformer from scratch in 3 weeks, then Iksky is 6 months. We multiply by 2 at once, so as not to get upset, in total - a year. Cool.

Chapter 2. The beginning of time


We caught fire. I wrote code, Dimon did floor textures and worked with freelancers who made models in md2 format. In addition to the soldiers themselves, for whom the freelancer with whom I worked was responsible. Well, and Fyodor Mikhalych thought over the structure of the game, the plot, the weapon, the architecture of the levels, the balance, and that’s all.

But, most importantly, I wrote the engine on OpenGL, as I wanted.

At first it was difficult. Most of the time I learned to write in Objective C and OpenGL. The smaller one wrote the game itself. But over time, I became involved, and after about a month, animated monsters from Quake 2 in the iPhone simulator were running after my finger in a square textured field (our models were not ready yet). Fedor Mikhalych customized the story for the game:

- There will be a future, but not far. The world is in the power of corporations. And the attacks here and there, suddenly, the whole world in the attacks.
“Terror attacks, this is bad,” I replied.
- Well, by itself, that's the point. And you will fight them.
“Fighting is good,” I replied. - But boring. This is not for you to shoot the Aliens.
- So what. We can and on Alien. As we want, so we will do, this is our game.
- According to the Aliens we can not, it will be X-com. And for people it is not interesting.
- Give on animals, - Feodor Mikhalych was not appeased. He would only burn for someone.
“Sorry for the animals,” I replied.
- Well, come on vile animals.
- Or maybe they are good in the soul?
- Here, you think correctly. And what if it is evil animals in the soul?
- In terms of? - I really did not understand then.
- Well, take Greenpeace. It protects, say, penguins, from extinction.

I was a little taken aback:

- When did the penguins start dying out? - I even got into Wikipedia. No, all right, do not die out. “They are not dying out,” I said out loud, and pointed my finger at the screen.
- Yes, you calm down, - Fedor Mikhalych answered, - it will be necessary, they will start dying out. You get into the idea. They save them from extinction, by creating a mutant penguin with a man to add intelligence to them, so that they stop dying out themselves.
“Human experiments are forbidden,” I retorted.
- Exactly, - Fedor Mikhalych did not let up. Let's say someone got wind of this, and they killed him. And staged the attack. And someone guessed, and he was also killed, like a terrorist attack. Then the deals with the terrorists went, the arms trade, human trafficking, and all this - under the auspices of Greenpeace, to hide the experiments on penguin people.
“Deep,” I said.
- Well, this whole machine of terrorism is gaining momentum and a self-sustaining reaction is already running, are you cutting what I mean?
- Sekou - I really sec. I still seku.
- Well. So it turns out that you seem to be shooting people, and there behind the mutant penguins and all this. It is interesting? - Fedor Mikhalych convinced me. I really found it interesting.

I called the next build of the project “pinguin” and took it upon myself to sharpen the code. Dimon threw about a hundred different textures on the floor, grass, concrete and other things. Fedor Mikhalych also dealt with textures. I in the code generated a floor model consisting of squares. Each square has its own texture. Loaded in memory a handful of models and showed Fyodor Mikhalych how all the fun follows his finger across the screen. In the meantime, the first model of our soldier from a freelancer arrived, and I added it instead of the monsters from Quake 2. In several copies.



But one day Fyodor Mikhalych said that we should see how everything works on the device. And I bought myself a developer subscription. For a while, it took setting up all certificates. For me it was a dark forest, but Fedor Mikhalych managed quickly. We uploaded the project to the phone, launched it, started downloading ... and the application crashed.

Misunderstood.

I started the build in the emulator - work.

The same build on a real device falls.

It's time to turn to debager.

Already at that time everything was relatively good with debugging. I launched the profiler and started looking at the app.

- Somehow a lot of memory goes away, Fedor Mikhalych, look. We have 20 freaks in a square field, and she already ate 150 MB ... 200 ... 250 ... 300 ... fell. - I thought. - Let's count. We create the floor. This is 128x128 squares. Each 4 peaks, it is 16 thousand peaks. Each consists of 3 coordinates and 2 texture coordinates, these are all floats. Total 82 thousand float. And each float is 4 bytes. Total 320 KB. Yes a little?
“Not much,” agreed Fedor Mikhalych.
- Then we load your textures with Dimon. We now have 20 of them. Each 512x512 and 32 bit color. Total 1 MB for texture, 20 MB out. Yes a little?
“Not much,” agreed Fedor Mikhalych.
- Then we ship models of our soldiers. I ship them 20 pieces. Each of 2 thousand polygons, each with 3 vertices, each with 5 floats, each with 4 bytes. Total ... 2.35 MB. Mute?
“Not much,” agreed Fedor Mikhalych.
- Although not. Each model has 95 frames. Total 220 MB.
- Aha, - Fedor Mikhalych agreed, - and the textures on them. 1024x1024 32 bits. Total 80 MB. Just over 300 MB comes out. And this is only a flat field and 20 freaks. And in the game there will be much more enemies on the level. And all sorts of objects. In the simulator, there is no limit on the amount of memory. And in its iPhone 512 MB. The part is occupied by the system, you remain Ponte.

I was devastated. At this rate, to download the level, you have to wait for the release of an iPhone with 5-10 GB of memory. But how? How did Carmack do Quake ???

Source: https://habr.com/ru/post/409825/