fcn从头开始

Recently, I’ve decided to take a break from coding on IDE’s and go back to the basics of exploring the logic behind programming. Scratch came to my mind. Scratch is such a wonderful yet simple application for those who want to grasp the main ideas of programming.

最近,我决定在IDE的编码上稍作休息,回到探索编程背后逻辑的基础知识。 划痕浮现在我的脑海。 对于那些想掌握编程主要思想的人来说,Scratch是一个奇妙而简单的应用程序。

In this Simple Games Series, you will learn about the process of creating simple games with Scratch from scratch. I hope you find it educational, fun, and engaging. Let’s get started!

在本“ 简单游戏系列”中 ,您将学习从头开始使用Scratch创建简单游戏的过程。 希望您发现它具有教育意义,娱乐性和吸引力。 让我们开始吧!

游戏总结 (Game Summary)

The goal of this game is to catch as much fish as you can within a one-minute time frame. The player controls the movement of the penguin with the arrow keys.

该游戏的目标是在一分钟的时间内捕获尽可能多的鱼。 播放器使用箭头键控制企鹅的移动。

Full game can be played here.

可以在这里玩完整游戏。

组件 (Components)

This game is fairly simple. It can be roughly divided into three parts:

这个游戏很简单。 它可以大致分为三个部分:

  1. Sprites (characters) and backdrops: Speech bubbles, controlling the movements of the penguin and the fish, as well as changing orientations.雪碧(人物)和背景:泡泡,控制企鹅和鱼的运动,以及改变方向。
  2. Variables: Keeping the score and the time.变量:保留分数和时间。
  3. Game Flow Control: Starting, initializing/resetting, and ending the game, as well as changing backdrops.游戏流程控制:开始,初始化/重置和结束游戏,以及更改背景。

1.精灵 (1. Sprites)

In this game, we are only using two sprites and two backdrops. The sprites are the penguin and fish. The backdrops are the arctic scene and the underwater scene. Credits to https://www.freepik.com/ for our fish and underwater backdrop.

在此游戏中,我们仅使用两个精灵和两个背景。 精灵是企鹅和鱼。 背景是北极场景和水下场景。 感谢 我们的鱼类和水下背景 https://www.freepik.com/

企鹅的运动 (Movement of the penguin)

We control the penguin with our arrow keys. Having the penguin selected in the sprites pane, we drag the when __ arrow key pressed Events block to our code. For each arrow, we would like to move left, right, up, and down correspondingly.

我们用箭头键控制企鹅。 在Sprites窗格中选中企鹅后,我们将按下__箭头键的 Events块拖动到了我们的代码上。 对于每个箭头,我们想分别向左,向右,向上和向下移动。

Image 1 — Arrow key controls for the penguin
图像1 —企鹅的箭头键控件

Because we want the penguin to be facing left/right as it moves left/right, we create two different costumes (one facing left and one facing right), switching costumes as the player controls the penguin with the left and right arrow keys (the switch costume to ___ block does the trick).

因为我们希望企鹅在向左/向右移动时朝左/向右,所以我们创建了两种不同的服装(一种朝向左,另一种朝向右),在玩家使用左右箭头键控制企鹅时切换服装。 将服装换成___块就可以了。

鱼的运动 (Movement of the fish)

In this game, the fish bounces off the edges and moves in random directions in the water. The idea behind this is that the fish picks a random direction to travel. As it hits the edge, it bounces off and picks a random direction to move again.

在这个游戏中,鱼从边缘弹起并在水中向随机方向移动。 这背后的想法是鱼会随机选择一个方向行驶。 当它撞到边缘时,会弹起并随机选择一个方向再次移动。

Image 2 — Fish movement logic
图片2-鱼运动逻辑

抓鱼 (Catching the fish)

When the penguin touches the fish, the fish should disappear and the score should increase by 1.

当企鹅碰到鱼时,鱼应消失并且分数应增加1。

We first create a variable, Score. Then we set a condition on the penguin: if it touches the fish, then we add 1 to the score and broadcasts a signal, caught.

我们首先创建一个变量Score 。 然后,我们在企鹅上设置条件:如果企鹅碰到了鱼,则将分数加1并广播信号catch

Image 3 — Logic for the penguin to catch the fish
图3 —企鹅捉鱼的逻辑

For the fish, we ask it to hide itself when it is touched by the penguin, then go to a random position. This is to create the illusion that it is eaten by the penguin, and a new fish has appeared.

对于鱼,我们要求它在被企鹅触摸时隐藏自身,然后移至随机位置。 这是给人一种幻想,它被企鹅吃掉了,并且出现了一条新鱼。

