L
LuckyGunn
Guest
I'm working on adding an upgrade system to my game where after the level timer runs out, it brings the player to an upgrade menu where you can spend points. I'm having trouble with a player movement speed upgrade at the moment.
The idea is that selecting the upgrade option runs a script that increases the global.moveSpeed variable (set at the create event of my start menu) which is used in the player object's step event for movement. The script then sends you to the next room (or in this case loops you back to the test room for testing purposes).
The player moves fine, but the movement speed does not increase at all after upgrading.
This is the line of code I'm trying to use in the script:
(global.moveSpeed is normally set to 5)
Otherwise, I'm just using basic side-scrolling movement code, which shouldn't be resetting the variable back to its normal value.
Any ideas on how to get this to work?
The idea is that selecting the upgrade option runs a script that increases the global.moveSpeed variable (set at the create event of my start menu) which is used in the player object's step event for movement. The script then sends you to the next room (or in this case loops you back to the test room for testing purposes).
The player moves fine, but the movement speed does not increase at all after upgrading.
This is the line of code I'm trying to use in the script:
Code:
with (obj_player){global.movespeed += 10};
Otherwise, I'm just using basic side-scrolling movement code, which shouldn't be resetting the variable back to its normal value.
Code:
///Player Movement
//Get Input
right = keyboard_check(vk_right);
left = keyboard_check(vk_left);
jump = keyboard_check_pressed(vk_up);
down = keyboard_check(vk_down);
//Horizontal Movement
move = right - left;
hsp = move * global.moveSpeed;
//Gravity
if( vsp < 20 )
{
vsp += grav;
}
//Jumping
if(place_meeting(x, y+1, obj_wall))
{
vsp = jump * -jumpPower;
}
//Horizontal Collision
if(place_meeting(x+hsp, y, obj_wall))
{
while(!place_meeting(x+sign(hsp), y, obj_wall))
{
x += sign(hsp);
}
hsp = 0;
}
//Move the Player Horizontally
x += hsp
//Vertical Collision & Bounce
if(place_meeting(x, y+vsp, obj_wall))
{
while(!place_meeting(x, y+sign(vsp), obj_wall))
{
y += sign(vsp);
}
if(vsp > 12 )
{
vsp = -(vsp/3)
}
else
{
vsp = 0;
}
}
//Move the Player Vertically
y += vsp
Any ideas on how to get this to work?