<?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_7_Enemies</id>
	<title>Tuto tiny-ecs beatemup Part 7 Enemies - 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_7_Enemies"/>
	<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_beatemup_Part_7_Enemies&amp;action=history"/>
	<updated>2026-11-17T17:25:00Z</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_7_Enemies&amp;diff=24675&amp;oldid=prev</id>
		<title>MoKaLux at 07:56, 11 September 2025</title>
		<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_beatemup_Part_7_Enemies&amp;diff=24675&amp;oldid=prev"/>
		<updated>2025-09-11T07:56:36Z</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 07:56, 11 September 2025&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-l4&quot;&gt;Line 4:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 4:&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;The next entities we are going to create: the enemies.&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;The next entities we are going to create: the enemies.&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; 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;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;/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;As I have mentioned before&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;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;/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;== eNme1.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;== eNme1.lua ==&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_7_Enemies&amp;diff=24066&amp;oldid=prev</id>
		<title>MoKaLux at 07:08, 20 November 2024</title>
		<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_beatemup_Part_7_Enemies&amp;diff=24066&amp;oldid=prev"/>
		<updated>2024-11-20T07:08:48Z</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 07:08, 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-l502&quot;&gt;Line 502:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 502:&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;That&amp;#039;s it, we have all our enemies!&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;That&amp;#039;s it, we have all our enemies!&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&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;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&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;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; &#039;&#039;&#039;Please note: our enemies have different attacks, some have 2 kind of attacks, some have 3, some can kick, some can jump attack, ...&#039;&#039;&#039;&lt;/ins&gt;&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;== Next? ==&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;== Next? ==&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_7_Enemies&amp;diff=24065&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_7_Enemies&amp;diff=24065&amp;oldid=prev"/>
		<updated>2024-11-20T07:02:06Z</updated>

		<summary type="html">&lt;p&gt;wip&lt;/p&gt;
&lt;a href=&quot;https://wiki.gideros.rocks/index.php?title=Tuto_tiny-ecs_beatemup_Part_7_Enemies&amp;amp;diff=24065&amp;amp;oldid=24062&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_7_Enemies&amp;diff=24062&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_7_Enemies&amp;diff=24062&amp;oldid=prev"/>
		<updated>2024-11-20T01:21:26Z</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;
