Main Menu

Character Control

Started by markel422, October 14, 2009, 01:03:58 AM

Previous topic - Next topic

markel422

Since using the PB program for a few weeks I came up with my method of animating my character. I was able to make my character animate when standing still, when it moves, you can also make it duck, and jump.

I want to show the animation but...I don't know how I can send this on the forum because if I just show the Code, it will not run because it contains the images I made myself.

If I can get help on this I will appreciate it so I can show it to you.  :)

kevin


Zip up the projects folder and attached it to your forum post.

markel422

How do I zip them?

What are the steps?  :)

kevin

#3
 depends on what operation system you've installed.

The process will be something along the lines of

  right click on the folder,  scroll down to send to then select compressed folder.

To find the exact steps www.google.com it



markel422

#4
Ok, Here is the file at the bottom...

When you run this program, you will see a character that has the ability to animate when standing still, move left & right, Duck, and Jump.

But there are a Few Problems:

First, you may notice that when it comes to while the character is in the "Jump Cycle", you are not able to make the character face and move at the other direction. When I tried to fix this, I would end up getting a bug where like if I was pressing the leftkey while going left then I wanted to go right by rightkey my character would end up (if it is jumping) staying in the present jumping air even when my character was still performing the original Jump Cycle was in, and it just repeats and repeats if I keep doing that. So all I could do was just leave it as it is now. I want to know how I can fix this problem.

Second, you are not able to make the character Jump while you are moving. This is another thing I need help to fix.

Third, if you were to press either left or right at the same time, the character will glitch and clip to another direction. This glitch even happens when Jumping...

I feel alittle uncertain that I have all these commands seperated like this, with all the mix ups, I'm not sure (at least of how I am doing it) that having all these "Function & EndFunctions" is the way to go...  :(

Big C.

Hi Markel,

i have a quick look to your code and saw many redundant code... I think there will be a solution but i would give u the hint to this. Maybe u can fix your problems yourself  ;)

kevin


  There's lots issues with the Project03.zip example,  mostly with the structure.   But rather than dwell on it,  here's a simplified example that introduces the concept of movement/animation.   

    Here we're loading all the available images into memory prior to the starting our game.   I've stored each sequence of frames starting at a image indexes that are multiples of 10.  So the Left animation sequence is stored at frames 10 through to 11.. The right frames are 20 through to 21..

    This example simply assumes that each animation sequence is 2 frames long and that every time the user is pressing a key a anim sequence is being bumped..




openscreen 320,240,32,1

setfps 60

global speed#=2
global x#=200
global y#=150


// Load all of the animation frames into a series of sequential image slots

// Walking left starts at image 10
LoadIMage "gfx/manwalkleft01.png",10
LoadIMage "gfx/manwalkleft02.png",11

// Walking left starts at image 20
LoadIMage "gfx/manwalkright01.png",20
LoadIMage "gfx/manwalkright02.png",21


// Init the startin animation state
CurrentAnim=10
CurrentFrame=0 ; frame offset within animation sequence


do
cls 0


// Check for user input - Move LEFT
if leftkey()=true

// Set our base animation variable to the Walking left sequence
CurrentAnim = 10

// Update the Animation frame
CurrentFrame=CurrentFrame+1
// chekc if the frame counter has exceeded the max frame in this anim
if CurrentFrame>1
CurrentFRame=0
endif

// move the character left
x#=x#-Speed#

endif





// Check for user input - Move RIGHT
if rightkey()=true

// Set our base animation variable to the Walking right sequence
CurrentAnim = 20

// Update the Animation frame
CurrentFrame=CurrentFrame+1
// chekc if the frame counter has exceeded the max frame in this anim
if CurrentFrame>1
CurrentFRame=0
endif

// move the character right
x#=x#+Speed#
endif


drawimage CurrentAnim+CurrentFrame,X#,y#,1

sync
loop



markel422

I think the problem has gotten worse... :-\

