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

I just did z = 100; and z=-100; and tried them between the two and nothing happened. the game still played so i dont think i did an error but is it harder than that? i know in adobe flash and actionscript you can just say layer = 1 or soemthing
werg

handsource-dyko

Where in the code did you exactly put this the z-value?
It should preferrably in the begin section of a process. You can also pass it as an argument.
Try adding some code in the process that you want to have a different z-value:




IF (key(_z))
   FRAME (100);
   say ("z="+z);
   
   z-=100;

   say("z changed to: "+z);
END

IF (key(_x))
   FRAME (100);
   say ("z="+z);
   
   z=100;

   say("z changed to: "+z);
END



(put this somewhere in the player's process if it's the player's process you want to alter the z of)

obviously this only has affect if you do something similair in other processes.

MisterN

I put it right after Process Player and Process Enemy as seen in my whole list of code (fully functional except for the layer thing, feel free to copy it and use it)
just look for the Processes, I would literally put (without the quotes) "z=100", "z+=100", "z-=100", or "z=-100" to try each one out underneath the private (which is
underneath the process's)
[code language="fenix"]
Program platform_engine;
//these are global variables
Global

    //initializes the player's sprites
    int Player_graph[14];
   
    //initializes the enemy(s) sprites
    //letter of alphabet sorts out the enemies
    int enemy_x_graph[12];

   //initializes the collectibles sprites
   int item_graph;
 
    //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); 
 
    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_graph[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");
   
    //animations for the enemy(s)
    enemy_x_graph[0]=load_png(".\sprites\enemies\x1.png");
    enemy_x_graph[1]=load_png(".\sprites\enemies\x1.png");
    enemy_x_graph[2]=load_png(".\sprites\enemies\x1.png");
    enemy_x_graph[3]=load_png(".\sprites\enemies\x2.png");
    enemy_x_graph[4]=load_png(".\sprites\enemies\x2.png");
    enemy_x_graph[5]=load_png(".\sprites\enemies\x2.png");
    enemy_x_graph[6]=load_png(".\sprites\enemies\x3.png");
    enemy_x_graph[7]=load_png(".\sprites\enemies\x3.png");
    enemy_x_graph[8]=load_png(".\sprites\enemies\x3.png");
    enemy_x_graph[9]=load_png(".\sprites\enemies\x2.png");
    enemy_x_graph[10]=load_png(".\sprites\enemies\x2.png");
    enemy_x_graph[11]=load_png(".\sprites\enemies\x2.png");
   
   //sets the image for the collectibles
   item_graph=load_png(".\sprites\collectibles\pellet.png");
   
    //sets the levels background images
    level=load_png(".\sprites\level\image\test-1.png");
    levelmask=load_png(".\sprites\level\mask\test-1.png");
 
    Player(50,100);
   
    EnemyX(290,100);

   Item(100,200);
   Item(116,200);
   Item(132,200);
   Item(148,200);
 
    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(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 <4)
                pixel = map_get_pixel(0, levelmask, x-16, y);
                get_rgb (pixel, & red, & green, & blue);
                if (blue>200)
                    ii = 0;
                    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 <4)
                pixel = map_get_pixel(0, levelmask, x + 16, y);
                get_rgb (pixel, & red, & green, & blue);
                if (blue>200)
                    ii = 0;
                    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 + 3;   
            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
       
Process EnemyX (x,y)
private
int i;
int ii;
int Xini;
int fall;
int falling;
int pixel;
int red,blue,green;
int inactive;
begin
   Xini = x;
   ctype = c_scroll;
   loop
      if(flags == 0)
            ii = 0;
            while (ii <3)
                pixel = map_get_pixel(0, levelmask, x + 16, y);
                get_rgb (pixel, & red, & green, & blue);
                if (blue>200)
                    ii = 0;
                    flags = 1;
                    break;
                end
                ii = ii + 1;
            end
            x = x + ii; 
      else
         if(flags == 1)
            ii = 0;
            while (ii <3)
                pixel = map_get_pixel(0, levelmask, x-16, y);
                get_rgb (pixel, & red, & green, & blue);
                if (blue>200)
                    ii = 0;
                    flags = 0;
                    break;
                end
                ii = ii + 1;
            end
            x = x-ii;
        end
        end
      i = i +1;
      graph = enemy_x_graph [i%12];
      falling=true;
      if (inactive==0)
            falling=true; 
        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);   
 
        // Acceleration of gravity   
        if (ii == 0)   
            fall = fall + 3;   
            falling=true;
        else   
            fall = 0;
        end 
      frame;
   end
end

process item(x,y)
begin
   ctype=c_scroll;
   graph=item_graph;
   loop
      if(collision(type player))
         break;
      end
      frame;
   end
end 
[/code]
werg

MisterN

Any idea how I can finish my scrolling thingy? i just need it to center follow (horizontally) the player. my hard drive crashed so i have an older version and i forgot the scrolling >.<

Program platform_engine; 
//these are global variables 
Global
 
    //initializes the player's sprites 
    int Player_graph[14];
 
    //initializes the enemy(s) sprites
    //letter of alphabet sorts out the enemies
    int enemy_x_graph[12];
 
//initializes the collectibles sprites
int pellet_graph[1];

//initializes the levels images
int level_graph[2];
 
    //initializes the levelmask
    int levelmask; 
 
//this sets up things like the games resolution and whatnot     
Begin 
    Set_mode(320,240,16); 
    Set_fps(20,0);   
 
    Map_clear(0,0,RGB(0,0,0)); 
    Write (0, 64, 16, 1, "Platform Game");

//Starts the scroller
scroller();

//starts the levelmask (par on with the scroller, but is the mask for the levels)
level_mask();

//players fpg, and position
    Player(50,100);
 
//enemy(s) fpg, and position
    EnemyX(260,100);

//collectibles fpg, and position
pellet(100,200);
pellet(116,200);
pellet(132,200);
pellet(148,200);
 
    Loop 
        If (key(_esc)) 
        Exit("Bye",0); 
        End 
        Frame; 
    End 
End

//This process is for all the levels, menu's, and cutscenes
Process scroller()
Begin
level_graph[0]=load_png(".\sprites\level\image\testlevel.png"); 
start_scroll(0,Player_graph,level_graph,0,0,1);//starts the scroll, variables:
/*
0: number of scroll, 0-9 are possible, this is the first one, so 0 :)
player_graph: the object/sprite that the scroller will follow
level_graph: the map in the library chosen
0: a background for the scroll you can choose (kind of second image scrolling
with the same parameters, but not necessarily the same way, and in behind the previously
selected image
0:is the part of the screen the scroll is shown in, 0 is default region, the entire screen
you can use this if you want to limit the size of the scrol (not in behind a menu or so)
for performance issues i guess, thigns on the scroll also won't show outside the region.
make sure you give your new regiona number other than 0 or it won't work ;)
0:the flags:
1:horizontal scroll of the map
2:vertical scroll of the map
4:horizontal scroll of the background
8:vertical scroll of the background
use: these are powers of two, it's like 4 bits,1=0001;2=0010,4=0100,8=1000
add the together to get all the scrolls you cant, so 1+2=3 is the map scrolling both ways
1+2+4=7 is map scrolling both ways, the background only scrolling horizontal
1+8=9= the map scrolling hotizontal, the background scrolling vertical
etc...
*/
    //sets the levels background images 
End

Process level_mask();
Begin
levelmask=load_png(".\sprites\level\mask\testlevelmask.png");
End
 
//This process is for the player, all code that belongs to him is in this part 
Process Player(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

int dir = 1; // -1 when the player faces left, 1 when it faces right

key_x_is_already_pressed = false; //this prevents rapid fire, to shoot 1 every time you
  //must press the x key
Begin
//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_graph[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");
    ctype=c_scroll; 
    Loop 
        //Player Movement 
        if (key (_left)) 
            flags = 1;
dir = -1;
            ii = 0; 
            while (ii <4) 
                pixel = map_get_pixel(0, levelmask, x-16, y);   
                get_rgb (pixel, & red, & green, & blue); 
                if (blue<200) 
                    ii = 0; 
                    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;
dir = 1;
            ii = 0; 
            while (ii <4) 
                pixel = map_get_pixel(0, levelmask, x + 16, y); 
                get_rgb (pixel, & red, & green, & blue); 
                if (blue<200) 
                    ii = 0; 
                    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

//Shooting
if(key(_x)) 
if(!key_x_is_already_pressed)//to make sure x isn't already being pressed     
if flags == 0;
playerbullet(x, y, dir);
end
if flags == 1;
playerbullet(x, y, dir);
  end
end
key_x_is_already_pressed = true;//as long as x is held down, this is true
  else
key_x_is_already_pressed = false;//once x is released, this is false 
          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<201) 
                    ii = ii + 1; 
                    falling=false; 
                    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   
        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 + 3;   
            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=(i+1)%12; 
        end 
        case 2: graph=Player_graph[13]; end 
        case 3: graph=Player_graph[13]; end 
        end
 
        //say("frame"); 
        Frame;
end
end

PROCESS playerbullet(x, y, dir);
private
     BULLET_SPEED = 8;
int pixel; 
    int red,blue,green;
end
begin
        graph = load_png(".\sprites\player\bullet.png");
        loop
            x = x + BULLET_SPEED * dir;
            if (collision(TYPE EnemyX))
                // do whatever you are supposed to do when you hit an enemy
                break;
end
pixel = map_get_pixel(0, levelmask, x, y);
get_rgb (pixel, & red, & green, & blue);
if (blue<201)
break;
            end
        frame;
    end
end
 
Process EnemyX (x,y) 
private 
int i;
int ii; 
int Xini;
int fall; 
int falling;
int pixel; 
int red,blue,green;
int inactive; 
begin
//animations for the enemy
    enemy_x_graph[0]=load_png(".\sprites\enemies\x\x1.png");
    enemy_x_graph[1]=load_png(".\sprites\enemies\x\x1.png");
    enemy_x_graph[2]=load_png(".\sprites\enemies\x\x1.png");
    enemy_x_graph[3]=load_png(".\sprites\enemies\x\x2.png");
    enemy_x_graph[4]=load_png(".\sprites\enemies\x\x2.png");
    enemy_x_graph[5]=load_png(".\sprites\enemies\x\x2.png");
    enemy_x_graph[6]=load_png(".\sprites\enemies\x\x3.png");
    enemy_x_graph[7]=load_png(".\sprites\enemies\x\x3.png");
    enemy_x_graph[8]=load_png(".\sprites\enemies\x\x3.png");
    enemy_x_graph[9]=load_png(".\sprites\enemies\x\x2.png");
    enemy_x_graph[10]=load_png(".\sprites\enemies\x\x2.png");
    enemy_x_graph[11]=load_png(".\sprites\enemies\x\x2.png");
Xini = x; 
loop 
if(flags == 0) 
            ii = 0; 
            while (ii <3) 
                pixel = map_get_pixel(0, levelmask, x + 16, y); 
                get_rgb (pixel, & red, & green, & blue); 
                if (blue<201) 
                    ii = 0;
                    flags = 1; 
                    break; 
                end 
                ii = ii + 1; 
            end 
            x = x + ii;   
else
if(flags == 1) 
            ii = 0; 
            while (ii <3) 
                pixel = map_get_pixel(0, levelmask, x-16, y); 
                get_rgb (pixel, & red, & green, & blue); 
                if (blue<201) 
                    ii = 0;
                    flags = 0; 
                    break; 
                end 
                ii = ii + 1; 
            end 
            x = x-ii; 
        end
        end 
i = i +1; 
graph = enemy_x_graph [i%12];
falling=true;
if (inactive==0) 
            falling=true;   
        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<201) 
                    ii = ii + 1; 
                    falling=false;   
                    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 + 3;   
            falling=true; 
        else   
            fall = 0; 
        end   
