• Guest
HabraHabr
  • Main
  • Users

  • Development
    • Programming
    • Information Security
    • Website development
    • JavaScript
    • Game development
    • Open source
    • Developed for Android
    • Machine learning
    • Abnormal programming
    • Java
    • Python
    • Development of mobile applications
    • Analysis and design of systems
    • .NET
    • Mathematics
    • Algorithms
    • C#
    • System Programming
    • C++
    • C
    • Go
    • PHP
    • Reverse engineering
    • Assembler
    • Development under Linux
    • Big Data
    • Rust
    • Cryptography
    • Entertaining problems
    • Testing of IT systems
    • Testing Web Services
    • HTML
    • Programming microcontrollers
    • API
    • High performance
    • Developed for iOS
    • CSS
    • Industrial Programming
    • Development under Windows
    • Image processing
    • Compilers
    • FPGA
    • Professional literature
    • OpenStreetMap
    • Google Chrome
    • Data Mining
    • PostgreSQL
    • Development of robotics
    • Visualization of data
    • Angular
    • ReactJS
    • Search technologies
    • Debugging
    • Test mobile applications
    • Browsers
    • Designing and refactoring
    • IT Standards
    • Solidity
    • Node.JS
    • Git
    • LaTeX
    • SQL
    • Haskell
    • Unreal Engine
    • Unity3D
    • Development for the Internet of things
    • Functional Programming
    • Amazon Web Services
    • Google Cloud Platform
    • Development under AR and VR
    • Assembly systems
    • Version control systems
    • Kotlin
    • R
    • CAD/CAM
    • Customer Optimization
    • Development of communication systems
    • Microsoft Azure
    • Perfect code
    • Atlassian
    • Visual Studio
    • NoSQL
    • Yii
    • Mono и Moonlight
    • Parallel Programming
    • Asterisk
    • Yandex API
    • WordPress
    • Sports programming
    • Lua
    • Microsoft SQL Server
    • Payment systems
    • TypeScript
    • Scala
    • Google API
    • Development of data transmission systems
    • XML
    • Regular expressions
    • Development under Tizen
    • Swift
    • MySQL
    • Geoinformation services
    • Global Positioning Systems
    • Qt
    • Dart
    • Django
    • Development for Office 365
    • Erlang/OTP
    • GPGPU
    • Eclipse
    • Maps API
    • Testing games
    • Browser Extensions
    • 1C-Bitrix
    • Development under e-commerce
    • Xamarin
    • Xcode
    • Development under Windows Phone
    • Semantics
    • CMS
    • VueJS
    • GitHub
    • Open data
    • Sphinx
    • Ruby on Rails
    • Ruby
    • Symfony
    • Drupal
    • Messaging Systems
    • CTF
    • SaaS / S+S
    • SharePoint
    • jQuery
    • Puppet
    • Firefox
    • Elm
    • MODX
    • Billing systems
    • Graphical shells
    • Kodobred
    • MongoDB
    • SCADA
    • Hadoop
    • Gradle
    • Clojure
    • F#
    • CoffeeScript
    • Matlab
    • Phalcon
    • Development under Sailfish OS
    • Magento
    • Elixir/Phoenix
    • Microsoft Edge
    • Layout of letters
    • Development for OS X
    • Forth
    • Smalltalk
    • Julia
    • Laravel
    • WebGL
    • Meteor.JS
    • Firebird/Interbase
    • SQLite
    • D
    • Mesh-networks
    • I2P
    • Derby.js
    • Emacs
    • Development under Bada
    • Mercurial
    • UML Design
    • Objective C
    • Fortran
    • Cocoa
    • Cobol
    • Apache Flex
    • Action Script
    • Joomla
    • IIS
    • Twitter API
    • Vkontakte API
    • Facebook API
    • Microsoft Access
    • PDF
    • Prolog
    • GTK+
    • LabVIEW
    • Brainfuck
    • Cubrid
    • Canvas
    • Doctrine ORM
    • Google App Engine
    • Twisted
    • XSLT
    • TDD
    • Small Basic
    • Kohana
    • Development for Java ME
    • LiveStreet
    • MooTools
    • Adobe Flash
    • GreaseMonkey
    • INFOLUST
    • Groovy & Grails
    • Lisp
    • Delphi
    • Zend Framework
    • ExtJS / Sencha Library
    • Internet Explorer
    • CodeIgniter
    • Silverlight
    • Google Web Toolkit
    • CakePHP
    • Safari
    • Opera
    • Microformats
    • Ajax
    • VIM
  • Administration
    • System administration
    • IT Infrastructure
    • *nix
    • Network technologies
    • DevOps
    • Server Administration
    • Cloud computing
    • Configuring Linux
    • Wireless technologies
    • Virtualization
    • Hosting
    • Data storage
    • Decentralized networks
    • Database Administration
    • Data Warehousing
    • Communication standards
    • PowerShell
    • Backup
    • Cisco
    • Nginx
    • Antivirus protection
    • DNS
    • Server Optimization
    • Data recovery
    • Apache
    • Spam and antispam
    • Data Compression
    • SAN
    • IPv6
    • Fidonet
    • IPTV
    • Shells
    • Administering domain names
  • Design
    • Interfaces
    • Web design
    • Working with sound
    • Usability
    • Graphic design
    • Design Games
    • Mobile App Design
    • Working with 3D-graphics
    • Typography
    • Working with video
    • Work with vector graphics
    • Accessibility
    • Prototyping
    • CGI (graphics)
    • Computer Animation
    • Working with icons
  • Control
    • Careers in the IT industry
    • Project management
    • Development Management
    • Personnel Management
    • Product Management
    • Start-up development
    • Managing the community
    • Service Desk
    • GTD
    • IT Terminology
    • Agile
    • Business Models
    • Legislation and IT-business
    • Sales management
    • CRM-systems
    • Product localization
    • ECM / EDS
    • Freelance
    • Venture investments
    • ERP-systems
    • Help Desk Software
    • Media management
    • Patenting
    • E-commerce management
    • Creative Commons
  • Marketing
    • Conferences
    • Promotion of games
    • Internet Marketing
    • Search Engine Optimization
    • Web Analytics
    • Monetize Web services
    • Content marketing
    • Monetization of IT systems
    • Monetize mobile apps
    • Mobile App Analytics
    • Growth Hacking
    • Branding
    • Monetize Games
    • Display ads
    • Contextual advertising
    • Increase Conversion Rate
  • Sundry
    • Reading room
    • Educational process in IT
    • Research and forecasts in IT
    • Finance in IT
    • Hakatonas
    • IT emigration
    • Education abroad
    • Lumber room
    • I'm on my way

The simplest game on the Arduino with display 1602 - Part # 2

 3r33700. 3r3-31.

PART # 2 from start to finish


 3r33700. We continue to make the game on arduino and in the future we stick this game into the program, which I do for the machine and with our acquired knowledge, we will create the second game, for fun and we will make the right music for it.
 3r33700.
 3r33700. To understand what we need to write now, we need to make a plan, what we will have and in what form. We have the main character, he has two frames of animation, and we already sorted it out in the last lesson. I didn’t make him change the sprite of the jump, not because I’m too lazy, I just don’t see the point. Next, we should have a life symbol, just making hearts in a row is not interesting, and the numbers are also trite, let's make three life points and mark them, for example, the battery charge level. And for the joy of the eye, a heart that will beat near this battery. The number of points per round, set on the left of the screen, purely in digital form and the enemy we will have an evil cactus, for starters, go.
 3r33700.
 3r33700. We have decided on the objects and let's draw them, immediately all the sprites and write them down.
 3r33700.
 3r33700. 3r318. The simplest game on the Arduino with display 1602 - Part # 2
 3r33700.
 3r33700. 3r330.
 3r33700. 3r3333.
 3r33700. We have working sprites and we can already imagine how it will look on the screen, following the first lesson we will write them out in the binary system, we remember where the zero is empty and where the unit is, we have a pixel. Let's start: 3r3684.  3r33700.
 3r33700.
3r33432. "------------------------------------------------- ------------------------- "
3r33700. //The main character is the first sprite:
byte Player_1[SYMBOL_HEIGHT]= {B0111? B0111? B0010? B0111? B1010? B0010? B0111? B0101?}; 3r33700. 3r33700. //The main character is the second sprite:
byte Player_2[SYMBOL_HEIGHT]= {B0000? B0111? B0111? B0010? B1111? B0010? B0111? B0101?}; 3r33700. 3r33700. //Angry cactus:
byte Enemy_1[SYMBOL_HEIGHT]= {B0001? B0011? B1011? B1011? B1111? B0011? B0011? B1111?}; 3r33700. 3r33700. //Big heart:
byte Heart_L[SYMBOL_HEIGHT]= {B0000? B0101? B1111? B1111? B1111? B0111? B0010? B0000?}; 3r33700. 3r33700. //Small heart:
byte Heart_R[SYMBOL_HEIGHT]= {B0000? B0000? B0101? B1111? B0111? B0010? B0000? B0000?}; 3r33700. 3r33700. //Battery three lives:
byte Battery1[SYMBOL_HEIGHT]= {B0111? B1111? B1111? B1111? B1111? B1111? B1111? B1111?}; 3r33700. 3r33700. //Battery two lives:
byte Battery2[SYMBOL_HEIGHT]= {B0111? B1000? B1001? B1011? B1111? B1111? B1111? B1111?}; 3r33700. 3r33700. //Battery one life:
byte Battery3[SYMBOL_HEIGHT]= {B0111? B1000? B1000? B1000? B1001? B1011? B1111? B1111?}; 3r33700. 3r33700. //Battery life zero: 3r30000. byte Battery4[SYMBOL_HEIGHT]= {B0111? B1000? B1000? B1000? B1000? B1000? B1000? B1111?}; 3r33700. "------------------------------------------------- ------------------------- "
3r3650.
 3r33700. Now we have sprites, and it's time to revive it all. First, let's think about what additional features we need. Knowing that the arduino does not work perfectly and in some places is even very capricious, we begin to try to make life as simple as possible for this microcontroller. Do not overload and at the same time demand complete returns. So we will derive such additional functions that will live their lives and do everything we need:
 3r33700.
 3r33700. - animation of the heart
 3r33700. - animation hero
 3r33700. - check hero damage 3r3684.  3r33700. - The movement of the evil cactus
 3r33700. - Scoring (so far every second +? then we change)
 3r33700. - screen update (but this is not accurate, most likely, we will remove this function and add another, I did not like that the screen is blinking, I want stability). Subsequently, we replace this function by deleting the hero's past location, this will remove the screen flicker, and zeroing the villain will be inside the evil script, I think there will be one or two lines maximum.
 3r33700. - remote control
 3r33700. - loop and setup settings
 3r33700.
 3r33700. We want to have an animation of the heartbeat. Putting it into a separate function and forcing it to live its own separate life, it will be easier for us to track the work and in the future it will be easier to edit, since we have everything, or almost everything is in one place. This code could be looped () and commented out, but I personally used to break into separate functions, you are not looking for code in the entire list and you know that a separate function controls certain elements of our game.
 3r33700.
 3r33700. Now, I will write the code segments, we will connect them at the end and get a full-fledged script, I will now explain the essence and idea to you, and then we will assemble the puzzle and enjoy the result.
 3r33700. Before the beginning of the code itself, I will explain a couple of moments.
 3r33700.
 3r33700. lcd.createChar //is a command to access the screen and use one of the memory cells to write new characters. The number of the cell is written in parentheses and separated by a comma, the name of the variable with information.
 3r33700.
 3r33700. Control over the drawing will be conducted through a digital variable, using four digits, for correct animation, if we wanted to make the heart just beat back and forth, then the usual variable bool would fit. But my thought is different, one big blow and two short ones, it will look more interesting.
 3r33700.
 3r33700.
3r33432. "------------------------------------------------- ------------------------- "
void HeartHit () //
heart animation function. {
if (HeartControl == 0 || HeartControl == 2) {lcd.createChar (? Heart_L);} //if our variable shows zero or two, we write one big heart to
in cell one. if (HeartControl == 1 || HeartControl == 3) {lcd.createChar (? Heart_R);} //if our variable shows one or two, we write one small heart
in cell one. if (currentMillis - HeartHitBigCheck> = HeartHitBig) {//time of big crash
if (currentMillis - HeartHitLightCheck> = HeartHitLight) {//short beats time
HeartHitLightCheck = currentMillis; //zeroing control of the time of short shots
if (HeartControl <3){HeartControl++;} //если переменная контроля отрисовки менее трех, то при каждом срабатывании скрипта мы плюсуем один к сумме
else {HeartControl = 0; HeartHitBigCheck = currentMillis;} //but if the sum of the variable has exceeded three, then reset it and reset the count of long heart sticking 3r3003700.} 3r30037.}
}
} -------------------------------------------------- -------------------- "
3r3-33650.
 3r33700. Once again, I want to focus your attention on this code:
 3r33700. lcd.createChar (x, y); assigning to the cell a memory “x” from (0… 7) data for displaying on the screen “y”
 3r33700.
 3r33700. Go ahead =)
 3r33700.
 3r33700. Now, we have a code that creates the effect of an interesting heartbeat, it doesn’t do anything useful, just show off =)
 3r33700.
 3r33700. Further, based on this, we will create the animation of our hero, there are huge advantages, the further we dive into this article, the more you will learn my thinking style, and I, less you need to explain and focus more on the code and the construction of the idea. I will try to explain more in the comments of the script in order to write less outside the script.
 3r33700. So let's get to the main character and create another function for this: 3r3684.  3r33700.
 3r33700.
3r33432. "------------------------------------------------- ------------------------- "
//I rewrote this piece of code and it will be different from the first part of the article (a bit). This is normal for me =) It does not affect the performance, but it is better to use the new version. 3r33700. void PlAn () //animation function of the main character
{
If (JumpB == true && GGpozY == 0) {//this is the control of the jump (the activation of the jump will be in another part of the code) If the jump = true And the position is at the top. 3r33700. if (currentMillis - JumpUPCheck> = JumpUP) {//check the flight time 0.8f
JumpB = false; GGclear (); GGpozY = 1; //when time is running out, return our hero to the ground and wait for the next jump. Jump = Lodges; activation of the function of purifying the location of the hero (); the vertical position of the protagonist = lower band; 3r33700.}
}
if (AnimPlayer == 1) {lcd.createChar (? Player_1);} //If the animation control variable is one, we write the first sprite of the hero
to the memory cell. if (AnimPlayer == 2) {lcd.createChar (? Player_2);} //If the animation control variable is two, we write the second sprite of the hero
to the memory cell. if (AnimPlayer 3r3-3666. {3r3-3700. lcd.setCursor (GGpozX, GGpozY); //put it at 3r3-300. /check the time
AnimatedTimeCheck = currentMillis; //reset the time
if (AnimPlayer == 2) {AnimPlayer = 1;} //if the animation control variable is two then one
else {AnimPlayer = 2;} //and if one, then two.
}
}
void GGclear () //hero update function
{
lcd.setCursor (GGpozX, GGpozY); //hero position
lcd.print (""). //clear it
}
"---------------------------------------- ---------------------------------- "
3r3-33650.
 3r33700. Now the timer, uh, or rather our glasses, which will be charged, let's just write a timer and we will assume that these are glasses.
 3r33700.
 3r33700.
3r33432. "------------------------------------------------- ------------------------- "
void timer () //function of points
{
if (currentMillis - DHTTimeRCheck> = DHTTimeR) //timer that fires once a second
{
DHTTimeRCheck = currentMillis; //reset the timer
Timer_z ++; //add one to the total amount of
lcd.setCursor (? 0); //set the cursor to the first top point
lcd.print (Timer_z); //display the data on the screen
}
}
-------------------------------------------------- ------------------------ "
3r3-33650.
 3r33700. That's all. The farther the easier.
 3r33700.
 3r33700. Now, it remains to work out our cactus.
 3r33700.
 3r33700. His task is simple, to appear, walk all the way from the right to the left and try to touch the hero to cause damage. With damage everything is easier, one touch - one hit. So far, the increase in complexity, we will not do. Let the cactus move at a speed of 0.5f (complexity will already be your homework =)) or Russian half a second - one step.
 3r33700.
 3r33700. Let's look at how this piece of code will look like:
 3r33700.
 3r33700.
3r33432. "------------------------------------------------- ------------------------- "
void enemy_go () //villain function
{
if (Emeny_check_1 == 0) //so that the enemy would appear with a random delay, we need to make it so that until there is a villain on the screen, we had a random number and the correct number, the villain was called, and this random waited until he was needed again 3r33700. {
Emeny_control = random (100); //I thought, if we use different methods, it will be more interesting, therefore, it will be possible to calculate the chance of a villain to appear by a random number. 3r33700. if (Emeny_control == 1) {//if random = 1 out of 100 then launch the villain. 3r33700. Emeny_check_1 = 1; //run the character, in fact, you can use bool here since we have two states, or yes or no, and now I was too lazy to redo
hitON = false; //this function checks if the damage to the main character has been 3-333700.}
}
if (Emeny_check_1 == 1) //when approved randomly, the villain went into battle
{
if (currentMillis - TimeBlinkCheck> = TimeBlink) //check for time 0.5f
{
TimeBlinkCheck = currentMillis; //zeroing checkout time
lcd.createChar (? Enemy_1); //Assign a sprite of cactus
to memory cell 2. lcd.setCursor (E1pozX, E1pozY); //chose the 1st point of the cactus
lcd.print (""); //reset it to
E1pozX--; //move one step to the left
lcd.setCursor (E1pozX, E1pozY); //set 2nd position
lcd.write (2); //draw the cactus
if (E1pozX <= 0) //если кактус дошел до края экрана
{
lcd.setCursor (?1); //put the cursor on the edge of the screen
lcd.print (""); //reset it to
Emeny_control = 0; //reset the random function
Emeny_check_1 = 0; //close access to this part of the script
E1pozX = 16; //- ///
E1pozY = 1; //- set the catus back to the X and Y position
}
}
}
}
"--------------------------------------------------- ------------------------------- "
3r3-33650.
 3r33700. It remains quite a bit and after the examination of each piece, I can already lay out the full script assembled, configured and ready for the test on your devices.
 3r33700.
 3r33700. So now we have one of the most important scripts in the queue, this is a script for checking damage and turning on the geymover in the absence of life. There is nothing supernatural in the script. Therefore, we can begin to disassemble it (by the way, if you were attentive, you would notice that when we created a heart, we didn’t display it on the screen, so you’ll see where I put this part of the code): 3r3684.  
 3r33700.
