I
Ian Kottra
Guest
Hello, I am a novice aspiring game designer currently learning the ins and outs of Game Maker 1.4,
I have decided to start off with a basic 2D platformer along the lines of Super Mario World. One of the things that I'd ultimately like to accomplish is having some kind of universal collision system that allows for level mechanics like the ones in the videos below to be implemented.
(0:56)
(12:11)
Here is the code I am currently using for collision with stationary objects:
if(place_meeting(x+hspd, y, obj_platform) || place_meeting(x+hspd, y, obj_solidHazard)) {
while(!place_meeting(x+sign(hspd), y, obj_platform) &&
place_meeting(x+sign(hspd), y, obj_solidHazard)){
x += sign(hspd);
}
hspd = 0;
}
// Move Player Horizontally: Left or right a certain number of pixels per step.
x += hspd;
//Vertical Collision
if(place_meeting(x, y+vspd, obj_platform) || place_meeting(x, y+vspd, obj_solidHazard)){
while(!place_meeting(x, y+sign(vspd), obj_platform) && !place_meeting(x,
}
vspd = 0;
}
// Move Player Vertically: Up or down a certain number of pixels per step.
y += vspd;
Generally, it works just fine. The while loop keeps the player object from clipping into child objects of obj_platform and obj_solidHazard, assuming that they don't move at all. If an object is moving, then what happens is that either the player object gets stuck in place as the object passes through it, or the game crashes, presumably as a result of an infinite loop. I am satisfied with my basic platforming movement, which is based on hspd increasing and decreasing depending on the arrow keys being pressed and held and vspd increasing and decreasing based on the space key being pressed and held.
If anyone has managed to pull off what I am hoping to, then I would greatly appreciate some tips.
I have decided to start off with a basic 2D platformer along the lines of Super Mario World. One of the things that I'd ultimately like to accomplish is having some kind of universal collision system that allows for level mechanics like the ones in the videos below to be implemented.
Here is the code I am currently using for collision with stationary objects:
if(place_meeting(x+hspd, y, obj_platform) || place_meeting(x+hspd, y, obj_solidHazard)) {
while(!place_meeting(x+sign(hspd), y, obj_platform) &&
place_meeting(x+sign(hspd), y, obj_solidHazard)){
x += sign(hspd);
// While player is not up against wall, move towards wall.
hspd = 0;
}
// Move Player Horizontally: Left or right a certain number of pixels per step.
x += hspd;
//Vertical Collision
if(place_meeting(x, y+vspd, obj_platform) || place_meeting(x, y+vspd, obj_solidHazard)){
while(!place_meeting(x, y+sign(vspd), obj_platform) && !place_meeting(x,
y+sign(vspd), obj_solidHazard)) {
y += sign(vspd);}
vspd = 0;
}
// Move Player Vertically: Up or down a certain number of pixels per step.
y += vspd;
Generally, it works just fine. The while loop keeps the player object from clipping into child objects of obj_platform and obj_solidHazard, assuming that they don't move at all. If an object is moving, then what happens is that either the player object gets stuck in place as the object passes through it, or the game crashes, presumably as a result of an infinite loop. I am satisfied with my basic platforming movement, which is based on hspd increasing and decreasing depending on the arrow keys being pressed and held and vspd increasing and decreasing based on the space key being pressed and held.
If anyone has managed to pull off what I am hoping to, then I would greatly appreciate some tips.