No matter what I do these codes or the structure, I just can't get it to go as I need it to, compared to how I have it with my previous one with nothing but Functions in it... :'(

Another Zip File is at the Bottom to see what it looks like...

|
|
|
|
\ /

kevin


Here's an expansion of the previous example.  Supports Standing, walking ,Ducking in either direction.    However there's nothing to set the playback rate...   




openscreen 320,240,32,1

setfps 60

global speed#=2
global x#=200
global y#=150

Direction =0   ; (0= character facing LEFT,  1 = facing right)


// Load all of the animation frames into a series of sequential image slots

// ========================================
// left frames
// ========================================
      loadimage "gfx/manstandleft01.png",10
      loadimage "gfx/manstandleft02.png",11

//
LoadIMage "gfx/manwalkleft01.png",20
LoadIMage "gfx/manwalkleft02.png",21

loadimage "gfx/manduckleft.png",50
loadimage "gfx/manduckleft.png",51


// ========================================
// Right Frames
// ========================================

      loadimage "gfx/manstandleft01.png",110
      loadimage "gfx/manstandleft02.png",111

// standing right
LoadIMage "gfx/manwalkright01.png",120
LoadIMage "gfx/manwalkright02.png",121

loadimage "gfx/manduckright.png" ,150
loadimage "gfx/manduckright.png" ,151



// Init the startin animation state
CurrentAnim=10
CurrentFrame=0 ; frame offset within animation sequence



do
cls 0


// USe this variable to KeyPressed flag

Did_Player_Press_A_Key=false


// ----------------------------------------
// Check for user input - Move LEFT
// ----------------------------------------
if leftkey()=true

Did_Player_Press_A_Key=true


// Set this character direction as 0, which we'll use this to represent LEFT
Direction =0

// Set our base animation variable to the Walking left sequence
CurrentAnim = 20

// Update the Animation frame
CurrentFrame=CurrentFrame+1
// chekc if the frame counter has exceeded the max frame in this anim
if CurrentFrame>1
CurrentFRame=0
endif

// move the character left
x#=x#-Speed#

endif





// ----------------------------------------
// Check for user input - Move RIGHT
// ----------------------------------------
if rightkey()=true

Did_Player_Press_A_Key=true


// Set this character direction as 1, which we'll use to represent RIGHT
Direction =1

// Set our base animation variable to the Walking sequence
CurrentAnim = 20

// Update the Animation frame
CurrentFrame=CurrentFrame+1
// chekc if the frame counter has exceeded the max frame in this anim
if CurrentFrame>1
CurrentFRame=0
endif

// move the character right
x#=x#+Speed#
endif




// ----------------------------------------
// Check for user input - Move DOWN
// ----------------------------------------
if downkey()=true

Did_Player_Press_A_Key=true

// Set our base animation variable to the duck sequence
CurrentAnim = 50

// Update the Animation frame
CurrentFrame=CurrentFrame+1
// chekc if the frame counter has exceeded the max frame in this anim
if CurrentFrame>1
CurrentFRame=0
endif

endif




// ----------------------------------------
// The Player press a key ?? , if not set the character to player it's standing anim
// ----------------------------------------
if Did_Player_Press_A_Key=false

// Set our base animation variable to the Standing
CurrentAnim = 10

// Update the Animation frame
CurrentFrame=CurrentFrame+1
// chekc if the frame counter has exceeded the max frame in this anim
if CurrentFrame>1
CurrentFRame=0
endif


endif



// draw the whatever image the CurrentAnim + direction and current frame are

drawimage CurrentAnim+(Direction*100)+CurrentFrame,X#,y#,1

sync
loop





kevin


   This version is the same as the previous, but it include a simple Speed control.   




openscreen 320,240,32,1

setfps 60

global speed#=2
global x#=200
global y#=150

Direction =0   ; (0= character facing LEFT,  1 = facing right)


// Load all of the animation frames into a series of sequential image slots

// ========================================
// left frames
// ========================================
      loadimage "gfx/manstandleft01.png",10
      loadimage "gfx/manstandleft02.png",11

//
LoadIMage "gfx/manwalkleft01.png",20
LoadIMage "gfx/manwalkleft02.png",21

loadimage "gfx/manduckleft.png",50
loadimage "gfx/manduckleft.png",51


// ========================================
// Right Frames
// ========================================

      loadimage "gfx/manstandleft01.png",110
      loadimage "gfx/manstandleft02.png",111

// standing right
LoadIMage "gfx/manwalkright01.png",120
LoadIMage "gfx/manwalkright02.png",121

loadimage "gfx/manduckright.png" ,150
loadimage "gfx/manduckright.png" ,151



// Init the startin animation state
CurrentAnim=10
CurrentFrame=0 ; frame offset within animation sequence

AnimSpeed=10


do
cls 0


// USe this variable to KeyPressed flag

Did_Player_Press_A_Key=false


// ----------------------------------------
// Check for user input - Move LEFT
// ----------------------------------------
if leftkey()=true

Did_Player_Press_A_Key=true


// Set this character direction as 0, which we'll use this to represent LEFT
Direction =0

// Set our base animation variable to the Walking left sequence
CurrentAnim = 20

// Update the Animation frame
CurrentFrame=CurrentFrame+1
// chekc if the frame counter has exceeded the max frame in this anim
if (CurrentFrame/AnimSpeed)>1
CurrentFRame=0
endif

// move the character left
x#=x#-Speed#

endif





// ----------------------------------------
// Check for user input - Move RIGHT
// ----------------------------------------
if rightkey()=true

Did_Player_Press_A_Key=true


// Set this character direction as 1, which we'll use to represent RIGHT
Direction =1

// Set our base animation variable to the Walking sequence
CurrentAnim = 20

// Update the Animation frame
CurrentFrame=CurrentFrame+1
// chekc if the frame counter has exceeded the max frame in this anim
if (CurrentFrame/AnimSpeed)>1
CurrentFRame=0
endif

// move the character right
x#=x#+Speed#
endif




// ----------------------------------------
// Check for user input - Move DOWN
// ----------------------------------------
if downkey()=true

Did_Player_Press_A_Key=true

// Set our base animation variable to the duck sequence
CurrentAnim = 50

// Update the Animation frame
CurrentFrame=CurrentFrame+1
// chekc if the frame counter has exceeded the max frame in this anim
if (CurrentFrame/AnimSpeed)>1
CurrentFRame=0
endif

endif




// ----------------------------------------
// The Player press a key ?? , if not set the character to player it's standing anim
// ----------------------------------------
if Did_Player_Press_A_Key=false

// Set our base animation variable to the Standing
CurrentAnim = 10

// Update the Animation frame
CurrentFrame=CurrentFrame+1
// chekc if the frame counter has exceeded the max frame in this anim
if (CurrentFrame/AnimSpeed)>1
CurrentFRame=0
endif


endif



// draw the whatever image the CurrentAnim + direction and current frame are
drawimage CurrentAnim+(Direction*100)+(CurrentFrame/AnimSpeed),X#,y#,1

sync
loop




markel422

#10
OMG!!!!!!!!! :o

I can finally make the character do everything!!! :)

