is there a structure tutorial?

Started by MisterN, January 17, 2012, 03:13:18 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MisterN

I still have no idea how to use structures even though I have them in my game.
// basic levelmap data structure (global data)
struct levelmap;

    // name for the levelmap
    string mapname;

    int level_transition_spot;
   
    // player position
    int playerx; playery;
    int playerspawnx; playerspawny;
    int x_to_enter_from; y_to_enter_from;
   
    // background and hardnessmap filepath references
    string level_graph_path;
    string level_mask_path;
   
    // music data
    bool has_music;
    string song_path;
    int music_repeat;
   
    struct level_mask;
       
        int x; y;
    end
   
    // data for enemyM (25 entities, 0...24)
    struct enemyM[24];
   
        bool used=false; // true or false, when true, it will be placed when the level is loaded,
                       // when false, it is ignored.
        int x; y;
    end
   
    // data for enemyS (25 entities, 0...24)
    struct enemyS[24];
   
        bool used=false;
        int x; y;
    end
   
    // data for enemyX (25 entities, 0...24)
    struct enemyX[24];
   
        bool used=false;
        int x; y;
    end
   
    // data for pellet (255 entities, 0...254)
    struct pellet[254];
   
        bool used=false;
        int x; y;
    end
   
    // data for bossa1
    struct bossa1;
   
        bool used=false;
        int x; y;
    end
   
end


and I want to

level_mask.level_mask();

and have the player be able to

//If colliding, a reference to the colliding process is returned:
    collided_obj = collision(TYPE level_mask); 

    //check if a reference took place. (loop over all found colliding objects in this frame) 
    //Always make sure you do not try to access local variables on an empty reference!
    WHILE(collided_obj) 
        //To illustrate simple behaviour implementation, I just check if there is an object somewhere on any x below this process:
        IF(collided_obj.y > y - fall + ii)
            //Some logic copied from your source which I think you'd want here
            falling = false;
            IF(!walking);
                player_status=0;
            ELSE
                player_status=1;
            END
        ELSE IF(collided_obj.y < y - fall + ii)
            //when hitting something above you:
            //Some logic copied from your source which I think you'd want here
            fall = 3;
        END
        //Find any other colliding level_mask processes
        collided_obj = collision(TYPE level_mask);
    END

werg

josebita

Maybe this helps:
http://wiki.bennugd.org/index.php?title=Struct

Anyway, I don't believe it's possible to do what you try to, right now. There's no object orientation in BennuGD and one cannot use pointers to functions. At least not yet with official modules.

MisterN

#2
could that be added to the next version of bennu? I can spawn an object using the struct system. like
EnemyS[0].EnemyS(x,y);
Or does it have to be done like
EnemyS[0].x=x;
EnemyS[0].y=y;

but then how would that spawn EnemyS?
werg

josebita

You must first create the enemy and then set its position:
Enemys[0]=enemy();
Enemys[0].x=x;
Enemys[0].y=y;

MisterN

EnemyS[0]=EnemyS();
    EnemyS[0].x=64;
    EnemyS[0].y=100;


error: Unknown identifier < token error: "ENEMYS">.

even though EnemyS is in struct struct enemys[24].
werg

BlackCurtain

Quote from: DoctorN on January 18, 2012, 10:31:14 PM
EnemyS[0]=EnemyS();
    EnemyS[0].x=64;
    EnemyS[0].y=100;


error: Unknown identifier < token error: "ENEMYS">.

even though EnemyS is in struct struct enemys[24].
I don't think it's recommended to naming your array and process the same name. I will cause naming violations/collisions.

MisterN

werg

MisterN

EDIT:

levelmap.enemy_S[0]=EnemyS(x,y);
levelmap.enemy_S[0].x=64;
levelmap.enemy_S[0].y=100;

works! :D

problem is now "error: struct required < token error: ">" >."
werg

MisterN

#8
Ok here is what I need to work on now. Loading the levels externally. Here is an example of level_5
FUNCTION level_5(topx,topy,botx,boty)
begin
z=255;
levelmap.can_pause = true;
   
    levelmap.level_graph_path = load_png("./LEVEL/LEVELS/a2_s1.png");
    levelmap.level_mask_path = load_png("./LEVEL/LEVELS/a2_s1_mask.png");
    levelmap.level_back_path = load_png("./LEVEL/BACKGROUNDS/snow_mountains_day.png");
   
        level_graph = levelmap.level_graph_path;

        levelmask = levelmap.level_mask_path;

        level_background = levelmap.level_back_path;
   
    levelmap.level_transition_spot = botx;

    //Starts the Player
    levelmap.playerspawnx = 32; levelmap.playerspawny = 176;
    scroll[0].camera=Player(levelmap.playerspawnx,levelmap.playerspawny);
   
    //levelmap.enemy_x[0]=EnemyX(x,y);
    levelmap.enemy_x[0].x=64;
    levelmap.enemy_x[0].y=100;
   
    start_scroll(0,0,level_graph,level_background,0,0);//starts the scroll, variables:
   
    levelmap.music_repeat = levelmap.music_repeat_true;
    levelmap.song_path=load_song("./MUSIC/LEVEL2.ogg");
        levelmap.song = levelmap.song_path;
    play_song(levelmap.song,levelmap.music_repeat); //the -1 means it will loop indefinitely until it is stopped
   
    fclose(handle);                // zipping up after business is done
   
    repeat
    frame;
   
    until(level_change)
    OnExit
    unload_map(file,graph);
end


I originally had taken out the:
    levelmap.level_graph_path = load_png("./LEVEL/LEVELS/a2_s1.png");
    levelmap.level_mask_path = load_png("./LEVEL/LEVELS/a2_s1_mask.png");
    levelmap.level_back_path = load_png("./LEVEL/BACKGROUNDS/snow_mountains_day.png");


and made it "test_level.gmf". I originally had handle open it up and I tried to use fread, that made no sense. I tried to use fget, i guess it work but it didnt load the any of the path stuff for it to be used.

so now I am stuck. could anyone help me out with some code to read from that .gmf (its a format i came up with! its basically a .txt file anywho) file and place them? for I plan to move some of the structure stuff in there (function level_5) to a loop process so it always changes as a .gmf file is loaded (and changes different things, loads objects). how would objects still be loaded (like scroll[0].camera = player() ??? ). Thanks

EDIT:
It appears to save variables and nothing more
werg