Pls , Whats Wrong In My Code?


spookyln

Member
Joined
Dec 21, 2006
Messages
107
Location
Czech Republic
Website
www.tbs-software.com
hi all,
i rewriting my game spokoban to fenix but some bug in my LevelEdit code.
whats wrong?
btw: im totally new in fenix. pls be tolerant :)

when i hit __START and save block number to Tiles[x][y], many others are filled too :(
thanks for help

i used 0.92a version of Fenix compiled on Ubuntu Feisty

CODE

/*
Level editor pro novou verzi spokobanu
*/

program LevelEdit;

global
// control keys for gp2x and keyboard
__A = _control;
__B = _alt;
__SELECT = _space;
__START = _enter;
__R = _tab;
__L = _backspace;
fpg;

struct Level
string name; // jmeno levelu
string autor; // jmeno autora
string poznamky; // poznamky k levelu
string tileset; // jaky tileset je pouzit v levelu
int completed; // jestli byl level dohran
word hiscore; // nejvyssi dosazene skore
int Tiles[20][14]; // 20 sloupcu na level 14 rad
end

begin
set_mode(320, 240, 16, 0);
//RenderLevel();
MakeLevel();
repeat
frame;
until(key(_esc))
unload_fpg(fpg);
let_me_alone();
end

process RenderLevel();
private
xp;
yp;
pnt;
begin
/*
load("level.spo", Level);
fpg = load_fpg("gfx/New.fpg");
from pnt=1 to 3
set_point(fpg,pnt,0,0,0);
end
*/
clear_screen();
from xp = 0 to 19
from yp = 0 to 13
put(fpg, Level.Tiles[xp][yp], xp << 4, yp << 4);
end
end
frame;
end

process MakeLevel();
private
block=1;
xpos=0;
ypos=0;
pnt;
begin
graph=block;
fpg = load_fpg("gfx/New.fpg");
from pnt=1 to 3
set_point(fpg,pnt,0,0,0);
end
write_int(0,0,230,0,&xpos);
write_int(0,50,230,0,&ypos);
write_int(0,100,230,0,&block);
loop
//RenderLevel();
if (key(_left))
xpos = xpos - 1;
if (xpos<=0) xpos=0; end
x=xpos << 4;
while(key(_left)) frame; end
end

if (key(_right))
xpos = xpos + 1;
if (xpos>=19) xpos=19; end
x = xpos << 4;
while(key(_right)) frame; end
end

if (key(_up))
ypos = ypos - 1;
if(ypos<=0) ypos=0; end
y=ypos << 4;
while(key(_up)) frame; end
end

if (key(_down))
ypos = ypos + 1;
if(ypos>=13) ypos=13; end
y=ypos << 4;
while(key(_down)) frame; end
end

if (key(_esc))
save("level.spo", Level);
exit("",0);
end

if (key(__SELECT))
block=(block %3)+1;
graph=block;
while(key(__SELECT)) frame; end
end

if (key(__START))
Level.Tiles[xpos][ypos] = block;
RenderLevel();
while(key(__START)) frame; end
end

if (key(__B))
Level.name = "test lvl";
Level.autor = "spooky.ln";
Level.poznamky = "bez poznamek";
Level.tileset="winter";
Level.completed = 0;
Level.hiscore = 3000;
save("level.spo", Level);
end

frame;
end
end
 
give us the fpg, so we can actually run the code, and try debuggin it that way, it's very hard by just reading the code without being able to do tests
 
I bet whats going wrong is saving a struct that has strings... I think Fenix is bugged on this part (0.84 atleast).

Also, not related to your problem, a few optimizations:

minor thing:
CODE

set_mode(320, 240, 16); //you can leave out the last parameter, 0 is default



slightly bigger minor stuff:
CODE

if(!key(_right)pressed=0;end; //check that no key is pressed, connect other keys with && here [ && !key(_left) && !... ]

if( key(_right) && xpos<19 && !pressed) //check if xpos is <19 here to prevent it going further than 19
xpos++; // use ++ instead of =xpos+1
//if (xpos>=19) xpos=19; end //****you can get rid of this line using xpos<19 in the if
x = xpos << 4;
//while(key(_right)) frame; end //****you can rid of this line using the pressed variable
pressed=1; //set pressed to true
end;



You could also modify x and y directly:
CODE

if( key(_right) && x < (19<<4) && !pressed )
x += 16; // <<4 == *16
pressed = 1;
end;

...

Level.Tiles[x>>4][y>>4] = block; //this way you could completely get rid of the xpos variables in the makelevel() process
 
thanks for reply and some hints.
i modified level struct like this and now it works
btw : shifting by 4 is still 16 i think ;)

CODE

struct Level
start_position[1];
struct xpos[x_dimension]
struct ypos[y_dimension]
tile;
movable;
breakable;
end
end
end
 
here is some video of editor in action :)

http://tbs-software.com/spookyln/files/editor.avi

i want make adventure game similar Valhalla on amiga.
but i think that Vulcan Software dont give me permission use their tilesets and bobs in game.
i using this tileset in editor for testing only.i dont have my own yet :(
i|ll try contact Vulcan software but my english is poor to do this :(

btw: editor runs on 40fps without any probs. video is grabbed using xvidcap on 10fps and converted in avidemux.
 
Ah right :p <<4 = *2*2*2*2 = *16 I wasn`t really thinking, just typing.
I`ll edit that.

Video looks great, as does the graphics, this looks like its going to be fun.
Good luck on finishing :)
 
Back
Top