//------------------------------------------------------------------------------ // Tutorial // Subject: Walking/Tiles // Author: Roelf Leenders(el.moog@gmail.com) // Started: 4-2-2005 (11:32:29h) //------------------------------------------------------------------------------ program tutorial; const //Size of the tiles(duh!) TILESIZE = 50; //Dimensions of the level(L*B = DIM*DIM) DIM = 50; //Screen size: SCREENX = 320; SCREENY = 240; global //Sometimes it's easy to group variables, easy for saving/loading and it keeps //the code organized and easier to read //Structure to save the level data: struct level; //Holds which tiles are where tile[DIM][DIM]; //Start position for a character start[1]; end //Structure for scrolling the level: //sx and sy are holding the 'camera' point in pixels, that point is in the upper //left corner of the screen struct scrol; sx; sy; cam; end //FPG file: fpg1; //true if editor, false if not editormode; //GP Keys __A = _control; __B = _alt; __SELECT = _space; __START = _enter; __R = _tab; __L = _backspace; local xs,ys; begin //Initialize screen: set_title("Serie Tutorials by Roelf Leenders"); full_screen = false; set_mode(SCREENX,SCREENY,16); //Load the fpg with the graphics for tiles/editor/character fpg1 = load_fpg("help.fpg"); //If the level exists it can be loaded, otherwise create a fresh one if(exists("level.lvl")) load("level.lvl",level); else //Fill up the level with tile number 1(normal ground) for(x=0;x DIM * TILESIZE - SCREENX)scrol.sx = DIM * TILESIZE - SCREENX;end if(scrol.sy > DIM * TILESIZE - SCREENY)scrol.sy = DIM * TILESIZE - SCREENY;end //Fix the real coordinates of the camera process(only a good solution when //there aren't multiple processes that need their coordinates converted) if(exists(scrol.cam)) scrol.cam.x = scrol.cam.xs - scrol.sx; scrol.cam.y = scrol.cam.ys - scrol.sy; end //Determine which tiles are on screen and should be drawn: tleft = scrol.sx / TILESIZE - 1; tright = tleft + SCREENX / TILESIZE + 2; tup = scrol.sy / TILESIZE - 1; tdown = tup + SCREENY / TILESIZE + 2; //Check if they stay within the borders of the level if(tleft < 0)tleft = 0;end if(tup < 0)tup = 0;end if(tright >= DIM)tright = DIM -1;end if(tdown >= DIM)tdown = DIM -1;end //And render the level: for(x=tleft;x=0)tilex--;end if(key(_right) and tilex0)tiley--;end if(key(_down) and tiley