<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://digida.mgpu.ru/index.php?action=history&amp;feed=atom&amp;title=How_to_Make_Game_AI</id>
	<title>How to Make Game AI - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://digida.mgpu.ru/index.php?action=history&amp;feed=atom&amp;title=How_to_Make_Game_AI"/>
	<link rel="alternate" type="text/html" href="http://digida.mgpu.ru/index.php?title=How_to_Make_Game_AI&amp;action=history"/>
	<updated>2026-05-20T11:17:41Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>http://digida.mgpu.ru/index.php?title=How_to_Make_Game_AI&amp;diff=1810&amp;oldid=prev</id>
		<title>Patarakin: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://digida.mgpu.ru/index.php?title=How_to_Make_Game_AI&amp;diff=1810&amp;oldid=prev"/>
		<updated>2022-07-21T08:33:17Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 11:33, 21 июля 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Patarakin</name></author>
	</entry>
	<entry>
		<id>http://digida.mgpu.ru/index.php?title=How_to_Make_Game_AI&amp;diff=1809&amp;oldid=prev</id>
		<title>scratch&gt;TheTrillion: Added a category.</title>
		<link rel="alternate" type="text/html" href="http://digida.mgpu.ru/index.php?title=How_to_Make_Game_AI&amp;diff=1809&amp;oldid=prev"/>
		<updated>2021-05-04T07:50:59Z</updated>

		<summary type="html">&lt;p&gt;Added a category.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;Artificial Intelligence&amp;#039;&amp;#039;&amp;#039; is the foundation of many games on Scratch. This article shows how to make an AI.&lt;br /&gt;
&lt;br /&gt;
==Coding the Program==&lt;br /&gt;
First, two [[Sprite]]s, the Player and the AI, need to be created.&lt;br /&gt;
&lt;br /&gt;
=== Variables Required ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
(touching player)&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This [[Variable]] will be used to let the game know that the AI is touching the player.&lt;br /&gt;
&lt;br /&gt;
=== Coding The Player ===&lt;br /&gt;
{{main|Sprite Controls}}&lt;br /&gt;
The movement for the player is simple:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
When green flag clicked&lt;br /&gt;
forever&lt;br /&gt;
	if &amp;lt;key (up arrow v) pressed&amp;gt; then&lt;br /&gt;
	change y by ()//Pick a number that best suits the player for movement.&lt;br /&gt;
	end&lt;br /&gt;
	if &amp;lt;key (down arrow v) pressed&amp;gt; then&lt;br /&gt;
	change y by ()&lt;br /&gt;
	end&lt;br /&gt;
	if &amp;lt;key (right arrow v) pressed&amp;gt; then&lt;br /&gt;
	change x by ()&lt;br /&gt;
	end&lt;br /&gt;
	if &amp;lt;key (left arrow v) pressed&amp;gt; then&lt;br /&gt;
	change x by ()&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Coding The AI ===&lt;br /&gt;
The coding for the AI is simple:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
When green flag clicked&lt;br /&gt;
forever&lt;br /&gt;
point towards (player v)&lt;br /&gt;
move () steps//Pick a speed that suits the project.&lt;br /&gt;
set [touching player v] to &amp;lt; touching (player v)?&amp;gt;//This will automatically set the variable to true if touching the player and false if it is not touching the player.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Creating an AI With Projectiles ==&lt;br /&gt;
Creating an AI with projectiles will be a bit of a challenge to any [[Scratch]] game. Another sprite needs to be created. This will be the projectile sprite.&lt;br /&gt;
&lt;br /&gt;
One more variable also needs to be created:&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
(player health)&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to the AI sprite, add this code to it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
When green flag clicked&lt;br /&gt;
set [player health v] to ()//Pick how much health the player has.&lt;br /&gt;
forever&lt;br /&gt;
create clone of (projectile v)&lt;br /&gt;
wait (pick random () to ()) seconds//Pick the amount of time in between each time the AI shoots the projectile at the player.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, go to the projectile sprite. The code for this is fairly simple.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when green flag clicked&lt;br /&gt;
hide&lt;br /&gt;
forever&lt;br /&gt;
go to (AI v)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when I start as a clone&lt;br /&gt;
show&lt;br /&gt;
point in direction ([direction v] of [AI v])&lt;br /&gt;
repeat until &amp;lt;&amp;lt;touching (player v)&amp;gt; or &amp;lt;touching (edge v)&lt;br /&gt;
move () steps&lt;br /&gt;
end&lt;br /&gt;
delete this clone&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The final bit of code that is going to be added will be to the player. This script will give the player its health system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when flag clicked&lt;br /&gt;
forever&lt;br /&gt;
	if &amp;lt;touching (projectile v)&amp;gt; then&lt;br /&gt;
	change [player health v] by ()&lt;br /&gt;
		repeat ()//This will let the player know that they&amp;#039;ve been hit by the AI&amp;#039;s projectile.&lt;br /&gt;
		set [brightness v] effect to (20)&lt;br /&gt;
		wait () seconds&lt;br /&gt;
		set [brightness v] effect to (0)&lt;br /&gt;
        wait () seconds&lt;br /&gt;
	    end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To end the game when the player has no health, just add this code to the game:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when flag clicked&lt;br /&gt;
forever&lt;br /&gt;
if &amp;lt;(player health) &amp;lt; [1]&amp;gt; then&lt;br /&gt;
stop [all v]&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secondary Method ==&lt;br /&gt;
Here is a second AI method that will detect when the player is within range of the AI. This does not use the following block: &amp;lt;scratchblocks&amp;gt; (distance to (mouse-pointer v)) &amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Sprites/Variables needed===&lt;br /&gt;
Like the method above, three sprites are needed. However, one of the three is going to be different: Player, AI, and a sprite that is a circle. After making the player sprite, give it the same movement code displayed up above in the first method. Only one new variable is needed:&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
(in radius)&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Coding The AI===&lt;br /&gt;
This time, the AI will need some new code to function like it needs to for this method. The code for the AI is still simple and it is as shown:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when green flag clicked&lt;br /&gt;
forever&lt;br /&gt;
	if &amp;lt;(in radius) = [1]&amp;gt; then&lt;br /&gt;
	point towards (player v)&lt;br /&gt;
	move (3) steps&lt;br /&gt;
	else&lt;br /&gt;
	point in direction (90)&lt;br /&gt;
	wait until &amp;lt;(in radius) = [1]&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The Radius===&lt;br /&gt;
The circle sprite that was made earlier is the &amp;quot;visibility radius&amp;quot; for the AI. To make this function, the following code is needed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when green flag clicked&lt;br /&gt;
forever&lt;br /&gt;
go to (AI v)&lt;br /&gt;
	if &amp;lt;touching (player v)?&amp;gt; then&lt;br /&gt;
	set [in radius v] to (1)&lt;br /&gt;
	else&lt;br /&gt;
	set [in radius v] to (0)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting Tutorials]]&lt;/div&gt;</summary>
		<author><name>scratch&gt;TheTrillion</name></author>
	</entry>
</feed>