How to Eject Viruses on the Corona SDK

image

$google = "We don't allow apps that lack reasonable sensitivity towards or capitalize on a natural disaster, atrocity, conflict, death, or other tragic event";
mysql_query("UPDATE cvirus_users SET winners = winners+19, message='$google' WHERE imea='$imea' ");

No panic guys, the article is not contagious! In addition, its author died last year. There is nothing to do in the next world, except to write and publish games yourself-know-where.

No more than 7 users per day are cut into fresh games. None of them are able to overcome the magic bar. The devils also laugh, - Weak to make a game so that more than 7 people stick to it? Say a thousand?

I had to try.

How did the idea come


Not in the bathroom this time, but in the development process. Two new games were card games, one - three-dimensional BlockOut II (veterans remember), three more on blocks (yatzee and doodo) and, attention, a couple of puzzle for the battle of emoticons against the crown viruses.

The last two ideas were born thanks to the animated stickers sent to me by the Telegram bot. Emoticons hid from funny viruses in them.

In one of the games a bug crawled out, which at first amazed me, then made me laugh, and then it turned out to be a good application of an unknown genre. Conclusion - write carelessly, bots.

Engine


It's been about 3 years since I got hooked on the Corona SDK. I managed to write three-dimensional games on it and even was on the staff of the company, but in 2018 all the loafers were dispersed, and the engine went to open-source. Let me remind you that the Corona SDK is a cross-platform 45 (see hex value) engine for all mobile phones, desktops and HTML5.

Look inside
, , , . : 11- iPhone . Xcode->Window->Devices->Drug and Drop.

Yes, gentlemen, the engine is very smart for development, the prototype of the game is done in a couple of hours, then as many days of grinding and the product is ready. For comparison, the publication on Habré took twice three times four times more time.

Art


I repeat, I took the pictures from the animated stickers in the Telegram - there they are stored in tgs format, in fact it is renamed gzip, it is unzipped to a json file and looks something like this:

