从零开始学游戏编程——可视化编程游戏开发工具学习指南
Scratch程序设计

Scratch程序设计Scratch是一款由麻省理工学院媒体实验室开发的图形化编程语言,用于教授编程概念和激发创造力。
它的用户界面简单易用,适用于初学者和儿童。
通过拖拽和组合各种图形化模块,人们可以简单快捷地创建交互式故事、动画和游戏。
一、Scratch的基础使用方法1. 登陆和创建账号要使用Scratch,首先需要登陆并创建一个账号。
这样可以保存你的项目,并与其他Scratch社区的用户进行交互。
2. 创建新的项目在Scratch界面上,点击“新项目”按钮,开始一个新的项目。
你可以自由命名和保存你的项目。
3. 编程积木Scratch使用积木来表示不同的编程指令。
例如,单击并拖动“向前移动10步”积木,将其放到项目背景中的一个角落里,角色会根据指令向前移动10步。
4. 角色和背景选择Scratch提供了丰富多样的角色和背景供用户选择,你可以根据需求选择合适的角色和背景进行创作。
二、Scratch的进阶功能1. 自定义积木为了满足特定需求,Scratch允许用户创建自定义积木。
通过自定义积木,你可以封装常用的代码片段,以便在项目中多次使用。
2. 事件积木Scratch的事件积木用于触发某些动作。
例如,当用户按下键盘上的特定按钮时,可以触发相应的动画或声音。
3. 控制积木控制积木用于控制程序的流程和循环。
通过控制积木,你可以实现条件判断、循环执行等功能。
4. 运算积木运算积木允许用户进行数学计算、字符串处理等操作。
例如,你可以通过运算积木实现得分计算、随机生成等功能。
三、Scratch在教育中的应用1. 培养创造力和逻辑思维Scratch的图形化编程方式使得编程变得直观可见,降低了入门门槛。
通过编写自己的故事、动画和游戏,学生可以培养创造力和逻辑思维能力。
2. 跨学科教学Scratch的应用不仅仅局限于计算机科学领域,还可以与其他学科进行结合。
例如,学生可以使用Scratch制作科学实验模拟,学习物理、化学等科学知识。
Kodu教程

目录:
零基础教会孩子学会 Kodu 编程---Kodu 少儿编程第零天 第什么是 Kodu---Kodu 少儿编程第一天 Kodu 的下载与安装---Kodu 少儿编程第二天 初识 Kodu 开发软件---Kodu 少儿编程第三天 Hello World---Kodu 少儿编程第四天 让 Kodu 动起来---Kodu 少儿编程第五天 Kodu 吃苹果---Kodu 少儿编程第六天 Kodu 程序的菜单---Kodu 少儿编程第七天 社群的使用---Kodu 少儿编程第八天 颜色选择器---Kodu 少儿编程第九天 计分---Kodu 少儿编程第十天 有赢有输---Kodu 少儿编程第十一天 会说话的 Kodu---Kodu 少儿编程第十二天
有了新的起跑线焦虑。随之产生了诸多疑问:要不要学少儿编程?几岁学?怎么学?学了有什么 用?等等一系列关于少儿编程的问题。有些问题我能解答,有些问题我也不懂。上了学的孩子们 肯定都知道“小马过河”的故事,也知道这个故事告诉我们要勇于尝试,所以,让孩子试试吧。 这系列文章非常适合了解电脑基本操作孩子学习。更适合家长和孩子一起学习。 此文是个引子,我会一直更新。文章会讲解 Kodu 的特点、安装、相关配置,Kodu 的每个一对象 (角色)的使用及特点,Kodu 的 UI 设计及大量实例,并在讲解过程中穿插真实编程中的基本概 念。因为是给未接触过编程的孩子写的,所以我会尽量简单,由浅入深。 学完了咱们的孩子坐着婴儿车,拿着奶瓶坐在院门口晒太阳,也许就会有掉光头发的大叔拿着一 本《设计模式》说:“小朋友,我看你骨骼精奇,是万中无一的编程奇才......这本书十块钱卖给你。” 一定要告诉孩子,千万别买。咱这儿有免费的公众号可以学。 学完家长朋友们也再也不会纠结报什么班,花多少钱了。因为咱懂,咱会,咱也是 IT 圈儿里人 了。 家长们,让孩子走进编程的世界,看看这个世界有什么,和孩子一起学习,和孩子一起成长。这, 一定是您和孩子拥有的一段美丽时光。以后,也是您和孩子一段美好的回忆。
scratch编程游戏教程