3r33432. "------------------------------------------------- ------------------------- "
void check_hit_gg_1 () //
damage taking function. {
if (E1pozX == GGpozX && E1pozY == GGpozY && hitON == false) {//check that the X and Y coordinates coincided with the hero, that with the cactus
LifeCheck - = 1; //minus one CP
hitON = true; //return the check and now our hero can take damage again
if (LifeCheck <= 0){ //если жизни меньше чем ноль
AnimPlayer = 50; //disable the triggering loop ()
Emeny_check_1 = 50; //disable the random triggering of the cactus
lcd.clear (); //clean the screen
lcd.setCursor (? 0) ; //set the cursor
lcd.print ("GAME OVER"); //write the cherished word
}
} else {//BUT! If the hero and the cactus did not converge in conjunction then 3r33700. lcd.setCursor ( 1? 0); //set the cursor and
Lcd.write (1); //display the heart
Lcd.setCursor (1? 0);
Lcd.print ("="); //it's easy equals
lcd.setCursor (1? 0);
lcd.write (3); //display of the battery
}
}
"---------------- ----------------------------- ----------------------------- "
3r3-33650.
 3r33700. This code is very simple, its main function is to check it, and wait until the conditions are all met to stop the game and tell us that we lost.
 3r33700.
 3r33700. Now the last function is control. In fact, if we have analyzed the code above, then it will seem easier for us to be simple. From the first lesson, we pulled out the remote control codes, I wrote them all out, they look like this:
 3r33700.
 3r33700. 3r33432. * CH- 0xFFA25D
 3r33700. * CH 0xFF629D
 3r33700. * CH + 0xFFE21D
 3r33700. * 0xFF22DD
 3r33700. * 0xFF02FD
 3r33700. *> || 0xFFC23D
 3r33700. * - 0xFFE01F
 3r33700. * + 0xFFA857
 3r33700. * EQ 0xFF906F
 3r33700. * 0 0xFF6897
 3r33700. * 100+ 0xFF9867
 3r33700. * 200+ 0xFFB04F
 3r33700. * 1 0xFF30CF
 3r33700. * 2 0xFF18E7
 3r33700. * 3 0xFF7A85
 3r33700. * 4 0xFF10EF
 3r33700. * 5 0xFF38C7 ​​
 3r33700. * 6 0xFF5AA5
 3r33700. * 7 0xFF42BD
 3r33700. * 8 0xFF4AB5
 3r33700. * 9 0xFF52AD
 3r33700.
 3r33700. Button _ code (attention!) (Codes on the consoles may differ)
 3r33700.
 3r33700. Who has not read, I advise you to read the 1st part.
 3r33700.
 3r33700. Something like that, then you will have it too, and you can customize everything you need without any problems.
 3r33700.
 3r33700. Now we will create the simplest algorithm based on what our game already knows and will come to life.
 3r33700.
 3r33700.
