Replacing One Object With Another


Atari

Still Fresh
Joined
Aug 9, 2005
Messages
30
What would be the best way to replace one object with another, and have the new object with it's own collision properties? For instance, in my game, the enemy will drop a bomb. If the player doesn't destroy the bomb, it'll hit the ground and leave a crater. The way I want to achieve this is to show an explosion animation, then replace the bomb with another object. If the player runs into this new object, he won't be able to move past it (a la Balloon Bomber, an old arcade game). Here's what I tried to do:

Code:
process enemyfire(x,y);
begin
graph=3;
loop
y=y+20;
  if (y=>420)
  	crater(x,y);
  	enfireflag=0;
  	frame;
  end
  if (collision (type ship))
  	signal(type ship, s_kill);
  	return;
  end
	frame;
	end
end

process crater(x,y);
private
i;
begin
signal(type enemyfire, s_freeze);
for(i=4;i<9;i=i+1);
    	graph=i;
      frame;
     end
  signal(type enemyfire, s_kill);   
  graph=8;
  frame;
	return;
end

This obviously doesn't work due to the fact that I killed the enemyfire process. I tried a number of other ideas and can get the crater to stay on the screen, but there is no collision detection associated with it. Does this all make sense?

Any suggestions? I appreciate any and all help, and sorry for being such a newbie :)
 
sam fisher posted on Aug 9 2005 at 03:40 PM said:
just make it so player cant move if colliding with it. I explain later but im sure quiest will come along with some brilliant code for it :p

I added:

Code:
process crater(x,y);
private
i;
begin
signal(type enemyfire, s_freeze);
for(i=4;i<9;i=i+1);
    	graph=i;
      frame;
     end
  graph=8;
  	if (collision(type ship))
    	signal(type ship,s_kill);
    	frame;
    	return;
    end	
  frame;
	return;
end

but the collision still isn't detected.
 
Last edited by a moderator:
That`s no easy problem, atleast for me...

You can try to add this to you player/ship process:

Code:
if(key(_left) and not collision(type crater))x-=5;end;

Or whatever you do for making the player move left.
Do the same for moving other directions.

The player should only walk if it`s not touching a crater...
don`t know if it will work...

Otherwise you have to work with the map_get_pixel command, but I have no idea how it works...


EDIT:
As long as it leaves a crater on screen, it has nothing to do with killing the enemyfire process... you have to add the right collision code to your player and not to the crater...

EDIT2:
I would know a much more "hardcore" solution, but that would only work right if you just moving the ship left and right, and it`s kinda hard to explain
You best pm me, if you can come up with no other solution, as my idea needs some working out...

EDIT3: Hmm another method maybe if the one on top does not work:

Code:
move=5:
lastkey=0; //1=left 2=right
...
if(key(_left)) x-=move; lastkey=1; end;
if(key(_right)) x+=move; lastkey=2; end;
if(collision(type crater))
  if(lastkey==1)x+=move;end;
  if(lastkey==2)x-=move;end;
 end;

All for the player process, of course... It just stores, which direction you were moving last, and if you collide with a crater, you move back into the direction you came from, not being able to get by the crater... again, I don`t know if it will work.
 
Quiest posted on Aug 9 2005 at 03:55 PM said:
That`s no easy problem, atleast for me...

You can try to add this to you player/ship process:

Code:
if(key(_left) and not collision(type crater))x-=5;end;

Or whatever you do for making the player move left.
Do the same for moving other directions.

The player should only walk if it`s not touching a crater...
don`t know if it will work...

Otherwise you have to work with the map_get_pixel command, but I have no idea how it works...


EDIT:
As long as it leaves a crater on screen, it has nothing to do with killing the enemyfire process... you have to add the right collision code to your player and not to the crater...

EDIT2:
I would know a much more "hardcore" solution, but that would only work right if you just moving the ship left and right, and it`s kinda hard to explain
You best pm me, if you can come up with no other solution, as my idea needs some working out...

EDIT3: Hmm another method maybe if the one on top does not work:

Code:
move=5:
lastkey=0; //1=left 2=right
...
if(key(_left)) x-=move; lastkey=1; end;
if(key(_right)) x+=move; lastkey=2; end;
if(collision(type crater))
  if(lastkey==1)x+=move;end;
  if(lastkey==2)x-=move;end;
 end;

All for the player process, of course... It just stores, which direction you were moving last, and if you collide with a crater, you move back into the direction you came from, not being able to get by the crater... again, I don`t know if it will work.


Duh! I was checking the wrong collision type. Someone slap me please.

I'll play around a bit and I'm sure a solution will present itself. Thanks for the heads up. Your last bit of code will definitely be used.
 
Last edited by a moderator:
Quiest posted on Aug 9 2005 at 05:16 PM said:
/me slaps Atari

:D

I used your movement code and it works like a charm. But only during the explosion animation (not your fault). Here's the code in question:

Code:
process crater(x,y);
private
i;
begin
signal(type enemyfire, s_freeze);
for(i=4;i<9;i=i+1);
    	graph=i;
      frame;
     end
  graph=8;
  signal(type enemyfire, s_kill);
  frame;
	return;
end

For some reason, it only works while the explosion animation is in progress. I'm sure I'm doing something wrong, as once the animation finishes, everything disappears. I tried using "graph=8" to put the crater at x,y after the explosion, but the crater doesn't appear.

Any suggestions?

Thanks!
 
Last edited by a moderator:
The process needs to stay, just add a loop; frame; end;
"graph" just tells the process which file he uses from the fpg.Okay here`s an easy version of what you want the crater to do:

Code:
process crater(x,y);
  private
    i=4;
  begin
    loop
      graph=i;     //I recommend you to do the animation like this
      if(i<9)i++;  //i starts at for and increases by one every frame until i=9
  
      frame;
     end; //this is the end of the loop; frame; end; that keeps the process alive
 end;


Also, add a "return;" to the enemy enemyfire process after calling the crater,
you don`t need the signal commands for that:
Code:
  if (y=>420)
  crater(x,y);
  enfireflag=0;
  return;
 end
 
Quiest posted on Aug 10 2005 at 05:05 AM said:
The process needs to stay, just add a loop; frame; end;
"graph" just tells the process which file he uses from the fpg.Okay here`s an easy version of what you want the crater to do:

Code:
process crater(x,y);
  private
    i=4;
  begin
    loop
      graph=i;     //I recommend you to do the animation like this
      if(i<9)i++;  //i starts at for and increases by one every frame until i=9
  
      frame;
     end; //this is the end of the loop; frame; end; that keeps the process alive
 end;


Also, add a "return;" to the enemy enemyfire process after calling the crater,
you don`t need the signal commands for that:
Code:
  if (y=>420)
  crater(x,y);
  enfireflag=0;
  return;
 end

Yes... a loop. Something I always forget that is necessary.

I'll give this a try. Thanks yet again :)
 
Last edited by a moderator:
Atari posted on Aug 10 2005 at 06:41 AM said:
Yes... a loop. Something I always forget that is necessary.

I'll give this a try. Thanks yet again :)

Damn... worked like a charm. Another major hurdle cleared!!

You rock... :)
 
Last edited by a moderator:
Back
Top