im confused on what to do for shooting? i think i might know what to do, but someone has to tell me if im on the right path. no im not asking for prebuilt code this time, just need to know.
I want to set up key X to shoot. I already put that part in. I also put in the sprite for the bullet. should I put just one or three (three at a time on screen) PlayerBullet(); ? Now what I got confused on the #1 thing (ill definitely need help with) is this: how can I spawn an object from the current coordinates from the Player (you know what I mean, like megaman firing his gun) and send that object in that direction (I know it could be done with game maker)(so standing right the object flys right, standing left it flys left). And finally how would I destroy that object when it runs into the blue, an enemy (in that case the enemy and the bullet would disappear), or goes off screen? Thanks
[code language="fenix"]
Program platform_engine;
//these are global variables
Global
//initializes the player's sprites
int Player_graph[14];
//initializes the enemy(s) sprites
//letter of alphabet sorts out the enemies
int enemy_x_graph[12];
//initializes the collectibles sprites
int pellet_graph[1];
//initializes the levels images
int level_graph[2];
//initializes the levelmask
int levelmask;
//this sets up things like the games resolution and whatnot
Begin
Set_mode(320,240,16);
Set_fps(20,0);
Map_clear(0,0,RGB(0,0,0));
Write (0, 64, 16, 1, "Platform Game");
//Starts the scroller
scroller();
//starts the levelmask (par on with the scroller, but is the mask for the levels)
level_mask();
//players fpg, and position
Player(50,100);
//enemy(s) fpg, and position
EnemyX(260,100);
//collectibles fpg, and position
pellet(100,200);
pellet(116,200);
pellet(132,200);
pellet(148,200);
Loop
If (key(_esc))
Exit("Bye",0);
End
Frame;
End
End
//This process is for all the levels, menu's, and cutscenes
Process scroller()
Begin
level_graph[0]=load_png(".\sprites\level\image\testlevel.png");
level_graph[1]=load_png(".\sprites\player\Walk1.png");
start_scroll(0,0,level_graph,0,0,0);//starts the scroll, variables:
/*
0: number of scroll, 0-9 are possible, this is the first one, so 0 :)
0: fpg library you use, i only laoded 1 fpg, so it's 0 (the first library) in this case :)
level: 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 regiona number other than 0 or it won't work ;)
0: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...
*/
//sets the levels background images
End
Process level_mask();
Begin
levelmask=load_png(".\sprites\level\mask\testlevelmask.png");
End
//This process is for the player, all code that belongs to him is in this part
Process Player(x,y)
Private
xspeed=3;
yspeed=0;
y_start_acceleration=4;
y_acceleration=0;
int fall;
int falling; //indicate if character is in falling mode or not
jump=0;
int i;
int ii; //you must say: counter to test every pixel of movement of hardness map
int pixel;
int red,blue,green;
int player_status; //0 is standing, 1 is walking, 2 is jumping, 3 is falling
Begin
//PlayerWalk Animations; it a good idea to repeat the same sprite 3 times so it doesn't
//look sped up unless you have many detailed frames, you can add as many as you want, just
//be sure to change int Player_graph[X] to the number of sprites you have (0 included, so
//its one number higher than the last Player_graph[X] you have
Player_graph[0]=load_png(".\sprites\player\Walk1.png");
Player_graph[1]=load_png(".\sprites\player\Walk1.png");
Player_graph[2]=load_png(".\sprites\player\Walk1.png");
Player_graph[3]=load_png(".\sprites\player\Walk2.png");
Player_graph[4]=load_png(".\sprites\player\Walk2.png");
Player_graph[5]=load_png(".\sprites\player\Walk2.png");
Player_graph[6]=load_png(".\sprites\player\Walk3.png");
Player_graph[7]=load_png(".\sprites\player\Walk3.png");
Player_graph[8]=load_png(".\sprites\player\Walk3.png");
Player_graph[9]=load_png(".\sprites\player\Walk2.png");
Player_graph[10]=load_png(".\sprites\player\Walk2.png");
Player_graph[11]=load_png(".\sprites\player\Walk2.png");
Player_graph[12]=load_png(".\sprites\player\Stand.png");
Player_graph[13]=load_png(".\sprites\player\Jump.png");
ctype=c_scroll;
Loop
//Player Movement
if (key (_left))
flags = 1;
ii = 0;
while (ii <4)
pixel = map_get_pixel(0, levelmask, x-16, y);
get_rgb (pixel, & red, & green, & blue);
if (blue<200)
ii = 0;
break;
else
if (player_status!=2 and player_status!=3) player_status=1; end
end
ii = ii + 1;
end
x = x-ii;
end
if (key (_right))
flags = 0;
ii = 0;
while (ii <4)
pixel = map_get_pixel(0, levelmask, x + 16, y);
get_rgb (pixel, & red, & green, & blue);
if (blue<200)
ii = 0;
break;
else
if (player_status!=2 and player_status!=3) player_status=1; end
end
ii = ii + 1;
end
x = x + ii;
end
if (!key(_left) and !key(_right) and player_status==1)
player_status=0;
end
// Jumping
if (key (_space))
player_status=2;
falling=true;
pixel = map_get_pixel(0, levelmask, x, y +1 +15);
get_rgb (pixel, & red, & green, & blue);
if (blue<200)
fall =- 20;
end
end
// Implementation of fall.
ii = fall;
if(ii > 0)
while(ii != 0)
pixel=map_get_pixel(0, levelmask, x, y + (fall-ii) +15);
get_rgb (pixel, & red, & green, & blue);
if (blue<201)
ii = ii + 1;
falling=false;
break;
end
ii = ii - 1;
end
else
ii = 0;
end
// Move the fall until we can.
y = y + (fall-ii);
//Ending of jumping and falling status
if (player_status==2 and !key(_space)) player_status=3; end
if (player_status==3 and !falling) player_status=0; end
// Acceleration of gravity
if (ii == 0)
fall = fall + 3;
falling=true;
else
fall = 0;
end
//Player Status
//say(player_status);
switch (player_status)
case 0: graph=Player_graph[12]; end
case 1:
graph=Player_graph;
i=(i+1)%12;
end
case 2: graph=Player_graph[13]; end
case 3: graph=Player_graph[13]; end
end
//say("frame");
Frame;
end
end
Process EnemyX (x,y)
private
int i;
int ii;
int Xini;
int fall;
int falling;
int pixel;
int red,blue,green;
int inactive;
begin
//animations for the enemy
enemy_x_graph[0]=load_png(".\sprites\enemies\x\x1.png");
enemy_x_graph[1]=load_png(".\sprites\enemies\x\x1.png");
enemy_x_graph[2]=load_png(".\sprites\enemies\x\x1.png");
enemy_x_graph[3]=load_png(".\sprites\enemies\x\x2.png");
enemy_x_graph[4]=load_png(".\sprites\enemies\x\x2.png");
enemy_x_graph[5]=load_png(".\sprites\enemies\x\x2.png");
enemy_x_graph[6]=load_png(".\sprites\enemies\x\x3.png");
enemy_x_graph[7]=load_png(".\sprites\enemies\x\x3.png");
enemy_x_graph[8]=load_png(".\sprites\enemies\x\x3.png");
enemy_x_graph[9]=load_png(".\sprites\enemies\x\x2.png");
enemy_x_graph[10]=load_png(".\sprites\enemies\x\x2.png");
enemy_x_graph[11]=load_png(".\sprites\enemies\x\x2.png");
Xini = x;
ctype = c_scroll;
loop
if(flags == 0)
ii = 0;
while (ii <3)
pixel = map_get_pixel(0, levelmask, x + 16, y);
get_rgb (pixel, & red, & green, & blue);
if (blue<201)
ii = 0;
flags = 1;
break;
end
ii = ii + 1;
end
x = x + ii;
else
if(flags == 1)
ii = 0;
while (ii <3)
pixel = map_get_pixel(0, levelmask, x-16, y);
get_rgb (pixel, & red, & green, & blue);
if (blue<201)
ii = 0;
flags = 0;
break;
end
ii = ii + 1;
end
x = x-ii;
end
end
i = i +1;
graph = enemy_x_graph [i%12];
falling=true;
if (inactive==0)
falling=true;
end
// Implementation of fall.
ii = fall;
if(ii > 0)
while(ii != 0)
pixel=map_get_pixel(0, levelmask, x, y + (fall-ii) +15);
get_rgb (pixel, & red, & green, & blue);
if (blue<201)
ii = ii + 1;
falling=false;
break;
end
ii = ii - 1;
end
else
ii = 0;
end
// Move the fall until we can.
y = y + (fall-ii);
// Acceleration of gravity
if (ii == 0)
fall = fall + 3;
falling=true;
else
fall = 0;
end
frame;
end
end
process pellet(x,y)
begin
//loads the fpg
graph=load_png(".\sprites\collectibles\pellet.png");
ctype=c_scroll;
loop
if(collision(type player))
break;
end
frame;
end
end [/code]
First, to get three bullets firing, you just call playerbullet() 3 times from your player process when the x key is pressed. You can use timers or the frame statement with a time duration like frame(1000) to adjust the time between the shots.
To spawn objects you can make use of some of the local variables from the player's process. To check whether the player is facing left of right you can acess the "flags" value.
To destroy objects, you can use signals when the collision occures, fist you'll let the bullet process kill the enemy instance it collides with (the collision function returns the identification code of the process that the caller process (the bullet process) collided with. You can now use that information as input for the kill signal.
Second, to make the bullet disappear, you'll put in some break statement in the bullet proces.
This is a conceptual example of how it could be done
PROCESS bullet(x,y,etc, etc);
PRIVATE
enemy_id;
etc
etc
etc
BEGIN
LOOP
IF (enemy_id=collision(TYPE enemy))
signal(enemy_id,s_kill);
BREAK; // ends the loop, thus killing the bullet instance itself
END
FRAME;
END
END
Obviously there's a bit more to it to do this nicely, but this is rougly the basic mechanism.
You have to be aware that when a kill signal is used, the program may crash when other processes attempt to acess this
particulair instaces of the enemy process. To prevent this from happening, you can use the exists() function to check if a
process instance (id code!) is still alive or not.
so I have incorporated what you told me with no errors now I am at stage 2.
can I have a line of code that send the object flinging in that direction until it is deleted?
another one for its creation would be nice to. pressing x makes my character face left.
and can you explain the 3 at a time thing? i was confused a little bit
[code language="fenix"]
Program platform_engine;
//these are global variables
Global
//initializes the player's sprites
int Player_graph[14];
//initializes the enemy(s) sprites
//letter of alphabet sorts out the enemies
int enemy_x_graph[12];
//initializes the collectibles sprites
int pellet_graph[1];
//initializes the levels images
int level_graph[2];
//initializes the levelmask
int levelmask;
//this sets up things like the games resolution and whatnot
Begin
Set_mode(320,240,16);
Set_fps(20,0);
Map_clear(0,0,RGB(0,0,0));
Write (0, 64, 16, 1, "Platform Game");
//Starts the scroller
scroller();
//starts the levelmask (par on with the scroller, but is the mask for the levels)
level_mask();
//players fpg, and position
Player(50,100);
//enemy(s) fpg, and position
EnemyX(260,100);
//collectibles fpg, and position
pellet(100,200);
pellet(116,200);
pellet(132,200);
pellet(148,200);
Loop
If (key(_esc))
Exit("Bye",0);
End
Frame;
End
End
//This process is for all the levels, menu's, and cutscenes
Process scroller()
Begin
level_graph[0]=load_png(".\sprites\level\image\testlevel.png");
level_graph[1]=load_png(".\sprites\player\Walk1.png");
start_scroll(0,0,level_graph,0,0,0);//starts the scroll, variables:
/*
0: number of scroll, 0-9 are possible, this is the first one, so 0 :)
0: fpg library you use, i only laoded 1 fpg, so it's 0 (the first library) in this case :)
level: 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 regiona number other than 0 or it won't work ;)
0: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...
*/
//sets the levels background images
End
Process level_mask();
Begin
levelmask=load_png(".\sprites\level\mask\testlevelmask.png");
End
//This process is for the player, all code that belongs to him is in this part
Process Player(x,y)
Private
xspeed=3;
yspeed=0;
y_start_acceleration=4;
y_acceleration=0;
int fall;
int falling; //indicate if character is in falling mode or not
jump=0;
int i;
int ii; //you must say: counter to test every pixel of movement of hardness map
int pixel;
int red,blue,green;
int player_status; //0 is standing, 1 is walking, 2 is jumping, 3 is falling
Begin
//PlayerWalk Animations; it a good idea to repeat the same sprite 3 times so it doesn't
//look sped up unless you have many detailed frames, you can add as many as you want, just
//be sure to change int Player_graph[X] to the number of sprites you have (0 included, so
//its one number higher than the last Player_graph[X] you have
Player_graph[0]=load_png(".\sprites\player\Walk1.png");
Player_graph[1]=load_png(".\sprites\player\Walk1.png");
Player_graph[2]=load_png(".\sprites\player\Walk1.png");
Player_graph[3]=load_png(".\sprites\player\Walk2.png");
Player_graph[4]=load_png(".\sprites\player\Walk2.png");
Player_graph[5]=load_png(".\sprites\player\Walk2.png");
Player_graph[6]=load_png(".\sprites\player\Walk3.png");
Player_graph[7]=load_png(".\sprites\player\Walk3.png");
Player_graph[8]=load_png(".\sprites\player\Walk3.png");
Player_graph[9]=load_png(".\sprites\player\Walk2.png");
Player_graph[10]=load_png(".\sprites\player\Walk2.png");
Player_graph[11]=load_png(".\sprites\player\Walk2.png");
Player_graph[12]=load_png(".\sprites\player\Stand.png");
Player_graph[13]=load_png(".\sprites\player\Jump.png");
ctype=c_scroll;
Loop
//Player Movement
if (key (_left))
flags = 1;
ii = 0;
while (ii <4)
pixel = map_get_pixel(0, levelmask, x-16, y);
get_rgb (pixel, & red, & green, & blue);
if (blue<200)
ii = 0;
break;
else
if (player_status!=2 and player_status!=3) player_status=1; end
end
ii = ii + 1;
end
x = x-ii;
end
if (key (_right))
flags = 0;
ii = 0;
while (ii <4)
pixel = map_get_pixel(0, levelmask, x + 16, y);
get_rgb (pixel, & red, & green, & blue);
if (blue<200)
ii = 0;
break;
else
if (player_status!=2 and player_status!=3) player_status=1; end
end
ii = ii + 1;
end
x = x + ii;
end
if (!key(_left) and !key(_right) and player_status==1)
player_status=0;
end
//Shooting
if (key (_X))
if flags = 0;
end
if flags = 1;
end
end
// Jumping
if (key (_space))
player_status=2;
falling=true;
pixel = map_get_pixel(0, levelmask, x, y +1 +15);
get_rgb (pixel, & red, & green, & blue);
if (blue<200)
fall =- 20;
end
end
// Implementation of fall.
ii = fall;
if(ii > 0)
while(ii != 0)
pixel=map_get_pixel(0, levelmask, x, y + (fall-ii) +15);
get_rgb (pixel, & red, & green, & blue);
if (blue<201)
ii = ii + 1;
falling=false;
break;
end
ii = ii - 1;
end
else
ii = 0;
end
// Move the fall until we can.
y = y + (fall-ii);
//Ending of jumping and falling status
if (player_status==2 and !key(_space)) player_status=3; end
if (player_status==3 and !falling) player_status=0; end
// Acceleration of gravity
if (ii == 0)
fall = fall + 3;
falling=true;
else
fall = 0;
end
//Player Status
//say(player_status);
switch (player_status)
case 0: graph=Player_graph[12]; end
case 1:
graph=Player_graph;
i=(i+1)%12;
end
case 2: graph=Player_graph[13]; end
case 3: graph=Player_graph[13]; end
end
//say("frame");
Frame;
end
end
PROCESS playerbullet(x,y,etc, etc);
PRIVATE
enemy_id;
BEGIN
LOOP
IF (enemy_id=collision(TYPE EnemyX))
signal(enemy_id,s_kill);
BREAK; // ends the loop, thus killing the bullet instance itself
END
FRAME;
END
END
Process EnemyX (x,y)
private
int i;
int ii;
int Xini;
int fall;
int falling;
int pixel;
int red,blue,green;
int inactive;
begin
//animations for the enemy
enemy_x_graph[0]=load_png(".\sprites\enemies\x\x1.png");
enemy_x_graph[1]=load_png(".\sprites\enemies\x\x1.png");
enemy_x_graph[2]=load_png(".\sprites\enemies\x\x1.png");
enemy_x_graph[3]=load_png(".\sprites\enemies\x\x2.png");
enemy_x_graph[4]=load_png(".\sprites\enemies\x\x2.png");
enemy_x_graph[5]=load_png(".\sprites\enemies\x\x2.png");
enemy_x_graph[6]=load_png(".\sprites\enemies\x\x3.png");
enemy_x_graph[7]=load_png(".\sprites\enemies\x\x3.png");
enemy_x_graph[8]=load_png(".\sprites\enemies\x\x3.png");
enemy_x_graph[9]=load_png(".\sprites\enemies\x\x2.png");
enemy_x_graph[10]=load_png(".\sprites\enemies\x\x2.png");
enemy_x_graph[11]=load_png(".\sprites\enemies\x\x2.png");
Xini = x;
ctype = c_scroll;
loop
if(flags == 0)
ii = 0;
while (ii <3)
pixel = map_get_pixel(0, levelmask, x + 16, y);
get_rgb (pixel, & red, & green, & blue);
if (blue<201)
ii = 0;
flags = 1;
break;
end
ii = ii + 1;
end
x = x + ii;
else
if(flags == 1)
ii = 0;
while (ii <3)
pixel = map_get_pixel(0, levelmask, x-16, y);
get_rgb (pixel, & red, & green, & blue);
if (blue<201)
ii = 0;
flags = 0;
break;
end
ii = ii + 1;
end
x = x-ii;
end
end
i = i +1;
graph = enemy_x_graph [i%12];
falling=true;
if (inactive==0)
falling=true;
end
// Implementation of fall.
ii = fall;
if(ii > 0)
while(ii != 0)
pixel=map_get_pixel(0, levelmask, x, y + (fall-ii) +15);
get_rgb (pixel, & red, & green, & blue);
if (blue<201)
ii = ii + 1;
falling=false;
break;
end
ii = ii - 1;
end
else
ii = 0;
end
// Move the fall until we can.
y = y + (fall-ii);
// Acceleration of gravity
if (ii == 0)
fall = fall + 3;
falling=true;
else
fall = 0;
end
frame;
end
end
process pellet(x,y)
begin
//loads the fpg
graph=load_png(".\sprites\collectibles\pellet.png");
ctype=c_scroll;
loop
if(collision(type player))
break;
end
frame;
end
end [/code]
A little bit offtopic, but why do you have -5 karma? ???
cause im so sexy i have my own karma
Amazing -7, you are in the hall of fame xDDDDD
can I have a line of code that send the object flinging in that direction until it is deleted? Do you mean a ricochet bullet when megaman fires a bullet and it ricochets when the bullet hit's the enemy? That's not so hard, when the collision occurs, have the bullet process check for a collision with an enemy type and at that point, animate it.
The third stage, do you refer to the use of signals? In that case, there should some examples of that in bennupack. Sooner or later you may stumble on it. When bennu crashes with a message that some instance (id-code) does not exist, you know you have something in your code trying to acces data from a process instance that has been killed, or wich code statements have been ended.
This code will end instantly:
PROCESS test();
BEGIN
END
It's instance will only exist for a wink of the eye. But this process will exist forever except when a kill signal is send to it.
PROCESS test();
BEGIN
LOOP
FRAME; // don't forget the frame statement, or the program execution will freeze.
END
END
Bottom line, a process will need to have a internal loop in a lot of cases. As long as the statements within that loop are
executed, the process manager will treat the instance as a living/frozen or sleeping process (depending wheter a non distructive
signal was send to it), so other processes can detect it with a collision or an identfication code.
that literally made no sense as to what i needed. i posted the code with the stuff in there. I just need to know how to make the bullets move now and when i pres x the character faces left.
Hellooooooo? anyone there? I swear the english part of this forum is practically dead.
They on vacations dude :)
I take a look in a couple of days if nobody come here before xD
can be a health var....
IF (enemy_id=collision(TYPE EnemyX))
enemy_id.health -= 10;
BREAK; // ends the loop, thus killing the bullet instance itself
END
Also, enemy_id.health must be a local or public variable, otherwise it's treated as a private, so you won't be able to acess it from outside the enemy process itself. Declaring it as a local is the easiest way, when declared as a public var it's a little more tricky and requires the process to be decared. Please read this for more info: http://wiki.bennugd.org/index.php?title=Public_variable (http://wiki.bennugd.org/index.php?title=Public_variable).
i know alot of this but none of you are explaining why the character turns left when i shoot. seriously, download the .zip file.
what this !??
//Shooting
if (key (_X))
if flags = 0;
end
if flags = 1;
end
end
this sentence compile and works ?!
another thing, don't do this:
Player_graph[6]=load_png(".\sprites\player\Walk3.png");
Player_graph[7]=load_png(".\sprites\player\Walk3.png");
you are repeting inecessary loads, use a fpg for the animations and asign the graph id at player_graph, or load the png's at the main program and asign an id for each one.
i just went over converting everything to .fpg last month, it completely screwed over my game. so to me its fine.
and yes that compiles. but please, how can i fix that?
but this sentence is invalid, you don't have nothing when you press x key, the code is complete ?
I need to execute them, when i finish my windows update, i take a look (tomorrow)...
The problem why your character faces left when you press X is easy:
//Shooting
if (key (_X))
if flags = 0;
end
if flags = 1;
end
end
you must use == instead of = to compare. "=" operator is used to assign so your code is actually making "flags" to be 1.
Regards
ok that helps. now onto part where i make the bullets move (should be that hard now that i figured out, but why ==?)
you can assign a value to a var in an if instructions, it's valid... but I don't know if you want do it in this case.
for compare you must use ==
ok. now if i have a definite thing like say act01 modifies the game the rest of the story, act01 was say a nuclear bomb and it made everything fallout. so the same levels are in fallout now. would i use = or == in this case?
Hint: = and == work like they do in C.
To be honest I don't follow you.
I don't know if you got the meaning of == and =. Here is an explanation.
== and = are different things. "==" is a comparison operator and "=" is an assignment operator. The reason why "if (flags=1)" compiles is because any expression can be evaluated as a boolean expression so you are actually doing: "flags = 1; if (flags) ...". Numbers are evaluated as false if they are 0 and true otherwise.
In any case I think what you want is some code, check the following:
const
BULLET_SPEED = 2;
end
...
process player (...)
private
int dir = 1; // -1 when the player faces left, 1 when it faces right
...
begin
...
loop
if (key(_left))
flags = 1;
dir = -1;
end
if (key(_right))
flags = 0;
dir = 1;
end
// fire
if (key(_x))
bullet(x, y, dir)
end if
....
frame;
end
end
process bullet(x, y, dir)
....
begin
graph = whatever;
loop
x = x + BULLET_SPEED * dir;
if (collision(TYPE enemy))
// do whatever you are supposed to do when you hit an enemy
break;
end
if (region_out(id, 0)) // the bullet when out of the screen
break;
end
frame;
end
....
end
If that's not enought, try to be more clear.
ok it works except for the region out. and when i hold down x its like a long erected *censored* coming out of his face XD. so like in gamemaker, theres a key (like if its being held down) and a keypress (where once its pressed, not being held down), is there something along the lines of a keypress?
look at the code in this page:
http://forum.bennugd.org/index.php?topic=1485.15
yeah that really didn't make any sense. remember as of right now im using the latest fenix because of the dreamcast.
Quote from: DoctorN on May 02, 2011, 04:46:51 AM
ok it works except for the region out. and when i hold down x its like a long erected *censored* coming out of his face XD. so like in gamemaker, theres a key (like if its being held down) and a keypress (where once its pressed, not being held down), is there something along the lines of a keypress?
no, you need to create the code yourself.
PROCESS whatever();
PRIVATE
key_x_is_already_pressed = false;
BEGIN
LOOP
IF(key(_x))
IF(!key_x_is_already_pressed)
// put the code here that you want to be executed each time x is pressed
END
key_x_is_already_pressed = true;
ELSE
key_x_is_already_pressed = false;
END
FRAME;
END
END
that code didn't even help at all. all it did was make the bullet slower.
[code language="fenix"]
Program platform_engine;
//these are global variables
Global
//initializes the player's sprites
int Player_graph[14];
//initializes the enemy(s) sprites
//letter of alphabet sorts out the enemies
int enemy_x_graph[12];
//initializes the collectibles sprites
int pellet_graph[1];
//initializes the levels images
int level_graph[2];
//initializes the levelmask
int levelmask;
//this sets up things like the games resolution and whatnot
Begin
Set_mode(320,240,16);
Set_fps(20,0);
Map_clear(0,0,RGB(0,0,0));
Write (0, 64, 16, 1, "Platform Game");
//Starts the scroller
scroller();
//starts the levelmask (par on with the scroller, but is the mask for the levels)
level_mask();
//players fpg, and position
Player(50,100);
//enemy(s) fpg, and position
EnemyX(260,100);
//collectibles fpg, and position
pellet(100,200);
pellet(116,200);
pellet(132,200);
pellet(148,200);
Loop
If (key(_esc))
Exit("Bye",0);
End
Frame;
End
End
//This process is for all the levels, menu's, and cutscenes
Process scroller()
Begin
level_graph[0]=load_png(".\sprites\level\image\testlevel.png");
start_scroll(0,0,level_graph,0,0,0);//starts the scroll, variables:
/*
0: number of scroll, 0-9 are possible, this is the first one, so 0 :)
0: fpg library you use, i only laoded 1 fpg, so it's 0 (the first library) in this case :)
level: 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 regiona number other than 0 or it won't work ;)
0: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...
*/
//sets the levels background images
End
Process level_mask();
Begin
levelmask=load_png(".\sprites\level\mask\testlevelmask.png");
End
//This process is for the player, all code that belongs to him is in this part
Process Player(x,y)
Private
xspeed=3;
yspeed=0;
y_start_acceleration=4;
y_acceleration=0;
int fall;
int falling; //indicate if character is in falling mode or not
jump=0;
int i;
int ii; //you must say: counter to test every pixel of movement of hardness map
int pixel;
int red,blue,green;
int player_status; //0 is standing, 1 is walking, 2 is jumping, 3 is falling
int dir = 1; // -1 when the player faces left, 1 when it faces right
Begin
//PlayerWalk Animations; it a good idea to repeat the same sprite 3 times so it doesn't
//look sped up unless you have many detailed frames, you can add as many as you want, just
//be sure to change int Player_graph[X] to the number of sprites you have (0 included, so
//its one number higher than the last Player_graph[X] you have
Player_graph[0]=load_png(".\sprites\player\Walk1.png");
Player_graph[1]=load_png(".\sprites\player\Walk1.png");
Player_graph[2]=load_png(".\sprites\player\Walk1.png");
Player_graph[3]=load_png(".\sprites\player\Walk2.png");
Player_graph[4]=load_png(".\sprites\player\Walk2.png");
Player_graph[5]=load_png(".\sprites\player\Walk2.png");
Player_graph[6]=load_png(".\sprites\player\Walk3.png");
Player_graph[7]=load_png(".\sprites\player\Walk3.png");
Player_graph[8]=load_png(".\sprites\player\Walk3.png");
Player_graph[9]=load_png(".\sprites\player\Walk2.png");
Player_graph[10]=load_png(".\sprites\player\Walk2.png");
Player_graph[11]=load_png(".\sprites\player\Walk2.png");
Player_graph[12]=load_png(".\sprites\player\Stand.png");
Player_graph[13]=load_png(".\sprites\player\Jump.png");
ctype=c_scroll;
Loop
//Player Movement
if (key (_left))
flags = 1;
dir = -1;
ii = 0;
while (ii <4)
pixel = map_get_pixel(0, levelmask, x-16, y);
get_rgb (pixel, & red, & green, & blue);
if (blue<200)
ii = 0;
break;
else
if (player_status!=2 and player_status!=3) player_status=1; end
end
ii = ii + 1;
end
x = x-ii;
end
if (key (_right))
flags = 0;
dir = 1;
ii = 0;
while (ii <4)
pixel = map_get_pixel(0, levelmask, x + 16, y);
get_rgb (pixel, & red, & green, & blue);
if (blue<200)
ii = 0;
break;
else
if (player_status!=2 and player_status!=3) player_status=1; end
end
ii = ii + 1;
end
x = x + ii;
end
if (!key(_left) and !key(_right) and player_status==1)
player_status=0;
end
//Shooting
if (key (_X))
if flags == 0;
playerbullet(x, y, dir);
end
if flags == 1;
playerbullet(x, y, dir);
end
end
// Jumping
if (key (_space))
player_status=2;
falling=true;
pixel = map_get_pixel(0, levelmask, x, y +1 +15);
get_rgb (pixel, & red, & green, & blue);
if (blue<200)
fall =- 20;
end
end
// Implementation of fall.
ii = fall;
if(ii > 0)
while(ii != 0)
pixel=map_get_pixel(0, levelmask, x, y + (fall-ii) +15);
get_rgb (pixel, & red, & green, & blue);
if (blue<201)
ii = ii + 1;
falling=false;
break;
end
ii = ii - 1;
end
else
ii = 0;
end
// Move the fall until we can.
y = y + (fall-ii);
//Ending of jumping and falling status
if (player_status==2 and !key(_space)) player_status=3; end
if (player_status==3 and !falling) player_status=0; end
// Acceleration of gravity
if (ii == 0)
fall = fall + 3;
falling=true;
else
fall = 0;
end
//Player Status
//say(player_status);
switch (player_status)
case 0: graph=Player_graph[12]; end
case 1:
graph=Player_graph;
i=(i+1)%12;
end
case 2: graph=Player_graph[13]; end
case 3: graph=Player_graph[13]; end
end
//say("frame");
Frame;
end
end
PROCESS playerbullet(x, y, dir);
private
BULLET_SPEED = 8;
int pixel;
int red,blue,green;
end
begin
graph = load_png(".\sprites\player\bullet.png");
loop
x = x + BULLET_SPEED * dir;
if (collision(TYPE EnemyX))
// do whatever you are supposed to do when you hit an enemy
break;
end
frame;
end
end
Process EnemyX (x,y)
private
int i;
int ii;
int Xini;
int fall;
int falling;
int pixel;
int red,blue,green;
int inactive;
begin
//animations for the enemy
enemy_x_graph[0]=load_png(".\sprites\enemies\x\x1.png");
enemy_x_graph[1]=load_png(".\sprites\enemies\x\x1.png");
enemy_x_graph[2]=load_png(".\sprites\enemies\x\x1.png");
enemy_x_graph[3]=load_png(".\sprites\enemies\x\x2.png");
enemy_x_graph[4]=load_png(".\sprites\enemies\x\x2.png");
enemy_x_graph[5]=load_png(".\sprites\enemies\x\x2.png");
enemy_x_graph[6]=load_png(".\sprites\enemies\x\x3.png");
enemy_x_graph[7]=load_png(".\sprites\enemies\x\x3.png");
enemy_x_graph[8]=load_png(".\sprites\enemies\x\x3.png");
enemy_x_graph[9]=load_png(".\sprites\enemies\x\x2.png");
enemy_x_graph[10]=load_png(".\sprites\enemies\x\x2.png");
enemy_x_graph[11]=load_png(".\sprites\enemies\x\x2.png");
Xini = x;
ctype = c_scroll;
loop
if(flags == 0)
ii = 0;
while (ii <3)
pixel = map_get_pixel(0, levelmask, x + 16, y);
get_rgb (pixel, & red, & green, & blue);
if (blue<201)
ii = 0;
flags = 1;
break;
end
ii = ii + 1;
end
x = x + ii;
else
if(flags == 1)
ii = 0;
while (ii <3)
pixel = map_get_pixel(0, levelmask, x-16, y);
get_rgb (pixel, & red, & green, & blue);
if (blue<201)
ii = 0;
flags = 0;
break;
end
ii = ii + 1;
end
x = x-ii;
end
end
i = i +1;
graph = enemy_x_graph [i%12];
falling=true;
if (inactive==0)
falling=true;
end
// Implementation of fall.
ii = fall;
if(ii > 0)
while(ii != 0)
pixel=map_get_pixel(0, levelmask, x, y + (fall-ii) +15);
get_rgb (pixel, & red, & green, & blue);
if (blue<201)
ii = ii + 1;
falling=false;
break;
end
ii = ii - 1;
end
else
ii = 0;
end
// Move the fall until we can.
y = y + (fall-ii);
// Acceleration of gravity
if (ii == 0)
fall = fall + 3;
falling=true;
else
fall = 0;
end
frame;
end
end
process pellet(x,y)
begin
//loads the fpg
graph=load_png(".\sprites\collectibles\pellet.png");
ctype=c_scroll;
loop
if(collision(type player))
break;
end
frame;
end
end [/code]
ok, let me be more explicit:
PROCESS Player(x,y);
PRIVATE
key_x_is_already_pressed = false;
BEGIN
LOOP
//Shooting
IF(key(_x))
IF(!key_x_is_already_pressed)
if flags == 0;
playerbullet(x, y, dir);
end
if flags == 1;
playerbullet(x, y, dir);
end
END
key_x_is_already_pressed = true;
ELSE
key_x_is_already_pressed = false;
END
FRAME;
END
END
you know, if you were a little more gracious to the people who have been trying to help you with your code, instead of complaining when you don't understand what they have been saying, they might be more inclined to continue helping you. if a piece of code, or a suggestion is given to you, and it doesn't seem to be working, start by saying something like, "i can't seem to get it to work," or "i must be doing something wrong" instead of "that didn't make any sense," or "that didn't work." a little humility goes a long way.
oh sorry about that, i dont have any manners :( thanks for helping me though. i just have really bad days lately so i can't think when i come on to tweak my game so sorry about that. but it works :D. on the sidenote I am talking to the russian programmer who ported over the latest version of fenix to the dreamcast and even created an operating system (dreamshell) to use on the dreamcast with those new fangled sd-card adapters is working on bennu at the moment. should I bring him over here?
it's ok. just remember that when other people are helping you, they're trying to do you a favor. :)