== ePlayer1.lua ==&lt;br /&gt;
This is going to be our first actor. Each actor will be an ECS Entity, let&amp;#039;s create a file &amp;quot;&amp;#039;&amp;#039;ePlayer1.lua&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.&lt;br /&gt;
&lt;br /&gt;
The arguments of the init function are: the layer the player sprite will be added to, the position as a vector, and the layer for any fancy graphics effects we may add to the player.&lt;br /&gt;
&lt;br /&gt;
The code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
EPlayer1 = Core.class()&lt;br /&gt;
&lt;br /&gt;
function EPlayer1:init(xspritelayer, xpos, xbgfxlayer)&lt;br /&gt;
	-- ids&lt;br /&gt;
	self.isplayer1 = true&lt;br /&gt;
	self.doanimate = true -- to save some cpu&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.positionystart = 0&lt;br /&gt;
	self.sx = 1&lt;br /&gt;
	self.sy = self.sx&lt;br /&gt;
	self.flip = 1&lt;br /&gt;
	self.totallives = 3&lt;br /&gt;
	self.totalhealth = 10&lt;br /&gt;
	self.currjumps = 5&lt;br /&gt;
	if g_difficulty == 0 then -- easy&lt;br /&gt;
		self.totallives = 5&lt;br /&gt;
		self.totalhealth = 20&lt;br /&gt;
		self.currjumps = 8&lt;br /&gt;
	elseif g_difficulty == 2 then -- hard&lt;br /&gt;
		self.currjumps = 3&lt;br /&gt;
	end&lt;br /&gt;
	self.currlives = self.totallives&lt;br /&gt;
	self.currhealth = self.totalhealth&lt;br /&gt;
	-- recovery&lt;br /&gt;
	self.washurt = 0&lt;br /&gt;
	self.wasbadlyhurt = 0&lt;br /&gt;
	self.recovertimer = 30&lt;br /&gt;
	self.recoverbadtimer = 90&lt;br /&gt;
	if g_difficulty == 0 then -- easy&lt;br /&gt;
		self.recovertimer *= 2&lt;br /&gt;
		self.recoverbadtimer *= 2&lt;br /&gt;
	elseif g_difficulty == 2 then -- hard&lt;br /&gt;
		self.recovertimer *= 0.5&lt;br /&gt;
		self.recoverbadtimer *= 0.5&lt;br /&gt;
	end&lt;br /&gt;
	self.ispaused = false -- &amp;#039;P&amp;#039; key for pausing the game&lt;br /&gt;
	self.hitfx = Bitmap.new(Texture.new(&amp;quot;gfx/fx/2.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/player1/mh_blue_haired2m_0130.png&amp;quot;&lt;br /&gt;
	local framerate = 1/10&lt;br /&gt;
	self.animation = CAnimation.new(texpath, 12, 11, 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() -- with applied scale&lt;br /&gt;
--	print(&amp;quot;player1 size: &amp;quot;, self.w, self.h)&lt;br /&gt;
	-- create basics animations: CAnimation:createAnim(xanimname, xstart, xfinish)&lt;br /&gt;
	self.animation:createAnim(g_ANIM_DEFAULT, 1, 15)&lt;br /&gt;
	self.animation:createAnim(g_ANIM_IDLE_R, 1, 15) -- fluid is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_WALK_R, 16, 26) -- fluid is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_JUMP1_R, 74, 76) -- fluid is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_HURT_R, 90, 100) -- fluid is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_STANDUP_R, 103, 113) -- fluid is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_LOSE1_R, 113, 124) -- fluid is best&lt;br /&gt;
	-- BODY: CBody:init(xspeed, xjumpspeed)&lt;br /&gt;
	self.body = CBody.new(192*32, 0.65) -- (192*32, 1), xspeed, xjumpspeed&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;
	-- head hurt box w &amp;amp; h&lt;br /&gt;
	local hhbw, hhbh = self.w*0.25, self.h*0.3&lt;br /&gt;
	self.headhurtbox = {&lt;br /&gt;
		isactive=false,&lt;br /&gt;
		x=-2*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;
	-- spine hurt box w &amp;amp; h&lt;br /&gt;
	local shbw, shbh = self.w*0.35, self.h*0.4&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, 50, 51) -- 28, 31, no or low anticipation / quick hit / no or low overhead is best&lt;br /&gt;
	self.animation.anims[g_ANIM_PUNCH_ATTACK1_R] = {}&lt;br /&gt;
	self.animation.anims[g_ANIM_PUNCH_ATTACK1_R][1] = self.animation.myanimsimgs[49]&lt;br /&gt;
	self.animation.anims[g_ANIM_PUNCH_ATTACK1_R][2] = self.animation.myanimsimgs[52]&lt;br /&gt;
	self.animation.anims[g_ANIM_PUNCH_ATTACK1_R][3] = self.animation.myanimsimgs[54]&lt;br /&gt;
	self.animation:createAnim(g_ANIM_PUNCH_ATTACK2_R, 50, 54) -- low or mid anticipation / quick hit / low or mid overhead is best&lt;br /&gt;
--	self.animation:createAnim(g_ANIM_KICK_ATTACK1_R, 62, 63) -- 35, 41, no or low anticipation / quick hit / no or low overhead is best&lt;br /&gt;
	self.animation.anims[g_ANIM_KICK_ATTACK1_R] = {}&lt;br /&gt;
	self.animation.anims[g_ANIM_KICK_ATTACK1_R][1] = self.animation.myanimsimgs[62]&lt;br /&gt;
	self.animation.anims[g_ANIM_KICK_ATTACK1_R][2] = self.animation.myanimsimgs[64]&lt;br /&gt;
	self.animation.anims[g_ANIM_KICK_ATTACK1_R][3] = self.animation.myanimsimgs[67]&lt;br /&gt;
	self.animation:createAnim(g_ANIM_KICK_ATTACK2_R, 62, 68) -- low or mid anticipation / quick hit / low or mid overhead is best&lt;br /&gt;
