Mar 16, 2016

Zelda Game Mechanics: #0.2 "Link Says I Collide"

Link Says: "I Collide"

 Link's body has a size of 16x16 pixels, but Link's body overlaps with the blocks in the map:


However, this is not Link's real size, he ocupies the bottom center of the sprite with a size of 10 pixels width and 12 pixels height:


This is not the same to NPC, wich doesn't allow an extra overlapping in the sides:


They have 12 pixels height but width is 16 pixels, (even thought a couple npc's sprites are a little bigger than 16x16)

It's looks like it's the same for monsters:



Mar 15, 2016

Zelda Game Mechanics: #0.1 "Link Says I Walk"

Hello everybody, in the next blog posts we are going to make an analysis of Link's game mechanics in the games The Legend of Zelda: Oracle of Ages and The Legend of Zelda: Oracle of Seasons.

I'm not a game designer, or a level designer, so I'll not explain why stuff one way or another, I'm a programmer and I'll focus on how stuff actually works and how to reproduce these behaviours. I'll make an introduction to every action Link can do and how to reproduce it.

Link Says "I Walk"
This is the first and most obvious mechanic, Link has a TopDown 8 directions movement with a 4 directions facing rules, taking steps of 1 pixel size:



If both RIGHT and LEFT keys are pressed, the LEFT key has priority, and if both UP and DOWN keys are pressed, the UP key has priority

If both vertical and horizontal keys are pressed together, Link will continue moving at maximum speed in both directions, this means diagonal movement is (in terms of linear movement velocity) slightly faster than horizontal or vertical:

Diagonal Speed = Sqrt(SPEED*SPEED+SPEED*SPEED)

With SPEED = 1 we have

Diagonal Speed = Sqrt(1*1+1*1) = Sqrt(2) = 1.4142

Additionally, when both horizontal and vertical keys are pressed, Link will face in the direction of the first pressed key, this gives us a tip that we need some data to calculate facing: we have to know if the other key was pressed before.

For a short and compact code, we may be tempted to simply change Link's position:

But this doesn't gives us a way to know what was the first  direction Link was facing, a simple way to have access to such information is use a couple variables to save current Speed on each axis, and apply it to the current position after it's calculated:


This meets all the needs we mentioned earlier, LEFT and UP keys have priority, and if there's no horizontal movement, vertical speed will decide the facing and vice versa.