B
Bengs
Guest
Hello everyone my name is Ben,
I just started using gamemaker and i am usingit for a school project.
This is my code so far except i have 2 problems
1) My attack animations doesnt seem to play al the wat
2) I dont know the code to make my character attack when he is stationary
Note: changing mouse_check_button(mb_left) to mouse_check_button_pressed(mb_left) only makes things worse.
I just started using gamemaker and i am usingit for a school project.
This is my code so far except i have 2 problems
1) My attack animations doesnt seem to play al the wat
2) I dont know the code to make my character attack when he is stationary
Note: changing mouse_check_button(mb_left) to mouse_check_button_pressed(mb_left) only makes things worse.
Code:
//Variables
key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_space = keyboard_check_pressed(vk_space);
key_w = keyboard_check_
pressed(ord("W"));
key_lmb = mouse_check_button(mb_left);
jump = 0;
//Attack Status
if key_lmb {
attack= 1;
} else {
attack = 0;
}
//Hp
if Chp <= 0
{
instance_destroy();
game_restart();
}
//calculating movement
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
//horizontal collission
if (place_meeting(x+hsp,y,Obj_Wall))
{
while (!place_meeting(x+sign(hsp),y,Obj_Wall))
{
x=x+sign(hsp);
}
hsp = 0;
}
if (place_meeting(x+hsp,y,Obj_GrassBlock))
{
while (!place_meeting(x+sign(hsp),y,Obj_GrassBlock))
{
x=x+sign(hsp);
}
hsp = 0;
}
//Vertical collission
if (place_meeting(x,y+vsp,Obj_GrassBlock))
{
while (!place_meeting(x,y+sign(vsp),Obj_GrassBlock))
{
y=y+sign(vsp);
}
vsp = 0;
}
//moving controls
if (keyboard_check(vk_nokey))
{
image_speed = 0;
image_index = 0;
attack = 0;
}
if (key_right) and (vsp=0){
if attack = 0
{
x = x + hsp;
Cdmg= 0;
image_speed = hsp/1.5;
sprite_index = Spr_CharacterWalkRight;
} else
{
attack = 1;
image_speed = 2;
sprite_index = Spr_CharacterAttack01Right;
if (place_meeting(x+1,y,par_enemy))
{
Cdmg=100;
}
}
}
if (key_left) and (vsp=0) {
if attack = 0
{
x = x + hsp;
Cdmg= 0;
image_speed = hsp/1.5;
sprite_index = Spr_CharacterWalkLeft;
} else
{
attack = 1;
image_speed = 2;
sprite_index = Spr_CharacterAttack01Left;
if (place_meeting(x+1,y,par_enemy))
{
Cdmg=100;
}
}
}
y = y + vsp;
if (place_meeting(x,y+1,Obj_GrassBlock)) and (key_space or key_w)
{
jump = 1;
vsp = -3.5;
}
if (key_left) and (vsp != 0) {
if attack = 0{
x = x + hsp;
Cdmg= 0;
image_speed = 0;
image_index = 0;
sprite_index = Spr_CharacterWalkLeft;
}
else {
image_speed = 2;
sprite_index = Spr_CharacterAttack01Left;
if (place_meeting(x-1,y,par_enemy))
{
Cdmg=100;
}
}
}
if (key_right) and (vsp !=0) {
if attack = 0{
x = x + hsp;
Cdmg= 0;
image_speed = 0;
image_index = 0;
sprite_index = Spr_CharacterWalkRight;
} else {
image_speed = 2;
sprite_index = Spr_CharacterAttack01Right;
if (place_meeting(x+1,y,par_enemy))
{
Cdmg=100;
}
}
}
//Stationary Attacks