C
Claudia
Guest
Hi there, I am very new to Game Maker and I have a module assignment due in a couple of months where I have to design a basic platformer. I'm basically coding mario but its shrek kind of. So far I have made a new room and have coded Shrek (the player) walking left, right and jumping (with animation). However I can't for the life of me figure out how to code the players attack button. I've been looking at a lot of tutorials but I can't get any of them to work with the code I already have.
I want to make my player attack animation play when you press space bar. I have 2 different sprites for attack. One facing left and the other facing right. If I could get the controls and animation down I could probably work out the whole hitbox thing.
Here's what I've got in my player object step event. It probably makes no sense:
///Platform Physics
MOVELEFT = keyboard_check(ord('A'));
MOVERIGHT = keyboard_check(ord('D'));
MOVEUP = keyboard_check(ord('W'));
//check ground
if place_meeting (x, y+1, obj_grass) {
vspd = 0
//jump
if MOVEUP {
sound_play(snd_jump)
vspd = -jspd
}
} else {
//gravity
if vspd < 10 {
vspd += grav
}
}
//right
if MOVERIGHT {
hspd = spd;
}
//left
if MOVELEFT {
hspd = -spd;
}
//attack
if (attack_key) {
image_index = 0;
state = scr_attack_state;
}
//check
if ((!MOVERIGHT && !MOVELEFT) || (MOVERIGHT && MOVELEFT)) {
hspd = 0
}
//horizontal collisions
if place_meeting(x+hspd, y, obj_grass) {
while !place_meeting (x+sign(hspd), y, obj_grass) {
x+=sign(hspd)
}
hspd = 0
}
//move x
x+=hspd
//vertical collisions
if place_meeting(x, y+vspd, obj_grass) {
while !place_meeting (x, y+sign(vspd), obj_grass) {
y+=sign(vspd)
}
vspd = 0
}
//move y
y+=vspd
///Animation
if (x > xprevious)
{
if (sprite_index != spr_shrek_walking_right)
sprite_index = spr_shrek_walking_right;
image_speed = 0.15;
}
else if (x < xprevious)
{
if (sprite_index != spr_shrek_walking_left)
sprite_index = spr_shrek_walking_left;
image_speed = 0.15;
}
else
{
sprite_index = spr_shrek_standing
}
Then I have a script activation for this script:
///Scr_attack_state
image_speed = .5;
switch (sprite_index) {
case spr_shrek_walking_right:
sprite_index = spr_shrek_hit;
break;
case spr_shrek_walking_left:
sprite_index = spr_shrek_hit_left;
break;
}
Any help is appreciated
I want to make my player attack animation play when you press space bar. I have 2 different sprites for attack. One facing left and the other facing right. If I could get the controls and animation down I could probably work out the whole hitbox thing.
Here's what I've got in my player object step event. It probably makes no sense:
///Platform Physics
MOVELEFT = keyboard_check(ord('A'));
MOVERIGHT = keyboard_check(ord('D'));
MOVEUP = keyboard_check(ord('W'));
//check ground
if place_meeting (x, y+1, obj_grass) {
vspd = 0
//jump
if MOVEUP {
sound_play(snd_jump)
vspd = -jspd
}
} else {
//gravity
if vspd < 10 {
vspd += grav
}
}
//right
if MOVERIGHT {
hspd = spd;
}
//left
if MOVELEFT {
hspd = -spd;
}
//attack
if (attack_key) {
image_index = 0;
state = scr_attack_state;
}
//check
if ((!MOVERIGHT && !MOVELEFT) || (MOVERIGHT && MOVELEFT)) {
hspd = 0
}
//horizontal collisions
if place_meeting(x+hspd, y, obj_grass) {
while !place_meeting (x+sign(hspd), y, obj_grass) {
x+=sign(hspd)
}
hspd = 0
}
//move x
x+=hspd
//vertical collisions
if place_meeting(x, y+vspd, obj_grass) {
while !place_meeting (x, y+sign(vspd), obj_grass) {
y+=sign(vspd)
}
vspd = 0
}
//move y
y+=vspd
///Animation
if (x > xprevious)
{
if (sprite_index != spr_shrek_walking_right)
sprite_index = spr_shrek_walking_right;
image_speed = 0.15;
}
else if (x < xprevious)
{
if (sprite_index != spr_shrek_walking_left)
sprite_index = spr_shrek_walking_left;
image_speed = 0.15;
}
else
{
sprite_index = spr_shrek_standing
}
Then I have a script activation for this script:
///Scr_attack_state
image_speed = .5;
switch (sprite_index) {
case spr_shrek_walking_right:
sprite_index = spr_shrek_hit;
break;
case spr_shrek_walking_left:
sprite_index = spr_shrek_hit_left;
break;
}
Any help is appreciated