P
piksil_demon
Guest
ok so heres what im aiming for.
1 i want my character to move in 8 directions, but attack in 4.
2 i want the direction he attacks in to be the direction of the last key he pressed.
with that said here is the problems i have with my current code.
1. it shoots in the diagonal directions. i want it to only shoot the up, down, left, and right
2. it shoots multiple at once
3. when i hole up and down together, or left and right together then shoot, the bullet always shoots to the right.
here is the code for my arrow and player
1 i want my character to move in 8 directions, but attack in 4.
2 i want the direction he attacks in to be the direction of the last key he pressed.
with that said here is the problems i have with my current code.
1. it shoots in the diagonal directions. i want it to only shoot the up, down, left, and right
2. it shoots multiple at once
3. when i hole up and down together, or left and right together then shoot, the bullet always shoots to the right.
here is the code for my arrow and player
Code:
[B]Information about object: obj_player[/B]
Sprite: spr_player
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:
MaxHp= 10
Hp = 10
Hspd= 0
Vspd= 0
Spd=5
SpdX = 1
Dblspd=false
Attack=1
DblAttk=false
Def=1
DblDef=false
Arrows=20
InfArrow = false
Inv=false
alarm[0]=0
Step Event:
execute code:
up = keyboard_check(ord('W'))
down = keyboard_check(ord('S'))
left = keyboard_check(ord('A'))
right = keyboard_check(ord('D'))
ranged = keyboard_check(vk_space)
//not moving/ pressing opposite keys
if!left & !right & !up &! down or up & down or left & right
{Spd=0}
else{Spd = 5*SpdX}
//movemnt code
var Hspd= (right - left)
var Vspd= (down - up);
//diagonal speed equlalizer
var d = point_direction(0, 0, Hspd, Vspd);
x += lengthdir_x(Spd, d);
y += lengthdir_y(Spd, d);
if (ranged) {
with (instance_create(x, y, obj_bullet)) {
direction = d;
speed = 11;
}
}
Code:
[B]Information about object: obj_bullet[/B]
Sprite: spr_bullet
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:
BulletSpd=11
Step Event:
execute code:
Collision Event with object obj_wall:
execute code:
instance_destroy()
Last edited by a moderator: