help with my platformer game

Started by MisterN, March 04, 2011, 03:34:57 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MisterN

with what you put in, thats the only sprite you see. so it needs to go back to stand when it lands. I have no idea how to put in the names for the status so youll have to show me where (im guessing its under "int player_status")
[code language="fenix"]
Program platform_engine;
//these are global variables
Global
   Playerfpg;
   
   //initializes the player's sprites
   int Player_graph[14];
   
   //initializes the level
   int level;
   int levelmask;

//this sets up things like the games resolution and whatnot      
Begin
   Set_mode(320,240,16);
   Set_fps(20,0);
   
   PlayerFPG=load_fpg("Player.fpg");

   Map_clear(0,0,RGB(0,0,0));
   Write (0, 64, 16, 1, "Platform Game");
   
   //PlayerWalk Animations; it a good idea to repeat the same sprite 3 times so it doesn't
   //look sped up unless you have many detailed frames, you can add as many as you want, just
   //be sure to change int Player_graph[X] to the number of sprites you have (0 included, so
   //its one number higher than the last Player_grap[X] you have
   Player_graph[0]=load_png(".\sprites\player\Walk1.png");
   Player_graph[1]=load_png(".\sprites\player\Walk1.png");
   Player_graph[2]=load_png(".\sprites\player\Walk1.png");
  Player_graph[3]=load_png(".\sprites\player\Walk2.png");
  Player_graph[4]=load_png(".\sprites\player\Walk2.png");
  Player_graph[5]=load_png(".\sprites\player\Walk2.png");
  Player_graph[6]=load_png(".\sprites\player\Walk3.png");
  Player_graph[7]=load_png(".\sprites\player\Walk3.png");
  Player_graph[8]=load_png(".\sprites\player\Walk3.png");
  Player_graph[9]=load_png(".\sprites\player\Walk2.png");
  Player_graph[10]=load_png(".\sprites\player\Walk2.png");
  Player_graph[11]=load_png(".\sprites\player\Walk2.png");
  Player_graph[12]=load_png(".\sprites\player\Stand.png");
  Player_graph[13]=load_png(".\sprites\player\Jump.png");
 
  level=load_png(".\sprites\level\image\test.png");
  levelmask=load_png(".\sprites\level\mask\test.png");

   Player(PlayerFPG,1,50,100);
   
   start_scroll(0,0,level,0,0,0);

   Loop
      If (key(_esc))
         Exit("Bye",0);
      End
      Frame;
   End
End

//This process is for the player, all code that belongs to him is in this part
Process Player(file,graph,x,y)
Private
   xspeed=3;
   yspeed=0;

   y_start_acceleration=4;
   y_acceleration=0;
   
   int fall;

   jump=0;
   
   int i;
   int ii;
   int pixel;
   int red,blue,green;
   
   int player_status; //0 is standing, 1 is walking, 2 is jumping, 3 is falling
   
   
Begin
   ctype=c_scroll;
   Loop
      // Walking
      If (key(_left) or key(_right))
         player_status=1;
         If (key(_left))
         flags=1;
         x-=xspeed;
         player_status=1;
         End
         if (key(_right))
         flags=0;
         x+=xspeed;
         player_status=1;
         End
      Else
      // Standing still
         player_status  = 0;
      End
      // Jumping
   if (key (_space))
   player_status=2;
         pixel = map_get_pixel(0, levelmask, x, y +1 +15); 
         get_rgb (pixel, & red, & green, & blue); 
         if (blue> 200)
            fall =- 20; 
         end   
      end
      // Implementation of fall. 
      ii = fall; 
      if(ii > 0)
         player_status=2;
         while(ii != 0) 
            pixel=map_get_pixel(0, levelmask, x, y + (fall-ii) +15);
            get_rgb (pixel, & red, & green, & blue);
            if (blue> 200) 
               ii = ii + 1; 
               break; 
            end 
            ii = ii - 1;   
         end 
      else 
         ii = 0; 
      end 
      // Move the fall until we can. 
      y = y + (fall-ii);; 
      // Acceleration of gravity 
      if (ii == 0) 
         fall = fall + 5;
         player_status=3; 
      else 
         fall = 0; 
      end
      //Player Status
      if(player_status==0)
      graph=graph=Player_graph[12];
      end
      if(player_status==1)
      graph=graph=Player_graph;
      i=(i+1)%12;
      end
      if(player_status==2)
      graph=graph=Player_graph[13];
      end
      if(player_status==3)
      graph=graph=Player_graph[13];
      end      
      Frame;
   End
