当前位置:网站首页>[IVX junior engineer training course 10 papers] 05 canvas and aircraft war game production
[IVX junior engineer training course 10 papers] 05 canvas and aircraft war game production
2022-07-02 01:14:00 【1_ bit】
Catalog
【iVX Junior engineer training course 10 Textual evidence 】01 understand iVX Complete the New Year greeting card
【iVX Junior engineer training course 10 Textual evidence 】02 Numerical binding and adaptive website production
【iVX Junior engineer training course 10 Textual evidence 】03 Events and guessing numbers games
【iVX Junior engineer training course 10 Textual evidence 】04 Canvas and me iVX Group photo
【iVX Junior engineer training course 10 Textual evidence 】05 Canvas and aircraft war game production
【iVX Junior engineer training course 10 Textual evidence 】06 Database and services
【iVX Junior engineer training course 10 Textual evidence 】07 08 News page making
【iVX Junior engineer training course 10 Textual evidence 】09 Chat room production
For high score promotion, please check the column :
iVX Beginner to master
Big talk IVX From actual combat to mastery
11、 ... and 、 Aircraft battle
The general process of making wechat games and wechat applet 、Web similar , The difference is the use of components .
11.1.1 Complete the production of game characters
First, we create a wechat 2D Little games :

After creating the game scene, you can add pictures in the game interface , As an element in the game . Click the picture component to draw a protagonist plane in the canvas . After clicking the picture, drag the mouse in the canvas to draw the area, and a resource selection box will pop up :


Select the picture material we need to add , The picture of the protagonist's plane will appear in the canvas :

Let's click on the picture , Drag to the right size :

11.1.2 Finish adding the physical world
In order to facilitate the detection of physical collision between aircraft and enemy aircraft , We need to add a physical world to the canvas , And take the protagonist plane as a sub object of the physical world :

In order for the protagonist's plane to be affected by the physical world , You need to add an object to the protagonist's plane . Click the aircraft picture component in the object tree species , Click the object in the left component bar to add :

At this point we pass through web Browser debugging , Click preview :

For better convenience of observation , We press... In the browser window that appears F12, Select this window as the mobile browser window :

After we refresh the interface, we will see the protagonist's plane falling from top to bottom :

Due to collisions in the physical world , There will be rotation between objects , We need to keep the plane's head up , It is necessary to prohibit the rotation angle of the protagonist aircraft . Click the object component under the main character of the aircraft , Turn on the fixed rotation angle of the object in the property bar :

11.1.3 Complete the anti gravity movement of the bullet object
Next, start setting up automatic bullet firing , Let's add a bullet picture component to the canvas again , And add the object component under the bullet picture component :


At this time, the preview finds that the bullet will fall automatically , To solve this problem, you only need to add a motion component under the bullet component :


We click on the motion component , Set the moving direction to 90 Degrees are vertical upward motion , Then set the moving speed in this direction , Set to -600 It indicates the movement in the opposite direction , Finally, you need to turn on autoplay to take effect :

Then we will find that we have successfully made the bullet move in the opposite direction , At this time, also note that the fixed rotation attribute of the bullet should be turned on , Otherwise, the bullet will have an unsatisfactory effect in the subsequent collision .
11.1.4 Use object groups to create bullets
Because bullets need to be fired automatically at certain intervals , We now use the object group component to uniformly manage bullets . At this point, add an object group to the physical world , Select the scope of management for the whole canvas ( Here you need to leave a little gap at the top and bottom for later collision treatment ):


After adding, it was found that the plane and bullets were missing , This is because the object group covers the picture of the protagonist of the aircraft and the picture of bullets . At this time, the order of object groups in the object tree can be placed at the bottom ( The closer the object tree is to the top, the higher the priority is displayed ).

Then add the bullet component to the picture group :

Because the bullets are fired at intervals , At this point, we need to create a trigger in the foreground to launch bullets regularly :

Then set the trigger interval to 0.3, And turn on autoplay :

Then set the event for the trigger , The condition is when the trigger is triggered , Use the create object action of the object group component and set the template object as bullet object :

We then set an initial position for the bullet , This position can be set as the position of the protagonist plane , Then fine tune the position of the bullet in the nose of the aircraft :

When we run the program, we will find that the bullet will be fired automatically :

11.1.5 Bullet optimization
The bullet will not disappear automatically , We can add a rectangular component at the top and name it top , After adding object components to this component , Set the position to fixed xy Coordinates and fixed rotation angle :

Next, let's add an event to the bullet , This event is triggered to start collision , Select the collision object as the top , The current action is automatically removed :

