In this tutorial we are going to make an arrow weapon that look at and affected with gravity for a plateformer game .
Firts of all we have to make the sprites of the game :
-The player.
-The bow.
-The arrow.
-The ground.
Then we have to make the object :
-The player.
-The bow.
-The arrow.
-The ground.
The ground object should be solid :
Now let's move to the player's code :
Go to the step event and write ths simple code :
Step event :
if keyboard_check(vk_right){
x += 4;
}
if keyboard_check(vk_left){
x -= 4;
}
Then it's the bow turn :
Create event :
throwSpeed = 0;
Go now to the step event :
Step event :
x = player.x;
y = player.y;
Make the bow follow the player's position.
direction = point_direction(x,y,mouse_x,mouse_y);
This will change the direction (not the sprite's angle) of the bow depending on mouse.
image_angle = direction;
This will make the bow rotate depending on direction, it will make it look at mouse.
if mouse_check_button(mb_left){
if throwSpeed < 20{
throwSpeed += 1;
}
}
If the left mouse is pressed the throwSpeed will increase until it arrive to 20 then it stop increasing.
if mouse_check_button_released(mb_left){
alarm[0] = 5;
arrowInstance = instance_create(x,y,arrow);
arrowInstance.speed = throwSpeed;
arrowInstance.direction = direction;
}
If the left mouse is released a new instance name arrowInstance will be created at the x's and y's bow position, and it's speed and direction will be the same as the throwSpeed variable and the bow's direction.
Alarm 0 event :
throwSpeed = 0;
After 5 milisecond the alarm 0 will execute it's code because in the other code we have indicated that alarm[0] = 5;
Now go to the arrow :
Step event :
image_angle = direction;
This the same as the other.
if place_free(x,y+1){
gravity = 0.5;
}else{
gravity = 0;
}
This will make the arrow fall if there nothing under.
Collision with ground :
move_contact_solid(direction,speed);
speed = 0;
To make the arrow stop while it collide with the ground.
That's all, now make a room and put the player and the bow, and the ground and run the game.
Have fun.
Firts of all we have to make the sprites of the game :
-The player.
-The bow.
-The arrow.
-The ground.
Then we have to make the object :
-The player.
-The bow.
-The arrow.
-The ground.
The ground object should be solid :
Now let's move to the player's code :
Go to the step event and write ths simple code :
Step event :
if keyboard_check(vk_right){
x += 4;
}
if keyboard_check(vk_left){
x -= 4;
}
Then it's the bow turn :
Create event :
throwSpeed = 0;
Go now to the step event :
Step event :
x = player.x;
y = player.y;
Make the bow follow the player's position.
direction = point_direction(x,y,mouse_x,mouse_y);
This will change the direction (not the sprite's angle) of the bow depending on mouse.
image_angle = direction;
This will make the bow rotate depending on direction, it will make it look at mouse.
if mouse_check_button(mb_left){
if throwSpeed < 20{
throwSpeed += 1;
}
}
If the left mouse is pressed the throwSpeed will increase until it arrive to 20 then it stop increasing.
if mouse_check_button_released(mb_left){
alarm[0] = 5;
arrowInstance = instance_create(x,y,arrow);
arrowInstance.speed = throwSpeed;
arrowInstance.direction = direction;
}
If the left mouse is released a new instance name arrowInstance will be created at the x's and y's bow position, and it's speed and direction will be the same as the throwSpeed variable and the bow's direction.
Alarm 0 event :
throwSpeed = 0;
After 5 milisecond the alarm 0 will execute it's code because in the other code we have indicated that alarm[0] = 5;
Now go to the arrow :
Step event :
image_angle = direction;
This the same as the other.
if place_free(x,y+1){
gravity = 0.5;
}else{
gravity = 0;
}
This will make the arrow fall if there nothing under.
Collision with ground :
move_contact_solid(direction,speed);
speed = 0;
To make the arrow stop while it collide with the ground.
That's all, now make a room and put the player and the bow, and the ground and run the game.
Have fun.
Comments
Post a Comment