Image 4 — When the fish is caught
图片4 —抓鱼时

After hiding for 1.5 seconds, it can then be displayed again using the movement logic in Image 2.

隐藏1.5秒后,可以使用图像2中的移动逻辑再次显示它。

2.变量 (2. Variables)

We will discuss mostly about the timer variable as we have already talked about the Score variable earlier.

由于我们之前已经讨论了Score变量,因此我们将主要讨论有关timer变量的内容。

Even though Scratch has a built-in timer, we are going to create our own timer because it is easier to control. We will be adding 1 to the timer variable for every 1 second that has passed until it reaches 60 (one-minute time limit).

即使Scratch具有内置计时器,我们仍将创建自己的计时器,因为它更易于控制。 我们将在每经过1秒的计时器变量中加1,直到达到60(一分钟的时间限制)为止。

Image 5 — Keeping track of the timer
图片5 —跟踪计时器

3.游戏流程控制 (3. Game Flow Control)

For any game set up, we need to be able to “initialize/reset the game”, “start the game”, and “end the game”.

对于任何设置的游戏,我们都需要能够“初始化/重置游戏”,“开始游戏”和“结束游戏”。

For more information on the types of Scratch Blocks, this page is a good reference.

有关暂存块类型的更多信息, 此页面是不错的参考。

初始化精灵的位置,背景和变量 (Initializing the sprite position, backdrop, and variables)

“Initializing/Resetting the game” simply means to set the game to its initial condition, so that the player starts with the same condition every time. In this case, we would like the game to start with setting both the timer and score to 0. We would also want to ensure that the timer is stopped before the player starts playing the game.

“初始化/重置游戏”只是意味着将游戏设置为初始状态,以便玩家每次都以相同的条件开始。 在这种情况下,我们希望游戏从将计时器和得分都设置为0开始。我们还希望确保在玩家开始玩游戏之前停止计时器。

Image 6 — Triggering initialization
图像6-触发初始化

The event that triggers the initialization is when the green flag is clicked. We make a signal, init, to tell the program that we need to set our game to the initial state. This can be done as shown in the image above.

触发初始化的事件 是单击绿色标志时 我们发出一个信号init 告诉程序我们需要将游戏设置为初始状态。 如上图所示,这可以完成。

The image below is a visualization of how our game starts. We are using the penguin sprite and the arctic backdrop provided by Scratch.

下图是我们的游戏开始方式的可视化视图。 我们正在使用Scratch提供的企鹅精灵和北极背景。

Image 7 — Starting Screen (graphic elements from Scratch)
图7 —启动屏幕(从头开始的图形元素)

Initialize the penguin

初始化企鹅

For the penguin, when it receives the init signal, it will switch its costume, go to the initial position (x:30 y:20), and stand upright (in the direction of 90), just as shown in Image 7. Image 8 is what it looks like in Scratch code.

对于企鹅,当它收到初始化信号时,它将转换其服装,转到初始位置(x:30 y:20),并直立(沿90方向),如图7所示。 8是Scratch代码中的样子。

Image 8 — Penguin init code
图8 —企鹅初始化代码

Initialize the fish

初始化鱼

We want to hide the fish when the game is not yet started. To achieve this, we simply construct the logic like below.

我们想在游戏尚未开始时将鱼藏起来。 为了实现这一点,我们只需构造如下的逻辑。

Image 9 — Hiding the fish
图片9 —隐藏鱼

Initialize the backdrop

初始化背景

The backdrop is initialized to the arctic scene.

背景被初始化为北极场景。

Image 10 — Initialize backdrop
图片10-初始化背景

Initialize the variables

初始化变量

The variables are all set to 0 before the player starts playing.

在播放器开始播放之前,所有变量都设置为0。

Image 11 — initialize variables
图11 —初始化变量

开始游戏 (Starting the game)

The game starts when the players “press the space key”. When the game receives the space key signal, the backdrop will switch from the arctic scene to the underwater scene, and the penguin will switch costumes. Additionally, we will also show the timer and the Score variables on the screen so the players can keep track of their progress.

当玩家“按下空格键”时,游戏开始。 当游戏收到空格键信号时,背景将从北极场景切换到水下场景,而企鹅将切换服装。 此外,我们还将在屏幕上显示计时器Score变量,以便玩家跟踪自己的进度。

Image 12— Starting the game
图12 —开始游戏

Then, the penguin can start catching the fish! All we need to do is grab the block that we made earlier in Catching the fish (Image 3) and put it in a forever block.

