当前位置:网站首页>["plaything determination" scratch children programming] tank turbulence - "implementation of" through wall control "and" bullet rebound "- including complete code
["plaything determination" scratch children programming] tank turbulence - "implementation of" through wall control "and" bullet rebound "- including complete code
2022-07-18 12:24:00 【A a a Feng】
Preface
Blogger Homepage : A Feng's homepage _CSDN
scratch It is a programming tool mainly for children , There are also many big friends like it , Because it does Simple and interesting , By building blocks , You can build some interesting programs . We've played 4399 Is the tank turbulent ? Have you tried to realize it by yourself ? This article records my use of scratch Try to realize the process of tank turbulence Games , Some of the problems we encountered .
In the process of making the program , I referred to b Video of the station , A video link is attached below .
Programming tools :scratch Web version
Reference material :scratch Tanks war -b standing
Get full code :.sb3 Complete source code
List of articles
1. Program demonstration

2. Through wall control
The solution of through wall control comes from the beginning of the article b standing up Lord
In the process of realizing the through wall control of character movement , I am used to using such logic :
1) Move in the specified direction
2) Check whether it touches the wall
3) If you come across , Then return to the original position
in other words , I put every time motion and Wall impact detection Bound together , But then I found one problem :
In order to make the tank move more smoothly , Every movement Stride They are all designed to be small . So if a part of the tank is already on the wall , At this point we No matter which direction you move , Will detect touching the wall , Then return to the original position .
in other words , The tank will get stuck on the wall .
But the rotation of the tank model , It often leads to the situation of some walls , Hard to avoid .
Solution :
Give the tank The front and back parts are painted with frames of different colors .
effect : When the front of the tank is on the wall , The tank can move backwards , Get rid of the wall .( The situation is similar when the rear of the tank is on the wall )
3. The bullet bounced
3. 1. explain
Be careful : Here we only realize the situation that the wall is horizontal or vertical
When considering the rebound of bullets , We should be aware of the following problems :
1) Usually , We need to know about bullets Own direction 、 The direction of the bullet Angle with the wall , We can get the direction after the bullet bounces .
2) Even if only horizontal and vertical walls are considered , There are also two situations . How do we judge the impact Is the wall horizontal or vertical ?
stay scratch Next , Judge the direction of the wall at the time of collision , I'm really a little confused .
But I have an idea behind me : Use intermediate results .
First assume that only one wall side needs to be considered , Here we consider the horizontal wall , Then the inclination of the wall is fixed , We Just know the direction of the bullet itself You can calculate the direction of the bullet after it bounces , Such as The figure below :

It's simple to consider only horizontal walls , What should we do with our vertical walls ? We consider such a factor : The wall is thick .
Considering all horizontal walls , What happens when a bullet collides with a vertical wall ? The bullet Still like hitting a horizontal wall Same rebound , Then it must Through the wall , So we can use this feature to judge whether the bullet hit the wall horizontally or vertically :
1) When the bullet hits the wall , First, press the bullet to hit the horizontal wall Change direction
2) The bullet continued to move a small step in a new direction
3) Check the collision between the bullet and the wall again :
- If the bullet is now No collision The wall , The bullet has separated from the wall , Explain that the wall is The transverse Of
- otherwise , It means that the bullet is trying to pass through the wall , Then the wall is vertical Of
4) If the wall is vertical , At this point, we will determine the direction of the bullet reverse That is, you can get the correct rebound direction

3. 2. Demonstration of rebound decomposition action
Above is 0, Directly below is 180(-180), On the right is 90, Positive left is -90

Conclusion
🧭 In the article start , There is complete program source code in csdn Of Download address , Friends in need can download by themselves .
🧭 The main content of this article has ended here !
🧭 This time, with my own try , Solved a small problem encountered , I still have a sense of achievement .
🧭 If this content sharing helps you , Just support bloggers !
边栏推荐
- pinctrl子系统和gpio子系统
- MYSQL一站式学习,看完即学完
- Redis data structure practice, see how microblogging, wechat, shopping cart, lottery applet is used?
- [chicken soup] things are difficult and easy in the world
- Luogu questionnaire - greed
- Openeuler knowledge: management strategy
- Gson解析生成json数据工具类
- thinkphp 代码执行 (CNVD-2018-24942)
- Community summit pulsar summit old golden peak conference topic highlights exposure!
- C # use jobject to resolve nested JSON
猜你喜欢

接口自动化测试:Postman实战教程

En trois étapes, j'ai terminé MySQL en une journée, ce qui m'a permis d'obtenir l'offre de tmall en douceur.

Excel-vba quick start (VII. Get cell objects)

Gin框架的使用

Introduction, installation and use of terrain command line tools

Openeuler knows: the solution of IP addr not finding IP

Introduction, installation et utilisation des outils en ligne de commande terraform

【Jailhouse 文章】Bao: A Lightweight Static Partitioning Hypervisor for Modern Multi-Core Embedded...

openEuler 知:SIG

Basic part of C language: pointer (elementary level)
随机推荐
【“玩物立志”scratch少儿编程】坦克动荡-“穿墙控制”和“子弹反弹”的实现-含完整代码
ThinkPHP code execution (cnvd-2018-24942)
逆向学习笔记(一)
ThreadLocal killed 11 people. I can't bear it
C# 使用JObject解析嵌套json
279. 完全平方数
Logic of automatic reasoning 02 propositional calculus
Xunwei Godson development board domestic dual core 64 bit loognix system dual Gigabit Ethernet more interfaces
【MOCO基础】Attention, learn to solve routing problems(Wouter Kool, 2018)
从应用到底层:36张图带你进入Redis世界(下)
管网管理GIS服务平台有何功能?
【对象转换】vo2dto使用
技术分享| 快对讲-5G对讲
Interview frequency: how does MySQL ensure high availability?
openEuler 知:SIG
Free SSL certificate application and deployment practice
【微信小程序】简洁好用的icon(94/100)
三个步骤,一天就搞定了MySQL,让我顺利拿下了天猫offer
Rebuild binary tree
【名词】LTS