3r33432. "------------------------------------------------- ------------------------- "
void IRCheck () //IR port function
{
if (irrecv.decode (& results)) //if the data came, then
{
if (results.value == 0xFF18E7 && GGpozY == 1) {//if you pressed the “2” button and the position on Earth
GGclear (); //clear the past whereabouts of the hero
GGpozY = 0; //set the position to the 2nd lane (jump type)
JumpB = true; //variable indicating that we are in the
jump phase. JumpUPCheck = currentMillis; //reset the time-finding counter in the air
} //2
if (results.value == 0xFF10EF && GGpozX> = 0) {//If you clicked on the four and you do not rest on the left edge of the screen
GGclear (); //same as
before. GGpozX - = 1; //move the main character to the left
} //4
if (results.value == 0xFF5AA5 && GGpozX <= 15){ //если нажали шесть и не упираемся в правую сторону экрана
GGclear (); //should have already memorized
GGpozX + = 1; //move to the right
} //6
if (results.value == 0xFF6897) {//0 //if you press zero, the game makes a restart
Lcd.clear (); //clear the screen
AnimPlayer = 1; //return the variable to start the animation
LifeCheck = 3; //restore HP
. Timer_z = 0; //reset the counter
GGpozX = 8; /////
GGpozY = 1; //return the main character to the center of the screen
Emenycheck_1 = 0; //return cactus generator data
E1pozX = 16; /////
E1pozY = 1; //vy Avatar start position of the cactus.
}
irrecv.resume (); //reset the sensor data 3r30000.}
"----------------------- -------------------------------------------------- - "
3r3650.
 3r33700. The output from the above written code:
 3r33700. Button 2 is jump
 3r33700. Button 4 is a step left
 3r33700. Button 6 is a step to the right
 3r33700. Button 0 resets the game and restarts it
 3r33700.
 3r33700. Here, now it remains for us to set up setup & loop, everything is already coming to an end. We have created all the additional functions and all we have to do is glue and add libraries. I think we will look at the variables and main settings of setuploop already in the common code, so let's get started, and then ctrl + c & ctrl + v is required of you and that's it =) and further independent development in this direction, if of course you enjoyed it.
 3r33700.
 3r33700.
3r33432. "------------------------------------------------- ------------------------- "
3r33700. #include
//IR module
#include
//i2P bus
#include
//display 1602
LiquidCrystal_I2C lcd (0x3F, 16.2); //Set the display
3r33700. int AnimPlayer = 1; //animation of the hero
int GGpozX = 8; //hero position x axis
int GGpozY = 1; //position of the hero axis W
int Emeny_check_1 = 0; //check the villain
int Emeny_control = 0; //Random this number so that there would be a delay between the call of the cactus 3r-3700. int E1pozX = 16; //the position of the villain X
int E1pozY = 1; //position of the villain W
int HeartControl = 0; //control the animation of the heart
int LifeCheck = 3; //number of lives
3r33700. long Timer_z = 0; //points counter
long AnimatedTime = 300; //update time of the hero animation
long AnimatedTimeCheck = 0; //check the above
long HeartHitBig = 800; //big heart delay time
long HeartHitLight = 250; //Heart Delay Small
long HeartHitBigCheck = 0; //check big heart beat
long HeartHitLightCheck = 0; //check small heart beat
long BatteyBlink = 200; //time of the glare battery when there is 1 HP left
long BatteyBlinkCheck = 0; //check the above
long JumpUP = 800; //time spent in the jump
long JumpUPCheck = 0; //check the above
long DHTTimeR = 1000; //update second
long DHTTimeRCheck = 0; //check the update seconds
long TimeBlink = 500; //update half a second
long TimeBlinkCheck = 0; //check flashing settings
long currentMillis = 0; //main time counter
3r33700. bool JumpB = false; //jump or not
bool BatteryB = false; //The battery is empty or almost
bool hitON = false; //hit or not
3r33700. decode_results results; //output the result of the data from IR
IRrecv irrecv (A0); //Analog port for IR module
3r33700. enum {SYMBOL_HEIGHT = 8}; 3r33700. byte Player_1[SYMBOL_HEIGHT]= {B0111? B0111? B0010? B0111? B1010? B0010? B0111? B0101?}; 3r33700. byte Player_2[SYMBOL_HEIGHT]= {B0000? B0111? B0111? B0010? B1111? B0010? B0111? B0101?}; 3r33700. byte Enemy_1[SYMBOL_HEIGHT]= {B0001? B0011? B1011? B1011? B1111? B0011? B0011? B1111?}; 3r33700. byte Heart_L[SYMBOL_HEIGHT]= {B0000? B0101? B1111? B1111? B1111? B0111? B0010? B0000?}; 3r33700. byte Heart_R[SYMBOL_HEIGHT]= {B0000? B0000? B0101? B1111? B0111? B0010? B0000? B0000?}; 3r33700. byte Battery1[SYMBOL_HEIGHT]= {B0111? B1111? B1111? B1111? B1111? B1111? B1111? B1111?}; 3r33700. byte Battery2[SYMBOL_HEIGHT]= {B0111? B1000? B1001? B1011? B1111? B1111? B1111? B1111?}; 3r33700. byte Battery3[SYMBOL_HEIGHT]= {B0111? B1000? B1000? B1000? B1001? B1011? B1111? B1111?}; 3r33700. byte Battery4[SYMBOL_HEIGHT]= {B0111? B1000? B1000? B1000? B1000? B1000? B1000? B1111?}; 3r33700. 3r33700. void setup () {
Serial.begin (9600); //speed of the port
irrecv.enableIRIn (); //start receiving r3r3700. lcd.init (); //start the screen
Wire.begin (); //start IR 3r300. lcd.backlight (); //Turn on the display backlight
}
void loop () {
currentMillis = millis (); //assign the milliseconds
IRCheck (); //run the function of the IR module
if (AnimPlayer < 3){ //если герой анимируется, значит он жив, значит работаем дальше
if (LifeCheck == 3) {lcd.createChar (? Battery1);} //show full life
if (LifeCheck == 2) {lcd.createChar (? Battery2);} //show average life
if (LifeCheck == 1) {//start blinding life when 1x left 3r33700. if (BatteryB == false) {lcd.createChar (? Battery3);} //show life almost empty
. if (BatteryB == true) {lcd.createChar (? Battery4);} //show life empty
if (currentMillis - BatteyBlinkCheck> = BatteyBlink) {BatteyBlinkCheck = currentMillis; //check the time
if (BatteryB = = false) {BatteryB = true;} else {BatteryB = false;}} //change the position
}
timer (); //start the timer
check_hit_gg_1 (); //start checking for damage 3 r3r3700. PlAn (); //launch of animation 3-333700 GG. HeartHit (); //start of animation of heart
enemy_go (); //launch the villain
}
}
void IRCheck () //IR port function
. {
if (irrecv.decode (& results)) //if the data came, then
{
if (results.value == 0xFF18E7 && GGpozY == 1) {//if you pressed the “2” button and the position on Earth
GGclear (); //clear the past whereabouts of the hero
GGpozY = 0; //set the position to the 2nd lane (jump type)
JumpB = true; //variable indicating that we are in the
jump phase. JumpUPCheck = currentMillis; //reset the time-finding counter in the air
} //2
if (results.value == 0xFF10EF && GGpozX> = 0) {//If you clicked on the four and you do not rest on the left edge of the screen
GGclear (); //same as
before. GGpozX - = 1; //move the main character to the left
} //4
if (results.value == 0xFF5AA5 && GGpozX <= 15){ //если нажали шесть и не упираемся в правую сторону экрана
GGclear (); //should have already memorized
GGpozX + = 1; //move to the right
} //6
if (results.value == 0xFF6897) {//0 //if you press zero, the game makes a restart
Lcd.clear (); //clear the screen
AnimPlayer = 1; //return the variable to start the animation
LifeCheck = 3; //restore HP
. Timer_z = 0; //reset the counter
GGpozX = 8; /////
GGpozY = 1; //return the main character to the center of the screen
Emenycheck_1 = 0; //return cactus generator data
E1pozX = 16; /////
E1pozY = 1; //vy Avoid the starting position of the cactus.
}
irrecv.resume (); //reset the sensor data to
}
) //timer that fires once a second
{
DHTTimeRCheck = currentMillis; //reset the timer
Timer_z ++; //add one to the total amount of
lcd.setCursor (? 0); //set the cursor to the first top point
lcd.print (Timer_z); //display the data on the screen
}
}
//I rewrote this piece of code and it will be different from the first part of the article (a bit). This is normal for me =) On efficienthost, it does not affect in any way but it is better to use the new version. 3r33700. void PlAn () //animation function of the main character
{
if (JumpB == true && GGpozY == 0) {//this is the control of the jump (the activation of the jump will be in another part of the code) If the jump = true And the position is at the top. 3r33700. if (currentMillis - JumpUPCheck> = JumpUP) {//check the flight time 0.8f
JumpB = false; GGclear (); GGpozY = 1; //when time is running out, return our hero to the ground and wait for the next jump. Jump = Lodges; activation of the function of purifying the location of the hero (); the vertical position of the protagonist = lower band; 3r33700.}
}
if (AnimPlayer == 1) {lcd.createChar (? Player_1);} //If the animation control variable is one, we write the first sprite of the hero
to the memory cell. if (AnimPlayer == 2) {lcd.createChar (? Player_2);} //If the animation control variable is two, we write the second sprite of the hero
to the memory cell. if (AnimPlayer 3r3-3666. {3r3-3700. lcd.setCursor (GGpozX, GGpozY); //put it at 3r3-300. /check the time
AnimatedTimeCheck = currentMillis; //reset the time
if (AnimPlayer == 2) {AnimPlayer = 1;} //if the animation control variable is two then one
else {AnimPlayer = 2;} //and if one, then two.
}
}
void GGclear () //hero update function
{3rr3700. lcd.setCursor (GGpozX, GGpozY); //hero position
lcd.print (""). //clear it
}
void enemy_go () //villain function
{
if (Emeny_check_1 == 0) //so that the enemy would appear with the case With this delay, we need to make it so that until there is a villain on the screen, we worked with random and with the correct number, the villain was called and this random waited until he needed again 3r30037. {
Emeny_control = random (100); //I thought, if we use different methods, it will be more interesting, therefore, it will be possible to calculate the chance of a villain to appear by a random number. 3r33700. if (Emeny_control == 1) {//if random = 1 out of 100 then launch the villain. 3r33700. Emeny_check_1 = 1; //run the character, in fact, you can use bool here since we have two states, or yes or no, and now I was too lazy to redo
hitON = false; //this function checks if the damage to the main character has been 3-333700.}
}
if (Emeny_check_1 == 1) //when approved randomly, the villain went into battle
{
if (currentMillis - TimeBlinkCheck> = TimeBlink) //check for time 0.5f
{
TimeBlinkCheck = currentMillis; //zeroing checkout time
lcd.createChar (? Enemy_1); //Assign a sprite of cactus
to memory cell 2. lcd.setCursor (E1pozX, E1pozY); //chose the 1st point of the cactus
lcd.print (""); //reset it to
E1pozX--; //move one step to the left
lcd.setCursor (E1pozX, E1pozY); //set 2nd position
lcd.write (2); //draw the cactus
if (E1pozX <= 0) //если кактус дошел до края экрана
{
lcd.setCursor (?1); //put the cursor on the edge of the screen
lcd.print (""); //reset it to
Emeny_control = 0; //reset the random function
Emeny_check_1 = 0; //close access to this part of the script
E1pozX = 16; //- ///
E1pozY = 1; //- set the catus back to the X and Y position
}
}
}
}
Void check_hit_gg_1 () //damage taking function
{
If (E1pozX == GGpozX && E1pozY == GGpozY && hitON == false) {//checking that the X and Y coordinates were the same a hero that the cactus has
LifeCheck - = 1; //minus one HP
hitON = true; //return the Verka and now our hero can again take damage
if (LifeCheck <= 0){ //если жизни меньше чем ноль
AnimPlayer = 50; //disable activation loop ()
Emeny_check_1 = 50;. //disable accidental operation cactus
lcd.clear (); //clean the screen
lcd.setCursor (? 0); //set the cursor
lcd.print ("GAME OVER"); //write the cherished word
}
} else {//BUT! If the hero and the cactus did not agree on the union then
lcd.setCursor (1? 0); //set the cursor and
lcd.write (1); //display the heart
lcd.setCursor (1? 0); 3r33700. lcd.print ("="); //this is just
lcd.setCursor (1? 0); 3r33700. lcd.write (3); //display the battery
}
}
void HeartHit () //
heart animation function. {
if (HeartControl == 0 || HeartControl == 2) {lcd.createChar (? Heart_L);} //if our variable shows zero or two, we write one big heart to
in cell one. if (HeartControl == 1 || HeartControl == 3) {lcd.createChar (? Heart_R);} //if our variable shows one or two, we write one small heart
in cell one. if (currentMillis - HeartHitBigCheck> = HeartHitBig) {//time of big crash
if (currentMillis - HeartHitLightCheck> = HeartHitLight) {//short beats time
HeartHitLightCheck = currentMillis; //zeroing control of the time of short shots
if (HeartControl <3){HeartControl++;} //если переменная контроля отрисовки менее трех, то при каждом срабатывании скрипта мы плюсуем один к сумме
else {HeartControl = 0; HeartHitBigCheck = currentMillis;} //but if the sum of the variable has exceeded three, then reset it and reset the count of long heart sticking 3r3003700.} 3r30037.}
}
} -------------------------------------------------- -------------------- "
3r3-33650.
 3r33700. By connecting. We did that code, but how to assemble the wires and what to stick in, I did not explain this to you. Although I am sure that more than 80% of those who decide to read this little article already know it, but as for me, the article will not be complete if I do not provide maximum information.
 3r33700.
 3r33700.  3r33700.
 3r33700. A5 Display 1602 - SCL 3r3684.  3r33700. A4 Display 1602 - SDA
 3r33700. A0 IR sensor 3r3684.  3r33700.
 3r33700. Now I am working on creating a radio key for a car based on an arduino, and on the 1602 screen I want to display the moisture and temperature sensor data outside the car (since I will soon be in Moscow, look for a new job, I will need to know what is happening behind the car so as it is very cold there), a clock, a voltmeter of the battery and the games to be put there (I have 4 pins left free, and I still have to shove there), so that I could poke this game at the traffic light or the second one I plan do like good old pockets ca 2000s from where the point was just to go around the obstacle and music to put on a background of the Rock n Roll Racing. Uhh classic =) and stick it in optimally all into one arduino without using external data storage (pure chelendzh), but I have already used ~ 60% and if the game code takes up a maximum of 15% - 20%, then the music oh there it will be problems, weighs a lot, it is necessary to optimize, I have already started collecting the track and managed to reduce the weight almost 10 times, but I made mistakes in the construction of notes and tones and now I have to do it all over again. I will most likely later write here a full version with a description of the project I'm working on. I hope someone has something new to think about, I have provided, if everything is good and time, I will continue to write articles. Any questions? Write in the comments.
 3r33700.
 3r33700. All subscribe, put likes, stay tuned for new articles.
 3r33700.
 3r33700. Thank you all for your attention, Chao-Cocoa!
 3r33700.
 3r33700. P.S .: I still can’t take a video out of the game’s performance, the camera on the phone has died and it’s very sad. But I will think of something and add a vidos to the article a little later.
 3r33700.
 3r33700. The first part of the article is>