--	self.animation:createAnim(g_ANIM_PUNCHJUMP_ATTACK1_R, 75, 82) -- low or mid anticipation / quick hit / low or mid overhead is best&lt;br /&gt;
	self.animation.anims[g_ANIM_PUNCHJUMP_ATTACK1_R] = {}&lt;br /&gt;
	self.animation.anims[g_ANIM_PUNCHJUMP_ATTACK1_R][1] = self.animation.myanimsimgs[78]&lt;br /&gt;
	self.animation.anims[g_ANIM_PUNCHJUMP_ATTACK1_R][2] = self.animation.myanimsimgs[80]&lt;br /&gt;
	self.animation.anims[g_ANIM_PUNCHJUMP_ATTACK1_R][3] = self.animation.myanimsimgs[82]&lt;br /&gt;
--	self.animation:createAnim(g_ANIM_KICKJUMP_ATTACK1_R, 83, 88) -- low or mid anticipation / quick hit / low or mid overhead is best&lt;br /&gt;
	self.animation.anims[g_ANIM_KICKJUMP_ATTACK1_R] = {}&lt;br /&gt;
	self.animation.anims[g_ANIM_KICKJUMP_ATTACK1_R][1] = self.animation.myanimsimgs[84]&lt;br /&gt;
	self.animation.anims[g_ANIM_KICKJUMP_ATTACK1_R][2] = self.animation.myanimsimgs[86]&lt;br /&gt;
	-- clean up&lt;br /&gt;
	self.animation.myanimsimgs = nil&lt;br /&gt;
	-- hit box&lt;br /&gt;
	self.headhitboxattack1 = { -- g_ANIM_PUNCH_ATTACK1_R&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*0.6,&lt;br /&gt;
		y=-self.h*0.6+collh*0.5,&lt;br /&gt;
		w=20*self.sx,&lt;br /&gt;
		h=32*self.sy,&lt;br /&gt;
	}&lt;br /&gt;
	self.headhitboxattack2 = { -- g_ANIM_PUNCH_ATTACK2_R X&lt;br /&gt;
		isactive=false,&lt;br /&gt;
		hitstartframe=1,&lt;br /&gt;
		hitendframe=4,&lt;br /&gt;
		damage=2,&lt;br /&gt;
		x=self.collbox.w*0.75,&lt;br /&gt;
		y=-self.h*0.65+collh*0.5,&lt;br /&gt;
		w=32*self.sx,&lt;br /&gt;
		h=32*self.sy,&lt;br /&gt;
	}&lt;br /&gt;
	self.spinehitboxattack1 = { -- g_ANIM_KICK_ATTACK1_R&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*0.7,&lt;br /&gt;
		y=-self.h*0.25+collh*0.5,&lt;br /&gt;
		w=40*self.sx,&lt;br /&gt;
		h=self.h*0.5,&lt;br /&gt;
	}&lt;br /&gt;
	self.spinehitboxattack2 = { -- g_ANIM_KICK_ATTACK2_R&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.8,&lt;br /&gt;
		y=-self.h*0.25+collh*0.5,&lt;br /&gt;
		w=32*self.sx,&lt;br /&gt;
		h=self.h*0.5,&lt;br /&gt;
	}&lt;br /&gt;
	self.headhitboxjattack1 = { -- g_ANIM_PUNCHJUMP_ATTACK1_R&lt;br /&gt;
		isactive=false,&lt;br /&gt;
		hitstartframe=6,&lt;br /&gt;
		hitendframe=8,&lt;br /&gt;
		damage=3,&lt;br /&gt;
		x=self.collbox.w*0.7,&lt;br /&gt;
		y=-self.h*0.5+collh*0.5,&lt;br /&gt;
		w=40*self.sx,&lt;br /&gt;
		h=self.h*0.5,&lt;br /&gt;
	}&lt;br /&gt;
	self.spinehitboxjattack1 = { -- g_ANIM_KICKJUMP_ATTACK1_R&lt;br /&gt;
		isactive=false,&lt;br /&gt;
		hitstartframe=3,&lt;br /&gt;
		hitendframe=5,&lt;br /&gt;
		damage=3,&lt;br /&gt;
		x=self.collbox.w*0.5,&lt;br /&gt;
		y=-self.h*0.25+collh*0.5,&lt;br /&gt;
		w=64*self.sx,&lt;br /&gt;
		h=self.h*0.5,&lt;br /&gt;
	}&lt;br /&gt;
	-- SHADOW: CShadow:init(xparentw, xshadowsx, xshadowsy)&lt;br /&gt;
	self.shadow = CShadow.new(self.w*0.6)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Code comments ==&lt;br /&gt;
