increase map and scroll size and keep everything in its place?

Started by MisterN, July 04, 2012, 01:55:13 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MisterN

This is the process that renders the level, theres no other process that renders it in any way.

/* Process that renders a map. It creates a new map in memory for drawing blocks onto, and uses that */
/* map in a scroll.                                                                                */

PROCESS rendermap(); // can be a function. you don't have use processes for everything.

PRIVATE

// x and y values for plotting the blocks
int temp_x;
int temp_y;

BEGIN

 
    // create a new map in memory
    scroll_map=map_new(level.width, level.height,16);
    say("creating map: w="+level.width+" h="+level.height);
   
    // start a scroll : scroll no.=0, file=0, foreground=scroll_map, background=0, region=0, locking indicator=0
    start_scroll(0,0,scroll_map,0,0,0);
    say("scroll started");
   
   
    // put the player
    player_id=player(level.player_x,level.player_y+4);
    say("putting player: x="+level.player_x+" y="+level.player_y);

   
   
    // put the blocks
    FOR (tile_count_x=0; tile_count_x<TILE_DIMX; tile_count_x+=1)
           
        FOR (tile_count_y=0; tile_count_y<TILE_DIMY; tile_count_y+=1)
   
            IF (level.tile[tile_count_x][tile_count_y].used==TRUE)
           
                // make sure that the tiles are put on the right place
                temp_x=(tile_count_x*block_size)+8;
                temp_y=(tile_count_y*block_size)+8;
                   
                block_graph=level.tile[tile_count_x][tile_count_y].kind;
       
                //map_xputnp ( <INT destinationFileID> , <INT destinationGraphID> , <INT originFileID> , <INT originGraphID> , <INT x> , <INT y> , <INT angle> , <INT scale_x> , <INT scale_y> , <INT blitflags> )
               
                // put a block into the scroll
                map_xputnp(0,scroll_map,block_fpg,block_graph,temp_x,temp_y,0,100,100,0);
                say("plotting tile: "+tile_count_x+" , "+tile_count_y);
            END
        END
    END
   
   
    // load fpg files
        //pellet
        IF(MAX_PEL>0)
            if(collec_fpg==0)
                collec_fpg = load_fpg("collectibles.fpg");
            end
        ELSE
            unload_fpg(collec_fpg);
        END
        //enemy_a
        IF(MAX_ENE_A>0)
            enemy_a_fpg = load_fpg("enemy_a.fpg");
        ELSE
            unload_fpg(enemy_a_fpg);
        END
        //enemy_b
        IF(MAX_ENE_B>0)
            enemy_b_fpg = load_fpg("enemy_b.fpg");
        ELSE
            unload_fpg(enemy_b_fpg);
        END
        //enemy_c
        IF(MAX_ENE_C>0)
            enemy_c_fpg = load_fpg("enemy_c.fpg");
        ELSE
            unload_fpg(enemy_c_fpg);
        END
        //enemy_d
        IF(MAX_ENE_D>0)
            enemy_d_fpg = load_fpg("enemy_d.fpg");
        ELSE
            unload_fpg(enemy_d_fpg);
        END
        //enemy_e
        IF(MAX_ENE_E>0)
            enemy_e_fpg = load_fpg("enemy_e.fpg");
        ELSE
            unload_fpg(enemy_e_fpg);
        END
        //enemy_f
        IF(MAX_ENE_F>0)
            enemy_f_fpg = load_fpg("enemy_f.fpg");
        ELSE
            unload_fpg(enemy_f_fpg);
        END
   

    // put the pellets
    FOR (count=0; count<MAX_PEL; count+=1)
   
        IF (level.obj_pellet[count].used==TRUE)
            obj_pellet_id[count]=pellet(level.obj_pellet[count].x,level.obj_pellet[count].y,count);
            say("putting pellet: "+count+" x="+level.obj_pellet[count].x+" y="+level.obj_pellet[count].y+" used: "+level.obj_pellet[count].used);
        END
    END
   
    // put the healthkits
    FOR (count=0; count<MAX_HKT; count+=1)
   
        IF (level.obj_healthkit[count].used==TRUE)
            obj_healthkit_id[count]=healthkit(level.obj_healthkit[count].x,level.obj_healthkit[count].y,count);
            say("putting healthkit: "+count+" x="+level.obj_healthkit[count].x+" y="+level.obj_healthkit[count].y+" used: "+level.obj_healthkit[count].used);
        END
    END
   
    // put the enemy A's
    FOR (count=0; count<MAX_ENE_A; count+=1)
   
        IF (level.obj_enemy_a[count].used==TRUE)
            obj_enemy_a_id[count]=enemy_a(level.obj_enemy_a[count].x,level.obj_enemy_a[count].y,level.obj_enemy_a[count].gravity,count);
            say("putting enemy A: "+count+" x="+level.obj_enemy_a[count].x+" y="+level.obj_enemy_a[count].y+" used: "+level.obj_enemy_a[count].used);
        END
    END
   
    // put the enemy B's
    FOR (count=0; count<MAX_ENE_B; count+=1)
       
        IF (level.obj_enemy_b[count].used==TRUE)
            obj_enemy_b_id[count]=enemy_b(level.obj_enemy_b[count].x,level.obj_enemy_b[count].y,count);
            say("putting enemy B: "+count+" x="+level.obj_enemy_b[count].x+" y="+level.obj_enemy_b[count].y+" used: "+level.obj_enemy_b[count].used);
        END
    END
   
    // put the enemy C's
    FOR (count=0; count<MAX_ENE_C; count+=1)
       
        IF (level.obj_enemy_c[count].used==TRUE)
            obj_enemy_c_id[count]=enemy_c(level.obj_enemy_c[count].x,level.obj_enemy_c[count].y,level.obj_enemy_c[count].direction,count);
            say("putting enemy C: "+count+" x="+level.obj_enemy_c[count].x+" y="+level.obj_enemy_c[count].y+" used: "+level.obj_enemy_c[count].used);
        END
    END
   
    // put the enemy D's
    FOR (count=0; count<MAX_ENE_D; count+=1)
       
        IF (level.obj_enemy_d[count].used==TRUE)
            obj_enemy_d_id[count]=enemy_d(level.obj_enemy_d[count].x,level.obj_enemy_d[count].y,count);
            say("putting enemy D: "+count+" x="+level.obj_enemy_d[count].x+" y="+level.obj_enemy_d[count].y+" used:
            "+level.obj_enemy_d[count].used);
        END
    END
   
    // put the enemy E's
    FOR (count=0; count<MAX_ENE_E; count+=1)
       
        IF (level.obj_enemy_e[count].used==TRUE)
            obj_enemy_e_id[count]=enemy_e(level.obj_enemy_e[count].x,level.obj_enemy_e[count].y,count);
            say("putting enemy E: "+count+" x="+level.obj_enemy_e[count].x+" y="+level.obj_enemy_e[count].y+" used:
            "+level.obj_enemy_e[count].used);
        END
    END
   
    // put the enemy F's
    FOR (count=0; count<MAX_ENE_F; count+=1)
       
        IF (level.obj_enemy_d[count].used==TRUE)
            obj_enemy_f_id[count]=enemy_f(level.obj_enemy_f[count].x,level.obj_enemy_f[count].y,count);
            say("putting enemy F: "+count+" x="+level.obj_enemy_f[count].x+" y="+level.obj_enemy_f[count].y+" used:
            "+level.obj_enemy_f[count].used);
        END
    END

END // end of map rendering process


Heres some stuff I want to be able to do now (if you know the answer to one of the questions just put the number before your sentence/paragraph  :) ):
1. Ive seen examples of stuff working like this but i want to know how i can type in the program itself, and im assuming what I type is a string? well how can I make that a variable?

2. I want to be able to change the size of level.width and level.height through a panel that lets me change the variables of them (dont worry about the panel, i just gotta know about the variable end). The problem is, the tiles are loaded on the map, and the thing I tried made a new map, so it clears all your hard work (minus the processes on the map, those are fine). Heres a question to my question, how can I change the map size and it will work all fine and dandy in the scroll and all that stuff?

Thanks
werg

handsource-dyko

Since I know how the level map rendering works in your engine (it's a fixed size array), I assume you want TILE_DIMX and TILE_DIMY to be variables?

That would require a completely different approach for saving the data (you need a dynamic array) wich is kinda tricky. It's not something you
can quickly implement, it requires a fair bit of manual memory managment designing first. Also the Load/Save functions are not suitable for data of unknown sizes. Basically it would have be changed to using the manual functuions.

It's not impossible, but it just takes a fair bit of time to implement and you have to make the tradeoff if you really need variable map sizes v.s. the design and test time to implement it. Even with malvado I didn't bother with variable map sizes (I simply choose a constrained maximum). In fact, a lot of engines use fixed (maximum) map sizes. Also the leveleditor and rendering logic becomes more eleborate if you want this.

Anyway I don't recommend it, maybe some other people have different thoughts on this (or suggestions).

B.tw  to clarify things for the others, what do you want with strings? Is it for an interface with an external dialog program? Maybe you could explain a bit more about your intend. ???

MisterN

Not necessarily TILE_DIMX and TILE_DIMY, I can easily set both of those to say 3000 and I the game will still work just fine. I mean changing level.width and level.height while inside the editor and it adds more room to the map.
werg

handsource-dyko

Oh, inside the editor. I see. Well, it still requires the map to be re-rendered (before it resizes it's current state has to be saved first).
Possible, as long as it's simply a resize of the viewport (because the map size is fixed in terms amount of tiles in x and y directions) I assume you
simply want the scroll bitmap size to change?

MisterN

Yeah I want to be able to change the scroll_map size at any given moment inside the editor
werg

handsource-dyko

Then you have unload the old map first and create a new one with the new size, and re-render the tiles. Unloading the old map is important in order to prevent memory leaks. Also the scroll must be refreshed, by stopping it first and then starting a new scroll again.

MisterN

can you show me how i can unload the map and place every tile again?
werg

MisterN

Ok so I got that working now but now I want to know this part.

*How can I view all the files in a certain directory of a certain format? (like you can in programming languages like C# and stuff with the openfiledialog) i'm not asking for an open file dialog, ill have it done in game. ill use some text and stuff, ill get it to work in this picture:


For example, I want it to only show me the format *.lvl, and in alpabetical order. And if there are more than (say 16), then a "page" will be made, that i can navigate with the arrow keys. can you show me code for this? thanks

Also: I want to be able to type string variables in the game, how can I do that?
werg

handsource-dyko

You can use the glob() function and readdir() for this purpose. Bennu doesn't have a textinput function, but can make your own. Here's an example: http://wiki.bennugd.org/index.php?title=Tutorial:Textinput

You could also opt for an oldskool textinput system with a grid of characters and a selection cursor.

MisterN

I noticed that every key (like tab and esc) also had their own character, how can I make it so that they dont?
werg

handsource-dyko

Simply ignore them. In fact, each key on the keyboard has it's on scancode.

MisterN

#11
im confused, everything should worked, the problem is with the string txtid. this is just the level editor. take a look inside the leveleditor_menu.prg, thats where all the magic happens. Can you tell me why its crashing upon me pressing enter and not making the level? Thanks
werg

handsource-dyko


MisterN

the menu should be there when you boot up the leveleditor

and dont tell me that the .prg's in that zip file dont have the menu, i just tested it
werg

handsource-dyko

#14
Do I need to do anything special? I'm getting this instead (see image):