I remodifyed the code you gave me to put in the spacekey to make my Character Jump.

Even added a code to make the character face "Right" when on "Right" Mode. It may have took me while but I finally got it to work.

It can even be controlled on left and right presses while it's in the Air this time! ;)

Never knew that just to make your character do this requires all this code.

Look at this!

openscreen 320,240,32,1

setfps 60

global speed#=2
global x#=200
global y#=150
global spdy#=2

     Jump=false
     
Direction =0  ; (0= character facing LEFT,  1 = facing right)


// Load all of the animation frames into a series of sequential image slots

// ========================================
// left frames
// ========================================
     loadimage "gfx/manstandleft01.png",10
     loadimage "gfx/manstandleft02.png",11

//
LoadIMage "gfx/manwalkleft01.png",20
LoadIMage "gfx/manwalkleft02.png",21

loadimage "gfx/manduckleft.png",50
loadimage "gfx/manduckleft.png",51

loadimage "gfx/manjumpleft.png",60
loadimage "gfx/manjumpleft.png",61


// ========================================
// Right Frames
// ========================================

     loadimage "gfx/manstandright01.png",110
     loadimage "gfx/manstandright02.png",111

// standing right
LoadIMage "gfx/manwalkright01.png",120
LoadIMage "gfx/manwalkright02.png",121

loadimage "gfx/manduckright.png" ,150
loadimage "gfx/manduckright.png" ,151

loadimage "gfx/manjumpright.png",160
loadimage "gfx/manjumpright.png",161



