[BENNU or FENIX] Help setting up structures and glob

Started by MisterN, November 12, 2011, 04:01:42 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MisterN

I need help setting up structures and globs. i tried doing the glob tutorial on the wiki but load_level doesn't work because its unknown. lololol. i really had no idea how to set up a structure, and i say that because in load(), you have the string filename you load and the structure. so thats why I am asking about the stucture. Here is an example of how the level is set up in my game:
Part 1:
//Level_Structue
INCLUDE ".\level_tree.prg";
process Game_Structure()
begin
ctype=c_scroll;
level_placement();
end

Part 2:
INCLUDE ".\MENU\menu.prg";
INCLUDE ".\LEVEL\level_1.prg";
FUNCTION int level_placement()
private
string level_list;
int room_number;
int number;
begin
room_number=0;
loop
  if(level_change==true)
   signal( Type player , s_kill_tree );
   signal( Type EnemyM , s_kill_tree );
   signal( Type EnemyS , s_kill_tree );
   signal( Type EnemyX , s_kill_tree );
   signal( Type pellet , s_kill_tree );
   signal( Type level_changer , s_kill_tree );
   signal( Type levelborder , s_kill_tree );
   unload_song(song);
   unload_map(0,graph);
   room_number=room_number + number;
    number = 1;
   level_change=false;
  end
 
  if(current_level == switch_to_level)
   current_level = room_number;
  end
   switch (room_number)
    case 0:
     current_level = start_menu();
     frame;
    end
    //Level 1
     case 1:
      current_level = level_1(0,0,3200,240);
     frame;
    end
   end

  frame;
end
end

Part 3:
FUNCTION level_1(topx,topy,botx,boty)
begin
z=255;
can_pause = true;
level_changer(320,0);
levelorient = 0;
level_graph = load_png(".\LEVEL\a1_s1.png");
levelmask = load_png(".\LEVEL\a1_s1mask.png");
level_background = load_png(".\LEVEL\concrete_wall.png");
//Starts the Player
playerspawnx = 32; playerspawny = 192;
scroll[0].camera=Player(playerspawnx,playerspawny);
//enemy/ies position(s)
EnemyS(208,192);
//pellets position(s)
pellet(96,192);
pellet(112,192);
pellet(128,192);
pellet(144,192);

start_scroll(0,0,level_graph,level_background,0,0);//starts the scroll, variables:
/*
0: number of scroll, 0-9 are possible, this is the first one, so 0 :)
0: 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 regional number other than 0 or it won't work ;)
4: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...
  I recommend using 0 for the background image stays still while everything else scrolls
*/
song=load_song(".\MUSIC\LEVEL2.ogg");
    play_song(song,-1); //the -1 means it will loop indefinitely until it is stopped
    repeat
frame;
    until(level_change)
OnExit
end


And what I want to do is change remove the level tree and level functions and do a .dat file that has (in order by line), the levels (with their variables as seen in line 37 of the level_tree, id add more variables like level order, but eh) will be files that have the same info as what part 3 had, but ill remove the functions and the ends and stuff.

Any help?

I say [BENNU or FENIX] now because I work sometimes on an older computer at school that has fenixpack on it and at home I work on bennu and if both wikis are the exact same, then that is what I will put.
werg

handsource-dyko

Basic dat file load/save example:


Data structure (struct.prg)




STRUCT hiscore;


     STRUCT entry[9];
           char player_name[9];
           int score;
     END

END




Save to file



PROGRAM save_test;

INCLUDE "struct.prg";

GLOBAL


BEGIN

     hiscore.entry[0].player_name="name1";
      hiscore.entry[0].score=100000;

      hiscore.entry[1].player_name="name2";
       hiscore.entry[1].score=88899;

     hiscore.entry[2].player_name="name3";
       hiscore.entry[2].score=44444;

    /*
    etc etc (hiscores 3-9), you may omit them, they'll be empty.
   */

    save ("hiscore.dat",hiscore);  // that's all

END





Load from file



PROGRAM load_test;

INCLUDE "struct.prg";

GLOBAL


BEGIN

     load ("hiscore.dat",hiscore);  // puts contents from the file into the data structure.
                                                   // will only work if the number of records and entry's matvh the size of the
                                                   // data structure


     // print hiscores
     FOR (i=0; i<9; i+=1)

           say( "hiscore.entry[" + i + "].player_name=" + hiscore.entry[i].player_name);
            say( "hiscore.entry[" + i + "].score=" + hiscore.entry[i].score);
     END
   
END




This is a very basic example but you can make it as comprehensive as you like.

MisterN

I coudlnt figure out how to reoptimize it for loading levels XD. could you show me a simple thing what you did for malvado?
werg

handsource-dyko

What I send you by mail is similair to malvado, but simpler.