End
[/code]

so at elast the code got somewhere after several days of asking. but i have no idea with it going back to stand.
werg

Drumpi

Quote from: DoctorN on March 13, 2011, 03:32:38 AM
with what you put in, thats the only sprite you see.
What sprite?

Quote from: DoctorN on March 13, 2011, 03:32:38 AM
I have no idea how to put in the names for the status so youll have to show me where (im guessing its under "int player_status")
I put names because i don't know what numbers are you using for every status. Don't take all we say literally, don't use copy/paste, just read, analyze, think about it and then write your own code.
We cannot code for you.

Quote from: DoctorN on March 13, 2011, 03:32:38 AM
so at elast the code got somewhere after several days of asking. but i have no idea with it going back to stand.
If you don't know what are you doing or you are going to do several changes in code, try to keep differents versions of your code, so if you do something wrong, you always can come back.

Try to write your code on paper, or do an schematic flow, and try to do it line by line. Don't try to force what you want to do it, just follow the code. It's slow and tedious, but you need to do it the firsts times until you know how to do it without paper.
There must be some examples (in Bennupack, in "catle of dr. Malvado" or other games, like "the amazing adventures of Echo"), so if you're lost, try to read o try another game more simple (a platform game is not recomended for noobs).
Hala, como con 1001 procesos sólo va a 9 FPS, vamos a meterle 32 veces más, a ver si revienta.
(Drumpi epic moment)

MisterN

im not a noob, im an expert at gml and actionscript 2-3 and something so simple doesnt even compute anymore. im sure you know what sprite im talking about (there is only ONE sprite I am talking about) and thats the jump sprite. I dont want to modify a finished game because its so clustered with stuff that I dont even want (and remember, fenix .84b for dreamcast). that really makes no sense to jot stuff down on paper. im just so flustered because of all the time i have wasted for this deadline, its taken me a week to try and get this jump part to work properly, i still want someone to help me with the red collision, but its like nothings been happening. so please, read my code, it should say everything in the //comments.
werg

Drumpi

Hey, calm down.
Getting started with a new languaje is not easy and take time and lots of easy and simple programs to get practice. You know GML (game maker languaje, i supose) and actionscript, but i know C, ASM, Matlab, Div, Fenix and now java (starting) so i know how first programs are, because none of them its the same.
Bennu is a process languaje, so if you haven't programmed in C with processes, you cannot call yourself an expert in Bennu. Concurrent programming is not the same as secuencial programming.

Don't think always that we know what are you thinking, because i didn't know if you were talking about standing sprite or walking sprite, but you told me about jumping sprite.
And i read your code, but i'm little limited for what I read.
I'm helping you because i had a little time to spend with you, i don't know others, but if you don't calm, i can't help you. I have lots of things to do too.

One week for first character, walking, jumping and more on hardness map for first bennu program i think its short time. Last character I made tooks me about a week with written code and years of experience, so keep going.

So, for now i will told you two questions to give some clues:
-in "If (key(_left) or key(_right))" block, you put "player_status=1;" 3 times, but they are redundant. You can delete, one or two if you do it right.
-You said that you always see the jump sprite but, can you tell me what's the player_status who do it? it tells you where is the problem.

I give clues to help, I don't write code for others (unless it can help many people). Correct your own errors is the best way to learn, that's what I think, but if you want written code, i'm the wrong guy. Ask another one or copy other code.
Hala, como con 1001 procesos sólo va a 9 FPS, vamos a meterle 32 veces más, a ver si revienta.
(Drumpi epic moment)

MisterN

#34
i also did visual basic and xna.

if you read the comments next to int player_status it should say
0 - standing
1 - walking
2 - jumping
3 - landing

also, how does the status 1 thing mean anything. i dont really see how it corresponds to jumping, or collision with the colour red.
werg

MisterN

#35
pay close attention to line 75 it should tell you everything in the //comment

[code language="fenix"]
Program platform_engine;
//these are global variables
Global
   Playerfpg;
   
   //initializes the player's sprites
   int Player_graph[14];
   
   //initializes the level
   int level;
   int levelmask;

//this sets up things like the games resolution and whatnot      
Begin
   Set_mode(320,240,16);
   Set_fps(20,0);
   
   PlayerFPG=load_fpg("Player.fpg");

   Map_clear(0,0,RGB(0,0,0));
   Write (0, 64, 16, 1, "Platform Game");
   
   //PlayerWalk Animations; it a good idea to repeat the same sprite 3 times so it doesn't
   //look sped up unless you have many detailed frames, you can add as many as you want, just
   //be sure to change int Player_graph[X] to the number of sprites you have (0 included, so
   //its one number higher than the last Player_grap[X] you have
   Player_graph[0]=load_png(".\sprites\player\Walk1.png");
   Player_graph[1]=load_png(".\sprites\player\Walk1.png");
   Player_graph[2]=load_png(".\sprites\player\Walk1.png");
  Player_graph[3]=load_png(".\sprites\player\Walk2.png");
  Player_graph[4]=load_png(".\sprites\player\Walk2.png");
  Player_graph[5]=load_png(".\sprites\player\Walk2.png");
  Player_graph[6]=load_png(".\sprites\player\Walk3.png");
  Player_graph[7]=load_png(".\sprites\player\Walk3.png");
  Player_graph[8]=load_png(".\sprites\player\Walk3.png");
  Player_graph[9]=load_png(".\sprites\player\Walk2.png");
  Player_graph[10]=load_png(".\sprites\player\Walk2.png");
  Player_graph[11]=load_png(".\sprites\player\Walk2.png");
  Player_graph[12]=load_png(".\sprites\player\Stand.png");
  Player_graph[13]=load_png(".\sprites\player\Jump.png");
 
  level=load_png(".\sprites\level\image\test.png");
  levelmask=load_png(".\sprites\level\mask\test.png");

   Player(PlayerFPG,1,50,100);
   
   start_scroll(0,0,level,0,0,0);

   Loop
      If (key(_esc))
         Exit("Bye",0);
      End
      Frame;
   End
End

//This process is for the player, all code that belongs to him is in this part
Process Player(file,graph,x,y)
Private
   xspeed=3;
   yspeed=0;

   y_start_acceleration=4;
   y_acceleration=0;
   
   int fall;

   jump=0;
   
   int i;
   int ii;
   int pixel;
   int red,blue,green;
   
   int player_status; //0 is standing, 1 is walking, 2 is jumping, 3 is falling
   
   