frame; 
end
end
 
process pellet(x,y)
begin
//loads the fpg
graph=load_png(".\sprites\collectibles\pellet.png");
loop
if(collision(type player))
break;
end
frame;
end
end 
werg

BlackCurtain

Why do you load the same sprites over and over again? It's just a waste of memory.
And you should really use FPGs for animations.

MisterN

I do it because earlier I actually transitioned everything to .fpg and the game collapsed on itself. then it was .fpg sprites and .png levels, didn't work, .png sprites and .fpg levels, didn't work. besides, the latest fenix (that was ported by SWAT, a noteable russian dreamcast programmer who invented the SDCard slot and Dreamshell, an operating system to use the SDCard slot) version that was ported to the dreamcast actually loads all the .png's just fine (of all 4 game systems released during that generation, the xbox and dreamcast had the exact same amount of video ram).
werg

BlackCurtain

Quote from: DoctorN on May 29, 2011, 04:06:51 PM
I do it because earlier I actually transitioned everything to .fpg and the game collapsed on itself.
Well then you do like this
[code language="bennu"]
Player_graph[0]=load_png(".\sprites\player\Walk1.png");
Player_graph[1]=Player_graph[0];
Player_graph[2]=Player_graph[0];
//etc...
[/code]

MisterN

ah that should help. now i have been confused about level size. i remember when the game actually scrolled i could only do a level of 640x480, it wont scroll anymore and i have no idea whats wrong, but is it possible to go bigger?
werg