AdriandotEXE
Member
Hello everyone
I'm having a bit of a hard time with my game. I recently began using states in the class I'm taking to help program my game. The idle animation appears to be working for my enemy object, however the jumping start state does not work at all. The instructor split the jump into three states, Jump_Start, Jump, and Jump_Land. I tried using the debugger, but I couldn't find anything wrong. I tried adjusting the origin point and using the instructors sprites and that didn't work either. Any help or guidance with this problem would be greatly appreciated.
Here is the Oenemy code in the create event:
/// Enemy Udemy Code
hsp = 0;
max_hsp_initial = 2;
max_hsp = max_hsp_initial;
vsp= 0;
spd= 2;
jump_spd = -6;
hsp_decimal= 0;
vsp_decimal = 0;
facing = choose(-1,1);
///Breathing
Breath_Timer_Initial = random_range(room_speed * 1.75, room_speed * 2.25);
Breath_Timer = Breath_Timer_Initial;
image_speed = 0;
///Jump
//Will he jump this chance
Jump_Chance = 0.5;
// how often to check for a jump chance
Jump_Timer_Initial = random_range(room_speed,room_speed * 1.5)
Jump_Timer = Jump_Timer_Initial;
enum Robot_States
{
IDLE,
JUMP_START,
JUMP,
JUMP_LAND
}
state = Robot_States.IDLE
states_array[Robot_States.IDLE] = Robot_Idle_State
states_array[Robot_States.JUMP_START] = Robot_Jump_Start_State
states_array[Robot_States.JUMP] = Robot_Jump_State
states_array[Robot_States.JUMP_LAND] = Robot_Jump_Land_State
sprites_array[Robot_States.IDLE] = S_Robot_Idle
sprites_array[Robot_States.JUMP_START]= S_Robot_Jump_Start
sprites_array[Robot_States.JUMP] = S_Robot_Jump
sprites_array[Robot_States.JUMP_LAND] = S_Robot_Jump_Land
Here is the Idle State Script:
// // Robot Idle State
function Robot_Idle_State()
{
//Get Input
Breathing();
//Calculate Movement
//Modify State
if (Jump_Timer < 0) {
//Reset Timer
Jump_Timer = Jump_Timer_Initial;
// Do we jump?
var _jump = random(1);
if _jump > Jump_Chance
{
state = Robot_States.JUMP_START;
//reset breathe values
image_index = 0;
image_speed = 1;
} else {
Jump_Timer --;
}
}
//Apply Movement
//Animations
Robot_Animation_Normal();
}
Here is the Jump Start State:
// // Robot Jump Start State
function Robot_Jump_Start_State()
{
//Get Input
//Calculate Movement
Player_Collision_Normal();
//Modify State
if image_index >= image_number - sprite_get_speed(image_index)/room_speed {
state = Robot_States.JUMP;
vsp = jump_spd;
}
//Apply Movement
//Animations
Robot_Animation_Normal();
}
Collision Code or Player_Collision_Normal();
function Player_Collision_Normal()
{
if hsp == 0 hsp_decimal = 0;
if vsp == 0 vsp_decimal = 0;
//apply carried over decimals
hsp += hsp_decimal;
vsp += vsp_decimal;
//floor decimals
//save and subtract decimals
hsp_decimal = frac(hsp);
hsp -= hsp_decimal;
vsp_decimal = frac(vsp);
vsp -= vsp_decimal;
//horizontal collision
var side;
//determine which side to test
if hsp > 0 side = bbox_right else side = bbox_left;
//check the top and bottom of the side
var t1 = tilemap_get_at_pixel(global.map, side + hsp, bbox_top);
var t2 = tilemap_get_at_pixel(global.map, side + hsp, bbox_bottom);
if ((t1 != VOID) and (t1 != PLATFORM)) or
((t2 != VOID) and (t2 != PLATFORM)) {
//collision found
if hsp > 0 x = x - (x mod global.tile_size) + global.tile_size - 1 - (side - x);
else x = x - (x mod global.tile_size) - (side - x);
hsp = 0;
}
x += hsp;
//vertical collision
var side;
//determine which side to test
if vsp > 0 side = bbox_bottom else side = bbox_top;
//check the left and right side
var t1 = tilemap_get_at_pixel(global.map, bbox_left, side + vsp);
var t2 = tilemap_get_at_pixel(global.map, bbox_right, side + vsp);
var t3 = tilemap_get_at_pixel(global.map, bbox_left, bbox_bottom);
var t4 = tilemap_get_at_pixel(global.map, bbox_right, bbox_bottom);
if (t1 != VOID and(((vsp >0 or t1 != PLATFORM)) and t3 != PLATFORM) or (t1 == SOLID and t3 == PLATFORM)) or
(t2 != VOID and (((vsp >0 or t2 != PLATFORM))and t4 != PLATFORM) or (t2 == SOLID and t4 == PLATFORM)) {
//collision found
if vsp > 0 y = y - (y mod global.tile_size) + global.tile_size - 1 - (side - y);
else y = y - (y mod global.tile_size) - (side - y);
vsp = 0;
}
y += vsp;
}
I'm having a bit of a hard time with my game. I recently began using states in the class I'm taking to help program my game. The idle animation appears to be working for my enemy object, however the jumping start state does not work at all. The instructor split the jump into three states, Jump_Start, Jump, and Jump_Land. I tried using the debugger, but I couldn't find anything wrong. I tried adjusting the origin point and using the instructors sprites and that didn't work either. Any help or guidance with this problem would be greatly appreciated.
Here is the Oenemy code in the create event:
/// Enemy Udemy Code
hsp = 0;
max_hsp_initial = 2;
max_hsp = max_hsp_initial;
vsp= 0;
spd= 2;
jump_spd = -6;
hsp_decimal= 0;
vsp_decimal = 0;
facing = choose(-1,1);
///Breathing
Breath_Timer_Initial = random_range(room_speed * 1.75, room_speed * 2.25);
Breath_Timer = Breath_Timer_Initial;
image_speed = 0;
///Jump
//Will he jump this chance
Jump_Chance = 0.5;
// how often to check for a jump chance
Jump_Timer_Initial = random_range(room_speed,room_speed * 1.5)
Jump_Timer = Jump_Timer_Initial;
enum Robot_States
{
IDLE,
JUMP_START,
JUMP,
JUMP_LAND
}
state = Robot_States.IDLE
states_array[Robot_States.IDLE] = Robot_Idle_State
states_array[Robot_States.JUMP_START] = Robot_Jump_Start_State
states_array[Robot_States.JUMP] = Robot_Jump_State
states_array[Robot_States.JUMP_LAND] = Robot_Jump_Land_State
sprites_array[Robot_States.IDLE] = S_Robot_Idle
sprites_array[Robot_States.JUMP_START]= S_Robot_Jump_Start
sprites_array[Robot_States.JUMP] = S_Robot_Jump
sprites_array[Robot_States.JUMP_LAND] = S_Robot_Jump_Land
Here is the Idle State Script:
// // Robot Idle State
function Robot_Idle_State()
{
//Get Input
Breathing();
//Calculate Movement
//Modify State
if (Jump_Timer < 0) {
//Reset Timer
Jump_Timer = Jump_Timer_Initial;
// Do we jump?
var _jump = random(1);
if _jump > Jump_Chance
{
state = Robot_States.JUMP_START;
//reset breathe values
image_index = 0;
image_speed = 1;
} else {
Jump_Timer --;
}
}
//Apply Movement
//Animations
Robot_Animation_Normal();
}
Here is the Jump Start State:
// // Robot Jump Start State
function Robot_Jump_Start_State()
{
//Get Input
//Calculate Movement
Player_Collision_Normal();
//Modify State
if image_index >= image_number - sprite_get_speed(image_index)/room_speed {
state = Robot_States.JUMP;
vsp = jump_spd;
}
//Apply Movement
//Animations
Robot_Animation_Normal();
}
Collision Code or Player_Collision_Normal();
function Player_Collision_Normal()
{
if hsp == 0 hsp_decimal = 0;
if vsp == 0 vsp_decimal = 0;
//apply carried over decimals
hsp += hsp_decimal;
vsp += vsp_decimal;
//floor decimals
//save and subtract decimals
hsp_decimal = frac(hsp);
hsp -= hsp_decimal;
vsp_decimal = frac(vsp);
vsp -= vsp_decimal;
//horizontal collision
var side;
//determine which side to test
if hsp > 0 side = bbox_right else side = bbox_left;
//check the top and bottom of the side
var t1 = tilemap_get_at_pixel(global.map, side + hsp, bbox_top);
var t2 = tilemap_get_at_pixel(global.map, side + hsp, bbox_bottom);
if ((t1 != VOID) and (t1 != PLATFORM)) or
((t2 != VOID) and (t2 != PLATFORM)) {
//collision found
if hsp > 0 x = x - (x mod global.tile_size) + global.tile_size - 1 - (side - x);
else x = x - (x mod global.tile_size) - (side - x);
hsp = 0;
}
x += hsp;
//vertical collision
var side;
//determine which side to test
if vsp > 0 side = bbox_bottom else side = bbox_top;
//check the left and right side
var t1 = tilemap_get_at_pixel(global.map, bbox_left, side + vsp);
var t2 = tilemap_get_at_pixel(global.map, bbox_right, side + vsp);
var t3 = tilemap_get_at_pixel(global.map, bbox_left, bbox_bottom);
var t4 = tilemap_get_at_pixel(global.map, bbox_right, bbox_bottom);
if (t1 != VOID and(((vsp >0 or t1 != PLATFORM)) and t3 != PLATFORM) or (t1 == SOLID and t3 == PLATFORM)) or
(t2 != VOID and (((vsp >0 or t2 != PLATFORM))and t4 != PLATFORM) or (t2 == SOLID and t4 == PLATFORM)) {
//collision found
if vsp > 0 y = y - (y mod global.tile_size) + global.tile_size - 1 - (side - y);
else y = y - (y mod global.tile_size) - (side - y);
vsp = 0;
}
y += vsp;
}
Last edited: