S
supesdupes
Guest
At the moment, I'm making a little test game--a super basic side scroller-- just to learn the basics of coding. I have a room, a player character (obj_player) that can walk left and right, a chest that I can "open" (really just made it so that when I press a button the animation changes makes it look open), and a sword (obj_sword) that I've made for the player to pick up and use.
My problem is that I can't figure out how to let the player be able to attack with the sword after he picks it up. Here's what I have within obj_player so far:
Any help would be much appreciated. Thanks!
My problem is that I can't figure out how to let the player be able to attack with the sword after he picks it up. Here's what I have within obj_player so far:
- Events:
- Create:
- ///Initialize Vars
grav = .4;
hsp = 0;
vsp = 0;
initial_movespeed = 1
movespeed = initial_movespeed
image_speed = .325
attacking = false
abletoattack = false
swordobtained = false
- ///Initialize Vars
- Step:
- ///Movement
scr_input()
scr_movement()
scr_collision() - ///Animation
if hsp != 0
{
sprite_index = spr_player_run
}
else
{
sprite_index = spr_player
}
if (place_meeting(x,y,obj_sword)) and (keyboard_check(ord('E')) and swordobtained = false)
{
swordobtained = true
abletoattack = true
}
- ///Movement
- <Space>:
- ///Sword Attack
if abletoattack = true and !attacking
{
sprite_index = spr_player_swordattack
image_index = 0
attacking = true
with instance_create(x,y,obj_sword_hitbox)
{
image_xscale = obj_player.image_xscale
}
}
- ///Sword Attack
- Create:
- Events
- Create
- swordobtained = false
- Create
- Step
- if (place_meeting(x,y,obj_player)) and (keyboard_check(ord('E')) and swordobtained = false)
{
swordobtained = true
}
- if (place_meeting(x,y,obj_player)) and (keyboard_check(ord('E')) and swordobtained = false)
- Post Draw
- if swordobtained = true
{
instance_destroy();
}
- if swordobtained = true