Move a Character 20px to X> or X< Only. Not Y.

Started by Olleh19, Tue 10/11/2020 14:43:12

Previous topic - Next topic

Olleh19

So i'm working on my little "fighting game scene" and i've run into this little problem now.
I need an Enemy or the Player to fall back after a Kick, falls to the left side or right side only, and stand up again, death animation is already done (just animated that). So i was thinking something along in theory that is "cEnemy1.Move.x++, or if getting hit from other side/player kick/Loop cEnemy1.Move.xx--;", but that synthax do not exist of course, too my knowledge. (laugh). but the ++; being instead perhaps 20px to x, or -20px if the enemy get's hit from the other side.

So i'm thinking just to animate the Z motion in photoshop of the enemy/player instead of scripting a falling curve (unless a basic function is simplistic ofc) and have the X motion be in code, only. Any code suggestions would be very helpful!


A custom function for this would be useful since it will most likely be used for a lot of animations  (laugh) Any suggestions how that would look like are very much welcomed!



Khris

You need
Code: ags
  player.Move(player.x + 20, player.y);

Olleh19

Quote from: Khris on Tue 10/11/2020 14:48:03
You need
Code: ags
  player.Move(player.x + 20, player.y);


This is why i love AGS. The syntax sometimes are not at all very complicated.


Thanks as always.

Khris

In case it is not obvious (I was by no means obvious to me when I started to program): there isn't any special syntax involved here at all.
You can split that code into three lines:
Code: ags
  int destX = player.x + 20; // this is a simple expression
  int destY = player.y;
  player.Move(destX, destY);


When you do this in one line instead, the Move() command still has absolutely no idea about the  + 20 even existing. AGS will essentially do the three line version above, but internally.
The idea that the Move() syntax somehow supports or allows a "+ 20" here couldn't be further from what's actually happening.

It's the same with
Code: ags
  if (complicatedExpression && evenMoreComplicatedExpression || someTruthyIntValue) ... 


The  if construct has no idea about the contents of the parens, and it doesn't care at all. The conditional expression is evaluated, and the final result is used to determine whether the if block is entered or not.
This is one of the things I learned very late into my foray into programming, long after I started to write AGS scripts. It's absolutely crucial to understand how to build algorithms from simple building blocks though.

Olleh19

#4
Quote from: Khris on Tue 10/11/2020 15:20:37
In case it is not obvious (I was by no means obvious to me when I started to program): there isn't any special syntax involved here at all.
You can split that code into three lines:
Code: ags
  int destX = player.x + 20; // this is a simple expression
  int destY = player.y;
  player.Move(destX, destY);


When you do this in one line instead, the Move() command still has absolutely no idea about the  + 20 even existing. AGS will essentially do the three line version above, but internally.
The idea that the Move() syntax somehow supports or allows a "+ 20" here couldn't be further from what's actually happening.

It's the same with
Code: ags
  if (complicatedExpression && evenMoreComplicatedExpression || someTruthyIntValue) ... 


The  if construct has no idea about the contents of the parens, and it doesn't care at all. The conditional expression is evaluated, and the final result is used to determine whether the if block is entered or not.
This is one of the things I learned very late into my foray into programming, long after I started to write AGS scripts. It's absolutely crucial to understand how to build algorithms from simple building blocks though.

Thanks as always for the explanation, i will study hard! (nod)  I've seen those syntaxes before actually, but thought i couldn't use them "that way". Interesting!

Edit: oh no sorry i was thinking about this player.DestinationX, or Y
Saw now you did something different.

Khris

Btw, please don't quote the entire previous post :) There's a Reply button below the last post on the right.

SMF spam blocked by CleanTalk