If you preview the item again, you will find that the bullet will disappear automatically , But the objects at the top have borders and colors , Let's click on the top component , Change the transparency of the background color to 0, Then change the border width of the component to 0, The component can visually disappear into the page :

Then we began to add mobile events to the aircraft protagonist . We click on the foreground to add an event , When the fingers are pressed , The aircraft protagonist assembly will move to this position within the specified range :

11.1.6 Set up enemy aircraft
Then we add enemy planes . Add a picture component to the object group , And add object components :

Click object component , Set the damping to 0.95 And turn on the fixed rotation angle , At this time, the speed of the aircraft falling from the top will slow down :

We will give another collision event to the enemy aircraft components at this time , It disappears automatically when it hits a bullet :

Add another event to the bullet assembly , It disappears automatically when it encounters an enemy plane :

At this point, we start to create enemy aircraft in batch , We create a numeric variable named random x, Random horizontal axis position for enemy aircraft :

Then we give random in the trigger x Random values of variables :

Then use the object group in the trigger to create the aircraft object ,X The value is random x A variable's value , Y Value gives a fixed value a certain distance from the top :

At this time, the enemy plane will fall to the bottom of the screen without hitting , At this time, add a transparent rectangular component at the bottom and name it bottom , The enemy plane disappears automatically after triggering :


11.1.7 Optimize the game
Next, create a variable to record the number of enemy planes shot down :

When the bullet touches the enemy aircraft, the value is increased by one :

We create a text named shoot down at the front desk , Used to display the variable value and set the initial text to 0:

Then add an action when the bullet touches the enemy plane , The contents of the variable will be displayed :

At this time, the preview content will achieve the scoring effect :

Finally, add the action when touching the enemy plane in the protagonist's plane :

In the above events, when the protagonist aircraft touches the enemy aircraft and uses the physical world and trigger to execute the pause action, the game will stop .
Finally, consider the user experience , After we stop, we will display a game end text . Add a text in the foreground and name it the end of the game , The default is invisible :

When the enemy plane touches the protagonist, add the end of the game text display operation :


边栏推荐
- Load and domcontentloaded in JS
- Infiltration records of CFS shooting range in the fourth phase of the western regions' Dadu Mansion
- Evolution of Himalayan self-developed gateway architecture
- 2022 operation of simulated examination platform for melting welding and thermal cutting work license
- About asp Net core uses a small detail of datetime date type parameter
- The first "mobile cloud Cup" empty publicity meeting, looking forward to working with developers to create a new world of computing!
- How to determine whether the current script is in the node environment or the browser environment?
- Global and Chinese market of avionics systems 2022-2028: Research Report on technology, participants, trends, market size and share
- The pain of Xiao Sha
- Slf4j print abnormal stack information
猜你喜欢

学习笔记24--多传感器后融合技术

Picture puzzle wechat applet source code_ Support multi template production and traffic master

Design and control of multi rotor aircraft (VII) -- sensor calibration and measurement model

Schrodinger's Japanese learning applet source code

Edge extraction edges based on Halcon learning_ image. Hdev routine

Common loss function of deep learning

Synthetic watermelon game wechat applet source code / wechat game applet source code

Weather forecast applet source code weather wechat applet source code

The pain of Xiao Sha

Datawhale 社区黑板报(第1期)
随机推荐
Picture puzzle wechat applet source code_ Support multi template production and traffic master
8.8.4-PointersOnC-20220215
Excel search and reference function
Since I understand the idea of dynamic planning, I have opened the door to a new world
一名优秀的软件测试人员,需要掌握哪些技能?
Summary of Aix storage management
[eight sorts ④] merge sort, sort not based on comparison (count sort, cardinal sort, bucket sort)
站在新的角度来看待产业互联网,并且去寻求产业互联网的正确方式和方法
Powerful calendar wechat applet source code - support the main mode of doing more traffic
Exclusive delivery of secret script move disassembly (the first time)
Sql--- related transactions
@Valid parameter verification does not take effect
Based on Simulink and FlightGear, the dynamic control of multi rotor UAV in equilibrium is modeled and simulated
Global and Chinese market of safety detection systems 2022-2028: Research Report on technology, participants, trends, market size and share
King combat power query renamed toolbox applet source code - with traffic main incentive advertisement
Han Zhichao: real time risk control practice of eBay based on graph neural network
SQL injection for Web Security (2)
MySQL winter vacation self-study 2022 12 (4)
970 golang realizes the communication between multithreaded server and client
ACM tutorial - quick sort (regular + tail recursion + random benchmark)