The day before yesterday, the company had a party and we played games together. Although the game is extremely simple, it is very suitable for playing at events. Because there are many people attending the party in the company, only some people can play it. After I got home in the evening, I tried to restore one of the games using HTML5 and played it for everyone the next day. It became very popular in the company, especially the girls. While playing, they shouted, "おもしろい!!", "It's difficult!" !”….
# Generally when everyone sees a girl liking it, they must be eager to know what game it is, right? The game interface is as follows.
##After seeing the game interface, I guess a few people have fallen to the ground. It’s just an extremely simple one. It's a physics game. After the game starts, hold down the mouse and slide the screen left and right. The protagonist will be like swinging on a swing, getting higher and higher. When the time is right, release the mouse and swing the protagonist out. Whoever flies the farthest will win. win.
In fact, the simpler and shorter the game, the more suitable it is to play in activities such as parties. Especially with the ranking system, everyone will also want to be ranked higher, and Competing to play.
Game test connection:
http://lufylegend.com/demo/box2dJumpNote: This game was purely created after taking about an hour to entertain colleagues at the company. The graphics and efficiency have not been optimized. Please use a PC to open it. The mobile version will probably freeze when running.
Production begins
1. PreparationTwo engines are used in the game
One is the HTML5 open source engine lufylegend.js. The following is my lufylegend-1.7.0 post on my blog, which has a brief introduction
http://blog .csdn.net/lufy_legend/article/details/8719768The other is Box2dWeb, the download address is as follows
http://code.google.com/p/ box2dweb/downloads/listSecond, game developmentAs you can see from the game interface, the focus of game development is a rope. How to implement the rope in HTML5?
There is no rope in box2d, but friends who are familiar with box2d should be familiar with the rotating joint setRevoluteJoint. To implement the rope, we can connect a series of rigid bodies with rotating joints. Together, these rigid bodies are almost like ropes when they swing.
Look at the code below. I connected 1 static rigid body and 20 dynamic rigid bodies with rotating joints.
Code List 1var bx = 250,by=40; var box01,box02; box01 = new LSprite(); box01.x = bx; box01.y = 30; backLayer.addChild(box01); box01.addBodyCircle(10,0,0,0,1,10,0.2); linelist = [box01]; for(var i=0;i<20;i++){ box02 = new LSprite(); box02.x = bx; box02.y = by+i*10; backLayer.addChild(box02); box02.addBodyCircle(10,0,0,1,1,10,0.2); LGlobal.box2d.setRevoluteJoint(box02.box2dBody, box01.box2dBody ); linelist.push(box02); box01 = box02; }
Finally, add a slightly larger rigid body as the protagonist in the game, and also use rotating joints with the previous rigid body connect them.
Code List 2hero = new LSprite(); var bit = new LBitmap(new LBitmapData(imglist["chara03"])); bit.x = -25; bit.y = -20; hero.addChild(bit); hero.bitmap = bit; hero.x = bx; hero.y = by+i*10; backLayer.addChild(hero); hero.addBodyPolygon(30,50,1,2,10,.2); joinline = LGlobal.box2d.setRevoluteJoint(hero.box2dBody, box01.box2dBody );
That’s it. All that’s left is how to control the protagonist’s swing and fly out. At this time, three events are needed.
Code List 3backLayer.addEventListener(LEvent.ENTER_FRAME,onframe); backLayer.addEventListener(LMouseEvent.MOUSE_DOWN,ondown); backLayer.addEventListener(LMouseEvent.MOUSE_UP,onup);
The onframe function in the above code is the timeline, ondown and onup are events called when the mouse is pressed and popped up respectively. When the mouse is pressed It is relatively simple to pop up, the code is as follows.
Code List 4function ondown(event){ if(out)return; monseIsDown = true; mouseObject.x = event.offsetX; } function onup(event){ if(out)return; monseIsDown = false; LGlobal.box2d.world.DestroyJoint(joinline); hero.bitmap.bitmapData = new LBitmapData(imglist["chara04"]) hero.bitmap.x = 0; hero.bitmap.y = 0; out = true; }
The onframe function basically contains all the logical parts of the game.
First of all, the "rope" made earlier has no skin, which means that it will not be displayed unless it is in debug mode. Then when the rope swings, follow these The rigid body draws a curve and turns it into a rope. The code is as follows.
Code List 5backLayer.graphics.clear(); backLayer.graphics.drawRect(1,"#000000",[0,0,LGlobal.width,LGlobal.height]); for(var i=0;i<linelist.length - 1;i++){ backLayer.graphics.drawLine(2,"#000000",[linelist[i].x,linelist[i].y,linelist[i+1].x,linelist[i+1].y]); }
Then, let the rope swing, judge whether the mouse is shaking left or right, and add a force to the rigid body to the left or right to make it The rigid body moves, the code is as follows
Code List 6if(monseIsDown && !out){ if(checkIndex++ > 10){ checkIndex = 0; if(LGlobal.offsetX - mouseObject.x > 50){ var force = 50; var vec = new LGlobal.box2d.b2Vec2(force,0); hero.box2dBody.ApplyForce(vec, hero.box2dBody.GetWorldCenter()); }else if(LGlobal.offsetX - mouseObject.x < -50){ var force = 50; var vec = new LGlobal.box2d.b2Vec2(-force,0); hero.box2dBody.ApplyForce(vec, hero.box2dBody.GetWorldCenter()); } mouseObject.x = LGlobal.offsetX; } }
Finally, when the mouse bounces up, because the protagonist is bounced out, let the game window follow Just move him together.
if(!out)return; backLayer.x = LGlobal.width*0.5 - hero.x; if(backLayer.x > 0){ backLayer.x=0; } LGlobal.box2d.synchronous(); if(!hero.box2dBody.IsAwake() && out){ backLayer.removeEventListener(LEvent.ENTER_FRAME,onframe); point = Math.floor((hero.x - 250)*0.1); var rank = new GameRanking(); backLayer.addChild(rank); }
The entire game is completed in this way. Preview it in debug mode first and you can see The "rope" we made is actually a string of rigid bodies
Finally, the source code of this game is given http://lufylegend.com/ lufylegend_download/box2dJump.rar Note: Only game source code is included. For lufylegend.js engine and box2dweb engine, please see the preparation section to download it yourself above It means taking 1 hour to make a simple physics game (rope principle). For more related content, please pay attention to the PHP Chinese website (www.php.cn)! Three, source code