scratch编程游戏教程Scratch 是一个非常流行的学习编程的工具,它使用简单的图形化界面和积木块的方式让编程变得更加容易学习和理解。
在这篇文章中,我将为你提供一个 Scratch 编程游戏的教程,帮助你开始编写自己的游戏!首先,你需要打开 Scratch 的网页版本或下载并安装 Scratch 软件,以便开始学习和编写代码。
一旦你进入 Scratch 的界面,你会看到一个空白的舞台和一个积木块的选择区。
第一步是为你的游戏创建一个角色。
在 Scratch 的右上角,你会看到一个角色库,在那里你可以选择一个已有的角色或者创建一个新的角色。
选择一个你喜欢的角色,并在舞台上将其放置到你想要的位置。
接下来,我们将给角色添加动作和行为。
在 Scratch 的积木块中,你会看到不同种类的积木块,如“运动”、“外观”、“声音”等。
为了使角色动起来,我们选取一个“运动”积木块,比如“移动 10 步”,然后将其放置在开始积木块下面,这样当你点击旗子图标时就会使角色移动。
此外,你还可以选择其他有趣的动作和行为来丰富游戏的体验。
比如,你可以使用“外观”积木块来改变角色的外观,使用“声音”积木块来让角色发出声音等等。
尝试不同的积木块来表达你的创意!在编写游戏时,你还可以创建条件来控制游戏的流程。
你可以使用“控制”积木块中的条件积木块,如“如果...那么”、“重复...次”等来控制程序的逻辑。
通过这些条件,你可以设置不同的游戏规则和胜利条件,使游戏更有挑战性。
当你已经编写了一些基础的动作和行为后,你可以开始思考其他游戏元素的添加。
你可以使用 Scratch 的绘图工具在角色上绘制图案,或者选择不同的角色来代表其他游戏元素。
你还可以创建新的角色,并与之交互,如碰撞检测或角色之间的对话等。
最后,当你完成了你的游戏之后,你可以点击 Scratch 的绿旗图标进行测试和玩游戏。
如果你发现了一些问题或需要做出改进,不要担心!Scratch 提供了非常丰富的文档和教程供你参考,你可以从 Scratch 的官网或社区中获取更多信息。
如何进行图形编程和可视化开发

如何进行图形编程和可视化开发图形编程和可视化开发是一种将数据、图像、动画等可视化呈现的技术,常用于数据分析、科学可视化、游戏开发等领域。
本文将介绍如何进行图形编程和可视化开发,并提供一些实用的工具和技术。
图形编程和可视化开发需要掌握一些基本的概念和技术,包括绘图、图形库、图形算法、图像处理、动画、交互等。
以下是进行图形编程和可视化开发的一些重要步骤和技巧:1.学习绘图基础:图形编程的基础是绘图,了解绘图的基本原理和概念是非常重要的。
例如,学习如何创建点、线、矩形、多边形等基本图形,并了解如何使用不同的颜色和样式进行填充和描边。
2.选择适合的图形库:选择适合的图形库可以大大简化图形编程和可视化开发的过程。
常用的图形库包括OpenGL、D3.js、Matplotlib 等。
根据所需的功能和语言选择相应的图形库。
3.理解图形算法:学习一些基本的图形算法,如线段相交、多边形区域判断等,可以帮助我们解决一些常见的图形编程问题。
4.学习图像处理技术:图像处理是可视化开发中的重要环节,可以通过一些图像处理算法和技术来实现图像的增强、滤波、分割和识别等功能。
学习一些图像处理库,如OpenCV,可以快速实现各种图像处理功能。
5.创建动画效果:动画可以增添可视化应用的吸引力和交互性。
学习如何使用图形库提供的动画功能来创建动态效果,如平移、缩放、旋转等。
6.添加交互功能:交互是可视化开发中的重要组成部分,可以通过鼠标、键盘等输入设备与图形进行交互。
学习如何通过图形库提供的事件处理功能来实现交互,如点击、拖拽、缩放等。
7.参考示例代码和教程:学习图形编程和可视化开发的最好方法是参考示例代码和教程。
可以通过搜索引擎找到一些优秀的图形编程和可视化开发的示例代码和教程,从中学习并实践。
另外,以下是一些实用的工具和技术,可以帮助进行图形编程和可视化开发:1.可视化开发工具:可视化开发工具可以帮助我们快速创建和调试可视化应用。
常见的可视化开发工具包括Processing、Unity、Tableau等。
scratch编程教程