Begin
   ctype=c_scroll;
   Loop
      //Player Movement
      if (key (_left))
         flags = 1;
         ii = 0;
         while (ii <5)
         pixel = map_get_pixel(0, levelmask, x-ii, y);
         get_rgb (pixel, & red, & green, & blue);
            if (red> 200)
            ii = ii - 1;
         break;
      end
      ii = ii +1;
      end
      x = x-ii;
      end
      if (key (_right))
         flags = 0;
         ii = 0;
         while (ii <5)
         pixel = map_get_pixel(0, levelmask, x + ii, y);
         get_rgb (pixel, & red, & green, & blue);
            if (red> 200)
            ii = ii - 1;
         break;
      end
      ii = ii +1;
      end
      x = x + ii;
      end
      // Players Status
      if ((!key (_left)) and (!key (_right))) 
         player_status=0;
      else
         player_status=1;
      end
      // Jumping
   if (key (_space))
         pixel = map_get_pixel(0, levelmask, x, y +1 +15); 
         get_rgb (pixel, & red, & green, & blue); 
         if (blue> 200)
            fall =- 20; 
         end   
      end
      // Implementation of fall. 
      ii = fall; 
      if(ii > 0) 
         while(ii != 0) 
            pixel=map_get_pixel(0, levelmask, x, y + (fall-ii) +15);
            get_rgb (pixel, & red, & green, & blue);
            if (blue> 200) 
               ii = ii + 1; 
               break; 
            end 
            ii = ii - 1;   
         end 
      else 
         ii = 0;
      end 
      // Move the fall until we can. 
      y = y + (fall-ii);;
      // Acceleration of gravity 
      if (ii == 0) 
         fall = fall + 5;   
      else 
         fall = 0;
      end
      //Player Status
      if(player_status==0)
      graph=graph=Player_graph[12];
      end
      if(player_status==1)
      graph=graph=Player_graph;
      i=(i+1)%12;
      end
      if(player_status==2)
      graph=graph=Player_graph[13];
      end
      if(player_status==3)
      graph=graph=Player_graph[13];
      end      
      Frame;
   End
End
[/code]

I took out the jumping for now, and I got rid of the two uneeded status thingamagigers in the left and right stuff (if it made any difference). at the very best so i can explain jumping let me lay it out for you:
*if set in the right place, the jumping sprite will be the only thing you see
*if set right after jump, it will flash for a second then proceed back to status 0 (standing) or status 1 (walking)
*if set in landing only (i forget most of this, but even somewhere in jumping too as i recall), it will flicker between the jump sprite, and whatever else is happening (standing/walking).

i hope that explains everything

EDIT: got the red collision to work :). still need help with that jump though
werg

Drumpi

Let's go step by step.
The jump code it this?

[code language="fenix"]
      // Jumping
           if (key (_space))
         pixel = map_get_pixel(0, levelmask, x, y +1 +15); 
         get_rgb (pixel, & red, & green, & blue); 
         if (blue> 200)
            fall =- 20; 
         end   
      end
[/code]

As I understand, it only jumps (and elevate) if space key is pressed, right?
Hala, como con 1001 procesos sólo va a 9 FPS, vamos a meterle 32 veces más, a ver si revienta.
(Drumpi epic moment)

MisterN

yes...
don't you have bennu/fenix on your computer?
werg

Drumpi

Yes, i have, but it's 2:00am here, and don't have your graphics.
Ok, if this is the jump code, put in the jump player_status:

[code language="fenix"]
      // Jumping
           if (key (_space))
                        player_status=2;
         pixel = map_get_pixel(0, levelmask, x, y +1 +15); 
         get_rgb (pixel, & red, & green, & blue); 
         if (blue> 200)
            fall =- 20; 
         end   
      end
[/code]

If it works, tell me the code who make the player falls until it reachs the floor.
Hala, como con 1001 procesos sólo va a 9 FPS, vamos a meterle 32 veces más, a ver si revienta.
(Drumpi epic moment)

MisterN

#39
all the graphics are are sprites of megaman: (but because im not just unpack this into the platform_engine folder and the code will work)
http://www.mediafire.com/?5sb855p5o0u5b8b

I had the status thing in there, and in //implementation of fall but it was one of the mentioned above:
Quote from: DoctorN on March 14, 2011, 01:54:36 AM
*if set in the right place, the jumping sprite will be the only thing you see
*if set right after jump, it will flash for a second then proceed back to status 0 (standing) or status 1 (walking)
*if set in landing only (i forget most of this, but even somewhere in jumping too as i recall), it will flicker between the jump sprite, and whatever else is happening (standing/walking).
werg

Drumpi

Ok, I could test your code and i made the needed changes, but do not get used to get so explicit answers ;)

[code language="bennu"]Program platform_engine;
//these are global variables
Global
    Playerfpg;

    //initializes the player's sprites
    int Player_graph[14];

    //initializes the level
    int level;
    int levelmask;

//this sets up things like the games resolution and whatnot   
Begin
    Set_mode(320,240,16);
    Set_fps(20,0);
     
    PlayerFPG=load_fpg("Player.fpg");
     
    Map_clear(0,0,RGB(0,0,0));
    Write (0, 64, 16, 1, "Platform Game");
     
    //PlayerWalk Animations; it a good idea to repeat the same sprite 3 times so it doesn't
    //look sped up unless you have many detailed frames, you can add as many as you want, just
    //be sure to change int Player_graph[X] to the number of sprites you have (0 included, so
    //its one number higher than the last Player_grap[X] you have
    Player_graph[0]=load_png(".\sprites\player\Walk1.png");
    Player_graph[1]=load_png(".\sprites\player\Walk1.png");
    Player_graph[2]=load_png(".\sprites\player\Walk1.png");
    Player_graph[3]=load_png(".\sprites\player\Walk2.png");
    Player_graph[4]=load_png(".\sprites\player\Walk2.png");
    Player_graph[5]=load_png(".\sprites\player\Walk2.png");
    Player_graph[6]=load_png(".\sprites\player\Walk3.png");
    Player_graph[7]=load_png(".\sprites\player\Walk3.png");
    Player_graph[8]=load_png(".\sprites\player\Walk3.png");
    Player_graph[9]=load_png(".\sprites\player\Walk2.png");
    Player_graph[10]=load_png(".\sprites\player\Walk2.png");
    Player_graph[11]=load_png(".\sprites\player\Walk2.png");
    Player_graph[12]=load_png(".\sprites\player\Stand.png");
    Player_graph[13]=load_png(".\sprites\player\Jump.png");
     
    level=load_png(".\sprites\level\image\test.png");
    levelmask=load_png(".\sprites\level\mask\test.png");
     
    Player(PlayerFPG,1,50,100);
     
    start_scroll(0,0,level,0,0,0);
     
    Loop
        If (key(_esc))
        Exit("Bye",0);
        End
        Frame;
    End
End

//This process is for the player, all code that belongs to him is in this part
Process Player(file,graph,x,y)
Private
    xspeed=3;
    yspeed=0;
     
    y_start_acceleration=4;
    y_acceleration=0;
     
    int fall;
    int falling;    //indicate if character is in falling mode or not
     
    jump=0;
     
    int i;
    int ii;         //you must say: counter to test every pixel of movement of hardness map
    int pixel;
    int red,blue,green;
     
    int player_status; //0 is standing, 1 is walking, 2 is jumping, 3 is falling
     

