<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.gideros.rocks/index.php?action=history&amp;feed=atom&amp;title=Tuto_tiny-ecs_beatemup_Part_8_Breakables</id>
	<title>Tuto tiny-ecs beatemup Part 8 Breakables - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.gideros.rocks/index.php?action=history&amp;feed=atom&amp;title=Tuto_tiny-ecs_beatemup_Part_8_Breakables"/>
	<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_beatemup_Part_8_Breakables&amp;action=history"/>
	<updated>2026-11-17T20:02:14Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_beatemup_Part_8_Breakables&amp;diff=24101&amp;oldid=prev</id>
		<title>MoKaLux: /* eDestructibleObject.lua */</title>
		<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_beatemup_Part_8_Breakables&amp;diff=24101&amp;oldid=prev"/>
		<updated>2024-11-25T01:30:27Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;eDestructibleObject.lua&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 01:30, 25 November 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l7&quot;&gt;Line 7:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 7:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== eDestructibleObject.lua ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== eDestructibleObject.lua ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &#039;&#039;&#039;Excuse my english, I am &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;not an &lt;/del&gt;english native speaker. I called the breakable objects destructibles!&#039;&#039;&#039;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &#039;&#039;&#039;Excuse my english, I am &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;no &lt;/ins&gt;english native speaker. I called the breakable objects destructibles!&#039;&#039;&#039;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Please create a file &amp;quot;&amp;#039;&amp;#039;&amp;#039;eDestructibleObject.lua&amp;#039;&amp;#039;&amp;#039;&amp;quot; in the &amp;#039;&amp;#039;&amp;#039;&amp;quot;_E&amp;quot;&amp;#039;&amp;#039;&amp;#039; folder and the code:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Please create a file &amp;quot;&amp;#039;&amp;#039;&amp;#039;eDestructibleObject.lua&amp;#039;&amp;#039;&amp;#039;&amp;quot; in the &amp;#039;&amp;#039;&amp;#039;&amp;quot;_E&amp;quot;&amp;#039;&amp;#039;&amp;#039; folder and the code:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>MoKaLux</name></author>
	</entry>
	<entry>
		<id>https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_beatemup_Part_8_Breakables&amp;diff=24070&amp;oldid=prev</id>
		<title>MoKaLux at 22:44, 20 November 2024</title>
		<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_beatemup_Part_8_Breakables&amp;diff=24070&amp;oldid=prev"/>
		<updated>2024-11-20T22:44:29Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 22:44, 20 November 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l147&quot;&gt;Line 147:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 147:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Prev.: [[Tuto tiny-ecs beatemup Part 7 Enemies]]&amp;lt;/br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Prev.: [[Tuto tiny-ecs beatemup Part 7 Enemies]]&amp;lt;/br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&#039;&#039;&#039;Next: [[Tuto tiny-ecs beatemup Part 9 &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;XXX&lt;/del&gt;]]&#039;&#039;&#039;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&#039;&#039;&#039;Next: [[Tuto tiny-ecs beatemup Part 9 &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Systems&lt;/ins&gt;]]&#039;&#039;&#039;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;[[Tutorial - tiny-ecs beatemup]]&amp;#039;&amp;#039;&amp;#039;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;[[Tutorial - tiny-ecs beatemup]]&amp;#039;&amp;#039;&amp;#039;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{GIDEROS IMPORTANT LINKS}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{GIDEROS IMPORTANT LINKS}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>MoKaLux</name></author>
	</entry>
	<entry>
		<id>https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_beatemup_Part_8_Breakables&amp;diff=24069&amp;oldid=prev</id>
		<title>MoKaLux at 17:29, 20 November 2024</title>
		<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_beatemup_Part_8_Breakables&amp;diff=24069&amp;oldid=prev"/>
		<updated>2024-11-20T17:29:35Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_beatemup_Part_8_Breakables&amp;amp;diff=24069&amp;amp;oldid=24067&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>MoKaLux</name></author>
	</entry>
	<entry>
		<id>https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_beatemup_Part_8_Breakables&amp;diff=24067&amp;oldid=prev</id>
		<title>MoKaLux: wip</title>
		<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_beatemup_Part_8_Breakables&amp;diff=24067&amp;oldid=prev"/>
		<updated>2024-11-20T14:22:49Z</updated>

		<summary type="html">&lt;p&gt;wip&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
== Enemies ==&lt;br /&gt;
The next entities we are going to create: the enemies.&lt;br /&gt;
&lt;br /&gt;
As I have mentioned before components are shared amongst entities and this is exactly the case here. The enemies share the same components as our player1. The structure of an enemy Entity is almost the same as the player1 Entity. I will however show the code for each one of them because their attributes have different values, like the graphics, the animations, their speed, strengths, ...&lt;br /&gt;
&lt;br /&gt;
== eNme1.lua ==&lt;br /&gt;
The first enemy actor, please create a file &amp;quot;&amp;#039;&amp;#039;&amp;#039;eNme1.lua&amp;#039;&amp;#039;&amp;#039;&amp;quot; in the &amp;#039;&amp;#039;&amp;#039;&amp;quot;_E&amp;quot;&amp;#039;&amp;#039;&amp;#039; folder and the code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
ENme1 = Core.class()&lt;br /&gt;
&lt;br /&gt;
function ENme1:init(xspritelayer, xpos, dx, dy, xbgfxlayer)&lt;br /&gt;
	-- ids&lt;br /&gt;
	self.isnme = true&lt;br /&gt;
	-- sprite layers&lt;br /&gt;
	self.spritelayer = xspritelayer&lt;br /&gt;
	self.bgfxlayer = xbgfxlayer&lt;br /&gt;
	-- params&lt;br /&gt;
	self.pos = xpos&lt;br /&gt;
	self.sx = 1.4&lt;br /&gt;
	self.sy = self.sx&lt;br /&gt;
	self.totallives = 2&lt;br /&gt;
	self.totalhealth = 2&lt;br /&gt;
	-- recovery&lt;br /&gt;
	self.recovertimer = 8&lt;br /&gt;
	self.recoverbadtimer = 30&lt;br /&gt;
	self.actiontimer = math.random(32, 96)&lt;br /&gt;
	if g_difficulty == 0 then -- easy&lt;br /&gt;
		self.totallives = 1&lt;br /&gt;
		self.totalhealth = 1&lt;br /&gt;
		self.recovertimer *= 0.5&lt;br /&gt;
		self.recoverbadtimer *= 0.5&lt;br /&gt;
		self.actiontimer *= 2&lt;br /&gt;
	elseif g_difficulty == 2 then -- hard&lt;br /&gt;
		self.totallives = 2&lt;br /&gt;
		self.totalhealth = 3&lt;br /&gt;
		self.recovertimer *= 2&lt;br /&gt;
		self.recoverbadtimer *= 2&lt;br /&gt;
		self.actiontimer *= 0.5&lt;br /&gt;
	end&lt;br /&gt;
	self.hitfx = Bitmap.new(Texture.new(&amp;quot;gfx/fx/1.png&amp;quot;))&lt;br /&gt;
	self.hitfx:setAnchorPoint(0.5, 0.5)&lt;br /&gt;
	-- COMPONENTS&lt;br /&gt;
	-- ANIMATION: CAnimation:init(xspritesheetpath, xcols, xrows, xanimspeed, xoffx, xoffy, sx, sy)&lt;br /&gt;
	local texpath = &amp;quot;gfx/nmes/Ravi-Rigged_m_0001.png&amp;quot;&lt;br /&gt;
	local framerate = 1/10 -- 1/12&lt;br /&gt;
	self.animation = CAnimation.new(texpath, 9, 6, framerate, 0, 0, self.sx, self.sy)&lt;br /&gt;
	self.sprite = self.animation.sprite&lt;br /&gt;
	self.animation.sprite = nil -- free some memory&lt;br /&gt;
	self.w, self.h = self.sprite:getWidth(), self.sprite:getHeight()&lt;br /&gt;
	-- create basics animations: CAnimation:createAnim(xanimname, xstart, xfinish)&lt;br /&gt;
	self.animation:createAnim(g_ANIM_DEFAULT, 1, 18)&lt;br /&gt;
	self.animation:createAnim(g_ANIM_IDLE_R, 1, 18) -- fluid is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_WALK_R, 19, 29) -- fluid is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_HURT_R, 48, 48) -- fluid is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_STANDUP_R, 30, 35) -- fluid is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_LOSE1_R, 33, 33) -- fluid is best&lt;br /&gt;
	-- BODY: CBody:init(xspeed, xjumpspeed)&lt;br /&gt;
	if g_difficulty == 0 then -- easy&lt;br /&gt;
		self.body = CBody.new(math.random(64, 128)*32, 1) -- xspeed, xjumpspeed&lt;br /&gt;
	else&lt;br /&gt;
		self.body = CBody.new(math.random(128, 160)*32, 1) -- xspeed, xjumpspeed&lt;br /&gt;
	end&lt;br /&gt;
	-- COLLISION BOX: CCollisionBox:init(xcollwidth, xcollheight)&lt;br /&gt;
	local collw, collh = self.w/3, 8*self.sy&lt;br /&gt;
	self.collbox = CCollisionBox.new(collw, collh)&lt;br /&gt;
	-- hurt box&lt;br /&gt;
	local hhbw, hhbh = self.w/2, self.h/3&lt;br /&gt;
	self.headhurtbox = {&lt;br /&gt;
		isactive=false,&lt;br /&gt;
		x=6*self.sx,&lt;br /&gt;
		y=0*self.sy-self.h/2-self.collbox.h*2,&lt;br /&gt;
		w=hhbw,&lt;br /&gt;
		h=hhbh,&lt;br /&gt;
	}&lt;br /&gt;
	local shbw, shbh = self.w/2, self.h/3 -- magik XXX&lt;br /&gt;
	self.spinehurtbox = {&lt;br /&gt;
		isactive=false,&lt;br /&gt;
		x=-0*self.sx,&lt;br /&gt;
		y=0*self.sy-shbh/2+self.collbox.h/2,&lt;br /&gt;
		w=shbw,&lt;br /&gt;
		h=shbh,&lt;br /&gt;
	}&lt;br /&gt;
	-- create attacks animations: CAnimation:createAnim(xanimname, xstart, xfinish)&lt;br /&gt;
	self.animation:createAnim(g_ANIM_PUNCH_ATTACK1_R, 37, 41) -- no or low anticipation / quick hit / no or low overhead is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_PUNCH_ATTACK2_R, 48, 51) -- no or low anticipation / quick hit / no or low overhead is best&lt;br /&gt;
	-- clean up&lt;br /&gt;
	self.animation.myanimsimgs = nil&lt;br /&gt;
	-- hit box&lt;br /&gt;
	self.headhitboxattack1 = {&lt;br /&gt;
		isactive=false,&lt;br /&gt;
		hitstartframe=2,&lt;br /&gt;
		hitendframe=3,&lt;br /&gt;
		damage=1,&lt;br /&gt;
		x=self.collbox.w*1.1,&lt;br /&gt;
		y=-self.h*0.7+collh*0.5,&lt;br /&gt;
		w=20*self.sx,&lt;br /&gt;
		h=20*self.sy,&lt;br /&gt;
	}&lt;br /&gt;
	self.headhitboxattack2 = {&lt;br /&gt;
		isactive=false,&lt;br /&gt;
		hitstartframe=2,&lt;br /&gt;
		hitendframe=3,&lt;br /&gt;
		damage=1,&lt;br /&gt;
		x=self.collbox.w*1.1,&lt;br /&gt;
		y=-self.h*0.7+collh*0.5,&lt;br /&gt;
		w=20*self.sx,&lt;br /&gt;
		h=20*self.sy,&lt;br /&gt;
	}&lt;br /&gt;
	-- AI: CAI:init(xstartpos, dx, dy)&lt;br /&gt;
	self.ai = CAI.new(self.pos, dx, dy)&lt;br /&gt;
	-- SHADOW: CShadow:init(xparentw, xshadowsx, xshadowsy)&lt;br /&gt;
	self.shadow = CShadow.new(self.w*0.75)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is almost exactly the same code as the player1, there are three main differences:&lt;br /&gt;
* some variables were moved to the enemy System, this makes the code for our enemies shorter&lt;br /&gt;
* we adjust the enemy speed parameters based on the level and the difficulty of the game&lt;br /&gt;
* we have an extra Component: the &amp;#039;&amp;#039;&amp;#039;AI Component&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
=== AI ===&lt;br /&gt;
In order for the enemies to attack the player we give them an artificial intelligence ability (Component). You can create a file &amp;quot;&amp;#039;&amp;#039;&amp;#039;cAI.lua&amp;#039;&amp;#039;&amp;#039;&amp;quot; in the &amp;#039;&amp;#039;&amp;#039;&amp;quot;_C&amp;quot;&amp;#039;&amp;#039;&amp;#039; folder. The code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
CAI = Core.class()&lt;br /&gt;
&lt;br /&gt;
function CAI:init(xstartpos, dx, dy)&lt;br /&gt;
	self.startpos = xstartpos&lt;br /&gt;
	self.dx = dx -- delta x&lt;br /&gt;
	self.dy = dy -- delta y&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It stores the enemy starting position and some range constraints (delta). This Component will be used in an AI System.&lt;br /&gt;
&lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;We have now created all the components for our game!&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== eNme2.lua ==&lt;br /&gt;
&amp;quot;&amp;#039;&amp;#039;&amp;#039;eNme2.lua&amp;#039;&amp;#039;&amp;#039;&amp;quot; in the &amp;#039;&amp;#039;&amp;#039;&amp;quot;_E&amp;quot;&amp;#039;&amp;#039;&amp;#039; folder. The code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
ENme2 = Core.class()&lt;br /&gt;
&lt;br /&gt;
function ENme2:init(xspritelayer, xpos, dx, dy, xbgfxlayer)&lt;br /&gt;
	-- ids&lt;br /&gt;
	self.isnme = true&lt;br /&gt;
	-- sprite layers&lt;br /&gt;
	self.spritelayer = xspritelayer&lt;br /&gt;
	self.bgfxlayer = xbgfxlayer&lt;br /&gt;
	-- params&lt;br /&gt;
	self.pos = xpos&lt;br /&gt;
	self.sx = 1.3&lt;br /&gt;
	self.sy = self.sx&lt;br /&gt;
	self.totallives = 2&lt;br /&gt;
	self.totalhealth = 2&lt;br /&gt;
	-- recovery&lt;br /&gt;
	self.recovertimer = 8&lt;br /&gt;
	self.recoverbadtimer = 30&lt;br /&gt;
	self.actiontimer = math.random(32, 96)&lt;br /&gt;
	if g_difficulty == 0 then -- easy&lt;br /&gt;
		self.totallives = 1&lt;br /&gt;
		self.totalhealth = 1&lt;br /&gt;
		self.recovertimer *= 0.5&lt;br /&gt;
		self.recoverbadtimer *= 0.5&lt;br /&gt;
		self.actiontimer *= 2&lt;br /&gt;
	elseif g_difficulty == 2 then -- hard&lt;br /&gt;
		self.totallives = 2&lt;br /&gt;
		self.totalhealth = 3&lt;br /&gt;
		self.recovertimer *= 2&lt;br /&gt;
		self.recoverbadtimer *= 2&lt;br /&gt;
		self.actiontimer *= 0.5&lt;br /&gt;
	end&lt;br /&gt;
	self.hitfx = Bitmap.new(Texture.new(&amp;quot;gfx/fx/1.png&amp;quot;))&lt;br /&gt;
	self.hitfx:setAnchorPoint(0.5, 0.5)&lt;br /&gt;
	-- COMPONENTS&lt;br /&gt;
	-- ANIMATION: CAnimation:init(xspritesheetpath, xcols, xrows, xanimspeed, xoffx, xoffy, sx, sy)&lt;br /&gt;
	local texpath = &amp;quot;gfx/nmes/Chad_m_0001.png&amp;quot;&lt;br /&gt;
	local framerate = 1/10 -- 1/12&lt;br /&gt;
	self.animation = CAnimation.new(texpath, 10, 6, framerate, 0, 0, self.sx, self.sy)&lt;br /&gt;
	self.sprite = self.animation.sprite&lt;br /&gt;
	self.animation.sprite = nil -- free some memory&lt;br /&gt;
	self.w, self.h = self.sprite:getWidth(), self.sprite:getHeight()&lt;br /&gt;
	-- create basics animations: CAnimation:createAnim(xanimname, xstart, xfinish)&lt;br /&gt;
	self.animation:createAnim(g_ANIM_DEFAULT, 1, 18)&lt;br /&gt;
	self.animation:createAnim(g_ANIM_IDLE_R, 1, 18) -- fluid is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_WALK_R, 19, 27) -- fluid is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_HURT_R, 56, 58) -- fluid is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_STANDUP_R, 29, 31) -- fluid is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_LOSE1_R, 56, 58) -- fluid is best&lt;br /&gt;
	-- BODY: CBody:init(xspeed, xjumpspeed)&lt;br /&gt;
	if g_difficulty == 0 then -- easy&lt;br /&gt;
		self.body = CBody.new(math.random(64, 128)*32, 1) -- xspeed, xjumpspeed&lt;br /&gt;
	else&lt;br /&gt;
		self.body = CBody.new(math.random(128, 160)*32, 1) -- xspeed, 1, xjumpspeed&lt;br /&gt;
	end&lt;br /&gt;
	-- COLLISION BOX: CCollisionBox:init(xcollwidth, xcollheight)&lt;br /&gt;
	local collw, collh = self.w*0.4, 8*self.sy&lt;br /&gt;
	self.collbox = CCollisionBox.new(collw, collh)&lt;br /&gt;
	-- hurt box&lt;br /&gt;
	local hhbw, hhbh = self.w/2, self.h/3&lt;br /&gt;
	self.headhurtbox = {&lt;br /&gt;
		isactive=false,&lt;br /&gt;
		x=-3*self.sx,&lt;br /&gt;
		y=0*self.sy-self.h/2-self.collbox.h/2,&lt;br /&gt;
		w=hhbw,&lt;br /&gt;
		h=hhbh,&lt;br /&gt;
	}&lt;br /&gt;
	local shbw, shbh = self.w/2, self.h/3&lt;br /&gt;
	self.spinehurtbox = {&lt;br /&gt;
		isactive=false,&lt;br /&gt;
		x=-3*self.sx,&lt;br /&gt;
		y=0*self.sy-shbh/2+self.collbox.h/2,&lt;br /&gt;
		w=shbw,&lt;br /&gt;
		h=shbh,&lt;br /&gt;
	}&lt;br /&gt;
	-- create attacks animations: CAnimation:createAnim(xanimname, xstart, xfinish)&lt;br /&gt;
	self.animation:createAnim(g_ANIM_PUNCH_ATTACK1_R, 28, 34) -- no or low anticipation / quick hit / no or low overhead is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_KICK_ATTACK1_R, 41, 46) -- no or low anticipation / quick hit / no or low overhead is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_PUNCHJUMP_ATTACK1_R, 35, 40) -- no or low anticipation / quick hit / no or low overhead is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_KICKJUMP_ATTACK1_R, 47, 55) -- no or low anticipation / quick hit / no or low overhead is best&lt;br /&gt;
	-- clean up&lt;br /&gt;
	self.animation.myanimsimgs = nil&lt;br /&gt;
	-- hit box&lt;br /&gt;
	self.headhitboxattack1 = {&lt;br /&gt;
		isactive=false,&lt;br /&gt;
		hitstartframe=1,&lt;br /&gt;
		hitendframe=6,&lt;br /&gt;
		damage=1,&lt;br /&gt;
		x=self.collbox.w*0.7,&lt;br /&gt;
		y=-self.h*0.5+collh*0.5,&lt;br /&gt;
		w=20*self.sx,&lt;br /&gt;
		h=self.h&lt;br /&gt;
	}&lt;br /&gt;
	self.spinehitboxattack1 = {&lt;br /&gt;
		isactive=false,&lt;br /&gt;
		hitstartframe=3,&lt;br /&gt;
		hitendframe=4,&lt;br /&gt;
		damage=1,&lt;br /&gt;
		x=self.collbox.w*0.75,&lt;br /&gt;
		y=-self.h*0.4,&lt;br /&gt;
		w=32*self.sx,&lt;br /&gt;
		h=48*self.sy,&lt;br /&gt;
	}&lt;br /&gt;
	self.headhitboxjattack1 = {&lt;br /&gt;
		isactive=false,&lt;br /&gt;
		hitstartframe=2,&lt;br /&gt;
		hitendframe=4,&lt;br /&gt;
		damage=2,&lt;br /&gt;
		x=self.collbox.w*0.7,&lt;br /&gt;
		y=-self.h*0.6,&lt;br /&gt;
		w=40*self.sx,&lt;br /&gt;
		h=40*self.sy,&lt;br /&gt;
	}&lt;br /&gt;
	self.spinehitboxjattack1 = {&lt;br /&gt;
		isactive=false,&lt;br /&gt;
		hitstartframe=6,&lt;br /&gt;
		hitendframe=8,&lt;br /&gt;
		damage=2,&lt;br /&gt;
		x=self.collbox.w*0.5,&lt;br /&gt;
		y=-self.h*0.25+collh*0.5,&lt;br /&gt;
		w=48*self.sx,&lt;br /&gt;
		h=self.h*0.5,&lt;br /&gt;
	}&lt;br /&gt;
	-- AI: CAI:init(xstartpos, dx, dy)&lt;br /&gt;
	self.ai = CAI.new(self.pos, dx, dy)&lt;br /&gt;
	-- SHADOW: CShadow:init(xparentw, xshadowsx, xshadowsy)&lt;br /&gt;
	self.shadow = CShadow.new(self.w*0.75)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Next? ==&lt;br /&gt;
Before tackling all the systems that will tie our game together, we will create the last two entities of our game: the &amp;#039;&amp;#039;&amp;#039;breakable objects&amp;#039;&amp;#039;&amp;#039; and the &amp;#039;&amp;#039;&amp;#039;collectibles&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prev.: [[Tuto tiny-ecs beatemup Part 7 Enemies]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Next: [[Tuto tiny-ecs beatemup Part 9 XXX]]&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[[Tutorial - tiny-ecs beatemup]]&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
{{GIDEROS IMPORTANT LINKS}}&lt;/div&gt;</summary>
		<author><name>MoKaLux</name></author>
	</entry>
</feed>