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

the code i posted has them listed as .png. i know how to use fpgedit2005
werg

MisterN

Ive got a perfectly walking megaman and the level. Im still stuck with the jump animation (it still shows for a split second then goes back to standing/walking) and my character cant run into the red walls i planted in the level, i had them coded in at some point, but the game crashed and i took out so much code the program itself crashed so i lost it inbetween the craks. could you fix those two meesly things?

[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(256,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;

Begin
   ctype=c_scroll;
   Loop
      // Walking
      If (key(_left) or key(_right))
         If (graph==Player_graph[12])
            graph=Player_graph;
            //Animation for movement
  • thru [11] - 12 frames of animation
                i=(i+1)%12;
             End
             If (key(_left))
             flags=1;
             x-=xspeed;
             graph=Player_graph;;
             //Animation for movement
    • thru [11] - 12 frames of animation
               i=(i+1)%12;
               End
               if (key(_right))
               flags=0;
               x+=xspeed;
               graph=Player_graph;;
               //Animation for movement
      • thru [11] - 12 frames of animation
                 i=(i+1)%12;
                 End
              Else
              // Standing still
                 graph=Player_Graph[12];
              End
              // Jumping
              if (key (_space))
                 pixel = map_get_pixel(0, levelmask, x, y +1 +15);
                 get_rgb (pixel, & red, & green, & blue);
                 if (blue> 200)
                    graph=Player_graph[13];
                    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   
              Frame;
           End
        End
        [/code]
werg

Zip

can u post the complete game whit graph  and all the rest?
thanx

Drumpi

Its because you press left or right button: then you assign to graph a new image.

flags=1;
x-=xspeed;
graph=Player_graph[ i ];;

So you get the graph of walking. Later you don't assign to graph the jump graphic (just only if you push space). You must assign graph again on jumping routine.

This is why I recomended to use a status variable: at the end of your character main loop, you can check if Player is walking, jumping or fireing, so you assign the graph you need once in a loop round.
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

Quote from: Zip on March 10, 2011, 12:58:55 PM
can u post the complete game whit graph  and all the rest?
thanx

thats the whole code
werg

MisterN

[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

Begin
   ctype=c_scroll;
   Loop
      // Walking
      If (key(_left) or key(_right))
         If (graph==Player_graph[12])
            graph=Player_graph;
            //Animation for movement
  • thru [11] - 12 frames of animation
                i=(i+1)%12;
             End
             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)
             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   
          Frame;
       End
    End
    [/code]

    problems now:
    *still the jump thing. i put the status in the jump and in the fall and heres the outcome:
    in both jump and fall: it flickers between the standing sprite and the jumping sprite
    in jump only: it flashes for a second but now if i hold down space, you see it as long as space is held down
    in fall only: thats the only sprite you see

    *and meeting with the red.

    thats the whole code, im sure if you test the code you can use whatever you want for images. its just megaman stuff im using.

    and: how can i turn the .pngs into fpg's? im not talking about using fpgedit, im talking about in the code itself. i know how to put one in there. but with the code i have out, can i just change the ".png" to a graph from an fpg? same thing for the level, the dreamcast crashes upon png_load
werg

Drumpi

You got the same problem than before, just think about this:

-If you don't move, your character will be on status=0.
-If you walk, you have status=1. Ok, no problem.
-If you hit space without moving, first you get status=0, and then, status=2, in the same frame. Ok.
-But if later you release the space button, yes, you are still jumping, but the "If (key(_left) or key(_right))" put status to 0 or 1, so when you reach the "graph control block" it looks for stand or walking animation. You must put status to 2 if you are jumping but not pressing space, or not assign status 0 or 1 if you are previously jumping.

About FPG, as I said later, you got FPG_ADD and SAVE_FPG to add a loaded/created map to a virtual FPG (you can create a new FPG with NEW_FPG) and to save it to disk. Just load your PNG as usual, and use its ID to put it in the FPG.
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)

handsource-dyko

I recommend virtual fpg's, too. It's very handy, and you can also save them to disk from your bennu program.
It is possible to create a full-blown fpg manager. Also, you have the added benifit of using controlpoints.

MisterN

ok...  :-\ im getting very flustered now. It could be the fact that i have an illness in my sinuses which lately have been giving me headaches to where i cant grasp many things or it could be soemthing else. but i cant get this to work how i want it. one line will cripple the entire code. I hate that. Im gonna repost the code where its at. can you please (please) just show me where to change the status (repost the code with it in there please). ive literally gone through every line and pasted it there, it always flickers or flashes for a split second... thnak you:
[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

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)
         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   
      Frame;
   End
End
[/code]
werg

handsource-dyko

First, I'd recommend using symbolic constants for the player status. This will clearify the code when you read it over.
So, in the beginning of the program put:


CONST

STANDING=0;
WALKING=1;
JUMPING=2;


No, anywhere you read or write status you could type:  player_status=WALKING;
Or in tests, IF (player_status==JUMPING) etc.
This will really come in handy some day, because it reduces the need to memorize wich is wich,
and the code is more readable. Believe me, you'll be able to spot bugs or logic errors faster this way.

Second, I highly discourage using one/two character variables, just give them meaningfull names.
Basically for the same reason that it's easier in code reviews. I see you've already made fairly decent
use of that. But I can't tell the difference between i and ii, but I'll guess they are counters.

Third, use the "say" function anywhere in your code where you feel something special happens. This
will also speed up finding logic errors. (Say is like printf so you can output values and anything you
like on the dos console).

Also, try changing variables at run time with the bennu debug console.

But why not use some existing code? Just have a look at the code from malvado, it's suitable for almost
any platform game variant, especially if you tweek it a little bit. I've used the malvado code in a lot of
projects in the past before I ported it to bennu.

But, I think the best thing to do is to do code reviews and debugging. What helps for me when I get stuck
is to go outside, walk around the block or take a ride on my bike and think on a more conceptual level about
the logic or certain patterns, and then come back at the code. I get the solution usally when I'm not behind
the computer.


MisterN

i tried that and none of it helped. you also have to remember im using fenix .84 for dreamcast. id really like someone to take my code, and put it in for me so i know later on. but thanks
werg

handsource-dyko

Fenix 0.84 is ancient......(and buggy).
I thought there was a newer dreamcast version, 0.89 or 0.90?
I'm not really sure.

MisterN

#27
i found a .93 beta someone released but can you change my code?

I have no idea how to get it from this site:
http://www.dc-swat.ru/page/fenix/ its in russian.

but for now, im staying with 0.84
werg

MisterN

but please, im begging you. i have no more time to spare to figure out how to make the player work. if i can get the collision with red to stop him and the jump sprite to work properly then I am good. i somewhat have a deadline and there really are no tutorials for div/fenix/bennu. so if someone will humbly add those things to my code and repost it, i would like that.

pero por favor, soy lo ruego. no tengo más tiempo de sobra para encontrar la manera de hacer que el jugador trabajo. si puedo conseguir la colisión con el rojo a detenerlo y el salto de sprite para que funcione correctamente, entonces estoy bien. i tienen una fecha límite y no hay realmente no hay tutoriales para div / Fenix ​​/ Bennu. así que si alguien puede hacer eso por mí, yo le agradecería
werg

Drumpi

The key is in this part:

[code language="fenix"]
      // 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[/code]

You did two separated IFs to jump state (for ascending and falling)... or I think they are, so you must put inside of both if the jumping state (or ascending and falling state if you gonna use two separated graphs/animations).
I'm not sure how you implement this (is kinda confusing using i or ii as variables), but i think you must do this:

[code language="fenix"]
      // Implementation of fall.
      ii = fall;
      if(ii > 0)
         player_status=JUMPING_STATE;
         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=FALLIN_STATUS;
      else
         fall = 0;
      end[/code]

I said before, you only assigned the jumping status if you are pressing space, because you enter on key(_space) if, but if you release it, from there to end you don't assigned a new status and hold the previous: standing or walking (the two previous IFs).
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)