Sistema de tiro com bug
Enviado: Ter Jan 01, 2019 11:00 pm
Criei um sistema de atirar laser, porém quando estou andando e atiro pra cima ou pra baixo o tiro não sai, somente se ando pra esquerda ou direita, quando parado não importa a direção funciona normalmente.
O código é o seguinte: (bem grande, mas não sei como diminuir e ainda vou incluir uma pausa durante o momento em que esta atirando)
////////////////////
// ATIRAR LASER ///
////////////////////
if keyboard_check_pressed (ord ("K")) and global.laser>0 {
if sprite_index = spr_player_parado_direita {
global.laser-=1 {
with ( instance_create_layer (x,y-16, "Instances", obj_laser)) {
motion_set (0, 4) {
sprite_index = spr_laser_horizontal
}
}
}
}
}
if keyboard_check_pressed (ord ("K")) and global.laser>0 {
if sprite_index = spr_player_parado_esquerda {
global.laser-=1 {
with ( instance_create_layer (x,y-16, "Instances", obj_laser)) {
motion_set (180, 4) {
sprite_index = spr_laser_horizontal
}
}
}
}
}
if keyboard_check_pressed (ord ("K")) and global.laser>0 {
if sprite_index = spr_player_parado_cima {
global.laser-=1 {
with ( instance_create_layer (x,y-16, "Instances", obj_laser)) {
motion_set (90, 4) {
}
}
}
}
}
if keyboard_check_pressed (ord ("K")) and global.laser>0 {
if sprite_index = spr_player_parado_baixo {
global.laser-=1
with ( instance_create_layer (x,y-16, "Instances", obj_laser)) {
motion_set (270, 4) {
}
}
}
}
// atirar andando
if keyboard_check_pressed (ord ("K")) and global.laser>0 {
if sprite_index = spr_player_movendo_direita {
global.laser-=1 {
with ( instance_create_layer (x,y-16, "Instances", obj_laser)) {
motion_set (0, 4) {
sprite_index = spr_laser_horizontal
}
}
}
}
}
if keyboard_check_pressed (ord ("K")) and global.laser>0 {
if sprite_index = spr_player_movendo_esquerda {
global.laser-=1 {
with ( instance_create_layer (x,y-16, "Instances", obj_laser)) {
motion_set (180, 4) {
sprite_index = spr_laser_horizontal
}
}
}
}
}
if keyboard_check_pressed (ord ("K")) and global.laser>0 {
if sprite_index = spr_player_movendo_cima {
global.laser-=1 {
with ( instance_create_layer (x,y-16, "Instances", obj_laser)) {
motion_set (90, 4) {
}
}
}
}
}
if keyboard_check_pressed (ord ("K")) and global.laser>0 {
if sprite_index = spr_player_movendo_baixo {
global.laser-=1
with ( instance_create_layer (x,y-16, "Instances", obj_laser)) {
motion_set (270, 4) {
}
}
}
}
O código é o seguinte: (bem grande, mas não sei como diminuir e ainda vou incluir uma pausa durante o momento em que esta atirando)
////////////////////
// ATIRAR LASER ///
////////////////////
if keyboard_check_pressed (ord ("K")) and global.laser>0 {
if sprite_index = spr_player_parado_direita {
global.laser-=1 {
with ( instance_create_layer (x,y-16, "Instances", obj_laser)) {
motion_set (0, 4) {
sprite_index = spr_laser_horizontal
}
}
}
}
}
if keyboard_check_pressed (ord ("K")) and global.laser>0 {
if sprite_index = spr_player_parado_esquerda {
global.laser-=1 {
with ( instance_create_layer (x,y-16, "Instances", obj_laser)) {
motion_set (180, 4) {
sprite_index = spr_laser_horizontal
}
}
}
}
}
if keyboard_check_pressed (ord ("K")) and global.laser>0 {
if sprite_index = spr_player_parado_cima {
global.laser-=1 {
with ( instance_create_layer (x,y-16, "Instances", obj_laser)) {
motion_set (90, 4) {
}
}
}
}
}
if keyboard_check_pressed (ord ("K")) and global.laser>0 {
if sprite_index = spr_player_parado_baixo {
global.laser-=1
with ( instance_create_layer (x,y-16, "Instances", obj_laser)) {
motion_set (270, 4) {
}
}
}
}
// atirar andando
if keyboard_check_pressed (ord ("K")) and global.laser>0 {
if sprite_index = spr_player_movendo_direita {
global.laser-=1 {
with ( instance_create_layer (x,y-16, "Instances", obj_laser)) {
motion_set (0, 4) {
sprite_index = spr_laser_horizontal
}
}
}
}
}
if keyboard_check_pressed (ord ("K")) and global.laser>0 {
if sprite_index = spr_player_movendo_esquerda {
global.laser-=1 {
with ( instance_create_layer (x,y-16, "Instances", obj_laser)) {
motion_set (180, 4) {
sprite_index = spr_laser_horizontal
}
}
}
}
}
if keyboard_check_pressed (ord ("K")) and global.laser>0 {
if sprite_index = spr_player_movendo_cima {
global.laser-=1 {
with ( instance_create_layer (x,y-16, "Instances", obj_laser)) {
motion_set (90, 4) {
}
}
}
}
}
if keyboard_check_pressed (ord ("K")) and global.laser>0 {
if sprite_index = spr_player_movendo_baixo {
global.laser-=1
with ( instance_create_layer (x,y-16, "Instances", obj_laser)) {
motion_set (270, 4) {
}
}
}
}