H5 is not just the abbreviation of HTML5, it represents a wider modern web development technology ecosystem: 1. H5 includes HTML5, CSS3, JavaScript and related APIs and technologies; 2. It provides a richer, interactive and smooth user experience, and can run seamlessly on multiple devices; 3. Using the H5 technology stack, you can create responsive web pages and complex interactive functions.

H5 and HTML5 refer to the same thing, namely HTML5. HTML5 is the fifth version of HTML, bringing new features such as semantic tags, multimedia support, canvas and graphics, offline storage and local storage, improving the expressiveness and interactivity of web pages.

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

The tools and frameworks that need to be mastered in H5 development include Vue.js, React and Webpack. 1.Vue.js is suitable for building user interfaces and supports component development. 2.React optimizes page rendering through virtual DOM, suitable for complex applications. 3.Webpack is used for module packaging and optimize resource loading.

HTML5hassignificantlytransformedwebdevelopmentbyintroducingsemanticelements,enhancingmultimediasupport,andimprovingperformance.1)ItmadewebsitesmoreaccessibleandSEO-friendlywithsemanticelementslike,,and.2)HTML5introducednativeandtags,eliminatingthenee

H5 improves web page accessibility and SEO effects through semantic elements and ARIA attributes. 1. Use, etc. to organize the content structure and improve SEO. 2. ARIA attributes such as aria-label enhance accessibility, and assistive technology users can use web pages smoothly.

"h5" and "HTML5" are the same in most cases, but they may have different meanings in certain specific scenarios. 1. "HTML5" is a W3C-defined standard that contains new tags and APIs. 2. "h5" is usually the abbreviation of HTML5, but in mobile development, it may refer to a framework based on HTML5. Understanding these differences helps to use these terms accurately in your project.

H5, or HTML5, is the fifth version of HTML. It provides developers with a stronger tool set, making it easier to create complex web applications. The core functions of H5 include: 1) elements that allow drawing graphics and animations on web pages; 2) semantic tags such as, etc. to make the web page structure clear and conducive to SEO optimization; 3) new APIs such as GeolocationAPI support location-based services; 4) Cross-browser compatibility needs to be ensured through compatibility testing and Polyfill library.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment