Help with some modules (SOLVED)

Started by R4L, Thu 05/07/2007 09:10:58

Previous topic - Next topic

R4L

OK, I'm using Bernie's Simple Platform Movement, which is great by the way, but it has something that I don't like very much.

When I move the character, the character doesn't animate. I've looked through the module's script, and I didn't find anything that relates to the character's view.

I think it has to do with this particular code block:

Code: ags

//managing movement values and gravity--

if (gravity < 6) {gravity=gravity+1;}

if ((IsKeyPressed(375)==1)&&(xmove>-3)) {xmove=xmove-1;}
if ((IsKeyPressed(377)==1)&&(xmove<3)) {xmove=xmove+1;}

if ((IsKeyPressed(375)==0)&&(IsKeyPressed(377)==0)&&(xmove>0)) {xmove=xmove-1;}

if ((IsKeyPressed(375)==0)&&(IsKeyPressed(377)==0)&&(xmove<0)) {xmove=xmove+1;}

//jump----------------------------------

if (IsKeyPressed(32)==1){
 player.y=player.y+2;
 if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())==1) {gravity=-12;}  // jump
 player.y=player.y-2;
}


}

function on_key_press(int keycode){

}




xmove is an int by the way. I don't understand why it doesn't animate the character. Any help is appreciated.

R4L


Scorpiorus

Could you please give a link to the module itself, I can't seem to find it. And it's hard to judge by the extract on to why it doesn't animate.

Gilbert

Can you elaborate more on what actually happened and what you actually want to happen?
Actually if that's really the part of code related, I don't see why the character would animate:
1. If the character is not moving or animating already, it should not animate anyway, because just modifying the y coordinate of the character will NOT trigger animation.
2. If the character is already moving and animating using its walking loop, and you modify its y coordinate directly to "jump", I think the character's original movement will either be stopped (which in turn will stop the animation) or messed up, since modifying coordinates while moving will mess up path-finding, and it's already warned in the manual (in Character.x and Character.y sections):
QuoteNOTE: Do NOT change this property while the character is moving. Make sure the character is standing still before changing his co-ordinates.

So, if 1. you want the character to "jump" when it's not moving you need to drop some animation code in the jumping part yourself, 2. if you want the character to "jump" while he's already moving, modify its z property instead of y, as modifying z would not mess up the path found (I think).

R4L

Well what happens is that when I use the left and right arrows to move, no animation plays while walking. I can walk, but the character doesn't animate. This is before jumping too, so I don't think its a problem with the jump code.

Scorpiorus- Here's a link

Scorpiorus

Ah ok thanks, I found the Simple Platform Movement module thread and from what I can see it doesn't deal with character animating at all.

At first I though you meant the module to interfere with your own animation routines  but if you asked why the module itself doesn't animate the character then that's because it's not meant to, as Gilbert proposed.

You can add if (player.Animating==false) player.Animate(..., eNoBlock); commands here and there within the module's code to make the player animate while moving.

Let us know if you need some help with details on how to implement this.

R4L

#5
Wow, I never thought of that Scorpiorus. I'll try my hand at it, seeing as how I'm a little accustomed to not sleeping (its 6:00 AM here!!)

I'll post back if I need some guidance.

EDIT: Hmm, doesn't seem to work. The game gets stuck in a loop I think.

Here:

Code: ags

// Main script for module 'Platform Movement v0.01a'

int gravity;
int xmove;

function game_start() {
  // called when the game starts, before the first room is loaded
}

function repeatedly_execute() {
  // put anything you want to happen every game cycle here

//down----------------------------------
int a;
while ((gravity>0)&&(a < gravity)){

 cEgo.y=cEgo.y+1; //move one down
 if (GetWalkableAreaAt(cEgo.x-GetViewportX(),cEgo.y-GetViewportY())==0) {cEgo.y=cEgo.y+1;} //1 down if no walkable area found
 cEgo.y=cEgo.y-1; //move one up

  a=a+1;
}

//up------------------------------------
int b;
while ((gravity<0)&&(b > gravity)){

 cEgo.y=cEgo.y-1; //move one up
 if (GetWalkableAreaAt(cEgo.x-GetViewportX(),cEgo.y-GetViewportY())==0) {cEgo.y=cEgo.y-1;} //1 up if no walkable area found abovw
 cEgo.y=cEgo.y+1; //move one down

  b=b-1;
}


//left and right (uses the same logic as moving up and down but has additional checks so uneven terrain won't cause problems)

//left----------------------------------

int c;
while ((xmove<0)&&(c > xmove)){
 
  

 cEgo.x=cEgo.x-1;
 if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())==0) {cEgo.x=cEgo.x-1;}
 cEgo.x=cEgo.x+1;

 cEgo.x=cEgo.x-1;
   int check=0;
   if (GetWalkableAreaAt(cEgo.x-GetViewportX(),cEgo.y-GetViewportY())>0) {check=1;}
     cEgo.y=cEgo.y-1;
       if ((GetWalkableAreaAt(cEgo.x-GetViewportX(),cEgo.y-GetViewportY())==0)&&(check==1)) {cEgo.y=cEgo.y-1;}
     cEgo.y=cEgo.y+1;

   if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())>0) {check=1;}
     cEgo.y=cEgo.y+1;
       if ((GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())==0)&&(check==1)) {cEgo.y=cEgo.y+1;}
     cEgo.y=cEgo.y-1;

 if (GetWalkableAreaAt(cEgo.x-GetViewportX(),cEgo.y-GetViewportY())>0) {cEgo.x=cEgo.x+1;}
 cEgo.x=cEgo.x+1;
 
 c=c-1;
}


//right---------------------------------

int d;
while ((xmove>0)&&(d < xmove)){

 cEgo.x=cEgo.x+1;

 if (GetWalkableAreaAt(cEgo.x-GetViewportX(),cEgo.y-GetViewportY())==0) {cEgo.x=cEgo.x+1;
}
 player.x=player.x-1;

 cEgo.x=cEgo.x+1;

   int check=0;
   if (GetWalkableAreaAt(cEgo.x-GetViewportX(),cEgo.y-GetViewportY())>0) {check=1;}
     cEgo.y=cEgo.y-1;
       if ((GetWalkableAreaAt(cEgo.x-GetViewportX(),cEgo.y-GetViewportY())==0)&&(check==1)) {cEgo.y=cEgo.y-1;}
     cEgo.y=cEgo.y+1;
     
   if (GetWalkableAreaAt(cEgo.x-GetViewportX(),cEgo.y-GetViewportY())>0) {check=1;}
     cEgo.y=cEgo.y+1;
       if ((GetWalkableAreaAt(cEgo.x-GetViewportX(),cEgo.y-GetViewportY())==0)&&(check==1)) {cEgo.y=cEgo.y+1;}
     cEgo.y=cEgo.y-1;
    
   if (GetWalkableAreaAt(cEgo.x-GetViewportX(),cEgo.y-GetViewportY())>0) {cEgo.x=cEgo.x-1;
}
 cEgo.x=cEgo.x-1;


 d=d+1;
}


//diagonal stuff------------------------

if (GetWalkableAreaAt(cEgo.x-GetViewportX(),cEgo.y-GetViewportY())>0) {cEgo.y=cEgo.y-1;}


//managing movement values and gravity--

if (gravity < 6) {gravity=gravity+1;}

if ((IsKeyPressed(375)==1)&&(xmove>-3)) {
 if (player.Animating == false){
player.Animate(1,eNoBlock) //1 is default view
}
xmove=xmove-1;}

if ((IsKeyPressed(377)==1)&&(xmove<3)) {xmove=xmove+1;}

if ((IsKeyPressed(375)==0)&&(IsKeyPressed(377)==0)&&(xmove>0)) {xmove=xmove-1;}

if ((IsKeyPressed(375)==0)&&(IsKeyPressed(377)==0)&&(xmove<0)) {xmove=xmove+1;}

//jump----------------------------------

if (IsKeyPressed(32)==1){
 cEgo.y=cEgo.y+2;
 if (GetWalkableAreaAt(cEgo.x-GetViewportX(),cEgo.y-GetViewportY())==1) {gravity=-12;}  // jump
 cEgo.y=cEgo.y-2;
}


}

function on_key_press(int keycode){

}




Look in the managing movement values and gravity code block. I added it there because thats where it checks for key press. In the //left code block, there is a while loop, so I thought that it wouldn't be good to put it there. Same goes for the //right code block portion.

R4L

Sorry for double posting. My last post was a bit crowded.

I found a way, but it isn't quite working.

In the module's script, at the end, under function on_key_press, I put the animation code. It works, but setting it to repeat just makes him animate forever, and setting it to once doesn't animate him enough.

Gilbert

#7
I'm not in good condition to read the whole thing, but since the keyboard detection codes (i.e. "movement codes") are in repeatedly_execute() already, can you just stop the character's animation when no key is pressed ?

Edit: Alright, just checked the manual, there isn't a StopAnimating() function for characters (odd), I'm not sure but you may try setting the frame property or changing the character's view and see if this stops animations.

R4L

#8
Quote from: Gilbot V7000a on Thu 05/07/2007 12:40:54
I'm not in good condition to read the whole thing, but since the keyboard detection codes (i.e. "movement codes") are in repeatedly_execute() already, can you just stop the character's animation when no key is pressed ?

That sounds like a good idea.

EDIT: Well, I think I got it!

I put this:

//managing movement values and gravity--

if (gravity < 6) {gravity=gravity+1;}

if ((IsKeyPressed(375)==0)&&(xmove>-3)&&(player.Animating == true)) {cEgo.Animate(1, 3, eOnce, eNoBlock);}
if ((IsKeyPressed(375)==1)&&(xmove>-3)) {xmove=xmove-1;}
if ((IsKeyPressed(377)==1)&&(xmove<3)) {xmove=xmove+1;}

if ((IsKeyPressed(375)==0)&&(IsKeyPressed(377)==0)&&(xmove>0)) {xmove=xmove-1;}

if ((IsKeyPressed(375)==0)&&(IsKeyPressed(377)==0)&&(xmove<0)) {xmove=xmove+1;}


And this:


function on_key_press(int keycode){
 
if (player.Animating == false){ player.Animate(1, 3, eRepeat,eNoBlock);}

 

}


But this only works for one direction... I just realized that! Damn it...

R4L

#9
Another double post, sorry!

I finally got it. I have a workaround that works perfectly. Thanks for the help guys.

EDIT: OK, apparently that workaround isn't working now.

Scorpiorus

Ok, as adding animating requires some changes in the module script here and there, I'm posting the whole thing:

Module Script:

Code: ags

// Main script for module 'Platform Movement v0.01a'

bool in_midair = false; // indicates if the player character is in midair

function StartAnimatingIfNotAnimating( int view, int loop, int delay ) {
  
    if (player.Animating == false)
    {
        player.LockView( view );
        player.Animate( loop, delay, eRepeat, eNoBlock );
    }

}

function StopAnimating( ) {
  
    if (player.Animating == true)
    {
        player.UnlockView(); // stop animating the player
    }

}


int gravity;
int xmove;

function game_start() {
  // called when the game starts, before the first room is loaded
}

function repeatedly_execute() {
  // put anything you want to happen every game cycle here


in_midair = true;

//down----------------------------------
int a;
while ((gravity>0)&&(a < gravity)){

 player.y=player.y+1; //move one down
 if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())==0) {player.y=player.y+1;} //1 down if no walkable area found
 else
 {
     in_midair = false; // blocked by a walkable area below, so player has just landed
 }
 player.y=player.y-1; //move one up

  a=a+1;
}

