📜 ⬆️ ⬇️

It is no exaggeration to say that this is a hyperbole

I offer Friday April theses about What is our life? Ellipse ...

There is no code and meaning, there is no math and links to GitHub. In short, the most not to read. But you read it.

It all started with this muzzle:
')

Rather, it all started with this line.
10 CLS

30 years ago, this command cleared the IBM PC / XT screen. I, as enchanted, looked at the extinct 320 by 200 black dots and realized that now I can ignite them, like stars in the sky. Simple team. Simple guy. And I lit. I lit it so that I still cannot cool down.

The first game, made in the late 80s, was written in BASIC, which did not have a compiler, but was executed by the command interpreter. And therefore, alternating pictures blinked like a blind drink at the sight of Billy Bones.

Pofik Before that, all the animation I created fit in 50 pages of a small notebook. At the bottom of each page we drew a little man who shot an arrow, the arrow flew and hit another man. Then the pages of the notebook were flipped through with the thumb of the right hand - live and and and and and and and and and and and and and and and and and and and and and -and-and-and-and-and-and-and-and and and and-and, and 50 frames of the cartoon caused an approving grunt. It was cool. The most beautiful girls of the school asked for a notebook. Gently put a hand on his shoulder and looked into his eyes. Stop, I'm drowning. Better back to Basik.

So, the first game made on BASIC was called Jaws . Jaws clenched and unclenched. The configuration of the teeth changed. The hero ran inside the mouth, ate fruit and tried not to fall on the tooth.

Short video gameplay


The time has passed. Very fast. Skipped compiler for BASIC, Pascal, C, C ++, JS, Obj-C and Swift.
I made games on everything that is plugged into the outlet, and it was including a very 3D simulator tank test site for the Murom / Arzamas (shh! Strict secret!) Plant armored personnel carriers and that just was not, it is better not to remember.

And suddenly yesterday I had that first game. Imagine? Well, what would you do in my place? And I am the same. 200 lines of code - and oops! The game is in the store , and the code is on GitHub .

What has changed in 30 years? Programming has changed - before jaws were compressed in a loop with more and more frequency, until they reached the speed of image rendering. And if the computer was weak - the player lived endlessly. Now everything is different. No cycles. Tacts mad. And to calculate the frequency of the collapse of the jaw using math. Let simple, but interesting. We proceed to the conclusion of the formula for the frequency of jaw movement.

Task statement


It is necessary to find the function of the frequency of the jaw collapse. At the start of the game, the jaw clicks 1 time per second, after 3 minutes of play, the frequency should be the limit for human capabilities.

So what do we have?

1) Set the iPhone screen refresh time to 50 hertz. That is 50 times per second. 50 ticks per second. Remember.

2) The ultimate reaction of the player. Recall that the sprinter at the start of the race reacts to a shot with a delay of 280 milliseconds - during this time the signal travels from its brain to its own calf muscles. The iPhone user sends a signal not to the legs, but to its tentacles, the path of the nerve signal of the nerve is shorter by half, = 140 milliseconds - this is the minimum response time. 7 ticks. The hero of the game must run from edge to edge of the jaw for 6 tapas . That is, at least 6 ticks. Total - the jaws, in the limit, can not shrink faster than 6 + 7 = 13 ticks.

3) The initial speed of the jaws - 1 click for 50 ticks. If the jaws click too slowly, the user will drop the game. Therefore, after 5-10 seconds, the frequency should be 1 / 25-1 / 35 tick.

Decision. We have a non-linear function:

f (0) = 50
f (10) = 30
f (10 ^ 10) = 13

Without fools it is clear - this is hyperbole. Write the formula:

f (t) = A + B / (C + t)

Three unknowns - three equations, solve (just a pleasure to solve school problems). The answer is recorded in the program listing.

func setupDelay(_ ticks:Int) { let t = Double(ticks) let a:Double = 12.0 let b:Double = 9000.0/2.2 let c:Double = 100.0/2.2 let d:Double = a + b/(c+t) delay = Int(d) } 

It is interesting to play at the limit of human abilities. Therefore, for those who are gaining more than 1000 points, advertising disappears. Sorry for the guys.

Praise Puno, brother!

Note trans. The code on GitHub is of course a hangover, but pictures, sounds, and some tricks will certainly be useful for beginner swift omans.

UPD: Some iPhone Alexander smacked me and scored 2000 points. I think he, a scoundrel, plays with two hands, but this is not fair.

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


All Articles