然后,企鹅就可以开始钓鱼了! 我们需要做的就是抓住我们先前在“捉鱼” (图3)中制作的方块,并将其放置在永久的方块中。

Image 13— Connecting Image 3 and Image 12
图13 —连接图3和图12

结束游戏 (Ending the game)

Now it works perfectly — the penguin can catch the fish and we can keep track of the Score. But how do we end the game? (Hint: what is the timer for?) There is only one situation that this game would end, that is, when the timer hits 1 minute.

现在它可以完美工作了-企鹅可以钓到鱼,并且我们可以跟踪得分 。 但是,我们如何结束游戏呢? ( 提示:计时器的作用是什么?)只有一种情况,该游戏将结束,即计时器达到1分钟时。

To set the “end game condition”, we need an if…then/else block nested in the forever block. When the timer reaches 60, we would set the timer to 0, and the penguin would tell the player his/her score. Finally, we will stop the game with the stop all block.

要设置“最终游戏条件”,我们需要一个if ... then / else块嵌套在永远块中。 当计时器达到60时,我们将计时器设置为0,企鹅会告诉玩家他/她的得分。 最后,我们将使用stop all块停止游戏。

forever永远的 block区块中添加“最终游戏条件”

And there you have it, a simple game made with Scratch!

有了Scratch制作的简单游戏!

您可以建立的东西… (Things you can build upon…)

  1. Make the fish move smarter. For example, moving away from the penguin instead of choosing a random direction to move.使鱼变得更聪明。 例如,远离企鹅而不是选择随机方向移动。
  2. Add game levels.添加游戏级别。
  3. Set a threshold score that the player should achieve in one minute.设置玩家在一分钟内应达到的阈值分数。
  4. ANYTHING ELSE!!还要别的吗!!

See my next post on Scratch: Simple Game Series 2 — Guess the Instrument!

请参阅我的下一篇关于Scratch:简单游戏系列2-猜猜乐器的信息!

翻译自: https://medium.com/swlh/scratch-simple-game-series-1-catch-the-fish-69265bcae84c

fcn从头开始


http://www.taodudu.cc/news/show-4529824.html

相关文章:

  • 百度之星2019决赛摸鱼记
  • 向上(向下)转型的理解与应用
  • Java基础之面向对象部分详解
  • 13. find
  • 我国羽绒制品在欧洲遭遇部分消费者抵制
  • 你真的认为iPhone只是一部手机?苹果惊天秘密之 二
  • 从计算机视觉角度深入解读了AR
  • 时间序列(一):上手体验
  • 深度学习目标检测之RCNN、SPP-net、Fast RCNN、Faster RCNN
  • Osg使用osgQt与Qt结合使用(附项目)(1)
  • 四元数绕某个轴旋转某度之后的得到的四元数+pcl使用总结
  • PCL 实战记录 (一)
  • 房价租金预测总结笔记
  • 《Python计算机视觉编程》一书中关于增强现实茶壶显示的程序
  • Python计算机视觉编程第三章——图像到图像的映射
  • 在cmd下import cv2报错——OpenCV实现BRISK
  • Python计算机视觉编程学习笔记 三 图像到图像的映射
  • 数据化运营chapter3_code--数据处理
  • 数据化运营chapter4_code--分析模型和方法
  • 姿态估计2-08:PVNet(6D姿态估计)-源码无死角解析(4)-RANSAC投票机制
  • 一小时让你成为点云建图小将(固定帧数法选取关键帧)
  • 分享一个电信永久0月租的手机卡
  • 刷题周记(八)——#区间DP:多边形、清空字符串 #状态机:股票买卖I~V、大盗阿福
  • Nvidia Jetson NX配置教程 for 阿福哥
  • 82599网卡驱动rx descriptor结构体分析
  • 看啊福卡
  • 石家庄阿福卡4G问题
  • 二维数组的偏移计算
  • 二维数组的定义和使用
  • (二)DDL操作数据库

