J
JohnSebek
Guest
Hello, so recently I want to fix my game shooting system by using the old school shooting like in Metroid. I have all programmed but I have no idea how to make the sprite to change when shooting in different directions.My player shoots in 8 directions: up,down,left,right,left,upright,down left,downright.I have the basic like when key pressed left up and down, but I have a problem to make animation while shooting in up-down and down directions and while moving. For more info, there is a shooting code.
NOTE
I am still learning in GMC language, so some stuff might still be unknown for me. I tried to look also on the internet but found only one tutorial/example but the code was so complex and vague that I lost myself in it. For more info feel free to ask me
Information about object: obj_player
Sprite: spr_iddleR
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:
// weapon variables:
heat = 0
cooldown = 20
Step Event:
COMMENT: shooting
execute code:
var dx, dy, db;
// shooting direction determination:
dx = (keyboard_check(vk_right) - keyboard_check(vk_left))
dy = (keyboard_check(vk_down) - keyboard_check(vk_up))
// is shooting in some direction:
if (dx != 0 || dy != 0) if (heat <= 0) {
(instance_create(x, y, obj_bullet)).direction = point_direction(0, 0, dx, dy)
heat = cooldown
}
heat = max(0, heat - 1) // cool down
COMMENT: walking
execute code:
if keyboard_check(ord("A")) = true
{
hspeed = -3 //must be negative to go left
sprite_index = spr_walkL
image_speed = 0.5
}
if keyboard_check(ord("D")) = true
{
hspeed = 3
sprite_index = spr_walkR
image_speed = 0.5
}
if keyboard_check(ord("A")) = false and keyboard_check(ord("D")) = false
{
hspeed = 0
sprite_index = spr_iddleR
}
Collision Event with object parent_block:
execute code:
//if the collided object is solid perform actions
if(other.solid == true) {
//make the player contact solid
if(vspeed < 0) move_contact_solid(90,5);
else move_contact_solid(270,5);
//set the vertical speed to 0, important!
vspeed=0
//if he has the jump sprite, we want him to show other sprites
if(sprite_index == spr_iddleL) {
if(wspeed = 0) sprite_index = spr_iddleL
else sprite_index = spr_walkL
} else if(sprite_index == spr_iddleR) {
if(wspeed = 0) sprite_index = spr_iddleR
else sprite_index = spr_walkR
}
}
Sprite: spr_iddleR
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:
// weapon variables:
heat = 0
cooldown = 20
Step Event:
COMMENT: shooting
execute code:
var dx, dy, db;
// shooting direction determination:
dx = (keyboard_check(vk_right) - keyboard_check(vk_left))
dy = (keyboard_check(vk_down) - keyboard_check(vk_up))
// is shooting in some direction:
if (dx != 0 || dy != 0) if (heat <= 0) {
(instance_create(x, y, obj_bullet)).direction = point_direction(0, 0, dx, dy)
heat = cooldown
}
heat = max(0, heat - 1) // cool down
COMMENT: walking
execute code:
if keyboard_check(ord("A")) = true
{
hspeed = -3 //must be negative to go left
sprite_index = spr_walkL
image_speed = 0.5
}
if keyboard_check(ord("D")) = true
{
hspeed = 3
sprite_index = spr_walkR
image_speed = 0.5
}
if keyboard_check(ord("A")) = false and keyboard_check(ord("D")) = false
{
hspeed = 0
sprite_index = spr_iddleR
}
Collision Event with object parent_block:
execute code:
//if the collided object is solid perform actions
if(other.solid == true) {
//make the player contact solid
if(vspeed < 0) move_contact_solid(90,5);
else move_contact_solid(270,5);
//set the vertical speed to 0, important!
vspeed=0
//if he has the jump sprite, we want him to show other sprites
if(sprite_index == spr_iddleL) {
if(wspeed = 0) sprite_index = spr_iddleL
else sprite_index = spr_walkL
} else if(sprite_index == spr_iddleR) {
if(wspeed = 0) sprite_index = spr_iddleR
else sprite_index = spr_walkR
}
}
NOTE
I am still learning in GMC language, so some stuff might still be unknown for me. I tried to look also on the internet but found only one tutorial/example but the code was so complex and vague that I lost myself in it. For more info feel free to ask me