know what you might do for shooting?

Started by MisterN, April 16, 2011, 06:19:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

FreeYourMind

but this sentence is invalid, you don't have nothing when you press x key, the code is complete ?
I need to execute them, when i finish my windows update, i take a look (tomorrow)...

darío

The problem why your character faces left when you press X is easy:


//Shooting
if (key (_X))
if flags = 0;
end
if flags = 1;
end
end


you must use == instead of = to compare. "=" operator is used to assign so your code is actually making "flags" to be 1.

Regards
My sites:
Smart Fpg Editor - Painless FPG Edition for Bennu and PixTudio
fenixlib - .NET support for manipulating PixTudio, Bennu and Div graphic formats

MisterN

ok that helps. now onto part where i make the bullets move (should be that hard now that i figured out, but why ==?)
werg

SplinterGU

you can assign a value to a var in an if instructions, it's valid... but I don't know if you want do it in this case.

for compare you must use ==
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

MisterN

ok. now if i have a definite thing like say act01 modifies the game the rest of the story, act01 was say a nuclear bomb and it made everything fallout. so the same levels are in fallout now. would i use = or == in this case?
werg

handsource-dyko

Hint: = and == work like they do in C.

darío

To be honest I don't follow you.

I don't know if you got the meaning of == and =. Here is an explanation.

== and = are different things. "==" is a comparison operator and "=" is an assignment operator. The reason why "if (flags=1)" compiles is because any expression can be evaluated as a boolean expression so you are actually doing: "flags = 1; if (flags) ...". Numbers are evaluated as false if they are 0 and true otherwise.

In any case I think what you want is some code, check the following:


const
     BULLET_SPEED = 2;
end
...
process player (...)
private
    int dir = 1; // -1 when the player faces left, 1 when it faces right
...
begin
...
    loop
        if (key(_left))
            flags = 1;
            dir = -1;
        end
        if (key(_right))
            flags = 0;
            dir = 1;
        end

        // fire
        if (key(_x))
            bullet(x, y, dir)
        end if
       
        ....

        frame;
    end
end

process bullet(x, y, dir)
....
begin
        graph = whatever;
        loop
            x = x + BULLET_SPEED * dir;
            if (collision(TYPE enemy))
                // do whatever you are supposed to do when you hit an enemy
                break;
            end
            if (region_out(id, 0)) // the bullet when out of the screen
                break;
            end
            frame;
        end
        ....
end


If that's not enought, try to be more clear.
My sites:
Smart Fpg Editor - Painless FPG Edition for Bennu and PixTudio
fenixlib - .NET support for manipulating PixTudio, Bennu and Div graphic formats

MisterN

#22
ok it works except for the region out. and when i hold down x its like a long erected *censored* coming out of his face XD. so like in gamemaker, theres a key (like if its being held down) and a keypress (where once its pressed, not being held down), is there something along the lines of a keypress?
werg


MisterN

yeah that really didn't make any sense. remember as of right now im using the latest fenix because of the dreamcast.
werg

tmoney

Quote from: DoctorN on May 02, 2011, 04:46:51 AM
ok it works except for the region out. and when i hold down x its like a long erected *censored* coming out of his face XD. so like in gamemaker, theres a key (like if its being held down) and a keypress (where once its pressed, not being held down), is there something along the lines of a keypress?

no, you need to create the code yourself. 


PROCESS whatever();
PRIVATE
  key_x_is_already_pressed = false;
BEGIN
  LOOP

      IF(key(_x)) 
        IF(!key_x_is_already_pressed)
          //    put the code here that you want to be executed each time x is pressed
        END
        key_x_is_already_pressed = true;
      ELSE
        key_x_is_already_pressed = false; 
      END

    FRAME;
  END
END


MisterN

#26
that code didn't even help at all. all it did was make the bullet slower.
[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 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,0,level_graph,0,0,0);//starts the scroll, variables:
   /*
   0: number of scroll, 0-9 are possible, this is the first one, so 0 :)
   0: fpg library you use, i only laoded 1 fpg, so it's 0 (the first library) in this case :)
   level: 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

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 flags == 0;
         playerbullet(x, y, dir);
         end
         if flags == 1;
         playerbullet(x, y, dir);
         end
      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+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
            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; 
   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<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");
   ctype=c_scroll;
   loop
      if(collision(type player))
         break;
      end
      frame;
   end
end  [/code]
werg

tmoney

ok, let me be more explicit:

PROCESS Player(x,y);
PRIVATE
  key_x_is_already_pressed = false;
BEGIN
  LOOP

      //Shooting
      IF(key(_x)) 
        IF(!key_x_is_already_pressed)    
          if flags == 0;
            playerbullet(x, y, dir);
          end
          if flags == 1;
            playerbullet(x, y, dir);
          end
        END
        key_x_is_already_pressed = true;
      ELSE
        key_x_is_already_pressed = false; 
      END

    FRAME;
  END
END


you know, if you were a little more gracious to the people who have been trying to help you with your code, instead of complaining when you don't understand what they have been saying, they might be more inclined to continue helping you.  if a piece of code, or a suggestion is given to you, and it doesn't seem to be working, start by saying something like, "i can't seem to get it to work," or "i must be doing something wrong" instead of "that didn't make any sense,"  or "that didn't work."  a little humility goes a long way.

MisterN

#28
oh sorry about that, i dont have any manners :( thanks for helping me though. i just have really bad days lately so i can't think when i come on to tweak my game so sorry about that. but it works :D. on the sidenote I am talking to the russian programmer who ported over the latest version of fenix to the dreamcast and even created an operating system (dreamshell) to use on the dreamcast with those new fangled sd-card adapters is working on bennu at the moment. should I bring him over here?
werg

tmoney

it's ok.  just remember that when other people are helping you, they're trying to do you a favor. :)