3r33700. 3r33700.
! function (e) {function t (t, n) {if (! (n in e)) {for (var r, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e.parentNode.insertBefore (r, e)}; "[object Opera]" == e.opera? a.addEventListener? a.addEventListener ("DOMContentLoaded", d ): d ()}}} t ("//mediator.mail.ru/script/2820404/"""_mediator") () (); 3r3694. 3r33700.
3r33700. 3r33700. 3r33700. 3r33700.

It may be interesting

  • Comments
  • About article
  • Similar news
This publication has no comments.

weber

Author

5-10-2018, 06:26

Publication Date

Development / Programming

Category
  • Comments: 0
  • Views: 277
Overview of the main mathematical
The simplest game on Ardruino with a
New books about children's programming
The clerk screwed the Canon EF 70-200
"Impossible" retro game
Description of the prototype of my
Write a comment
Name:*
E-Mail:


Comments
Inursing test bank was very pleased  to find this site.I wanted to thank you for this great read!! I definitely  enjoying every little bit of it and I have you bookmarked to check out new  stuff you post.  
Today, 18:20

taxiseo2

You completed certain  reliable points there. I did a search on the subject and found nearly all  persons will agree with your blog.  
nursing test bank
Today, 18:04

taxiseo2

Great post i must say  and thanks for the information. Education is definitely a sticky subject.  However, is still among the leading topics of our time. I appreciate your  post and look forward to more.
nursing test bank
Today, 17:29

taxiseo2

So good! This web post provides knowledge, knowledge, good news, and is very useful. Thank you for everything Taxi Driver Jacket
Today, 15:35

MalenaMorgan

I know this is one of the most meaningful information for me. And I'm animated reading your article. But should remark on some general things, the website style is perfect; the articles are great. Thanks for the ton of tangible and attainable help.2movierulz

Today, 15:34

raymond weber

Adv
Website for web developers. New scripts, best ideas, programming tips. How to write a script for you here, we have a lot of information about various programming languages. You are a webmaster or a beginner programmer, it does not matter, useful articles will help to make your favorite business faster.

Login

Registration Forgot password