scratch编程教程Scratch编程教程在这个教程中,你将学习如何使用Scratch编程语言来创建自己的项目。
无需担心前期的编程经验,Scratch是一种很容易上手的编程语言,适合初学者。
1. 创建新项目打开Scratch网站,点击“新项目”按钮来创建一个全新的项目。
你将进入到一个空白的舞台,这是你的创作空间。
2. 添加角色在舞台上方的“角色”选项卡中,你可以选择一个角色并将其添加到舞台上。
Scratch提供了许多不同的角色,你可以选择你喜欢的,或者自己绘制一个。
3. 创建动画在Scratch中,你可以使用积木来创建动画效果。
在“运动”类别下,可以找到许多控制角色运动的积木。
尝试拖动一个“移动10步”积木到脚本区域,看看你的角色是如何移动的。
4. 添加声音Scratch还支持添加声音效果。
在“声音”类别下,你可以找到许多控制声音的积木。
试着添加一个“播放音效”积木,选择一个你喜欢的音效来播放。
5. 用户输入在Scratch中,你可以让用户与你的项目进行交互。
在“事件”类别下,你可以找到“当绿旗被点击时”这个积木,将它与其他积木组合使用,例如在用户点击绿旗后,角色开始移动。
6. 分享和展示当你完成了你的项目后,你可以点击“分享”按钮将你的作品分享给其他人。
你还可以参加Scratch社区的活动,展示你的作品给其他Scratch用户。
这是一个简单的Scratch编程教程,从中你可以掌握一些基本的操作和概念。
继续探索Scratch,你将能够创建更复杂的项目,并展示你的创造力。
祝你玩得开心!。
从零开始学游戏编程——可视化编程游戏开发工具学习指南

从零开始学游戏编程——可视化编程游戏开发工具学习指南游戏编程一直以来都是一个备受热爱游戏的人们追求的领域。
然而,对于初学者来说,传统的游戏编程语言往往难以理解和掌握,需要较高的编程基础和逻辑思维能力。
而可视化编程游戏开发工具则为初学者提供了一个更加友好和简化的入门方式。
本文将介绍几个常用的可视化编程游戏开发工具,并给出学习指南。
1. Scratch(适合基础学习)Scratch是一款由麻省理工学院媒体实验室开发的可视化编程语言,旨在帮助孩子和初学者学习编程。
它采用拖拽式编程,用户只需要将不同的代码块拖入工作区中并组合起来,就能够完成一些简单的游戏开发。
而且Scratch的界面简洁直观,适合初学者快速上手。
在学习过程中,可以通过官方网站上的教程和项目来进行学习和实践,逐渐提升编程技能。
2. Unity(适合进阶学习)Unity是一款功能强大的游戏引擎,拥有广泛的应用领域。
它支持可视化编程和脚本编程,适合初学者和进阶者学习和使用。
对于初学者来说,可以先学习Unity中的可视化编程工具,PlayMaker,它将复杂的游戏逻辑封装成了一系列可拖拽的图形节点,极大地简化了编程过程。
随着对Unity的进一步掌握,可以逐步学习C#脚本编程,实现更高级的游戏功能。
3. GameMaker(适合创作独立游戏)GameMaker是一个流行的游戏开发引擎,既可以进行可视化编程,也可以使用其内置的脚本语言,GML进行编程。
GameMaker适合想要创作独立游戏的人们,它提供了强大的功能和灵活的定制能力,能够帮助开发者实现自己的游戏创意。
对于初学者来说,可以先尝试使用GameMaker的可视化编程工具,了解游戏制作的基本流程和逻辑,然后再逐步学习GML脚本,实现更复杂的游戏功能。
学习可视化编程游戏开发工具的指南如下:1. 选择合适的工具:根据自己的需求和兴趣选择一款适合自己的可视化编程游戏开发工具,例如Scratch、Unity或GameMaker等。
Scratch游戏开发指南说明书

