Mac OSX Help in Programming a Platformer Game

J

Justin911

Guest
I'm creating a game based on bullying. It's about a bully (obj_bully) stealing a kid's phone and running away with it. So the victim (obj_player) chases the bully (obj_bully).

While chasing the bully the player sees some power-ups (bicycle, skateboard), so when he comes in contact with those power-ups his speed increases.

As the game goes on a teacher (obj_teacher) would appear, what I want the teacher to do it to chase the player only if he is using a power-up (like normal teachers when using bikes in school).

The teacher should check if the player's speed is more than 5 (5 is the original speed). If the speed is more than 5 (hence he is using a power-up) the teacher should chase him at a speed of 8.

When the teacher starts chasing and catches (collides with obj_player), the game will move to another room (game_over room).


This is the coding I'm trying to do, I've tried all I can and can't get it together. Please could help, it would be greatly appreciated. :)
 

NightFrost

Member
You should specify which part of that you're having trouble with. Also, pathfinding intelligently across platforms is a little complex matter that may not be the best of ideas to tackle at beginner level; you may want to experiment with top-downish view approach first.
 
J

Justin911

Guest
Sorry, the part I'm having trouble with is that the teacher isn't checking if the speed on the player is more than 5 and that the teacher isn't moving.

Thanks for the reply, thought no one would reply :)
 

Mr Errorz

Member
in the teacher obj, you can try something like-

if objPlayer.speed > 5
{
//YOUR TEACHER MOVEMENT CODE
}
 

Mr Errorz

Member
well, that's how you can check for player's speed.
that is of course a "blind" answer, as you might need a different solution depending on your code or how your game is set up.
I'm afraid I can't offer any other suggestion without seeing that code.
 
R

RetroKingofHarts

Guest
what is your speed variable determining your player's speed? If you are simply adding to X based on a button press, that probably won't work so well with what you are trying to do. Like noted above, we'd need to see the snippet of code that is giving you trouble.

What about other aspects of your platformer? Is everything else handling ok? It COULD be possible that this part is not working due to a bug elsewhere somehow? Again though, you're requesting advice from blindfolded assistants. Let's see what it is you're doing.
 
J

Justin911

Guest
Okay, sure.
In the obj_teacher:

Create:
chasingDistance = 128;

speedLimit = 5;

teacherChaseSpeed = 7;

Step:

if (obj_player.speed > 5 && point_distance (x, y, obj_player.x, obj_player.y ) < 128)
{
move_towards_point(obj_player.x, obj_player.y, teacherChaseSpeed);
}


And just in case I'll add the obj_player:

Create:

///Initialize Variables
grav = 0.6;
hsp = 0;
vsp = 0;
jumpspeed = 7;


movespeed_normal = 5;
movespeed_bicycle = 7;
movespeed_crowd = 4;
movespeed_skateboard = 6;


movespeed = movespeed_normal

Step:

//Get the player's input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_space);

//React to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;

if (place_meeting(x,y+1,obj_wall))
{
vsp = key_jump * -jumpspeed
}

//Horizontal Collision
if (place_meeting(x+hsp,y,obj_wall))
{
while(!place_meeting(x+sign(hsp),y,obj_wall))
{
x += sign(hsp);
}
hsp = 0;
}
x += hsp;

//Vertical Collision
if (place_meeting(x,y+vsp,obj_wall))
{
while(!place_meeting(x,y+sign(vsp),obj_wall))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;




Again, thanks a lot for your help, :).

 

NightFrost

Member
You should be checking against player's movespeed, not speed, since that's the variable you've made to control the current movement speed.
 
Top