{"tgs":1,"v":"5.5.2","fr":60,"ip":0,"op":180,"w":512,"h":512,"nm":"05_STAYHOME_OUT","ddd":0,"assets":[{"id":"comp_0","layers":[{"ddd":0,"ind":1,"ty":3,"nm"

In haste, I began to invent my own program for rendering json, but, having burned myself, I spat on the Internet. And I received in response a telegram bot #GIF Export Bot, which converts tgs-stickers into a GIF file. God, how old I am, I remember GIFs and still so small ... Each GIF stores about 100-200 frames of 512x512 in size. GIMP.app is launched on the GIF, then the scale, transform , well, you know, the main thing is not to get stuck on editing the art ...

image

That's one of the negative characters. Coronovirus - fucking off ... (c) Slepakov.

Game and physics


The Corona SDK has a magical, incredible box2D engine. Watch how the playing field and co-viruses are written on it

 physics.start() 
 physics.setGravity( 0, 0 )
 physics.addBody( downBox, "static", {shape=rect }  )
 physics.addBody( cvirus, "dynamic", {shape=octogon,  density=2, 
          friction=1, bounce=0.2 } )
 physics.setGravity( 0, 9.8 )

--  

 physics.stop() 

--     

 

Basically, I have nothing to add to this piece of code - you all understand.

Game idea itself


Remember the hit Panda ? There (in the field of gravity), panda bears and mommy separate colored cubes. They need to be killed (cubes, not bears), but they nasty multiply like the heads of a Lirnean hydra and do not want to join the Panda gang.

Panda Gangs
. .

So, the colored cubes in this game are located on a uniform orthogonal regular grid. About five years ago, Panda was a bestseller, even I wrote a remix of Hex Rabbit to her. On the same grid, only hexagonal and with the same pandas, only rabbits. I was surprised that rabbits are still being driven - seven (damn you!) People.

And if you check?
, Apple .

Hex-rabbits then painted for me by the artist Andryukha Chesnokov. Bright memory to him. Although he is alive, thank God, move on.

So? Tell me, why do you need a net in this panda game? Take it away, add physics. We replace the evil cubes with octagonal squares (forgive me Professor Ponomarev and analytic geometry) and turn the gang of pandas into koloboks.
Co-viruses against co-pubis.
It’s indecent, but funny. I drive koloboks for the second week, I wait when I'm tired. Thanks to self-isolation, enough time.

Debug physics


Corona has a corresponding function for debugging physics, like this

 physics.setDrawMode( "debug" )  
 

In this mode, elements of the physical world are schematically depicted.

image

By the way, there was a jamb - the glass walls were initially set not very high (three screens) and at some levels the buns fell out. I wondered - where did they go? Probably still fly to the center of the Earth ... Although no, most likely they have already flown taking into account the air resistance K_ {air} = 0.75.

Turn off debug mode

--  physics.setDrawMode( "debug" )  
 

and we get art

image

I admit to you, as an artist to an artist - I limited the animation of sprites to two frames - added the blinking of the heroes, and I'm good. Let Kisa Vorobyaninov draw, I personally - pass.

Level editor


The buttons on the level selection screen were drawn by myself, in the coronavirus style.

image

Initially, he determined 12 levels, thinking of gradually increasing the number of co-viruses and rabbits on the blackboard, which are #anobolics.

He reasoned like this:
On the first two levels, only 2 types of villains live. Green is the most dangerous (c) DMB.
On the next two - more complicated, 3 types of villains live.
Then - 4 species.
Five - the planet cannot be saved.
Sh (G) is - an imposible.

With pleasure I rushed to debug the game and after 24 hours I noticed boredom at levels with 5 or 6 types of monsters. It is difficult to think.

What to do? Oh, I took the skis, went outside, returned, replaced the skis with sticks and ran into the forest. At the 19th minute of the run, the brains started and I abruptly realized - I would add horizontal sticks to the field of play! By type of partitions in open-space . So open-space is a rare muck in life, but in a game it's normal.

Things went - everything was breathing, each level began to demonstrate its character, pulse and temperature. You check too! I mean, the temperature ... The number of playing fields in this setting, you know, is infinite. But counting. I limited myself to a dozen levels and attracted a dunce-third-grader son to debugging, putting one of the fifth iPhone in his hand. And he is happy, there is something to do in the video lesson.

Voila, the lessons are done, the levels are debugged and named places on the planetA land where I felt good.

And it would be nice to save these places . Now I’m not joking.

More geometry


Who said the heroes of the game are octagons? I added squares, hexagons, circles, pentagons. In honor of professors Dubrovsky, Mishchenko and Fomenko. Diff The geometry of the viruses markedly changed the mood of the game. See for yourself.

image

And you can make koloboks square. Russian folk bun and will not tolerate it.

image

Oh! Where did the viruses go? Removed ... Google takes the brutal seriousness of the word viruses, infected, cured ... I had to edit the meta-data, co-viruses became colored monsters , everyone died , try again , etc.

Parallel replaced Telegram-pictures. Eh, eh, forgive Pavel Durov, irony and laughter will not save the world.

Mistakes, bored without them


Box2D sometimes crashed by mistake in the onGlobalCollision function. Especially on real devices, that is, iPhones. It's funny, but I have not a single Android in the house, and the application is in Google Play ...

The code looks extremely simple, but it breaks like a girl.

I turn off the sound - it does not break. Does the girl come out deaf?

We look at the code:


local function onGlobalCollision( event )
  if ( event.phase == "began" ) then

    local ball = event.object1
    local u, v = ball:getLinearVelocity()
    local speed = u*u + v*v
--    print( "speed: " .. speed  )
     if speed>10000 then
       if speed<20000 then
         audio.play( rockSound )
       else
         audio.play( woodenSound )
       end
    end
  end
end

You see, in the onGlobalCollision function I catch collisions of koloboks and lose 2 types of sounds from collisions. So, at some levels the sine was equal to two , more than 500 objects collided at the same time (or at the same time? Grishkovets). At this rare moment, when calling sounds inside collision , a terrible crash occurs in runtime . <kznm! Don't turn off the sound, right?

How to fix? Decided not to call play (sound) directly from the onGlobalCollision function, and accumulate the number of collisions in the variables boom1 and boom2. Then in the runTimeLoop cycle (this function is called in the game 10 times per second, don’t understand why) check boom1 and boom2 and play the sound if necessary.

       if boom1>0 then
          audio.play( rockSound )
          boom1=0
       end

The error disappeared, but the sound became unpleasantly rhythmic (it is understandable, 10 times per second)
Then I just entered a time-delay noise. A random delay of 100 milliseconds - and oppa! everything began to sound very natural:


local function play1()
  audio.play( rockSound )
end

local function play2()
  audio.play( woodenSound )
end

local function playSound()
  local t = math.random(100)
  if boom1>0 then
    boom1=0
    timer.performWithDelay(t, play1)
  end
  if boom2>0 then
    boom2=0
    timer.performWithDelay(t, play2)
  end
end
  

Handsomely? Who is well done? I know, I know, you yourself would do that.

Google Play and YouTube


I prepared screenshots and shot a video for youtube, the author is behind the piano. It looks slowed down, but I’m such in life, this can’t be fixed:


The video was recorded by the native poppy program QuickTime.app . For the Apple store, the received video needs to be edited (set the frame-rate to 30). For this, I usually use the handBrake.app application , I highly recommend it.

Server, no way without it


Interest in the game is fueled by distance competition. The best results are stored on the server. Masterhost is a separate pain, why the heck they are ...

Okay, forget the insult ... On the server I store the best results of the day and rank the players. Players, of course, want to be the first and take the Cup.

Every midnight (MSK timezone), the high score table on the server is reset and the day King turns into a night Pumpkin. You turns Kings into bergers ... Good song.

The winner of the day goes to the Hall of Fame, a new battle ensues for the next Cup.

How did the backend?

Created 4 mysql tables: cvirus_users, cvirus_events, cvirus_today, cvirus_ticks.
The cvirus_ticks table has only one entry and two day and tick fields.

UPD . Now I realized that the tick field is superfluous.

Every midnight, the entry in the table is checked against the current date and updated as follows.

    $new_day_flag = 0;
    $day = date("d");  //  
    $result = mysql_query("SELECT * FROM cvirus_ticks LIMIT 1 ");
    if ($row = mysql_fetch_array($result)) {
      $d=$row['day'];
      if ($day<>$d) {
         $new_day_flag = $day;
      }
    } 

    if ($newday <> 0) {
      mysql_query( "UPDATE cvirus_ticks SET day = '$new_day_flag', tick = tick + 1 ");
    } 

After the script is triggered, all the results of the players are recorded in the cvirus_today table with the updated tick tag . Thus, the cvirus_today table stores player records sorted by day. Losers can see who became the winner in previous days.

It is interesting to observe the geography of users - for this I pull out his IP address from the player’s request, etch the address to api.wipmania.com , in return I get the country’s domain name (for example, RU or UA) and show the RU.PNG or UA.PNG flag opposite the player’s name. In some games, the geography of users is impressive and thought-provoking. But we will not indulge in travel dreams (what kind of geography is in self-isolation mode ?!), but look at the php-example how to turn ip -> country

$ipAddress = $_SERVER['REMOTE_ADDR'];
$ipCode = file_get_contents('http://api.wipmania.com/' . $ipAddress . '?k=3g-Y6QrmGQ7');
 if (strlen($ipCode)!=2) $ipCode = 'HN';  // - )

We don't allow apps that lack reasonable sensitivity towards or capitalize on a natural disaster, atrocity, conflict, death, or other tragic event.

This is not me, this is Google-UFO ...

List of used links


Meanwhile, in the Play the Google of N-th 12th day waiting check my poor game. Just one - without a host, without advertising, without support. But I do not cry. I have already replaced words, pictures and sounds in it. And thanks to Google, it got better, in addition, I fixed a couple of irregularities.
So, the result is a game on Google Play. No ads and no price. I have long understood that the time of casual loners is gone.

However, remind me, son, you can’t give download links ? And then you turn into an evil Pinocchio, twice a scoundrel (a scoundrel + a scoundrel) and a villain, right?

Link to download
! ?!

Yes, who just did not ban me for it is not known what - Google banned, Apple - banned, Habr - banned twice ... In times there were.

But I'm not discouraged - I’m sitting at home, fixing a stove, eating buckwheat. What for bought so much?

HTML5 saves everyone


-Let me, but what about h t ml5 version? Where is the vaunted cross-platform? - the attentive reader will exclaim.

And be right, Github is in his hand.

Let me remind you that on Github each user has the opportunity to keep one free site - I spent this chance for the web version of the game .
I warn you, d-design is old, uncensored. Nervous (and without humor), please do not run.

Tell me, wise guys
, remote web- ( ) - . , .htaccess Access-Control-Allow-Origin: papabubadiop.imtqy.com, . — , .

I almost forgot! There was another browser error. When starting the game in Safari, he received a dozen identical messages / warnings

libpng warning: iCCP: CRC error

The error is not critical (you press OK ten times and play), but unpleasant. The Internet claims that the GIMP image editor is to blame. It is b-free and saves PNG files with the wrong color palette checksum. Online tips didn't help
uncheck envelope
- no, it doesn't work.

He fixed the problem stupidly - he opened all PNG files in the Preview application (Mac OS system application for viewing and editing all types of files), made Flip twice and closed it. All pictures are resaved in the correct format.

Perhaps some of the readers may get other bugs, well, I'm not holy HelloWorld , I code quickly and carelessly.
Write about errors in the comments, we will.

Epilogue


I wish your families good health. To you, the reader - patience.

PS All typos - intentional, do not write in PM.

All Articles