Coding and Game DesignLearner GuideDo you like to play video games? Have you ever wondered what it takes to make one? Teams of people, including designers, artists, and software developers, work together to create the final game that you can play and enjoy.Watch the Coding and Game Design video to learn more about the day in a life of a game developer.In this activity, you will use Scratch to create a video game called Hungry Mouse. Here the player moves a mouse around to collect all the food without the cats catching it. You begin with starter code—an unfinished version of the code—and will be introduced to some basics of programming that you will use to finish building the game.During this activity, you will practice problem solving and persistence as you code, test, and fix your program.ExploreWhenever you design a video game, you need to identify the goal of the game, the setting, the characters, and their behavior. The table below explains these characteristics for the Hungry Mouse game.Learner Guide | 2Table 1. Game RequirementsIt is time to dive into the source code and start to build your Hungry Mouse game!CollaborationDesigners and software engineers do not work alone. They collaborate during most stages of their design and development of a solution.One common method of collaboration when creating code is pair programming. In pair programming, one person is the driver,who types the code; the other person is the navigator,who sits by the driver’s side and reviews the code, helps fix any errors, and provides any feedback and potential improvements to the program. Software engineers who pair program take turns being driver and navigator, switching roles (every set number of minutes, or every time they change tasks.)If you have a partner to pair up with, try using pair programming to complete the game.1. In a web browser, access the starter code at https:///projects/365612175. Theproject page for HungryMouseStarterCode will appear. Note the game description in the Instructions section.2. Select the See inside button to load the project. The Scratch editor will open allowing you to view andedit the project as you wish.3. Look at the different sections in the Scratch editor.Learner Guide | 3Figure 1. The Scratch EditorThe StageThe top-right section of the Scratch editor —referred to as the stage preview—is where you design what your game will look like. In the section below the stage preview, you can:•Add sprites, such as characters and objects, using the Choose a sprite button•Choose a backdrop for your stage using the Choose a backdrop button•Start the game using the green flag above the stage preview•Stop the game using the stop sign above the stage preview4. Select the Mouse sprite found in the sprites section below the stage. Below the stage you will see allthe properties for the selected sprite.•You can change the properties of a sprite, such as its name, direction, and size.•Note that the stage is a coordinate plane with the origin (0, 0) at the center of the stage. You can specify the starting location of a sprite by setting its x-and y-coordinates.Learner Guide | 45. Select the Costumes tab in the top-left corner of the screen.Make ObservationsA. What do you see?B. What do you think we use costumes for?6. Select the Code tab to view the code for the Mouse sprite.Additional InformationCode is also known as a program. It controls how a sprite behaves when you play the game, which is different from the costumes of the sprite, which define how the sprite looks.7. Select the different code block categories to see the code blocks they include.Make Observations1. What do you think the Events blocks are used for?Learner Guide | 58. Take a few minutes to look through the costumes and the code for all the sprites provided in thegame.Make ObservationsPredict how each of the following sprites will behave when the game begins.1. Mouse:2. Cat1:3. Corn bread:4. Stage:9. Select the green flag located above the stage to start the game. Did you guess the behaviorscorrectly?Learner Guide | 6CreateIn this section, you will complete the code and test the game to make sure it meets all the requirements stated in Table 1.Note: To save your work, you can do one of the following:1. If you have a Scratch account, log in and save your work as frequently as you want,by selecting File > Save now.2. If you do not have a Scratch account, work on the project, then when you are ready to save,download the project to your computer by selecting File > Save to your computer.When you are ready to continue your work, go to https:///projects/editor/,and select File > Load from your computer to open up your saved project and continueyour work.3. Depending on the file storage of your tablet, you may not be able to download and save your files.If you are unable to download the project on your tablet, you will need a Scratch account to save your work.Program the MouseWhen you play the game as it is currently written, the mouse spins around in place and follows the mouse-pointer or fingertip (depending on if you are using a computer or tablet). Read through the pseudocode below to lear n what the mouse’s behavior should be during the game.Pseudocode is an outline written in spoken language for a computer program. This makes it is easy to read but follows coding structure so looks a bit like code.Pseudocode for Mouse behavior when the game begins:When the green flag is clicked (game starts):a. Reset the mouse (back its original position, direction, and look)b. Do the countdown (ready, set, go)c. Reset the timerd. Repeat forever:Mouse moves towards the mouse-pointer/fingertipIf mouse touches cat1 or mouse touches cat2 then:Mouse changes to a hurt mouse costumeLearner Guide | 7Game ends (all sprites stop in place)If time is up, then:Display the“Times Up”backdrop.Game ends (all sprites disappear)10. Make sure you hav e the Mouse’s code open.11. From the Motion category, drag the move 10 steps block and place it below the point towardsmouse-pointer block.12. Select the green flag to test the mouse’s behavior. The mouse should now follow the mouse-pointervery fast. When in place it will look like it is shaking.13. Change the number of steps from 10 to 5 to slow the mouse down and make its motion smoother.14. Run the game to test the code again.Make Observations1. What happens when the mouse collides with the corn bread?2. What happens when the mouse collides with the cats?3. Do these behaviors match the behavior described in the pseudocode above?Learner Guide | 815. From the Looks category, drag the switch costume to Mouse-hurt block and place it in the first ifblock.16. From the Control category, add the stop all block.17. Test your game again and make sure that when the mouse touches either cat, it changes to theMouse-hurt costume and all sprites stop moving.What Is Iteration?By now, you may have noticed that working on a solution requires a lot of testing. Solutions rarely work on the first attempt! They take patience and perseverance. When writing code, you must test your code often and be prepared to fix errors repeatedly as you proceed through the development of your program. The process of repeatedly testing and modifying is known as iteration.18. From the Looks category, drag the hide block and place it in the second if block.Learner Guide | 9What is a broadcast?In a Scratch program, each sprite has its own set of scripts (code) that controls its behavior. But what if you need a sprite’s script to communicate with the other sprites? For example,what if you want one sprite to announce to another that the game has ended or that the game has been reset? You can accomplish this type of interaction between sprites using the broadcast block.In the Hungry Mouse game,whenever the mouse touches a cat, it will need to broadcast the “game over” message to the other sprites. However, simply having the mouse sprite broadcast that message to the other sprites is not enough. The other sprites need programming for how to respond when they receive this message. You will use the when I receive message event block and program the event to react to the broadcast message by stopping all movements on the screen.19. From the Events category, add the broadcast ____ block right below the hide block.20. Select the message dropdown list within the broadcast block, select New message, type“game over”and select OK.21. From the Control category, drag the stop all block and snap it below the broadcast block.Learner Guide | 1022. Select the dropdown list within the stop block and select this script to stop that particular script fromrunning.23. Test your game (make sure to wait 10 seconds) to see how the sprites behave when the time is up,and the game is over.Make Observations1. Do the cats stop moving?2. Do all the sprites disappear?3. Why or why not?Program the Cats to DisappearIn order to make the two cats stop moving when the time is up, you will need to add a new event to handle that scenario.24. Select the Cat1 sprite to edit its code.25. From the Events category, drag the when I receive block and drop it in an open area in Cat1’s codeeditor,and select the“game over” message from the drop down list.What is this block used for?26. From the Looks category, drag the hide block and add it to the event block from the previous step.Learner Guide | 1127. From the Control category, drag the stop all block, and select the“other scripts in sprite”option tomake Cat1 stop moving on the screen.28. Test your game and make sure that Cat1 disappears when time is up.29. Add the same code to Cat2to make it stop and disappear when it receives the“game over” message.Helpful tipIf you are using a Scratch account, you will have the ability to copy and paste code (within the same sprite or across multiple sprites) using the backpack feature, located at the bottom of your screen.To do so, drag the code blocks from the spri te’s code editor to the backpack.You can then switch to another sprite and drag the code blocks from the backpack to the new sprite’s script.This can save you a lot of time if you have very similar code to add to multiple sprites!Program the Corn Bread to DisappearWhenever the mouse touches the corn bread sprite, the code has it change its costume to be half-eaten and then completely gone. However, the corn bread sprite does not disappear when the time runs out. Your next challenge is to add the code blocks to make this happen.30. Like what you did with the cat sprites, add code to the Corn Bread sprite to make it disappear whenthe game is over. Again, make sure to always test the code you add.Program the Stage to ChangeWhen selecting the green flag, the stage’s code currently sets the backdrop to“Woods”and the score to 0.Learner Guide | 1231.the “TimesUp”32. touches the corn 33. 34. From the Variables 35.Real World ConnectionDesigners and software engineers follow an iterative multi-step design process when creating their solutions.Learner Guide | 14Note that at any point during the design process, the team may see the need to go back to a previous step and adjust their design. It is a very iterative approach to solving a problem.ReflectionWhich part of the design process do you think you completed in the coding activity today?Your Next Move1. List three ideas that we can use programming for.2. Pick one of the ideas you listed. What can you do as a next step to make one of your ideas areality?Extension ChallengesIf you would like to add more features to this game, here are some ideas for you to complete on your own!A. Add other pieces of food that the mouse can collect and score more points.B. Add other predators that can catch the mouse.C. Change the behavior of the cats to be random across the screen.D. Add a“You lose!”backdrop that will appear when one of the cats catches the mouse.E. Add another level for the game.Learner Guide | 15。
编程软件scratch教程

