L
Latch
Guest
Am I right in assuming I can create an object with all the code required inside it, and then have other objects use the code inside of it?
For example I could create an object that each of 4 players (human controlled) use the same parent that code is taken from but are each unique and wont interfere with each other?
Here is how I setup the player object:
Would I then create two objects that use this as the parent, assign them the 'player' variable relevant to the player they are and they should move around freely able to alter their speed etc independently, or have I gone wrong somewhere?
For example I could create an object that each of 4 players (human controlled) use the same parent that code is taken from but are each unique and wont interfere with each other?
Here is how I setup the player object:
Code:
if canmove = true//If the player is allowed to move
{
//PLAYER ONE
if global.p1input = 0 && player = 1//If the user is using a keyboard
{
up = keyboard_check (ord('W'));//Set the movement keys
down = keyboard_check (ord('S'));
left = keyboard_check (ord('A'));
right = keyboard_check (ord('D'));
attack = keyboard_check_pressed (ord('Q'));
interact = keyboard_check_pressed (ord('E'));
useitem = keyboard_check_pressed (ord('F'));
}
//PLAYER TWO
if global.p2input = 0 && player = 2//If the user is using a keyboard
{
up = keyboard_check (vk_up);//Set the movement keys
down = keyboard_check (vk_down);
left = keyboard_check (vk_left);
right = keyboard_check (vk_right);
attack = keyboard_check_pressed (vk_space);
interact = keyboard_check_pressed (vk_rcontrol);
useitem = keyboard_check_pressed (vk_numpad0);
}
//Movement
if up = true {if canmoveup = true {y-= playerspeed;}}//If the player presses the correct key, perform the actions if they are allowed to
if right = true {if canmoveright = true {x+= playerspeed;}}
if down = true {if canmovedown = true {y+= playerspeed;}}
if left = true {if canmoveleft = true {x-= playerspeed;}}
//Setting the facing of the player
if up = true && left = false && right = false {facing = 0;}
if up = true && right = true {facing = 1;}
if right = true && up = false && down = false {facing = 2;}
if right = true && down = true {facing = 3;}
if down = true && left = false && right = false {facing = 4;}
if down = true && left = true {facing = 5;}
if left = true && up = false && down = false {facing = 6;}
if up = true && left = true {facing = 7;}
}
Would I then create two objects that use this as the parent, assign them the 'player' variable relevant to the player they are and they should move around freely able to alter their speed etc independently, or have I gone wrong somewhere?