so i'm trying to put together this simple platformer, and there's 2 things that i just can't wrap my head around:
player states and
hitboxes. spoiler alert: i don't really have any experience with programming aside from very basic GML and some AS3 so these questions might be really dumb.
please note that i'm using game maker 7 so i can't access a lot of the dummy engines that explain these things.let's start with player states. i found
this tutorial which seemed pretty useful (and i think i do kind of understand how it works), but game maker doesn't seem to register the "enum" function for me at all? i'm not really sure where i'm supposed to put it either, to be honest. anyway, here's my code so far:
//initialize variables
grav = 1;
hsp = 0;
vsp = 0;
frc = 1;
movespeed = 4;
jumpspeed = 10;
crouchspeed = 2;
//state machine
myState_physical = state_physical.ground;
myState_combat = state_combat.idle;
//receive player input
key_right = keyboard_check(vk_right);
key_left = keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_up);
key_crouch = keyboard_check(vk_down);
key_attack = keyboard_check(ord('Z'));
//initialize state machine
scr_playerState();
//check for ground
if (place_meeting(x, y+1, obj_solid)) {
myState_physical = state_physical.ground;
vsp = 0;
//jumping
if (key_jump) {
vsp = -jumpspeed;
}
//crouching
if (key_crouch) {
sprite_index = spr_player_crouch;
}
} else {
//gravity
myState_physical = state_physical.air;
if (vsp < 10) {
vsp += grav;
}
//controlled jumping
if (keyboard_check_released(vk_up) && vsp < 0) {
vsp /= 2;
}
}
//moving right
if (key_right) {
if (hsp < movespeed) {
hsp += frc;
}
hsp = movespeed;
}
//moving left
if (key_left) {
if (hsp > -movespeed) {
hsp -= frc;
}
hsp = -movespeed;
}
//atacking
if (key_attack && myState_combat != state_combat.attack) {
myState_combat = state_combat.attack;
}
//check for not moving
if ((!key_left && !key_right) || (key_left && key_right)) {
if (hsp != 0) {
if (hsp < 0) {
hsp += frc;
} else {
hsp -= frc;
}
}
}
//horizontal collisions
if (place_meeting(x+hsp, y, obj_solid)) {
while (!place_meeting(x+sign(hsp), y, obj_solid)) {
x += sign(hsp);
}
hsp = 0;
}
x += hsp;
//vertical collisions
if (place_meeting(x, y+vsp, obj_solid)) {
while (!place_meeting(x, y+sign(vsp), obj_solid)) {
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
switch (myState_physical) {
case state_physical.ground:
{
//scr_physicalState_ground();
}; break;
case state_physical.air:
{
//scr_physicalState_air();
}; break;
}
switch (myState_combat) {
case state_combat.idle:
{
//scr_combatState_idle();
}; break;
case state_combat.attack:
{
scr_combatState_attack();
}; break;
}
i'm sorry guys, it's a mess. but yeah, then come hitboxes. i'm just quite confused when it comes to the whole collision mask thing. i made a placeholder spritesheet thing that looks like this, but now it's just kind of, you know - now what?