Let&amp;#039;s break it down!&lt;br /&gt;
&lt;br /&gt;
=== ids ===&lt;br /&gt;
Ids are used as filters by the ECS systems. Based on an Entity id, a System will process it or not. Here we have an id to tell this is the player1 Entity and an id telling this sprite is animated.&lt;br /&gt;
&lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;All the player1 variables below can be used as ids as well, should we want to narrow down a System filter&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
=== variables: the basics  ===&lt;br /&gt;
The systems will need to know a bunch of information about the Entity it is processing:&lt;br /&gt;
* the sprite layers the actor lives in&lt;br /&gt;
* the actor position and scale&lt;br /&gt;
* &amp;#039;&amp;#039;positionystart&amp;#039;&amp;#039; the starting position on the y axis before the actor performs a jump&lt;br /&gt;
* flip to indicate the direction the actor is facing&lt;br /&gt;
* the number of lives, health, jumps, ...&lt;br /&gt;
&lt;br /&gt;
=== recovery ===&lt;br /&gt;
When the actor is hit, we give it some time to recover. During this time the actor is invincible.&lt;br /&gt;
&lt;br /&gt;
=== my mistake! ===&lt;br /&gt;
I added a &amp;#039;&amp;#039;self.ispaused&amp;#039;&amp;#039; variable which is completly useless, you can safely delete it :-)&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;self.hitfx&amp;#039;&amp;#039; is one of those fx we add to the fxlayer when the player1 successfully hits another actor.&lt;br /&gt;
&lt;br /&gt;
== COMPONENTS ==&lt;br /&gt;
The beauty of ECS is its modularity. Let&amp;#039;s add our player1 some components. A Component is an ability you add to an Entity. Entities can and will share the same components.&lt;br /&gt;
&lt;br /&gt;
=== ANIMATION ===&lt;br /&gt;
The first component we add is the Animation Component. Create a file called &amp;quot;&amp;#039;&amp;#039;cAnimation.lua&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 and add the following code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
CAnimation = Core.class()&lt;br /&gt;
&lt;br /&gt;
function CAnimation:init(xspritesheetpath, xcols, xrows, xanimspeed, xoffx, xoffy, sx, sy)&lt;br /&gt;
	-- animation&lt;br /&gt;
	self.curranim = g_ANIM_DEFAULT&lt;br /&gt;
	self.frame = 0&lt;br /&gt;
	self.animspeed = xanimspeed&lt;br /&gt;
	self.animtimer = self.animspeed&lt;br /&gt;
	-- retrieve all anims in texture&lt;br /&gt;
	local myanimstex = Texture.new(xspritesheetpath)&lt;br /&gt;
	local cellw = myanimstex:getWidth() / xcols&lt;br /&gt;
	local cellh = myanimstex:getHeight() / xrows&lt;br /&gt;
	self.myanimsimgs = {}&lt;br /&gt;
	local myanimstexregion&lt;br /&gt;
	for r = 1, xrows do&lt;br /&gt;
		for c = 1, xcols do&lt;br /&gt;
			myanimstexregion = TextureRegion.new(myanimstex, (c - 1) * cellw, (r - 1) * cellh, cellw, cellh)&lt;br /&gt;
			self.myanimsimgs[#self.myanimsimgs + 1] = myanimstexregion&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	-- anims table (&amp;quot;walk&amp;quot;, &amp;quot;jump&amp;quot;, &amp;quot;shoot&amp;quot;, ...)&lt;br /&gt;
	self.anims = {}&lt;br /&gt;
	-- the bitmap&lt;br /&gt;
	self.bmp = Bitmap.new(self.myanimsimgs[1]) -- starting bmp texture&lt;br /&gt;
	self.bmp:setScale(sx, sy) -- scale!&lt;br /&gt;
	self.bmp:setAnchorPoint(0.5, 0.5) -- we will flip the bitmap&lt;br /&gt;
	-- set position inside sprite&lt;br /&gt;
	self.bmp:setPosition(xoffx*sx, xoffy*sy) -- work best with image centered spritesheets&lt;br /&gt;
	-- our final sprite&lt;br /&gt;
	self.sprite = Sprite.new()&lt;br /&gt;
	self.sprite:addChild(self.bmp)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function CAnimation:createAnim(xanimname, xstart, xfinish)&lt;br /&gt;
	self.anims[xanimname] = {}&lt;br /&gt;
	for i = xstart, xfinish do&lt;br /&gt;
		self.anims[xanimname][#self.anims[xanimname]+1] = self.myanimsimgs[i]&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The parameters are:&lt;br /&gt;
* xspritesheetpath: the path to the player1 spritesheet&lt;br /&gt;
* xcols, xrows: the spritesheet number of columns and rows&lt;br /&gt;
* xanimspeed: the animation speed in ms&lt;br /&gt;
* xoffx, xoffy: an offset in case we need to&lt;br /&gt;
* sx, sy: the scale of the sprite&lt;br /&gt;
&lt;br /&gt;
The Animation Component cuts the spritesheet into single images and puts them in the &amp;#039;&amp;#039;self.myanimsimgs&amp;#039;&amp;#039; table. We then use &amp;#039;&amp;#039;self.myanimsimgs&amp;#039;&amp;#039; and pick the first image as our player1 bitmap. The &amp;#039;&amp;#039;self.myanimsimgs&amp;#039;&amp;#039; table is also used to create the animations with the &amp;#039;&amp;#039;&amp;#039;createAnim&amp;#039;&amp;#039;&amp;#039; function as we see next.&lt;br /&gt;
&lt;br /&gt;
==== animations ====&lt;br /&gt;
Back to the &amp;#039;&amp;#039;&amp;#039;&amp;quot;ePlayer1.lua&amp;quot;&amp;#039;&amp;#039;&amp;#039; code we create its animations.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
	self.animation:createAnim(g_ANIM_DEFAULT, 1, 15)&lt;br /&gt;
	self.animation:createAnim(g_ANIM_IDLE_R, 1, 15) -- fluid is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_WALK_R, 16, 26) -- fluid is best&lt;br /&gt;
	self.animation:createAnim(g_ANIM_JUMP1_R, 74, 76) -- fluid is best&lt;br /&gt;
	...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We first create the basics animations: idle, walk, jump. We also have extra animations: hurt, stand up and lose. Here it is better to have smooth animations so we have quite a few images. The g_ANIM_DEFAULT animation was used when building the game, we shouldn&amp;#039;t need it anymore but I left it in the project ;-)&lt;br /&gt;
&lt;br /&gt;
We assign the starting image and the ending image in the spritesheet for each animations. The animations names were declared in the &amp;#039;&amp;#039;&amp;#039;&amp;quot;main.lua&amp;quot;&amp;#039;&amp;#039;&amp;#039; file (this is where you would add any extra animations).&lt;br /&gt;
&lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;SELF PROMOTION: I made an app to count images in a spritesheet: https://mokatunprod.itch.io/spritesheet-maker-viewer&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Next? ==&lt;br /&gt;
To shorten the length of this part, let&amp;#039;s see the other components in the next chapter.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prev.: [[Tuto tiny-ecs beatemup Part 6 ECS Components]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Next: [[Tuto tiny-ecs beatemup Part 8 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>