Begin
    ctype=c_scroll;
    Loop
        //Player Movement
        if (key (_left))
            flags = 1;
            ii = 0;
            while (ii <5)
                pixel = map_get_pixel(0, levelmask, x-ii, y);
                get_rgb (pixel, & red, & green, & blue);
                if (red>200)
                    ii = ii - 1;
                    break;
                else
                    if (player_status!=2 and player_status!=3) player_status=1; end
                end
                ii = ii + 1;
            end
            x = x-ii;
        end
        if (key (_right))
            flags = 0;
            ii = 0;
            while (ii <5)
                pixel = map_get_pixel(0, levelmask, x + ii, y);
                get_rgb (pixel, & red, & green, & blue);
                if (red>200)
                    ii = ii - 1;
                    break;
                else
                    if (player_status!=2 and player_status!=3) player_status=1; end
                end
                ii = ii + 1;
            end
            x = x + ii;
        end
       
        if (!key(_left) and !key(_right) and player_status==1)
            player_status=0;
        end
       
        // Jumping
        if (key (_space))
            player_status=2;
            falling=true;
            pixel = map_get_pixel(0, levelmask, x, y +1 +15); 
            get_rgb (pixel, & red, & green, & blue); 
            if (blue> 200)
                fall =- 20; 
            end 
        end
        // Implementation of fall. 
        ii = fall; 
        if(ii > 0) 
            while(ii != 0)
                pixel=map_get_pixel(0, levelmask, x, y + (fall-ii) +15);
                get_rgb (pixel, & red, & green, & blue);
               
                if (blue>200)
                    ii = ii + 1;
                    falling=false;
                    say("I'm in ground now");
                    break;
                end
                ii = ii - 1;
            end 
        else 
            ii = 0;
        end 
        // Move the fall until we can. 
        y = y + (fall-ii);
       
        //Ending of jumping and falling status
        say("FALLING: "+falling+"   Player status: "+player_status);
        if (player_status==2 and !key(_space)) player_status=3; end
        if (player_status==3 and !falling) player_status=0; end
       
       
        // Acceleration of gravity 
        if (ii == 0) 
            fall = fall + 5; 
            falling=true;
        else 
            fall = 0;
        end
       
        //Player Status
        //say(player_status);
        switch (player_status)
        case 0: graph=Player_graph[12]; end
        case 1:
            graph=Player_graph;
            i=(i+1)%12;
        end
        case 2: graph=Player_graph[13]; end
        case 3: graph=Player_graph[13]; end
        end
       
        //say("frame");
        Frame;
    End
End
[/code]

First, as i said, you must comment the ii use, I cannot understand his use untill several reads (maybe you are one of a few peolple who used a loop to check every pixel on hardness map movement :P)
I added a new variable who indicates if character is falling or not. I'm not sure if you can do this in another way (checking vertical speed or else), I did this way.
Then I can add the player_status statements and his changes. Maybe, make a status flow and its possibles changes in paper can help to do this.

I left some SAY statements to show you some tips for debug, you can delete them if you want. You'd better watch what really variables has, not what you thinking it had, usually they are differents ;)

And there are minor changes, but it's because I'm used to it.

I hope it helps to you, I'm waiting to se your project finished.
Hala, como con 1001 procesos sólo va a 9 FPS, vamos a meterle 32 veces más, a ver si revienta.
(Drumpi epic moment)

Drumpi

By the way:
You don't need to load the same graphic many times, you can:
-Have a list of mpas loaded, and another list with animations, where you can repeat the same map_id without having it on memory twice.
-Create a counter to check animation delay: if it reachs 3 (or another number), put it to 0 and advance an animation frame. But you must put it to 0 every time you change player_status.
Hala, como con 1001 procesos sólo va a 9 FPS, vamos a meterle 32 veces más, a ver si revienta.
(Drumpi epic moment)

MisterN

thanks :) and technically you did help others because they can download those sprites and use the code thats on this thread to start their platform engine XD
werg

MisterN

Anyone got any idea how to do "layers" i want my player to be in front of everything else with the level being the layer behind everything.
werg

handsource-dyko

Layers... Well, graphs from processes have a z-value. The mouse cursor has a predifined z-value of -512. This means that it is on the topmost layer.

This is the range of layer depth:   -etc -etc -512 -200 -100 0 100 200 etc etc 512 etc, so to put something behind an other object, use values like 100 or 200, and to bring stuff to the front you add a minus to the number. (I'm not really sure what the maximum and minimum value's of the range are, but hese should be fine).

Scrolls have a predifined z value, too. You can freely change those values in case you want to do special things. In case you feel restricted by the standard scrolls, you can create your own scroll layers by using some of the more advanced features of the scroll structure. This advanced feature allows to manually manipulate the scroll window and the speed ratio of the layers but, this is a rather sophisticated feature that I don't recommend for beginners. (Once you know more about the language you can delve into these things).