// Init the startin animation state
CurrentAnim=10
CurrentFrame=0 ; frame offset within animation sequence

AnimSpeed=30


do
cls 0


// USe this variable to KeyPressed flag

Did_Player_Press_A_Key=false


// ----------------------------------------
// Check for user input - Move LEFT
// ----------------------------------------
if leftkey()=true

Did_Player_Press_A_Key=true


// Set this character direction as 0, which we'll use this to represent LEFT
Direction =0

// Set our base animation variable to the Walking left sequence
CurrentAnim = 20

// Update the Animation frame
CurrentFrame=CurrentFrame+1
// chekc if the frame counter has exceeded the max frame in this anim
if (CurrentFrame/AnimSpeed)>1
CurrentFRame=0
endif

// move the character left
x#=x#-Speed#

endif





// ----------------------------------------
// Check for user input - Move RIGHT
// ----------------------------------------
if rightkey()=true

Did_Player_Press_A_Key=true


// Set this character direction as 1, which we'll use to represent RIGHT
Direction =1

// Set our base animation variable to the Walking sequence
CurrentAnim = 20

// Update the Animation frame
CurrentFrame=CurrentFrame+1
// chekc if the frame counter has exceeded the max frame in this anim
if (CurrentFrame/AnimSpeed)>1
CurrentFRame=0
endif

// move the character right
x#=x#+Speed#
endif

           // ----------------------------------------
           // Check for user input - Jump Up
           // ----------------------------------------
           if jump=false
           if spacekey()=true
           
            Did_Player_Press_A_Key=true
            jump=true
            up=30
            down=30
            endif
            endif
           
            if jump=true
            did_player_press_a_key=true
            CurrentAnim = 60
           
           
            if up>0
            y#=y#-spdy#
            up=up-1
            else
            if down>0
            y#=y#+spdY#
            down=down-1
            else
            jump=false
           
            endif
            endif
            endif
            if leftkey()=true
            if jump=true
            did_player_press_a_key=true
            direction=0
            CurrentAnim = 60
           
           
            endif
            endif
            if rightkey()=true
            if jumps=true
            did_player_press_a_key=true
            direction=1
            CurrentAnim = 60
            currentframe=currentframe+1
           
            if (currentframe/animspeed)>1
            currentframe=0
            endif
            endif
            endif
           


// ----------------------------------------
// Check for user input - Move DOWN
// ----------------------------------------
if downkey()=true

Did_Player_Press_A_Key=true

// Set our base animation variable to the duck sequence
CurrentAnim = 50

// Update the Animation frame
CurrentFrame=CurrentFrame+1
// chekc if the frame counter has exceeded the max frame in this anim
if (CurrentFrame/AnimSpeed)>1
CurrentFRame=0
endif

endif




// ----------------------------------------
// The Player press a key ?? , if not set the character to player it's standing anim
// ----------------------------------------
if Did_Player_Press_A_Key=false

// Set our base animation variable to the Standing
CurrentAnim = 10

// Update the Animation frame
CurrentFrame=CurrentFrame+1
// chekc if the frame counter has exceeded the max frame in this anim
if (CurrentFrame/AnimSpeed)>1
CurrentFRame=0
endif
endif
           
           if did_player_press_a_key=false
            if direction=1
            currentanim=10
            // Update the Animation frame
CurrentFrame=CurrentFrame+1
// chekc if the frame counter has exceeded the max frame in this anim
if (CurrentFrame/AnimSpeed)>1
CurrentFRame=0
endif
endif
endif


// draw the whatever image the CurrentAnim + direction and current frame are
drawimage CurrentAnim+(Direction*100)+(CurrentFrame/AnimSpeed),X#,y#,1

sync
loop



Also a few questions...

There's also a slight problem, when it comes to my character facing right it animates alittle faster with the same set code so I wonder why this is happening?


Do I really have to have more than one image of the same thing when always doing this? (As I saw in your code you gave me.)

kevin

#11
QuoteNever knew that just to make your character do this requires all this code.

  Not really,  this example was written to be easier to understand, rather than compact code.   


QuoteDo I really have to have more than one image of the same thing when always doing this? (As I saw in your code you gave me.)

  Nope.   Lets see if you can change this...