//up------------------------------------
int b;
while ((gravity<0)&&(b > gravity)){

 player.y=player.y-1; //move one up
 if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())==0) {player.y=player.y-1;} //1 up if no walkable area found abovw
 player.y=player.y+1; //move one down

  b=b-1;
}


//left and right (uses the same logic as moving up and down but has additional checks so uneven terrain won't cause problems)

//left----------------------------------

int c;
while ((xmove<0)&&(c > xmove)){

 player.x=player.x-1;
 if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())==0) {player.x=player.x-1;}
 player.x=player.x+1;

 player.x=player.x-1;
   int check=0;
   if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())>0) {check=1;}
     player.y=player.y-1;
       if ((GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())==0)&&(check==1)) {player.y=player.y-1;}
     player.y=player.y+1;

   if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())>0) {check=1;}
     player.y=player.y+1;
       if ((GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())==0)&&(check==1)) {player.y=player.y+1;}
     player.y=player.y-1;

 if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())>0) {player.x=player.x+1;}
 player.x=player.x+1;
 
 c=c-1;
}


//right---------------------------------

int d;
while ((xmove>0)&&(d < xmove)){

 player.x=player.x+1;
 if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())==0) {player.x=player.x+1;}
 player.x=player.x-1;

 player.x=player.x+1;
   int check=0;
   if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())>0) {check=1;}
     player.y=player.y-1;
       if ((GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())==0)&&(check==1)) {player.y=player.y-1;}
     player.y=player.y+1;
     
   if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())>0) {check=1;}
     player.y=player.y+1;
       if ((GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())==0)&&(check==1)) {player.y=player.y+1;}
     player.y=player.y-1;
    
   if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())>0) {player.x=player.x-1;}
 player.x=player.x-1;

 d=d+1;
}


//diagonal stuff------------------------

if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())>0) {player.y=player.y-1;}


//managing movement values and gravity--

if (gravity < 6) {gravity=gravity+1;}

if ((IsKeyPressed(375)==1)&&(xmove>-3)) {xmove=xmove-1;} // left arrow
if ((IsKeyPressed(377)==1)&&(xmove<3)) {xmove=xmove+1;} // right arrow

if ((IsKeyPressed(375)==0)&&(IsKeyPressed(377)==0)&&(xmove>0)) {xmove=xmove-1;} // slow down by friction

if ((IsKeyPressed(375)==0)&&(IsKeyPressed(377)==0)&&(xmove<0)) {xmove=xmove+1;} // slow down by friction

//jump----------------------------------

if (IsKeyPressed(32)==1){
 player.y=player.y+2;
 if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY())==1) {gravity=-12;}  // jump
 player.y=player.y-2;
}


// Animating
//--------------------------------------------------------------------------------------
if      (xmove > 0)
{
    StartAnimatingIfNotAnimating( VIEW1, LOOP1, DELAY1 ); // animate while moving to the right
}
else if (xmove < 0)
{
    StartAnimatingIfNotAnimating( VIEW2, LOOP2, DELAY2 ); // animate while moving to the left
}
else
{
    StopAnimating(); // stop animating if not moving
}


if (in_midair == true)
{
    StopAnimating(); // stop animating in midair (animating the player is also possible here)
}
//--------------------------------------------------------------------------------------


}

function on_key_press(int keycode){

}

R4L

#11
Thank you so much Scorpiorus! I was working on that for too long. My way was working, until I did something.

Also, I added a bit to the //up code clock. It just makes it so that if someone tries to jump up into something with a walkable area, it gets the player character's y-40, so it stops if EGO's head reaches a walkable area.

Scorpiorus

You're welcome, I'm glad you got it working the way you want :)

By the way, you can also have animation while the player is jumping/falling. It would probably have something to do with an "if" check for "gravity" or something similar.

R4L

OK, thanks. There's some code somewhere in the module that can help with that.

SMF spam blocked by CleanTalk