fcn从头开始_从头开始:简单游戏系列1-抓鱼相关推荐

  1. java \t怎么从头开始_通过这些简单的步骤从头开始学习Java

    java \t怎么从头开始 Java是用于软件开发的最受欢迎的编程语言之一. 无论您的最终目标或技能水平如何,学习和掌握Java都将为您作为开发人员打开大门. 今天,我们将讨论一些原因,我们认为您应该 ...

  2. fcn从头开始_从头开始有营销问题

    fcn从头开始 by Steve Krouse 史蒂夫·克劳斯(Steve Krouse) 从头开始有营销问题 (Scratch Has a Marketing Problem) At first, ...

  3. 小班计算机游戏教案,幼儿园小班游戏教案15篇_幼儿小班简单游戏教案

    学习目标: 锻炼控制身体活动的能力. 活动准备: 轻快的音乐. 活动过程 1.播放轻快音乐,幼儿随意走动. 2.当老师说"我们都是木头人,一不准说话.二不准动,三不准露出大门牙"时 ...

  4. python大鱼吃小鱼_写简单游戏,学编程语言-python篇:大鱼吃小鱼

    下面的图片是网上随便找的素材,这里用于切换主角的图片有三张,其他则是其他小鱼和boss鱼.我们控制的主人鱼的大小范围来决定加载不同的图片.以上准备的素材,其中一些背景色没有时间做处理,所以游戏中会有难 ...

  5. 使用红孩儿工具箱完成基于Cocos2d-x的简单游戏动画界面

    [Cocos2d-x相关教程来源于红孩儿的游戏编程之路CSDN博客地址:http://blog.csdn.net/honghaier 红孩儿Cocos2d-X学习园地QQ3群:205100149,47 ...

  6. 碰撞检测碰撞Java简单游戏开发之碰撞检测

    最近研究碰撞检测碰撞,稍微总结一下,以后继续补充: 前言 未几之前在论坛上有人发贴,使用java编写的超级马里奥如何实现碰撞检测,笔者自己以前 也做过Tank大战.里面一样涉及到碰撞检测,翻翻U盘里的 ...

  7. 用python写数字_用python 写游戏之数字华容道

    当初对这个游戏颇有印象还是在最强大脑节目上面,何猷君以几十秒就完成了这个游戏.写2048游戏的时候,又想起了这个游戏,想着来研究一下. 游戏玩法 用尽量少的步数,尽量短的时间,将棋盘上的数字方块,按照 ...

  8. 【dfs】简单游戏(jzoj 2121)

    简单游戏 题目大意 原本有n个数字,第1,2个相加,第2,3个相加--第n-1,n个相加,由此得出一个长度为n-1的新序列,然后不停重复,最后得出一个t,现在给出一开始的n和t求符合的序列(字典序最小 ...

  9. 05-Flutter移动电商实战-dio基础_引入和简单的Get请求

    05-Flutter移动电商实战-dio基础_引入和简单的Get请求 这篇开始我们学习Dart第三方Http请求库dio,这是国人开源的一个项目,也是国内用的最广泛的Dart Http请求库. 1.d ...

最新文章

  1. Linux系统调用的运行过程【转】
  2. 如何把word分装到两个byte_如何核对两个Word文档的内容差别?同事加班半小时,我只花了30秒...
  3. 计算机大学一个专业几个班,2016年兰州大学计算机类(含基地班、计算机科学与技术等4个专业)专业最低分是多少?...
  4. 百度发布AI芯片“昆仑”;李笑来脏话录音曝光;Facebook再现新漏洞 | CSDN 极客头条...
  5. 学习git: 忽略某些文件(夹)的跟踪
  6. Acrobat Pro DC 教程,如何使用文本和图片文件创建 PDF?
  7. c++ time_t和tm
  8. 被称为海淀妈妈四大神器之一的倾听者K3 硬件拆解
  9. [蛋蛋涂鸦]难道要学达芬奇画鸡蛋喵??
  10. 表示美元的符号html代码,美元符号HTML属性名称
  11. 【Python】基于机器学习的财务数据分析——识别财务造假
  12. 大数定理与中心极限定理
  13. Python视觉深度学习系列教程 第一卷 第21章 案例:使用CNN破解验证码
  14. Joint Discriminative and Generative Learning for Person Re-identification 论文翻译
  15. 应用上云2小时烧掉近50万,创始人:差点破产
  16. 【详细图解】一步一步教你自定义博客园(cnblog)界面
  17. Java 多张图片 转PDF格式
  18. A星(A*, A Star)算法详解
  19. Arduino UNO通过电容的直接检测实现简易触摸开关
  20. RTSP+RTP协议剖析

热门文章

  1. 单例模式-多线程单例模式
  2. Flutter 状态管理之Bloc上
  3. CAP理论为什么不能同时满足
  4. CatDriver 小米 猫盘 Boot Info
  5. 牛叔说电影-圣堂四骑士
  6. 老婆的美丽背影------俞敏洪
  7. 项目总估值从70亿到150多亿,成功运营首期的腾讯AI加速器正招募第二期
  8. 留数定理构造围道计算实积分类型大全
  9. 川崎机器人signal_川崎机器人信号表
  10. 提供一些网上webservice的WSDL地址