M
manouijpelaar
Guest
I am working on a assignment for school to make a game and I putted some code in different events, but when I run the game my player doesn't have his 'feet' on the ground
I have used the code in these videos:
in the create event I have this:
hspeed_ = 0;
max_hspeed_ = 4;
vspeed_ = 0;
gravity_ = 0.5;
acceleration_ = 1;
friction_ = .3;
jump_height_ = -10;
// Map keys
keyboard_set_map(ord("W"), vk_up);
keyboard_set_map(ord("A"), vk_left);
keyboard_set_map(ord("S"), vk_down);
keyboard_set_map(ord("D"), vk_right);
in the step event I have this:
var hinput = keyboard_check(vk_right) - keyboard_check(vk_left);
if hinput != 0 {
hspeed_ += hinput*acceleration_;
hspeed_ = clamp(hspeed_, -max_hspeed_, max_hspeed_);
} else {
hspeed_ = lerp(hspeed_, 0, friction_);
}
if !place_meeting(x, y+1, objGrotto_platform) {
vspeed_ += gravity_;
} else {
if keyboard_check(vk_up) {
vspeed_ = jump_height_;
}
}
// horizontal
if (place_meeting(x+ hspeed_,y,objGrotto_platform))
{
while (!place_meeting(x+sign(hspeed_),y,objGrotto_platform))
{
x = x + sign(hspeed_);
}
hspeed_ = 0;
}
x += hspeed_;
// vertical
if (place_meeting(x,y+ vspeed_,objGrotto_platform))
{
while (!place_meeting(x,y+sign(vspeed_),objGrotto_platform))
{
y = y + sign(vspeed_);
}
vspeed_ = 0;
}
y += vspeed_;
in the draw event I have this:
//Draw Player and Power orb
var dir = point_direction(x, y, mouse_x, mouse_y);
var flipped = (mouse_x < x)*2-1;
//Draw Player
draw_sprite_ext(objEle, 0, x, y, flipped, 1, 1, image_blend, image_alpha);
//Draw Power orb
draw_sprite_ext(Power_orb, 0, x, y, 1, flipped, dir, image_blend, image_alpha);
I have used the code in these videos:
in the create event I have this:
hspeed_ = 0;
max_hspeed_ = 4;
vspeed_ = 0;
gravity_ = 0.5;
acceleration_ = 1;
friction_ = .3;
jump_height_ = -10;
// Map keys
keyboard_set_map(ord("W"), vk_up);
keyboard_set_map(ord("A"), vk_left);
keyboard_set_map(ord("S"), vk_down);
keyboard_set_map(ord("D"), vk_right);
in the step event I have this:
var hinput = keyboard_check(vk_right) - keyboard_check(vk_left);
if hinput != 0 {
hspeed_ += hinput*acceleration_;
hspeed_ = clamp(hspeed_, -max_hspeed_, max_hspeed_);
} else {
hspeed_ = lerp(hspeed_, 0, friction_);
}
if !place_meeting(x, y+1, objGrotto_platform) {
vspeed_ += gravity_;
} else {
if keyboard_check(vk_up) {
vspeed_ = jump_height_;
}
}
// horizontal
if (place_meeting(x+ hspeed_,y,objGrotto_platform))
{
while (!place_meeting(x+sign(hspeed_),y,objGrotto_platform))
{
x = x + sign(hspeed_);
}
hspeed_ = 0;
}
x += hspeed_;
// vertical
if (place_meeting(x,y+ vspeed_,objGrotto_platform))
{
while (!place_meeting(x,y+sign(vspeed_),objGrotto_platform))
{
y = y + sign(vspeed_);
}
vspeed_ = 0;
}
y += vspeed_;
in the draw event I have this:
//Draw Player and Power orb
var dir = point_direction(x, y, mouse_x, mouse_y);
var flipped = (mouse_x < x)*2-1;
//Draw Player
draw_sprite_ext(objEle, 0, x, y, flipped, 1, 1, image_blend, image_alpha);
//Draw Power orb
draw_sprite_ext(Power_orb, 0, x, y, 1, flipped, dir, image_blend, image_alpha);
Attachments
-
40.5 KB Views: 6