编程软件scratch教程编程软件Scratch教程1. 简介Scratch是一款适合初学者的编程软件,它使用图形化的编程语言,而不是传统的代码编写。
通过将图形组合在一起,你可以创建动画、游戏和交互式应用程序。
2. 界面概览打开Scratch后,你会看到一个舞台以及一系列颜色鲜艳的积木。
舞台是你的作品展示区,而积木是不同功能的代码块。
你可以将积木拖动到脚本区域,然后组合起来创建你的程序。
3. 创建角色在Scratch中,角色是你的程序中的可移动对象。
你可以通过点击右下角的角色库图标来选择一个角色,或者自己绘制一个新角色。
你还可以为角色添加不同的背景图像,并对其特征进行自定义。
4. 积木介绍Scratch有许多不同类型的积木,用来控制角色的动作、声音、运动和事件等。
以下是一些常用的积木:- 运动积木:让角色移动、转动或改变尺寸的积木。
- 外观积木:控制角色的外观,如改变颜色、显示隐藏等。
- 事件积木:触发程序中的特定事件,如按下键盘、点击角色等。
- 控制积木:用来控制程序的流程,如循环、条件判断等。
5. 创建程序要创建一个程序,你可以将适当的积木拖到脚本区域,并按照逻辑顺序组织它们。
当你运行程序时,Scratch会按照你的指令执行积木,并在舞台上产生相应的效果。
6. 分享你的作品当你完成一个程序后,你可以将其分享给他人。
在Scratch中,你可以上传你的作品到Scratch网站上的社区,也可以导出为可运行的文件或嵌入到网页中。
总结:通过本教程,你了解了Scratch的基本使用方法和一些常用的积木类型。
现在你可以开始尝试创建自己的程序了!。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
从零开始学游戏编程——可视化编程游戏开发工具学习指南开发游戏可能是学习编程的理由中最吸引人的一条了。
但如何从零开始入门,达到能够开发游戏的编程水平,是困扰无数勇敢少年们的传统难题。
作为一名游戏设计师,我没有系统地学习过编程。
从5年前开始,我有了自己从头完整开发游戏的念头,于是断断续续地看了很多书,试过了很多入门方法和开发环境,但直到近半年才找到正确的门路。
现在我在Unity开发环境下独立制作游戏原型和利用成型的框架完善游戏功能已不成问题。
本文会介绍如何从零开始学习游戏开发编程的方法,希望能为和我一样挣扎在编程大门之外的游戏开发爱好者们提供帮助。
不过事先要说明的是,这种学习思路是为了帮助你在做游戏的过程中逐渐学习编写程序,不适用于其他领域,但作为一种入门方法,它能让你在半年到一年的学习之后,做到独立制做小游戏(或原型)。
门外汉学编程的难点介绍学习方法之前,我们先看看门外汉学编程最常遇到的问题。
第一,程序员们经常说程序语言只是编程工具,但市面上常见的教程都喜欢从语法、算法和程序语言的使用思想开始教学,而不是把编程语言当做解决实际问题的工具来入手。
因此,初学者经常耗费很大精力才能理解书上写的算法和思想,却完全不知道理解之后能用来做什么。
第二,很多编程教程虽然配有实例,但一方面例子的学习难度曲线增加得很快,刚看完一个“Hello World”实例,下一个例子可能就变成教你如何分配内存(真实的故事,我的一本学习Objective-C 的教程就是这样的)。
另一方面初学者在对开发流程不熟悉的情况下,很难做到举一反三,从一个实例里总结出做另外三个游戏的方法,我经常遇见看了三个不同类型的游戏实例,放下书后却连一个游戏都做不出来的情况。
第三,很多编程教程为了提高普适性,在使用现成架构方面都很保守,导致了很多重复造轮子的教程出现。
例如在前几年Cocos2D(一个用于iOS平台游戏开发的游戏引擎)还没有现在这么火时,几乎所有的iOS游戏开发教程讲的都是如何使用OpenGLES来制作游戏图像,而这些底层架构的实现对初学者来说是根本不可能完成的任务。
因此,适合初学者的学习方针是:从实际需求出发;“怎么做”优于“为什么”(为什么可以在入门之后再慢慢理解);使用允许你偷懒的工具或架构(需要做的越少越好)。
这些要求其实很容易满足,答案恰恰在看起来和编程关系不大的领域——可视化编程工具里(Visual Programming Tools)。
可视化编程游戏引擎让你先做再想可视化编程泛指一切使用可视化元素的操作代替文本输入的程序设计方式,大体上就是像画流程图一样通过连接若干“盒子”和“箭头”来实现程序逻辑。
这个概念在游戏开发工具上的应用越来越流行,近年来还有井喷趋势,从老牌的GameMaker、RPGMaker、TorqueGameBuilder、到新兴的GameSalad、Construct 2和Unity都是其中的代表。
尽管这些工具和引擎各有不同的开发方式,但它们都能让初学者在完全不懂编程语法和复杂算法的情况下快速实现自己的游戏设计。
我之前的态度是宁可抱着“看也看不懂,看懂了也不会做”的书苦学XNA(一个微软发布的使用C#的游戏开发架构)和Cocoa(苹果发布的使用Objective-C的应用开发架构),也不屑于使用GameMaker、GameSalad之类的图形界面开发工具。
认为这些工具属于“业余型”,就算能做出游戏来也是旁门左道,不能修炼内功。
直到有一次参加了柏林独立游戏BIG Jam的活动,接触了很多非常优秀的游戏开发者。
他们大部分人都把GameMaker和Flash这些简单的工具当做制作独立游戏的最佳选择。
原因是他们多年以前开始学习游戏开发时使用的就是这些工具,常年的使用经验让他们能在最短的时间里用这些工具实现想法。
而使用这些工具从头到尾制作了大量游戏的经历,也在他们以后学习用编程语言开发游戏时打下了很好的基础。
从那之后,为了快速开发原型,我开始物色入门级的可视化编程游戏引擎。
HTML5游戏引擎Construct 2偶然进入了我的视线。
花十几分钟学习教程实例之后,我很快用几个小时做出了一个一直在构思的游戏想法(当然想法本身就很简单,而且制作过程中碰到实现困难的设计都进行了进一步简化)。
说来惭愧,尽管在主机游戏业从业多年,这次使用Construct 2的开发过程中我第一次感觉到对游戏开发的整个过程和架构有了初步认识。
首先,可视化编程工具里一般都有一个现成的游戏场景(任何游戏开发过程中都需要一个画布或一个摄像机来描述玩家可以看到的图像范围),然后你需要把游戏中需要的各个元素(一般称为Actor,例如主角、敌人、子弹等,这就是编程语言里对象的概念)放进场景里,然后通过关联逻辑模块来让它们快速互动起来。
Construct 2的逻辑模块使用了非常贴近编程语言的按行号从上到下的执行顺序。
而且你将从教程中学习到,原来游戏开始运行后每一帧都会按顺序执行一遍所有的逻辑,这就是游戏开发的基本框架中最常说的主游戏循环(Main Game Loop)。
除此之外,用户使用逻辑模块时不用担心语法错误和算法的设计,一般这类引擎里都会提供大量现成的算法模块可供挑选。
只要专注于设计游戏逻辑,其他事情可以说都是软件自动帮你完成。
在观看教程和其他范例项目时也一目了然,学习别人的设计思想更加容易。
通过使用Construct 2独立完成了第一个游戏原型后,我学到了相似的游戏元素可以共享一部分属性(编程语言里使用类和继承的概念);学到了所有活动的游戏元素都需要在每一帧的循环里进行驱动,每帧只运动一小段距离;还学到了应该在主游戏循环的什么位置判断是否Game Over,以及Game Over时进入另一个循环来等待玩家重新开始游戏等内容。
这段经历让我认识到有能力从头到尾制作游戏(或者原型)对于游戏开发的理解有多么重要。
但有一个问题出现了—如果可视化工具那么好用,那为什么还要继续学习编程呢?我当时也光顾着高兴了,并没有从可视化编程工具转到真正编写代码的计划,直到……由需求出发向编写代码的转型直到我打算做个稍大一点的战略游戏项目,才开始在各种游戏开发工具中碰壁。
接连尝试了Construct 2、GameMaker、Stencyl,可不管哪一个工具都无法很容易地提供我所需要的数据结构。
重新审视了需求的增加和工具的局限性之后,我才决定开始学习Unity下的C#编程。
在请教了团队里的程序员和有针对性地学习了一部分数据结构知识后,我终于在Unity中搭建出了设计需要的基本游戏结构。
并在之后开始正式学习Unity的C#脚本,一步步地掌握了C#里类的继承、列表和字典的使用与委托等难以读懂,学了也不知道怎么用的概念。
刚开始在Unity开发环境里独立制作游戏原型时,我也感觉从零开始独立完成所有的代码非常和困难。
但幸运的是,Unity引擎有个特点,就是有一个内容非常丰富的插件市场,其中最流行的插件类型之一就是可视化编程插件。
这些插件(PlayMaker、uScript、Antares Universe等)将Unity游戏开发的常用功能打包成函数块,并按需求类别归纳成组,只要花一点时间阅读手册就相当于掌握了Unity里大部分的常用函数功能。
之后用户通过连接不同函数块的输入输出接口来实现完整的游戏逻辑。
当时我为了开发一个动画状态很多的动作游戏原型,购买了PlayMaker插件,并且使用这个插件强大的状态和动画控制功能第一次学习了有限状态机的制作和使用。
之后又经身边的程序员指点了解到有限状态机在游戏开发中的运用非常广泛,不光是控制动画,还可以用来控制菜单和不同条件下需要不同处理方式的很多游戏逻辑。
就像之前的Construct 2一样,我也只在一个项目中使用了PlayMaker的状态机。
在了解了有限状态机的基本工作方式后,我在之后的项目中都使用了团队里的程序员开发的纯代码的有限状态机系统(开源的exUnity,还包括其他Unity下的游戏开发实用架构:https:///jwu/exUnity),完成了从可视化编程到代码编程的转型。
这就是Unity下的可视化编程插件很适合用来学习编程的原因:和其他较为简单的工具的区别在于,Unity使用JavaScript和C#作为脚本语言,这个环境下的可视化编程插件只是把C#函数和脚本打包成了可视化的逻辑块,并没有改变其设计思路。
对于初学者来说,用可视化插件组装起来的游戏逻辑和用C#手动编写的游戏程序几乎是一一对应的,有时甚至能精确到函数段落(例如Antares Universe里的函数块就和Unity的全部函数功能一一对应)。
在已熟悉整个设计流程的情况下,只需查阅Unity官方的脚本参考手册,就能完成从可视化编程到文本编程的翻译。
我经过可视化工具的启发,很快就发现插件有些臃肿和烦琐,也无法实现一些需求实现。
在接下来的两个原型中就越来越多地开始手动编写代码,对工具的依赖越来越小,直到完全抛弃。
现在可以回答前面提出的“为什么有了不用编程就能开发游戏的工具,还要学习编程”的问题了。
如果你的所有设计需求都可以被可视化游戏开发工具完成,那么确实不需要进一步学习编程。
但如果有的需求无论如何都不能用其他工具完成,那么自己写代码来实现就是唯一的出路,这时你有强烈的需求和目标,就可以通过询问或搜索“怎么做”来学习编程并满足需求。
我的程序员好友经常说:“能否学会编程其实只取决于你的需求是否强烈,不得其门而入、或半途而废的都是需求不够明确或不够强烈的人。
”可视化编程工具对于游戏开发者来说就是一个筛选需求的过程:在硬啃编程书籍时,感觉自己有100个需求,但都不知道从哪开始学习、如何去实现;使用可视化工具,可以轻松实现90个需求,剩下10个就被放大并明确化了。
接下来依靠上网学习或向他人请教,终究也能自己实现(个别超出能力的需求不要强求,请别人做或者放弃都比钻牛角尖要好)。
可视化编程工具能够培养我们由浅入深的思考习惯。
先尽可能地用简单的逻辑去实现设计,如果用“盒子”和“箭头”无法完成,那么你在寻求代码上的解决方案时,就回答了“为什么要用这样的程序设计思想”的问题。
经历了这个过程,你对“为什么”的理解会比一开始就去看专门讲解“为什么”的大部头程序书籍深刻许多。
而通过实践理解了需求和程序设计之间的关系后,再去系统地阅读程序设计教程效果会好得多。
可视化编程虽然依赖于工具,但也能帮助你时刻把“程序语言即工具”的概念装在脑袋里。
之后无论换什么引擎,用哪种语言,首先应该问自己:“这个工具能帮我做什么?我要怎样做才能实现需求?”另外,程序设计和画流程图之间的距离没有想象中那么大,通过反复用可视化编程工具画“流程图”的过程,能够从实践中学习各种游戏设计的实现方法,当你能准确地画出逻辑完美的流程图时,离你写出同样逻辑完美的程序距离已不远了。