Skip to content

Commit

Permalink
Updated demo
Browse files Browse the repository at this point in the history
  • Loading branch information
sohomsahaun committed Jul 9, 2021
1 parent 18b9bc0 commit 669bb9b
Show file tree
Hide file tree
Showing 19 changed files with 126 additions and 88 deletions.
1 change: 1 addition & 0 deletions SnowState.yyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions objects/oCamera/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ view_visible[0] = true;
alarm[0] = 1;

// State Machine
state = new SnowState("instance");
fsm = new SnowState("instance");

state
fsm
.add("instance", {
step: function() {
var _targ = targetInst;
Expand Down
2 changes: 1 addition & 1 deletion objects/oCamera/Step_0.gml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
state.step();
fsm.step();
2 changes: 1 addition & 1 deletion objects/oGame/Draw_64.gml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if (showHistory) {
_y = 10;

var _str, _states, _i;
_states = oPlayer.state.get_history();
_states = oPlayer.fsm.get_history();
_str = "groundAttack3";

draw_set_alpha(.9);
Expand Down
76 changes: 38 additions & 38 deletions objects/oPlayer/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ input = {};
check_input();

// State Machine
state = new SnowState("idle");
fsm = new SnowState("idle");

state
fsm
.history_enable()
.set_history_max_size(20)
.event_set_default_function("draw", function() {
Expand All @@ -73,26 +73,26 @@ state

// If left or right keys are pressed, run
if (abs(input.hdir)) {
state.change("run");
fsm.change("run");
return;
}

// If jump key is pressed, jump
if (input.jump) {
state.change("jump");
fsm.change("jump");
return;
}

if (hasSword) {
// If attack key is pressed, go into groundAttack1
if (input.attack) {
state.change("groundAttack1");
fsm.change("groundAttack1");
return;
}

// Throw the sword
if (input.throwSword && hasSword) {
state.change("throwSword");
fsm.change("throwSword");
return;
}
} else {
Expand All @@ -109,7 +109,7 @@ state

// Check if I'm flating
if (!on_ground()) {
state.change("fall");
fsm.change("fall");
return;
}
}
Expand All @@ -127,28 +127,28 @@ state

// If left and right keys are not pressed, switch back to idle
if (_dir == 0) {
state.change("idle");
fsm.change("idle");
return;
}

face = _dir;

// If jump key is pressed, jump
if (input.jump) {
state.change("jump");
fsm.change("jump");
return;
}

if (hasSword) {
// If attack key is pressed, go into groundAttack1
if (input.attack) {
state.change("groundAttack1");
fsm.change("groundAttack1");
return;
}

// Throw the sword
if (input.throwSword && hasSword) {
state.change("throwSword");
fsm.change("throwSword");
return;
}
} else {
Expand All @@ -165,7 +165,7 @@ state

// Check if I'm flating
if (!on_ground()) {
state.change("fall");
fsm.change("fall");
return;
}
}
Expand All @@ -189,7 +189,7 @@ state

// Throw the sword
if (input.throwSword && hasSword) {
state.change("throwSword");
fsm.change("throwSword");
return;
}

Expand All @@ -205,7 +205,7 @@ state

// Check when we should start falling
if (vspd >= 0) {
state.change("fall");
fsm.change("fall");
return;
}
}
Expand All @@ -218,7 +218,7 @@ state

// If I have not done air attack when falling now, activate air attack
// Air attack can be done once when falling
if (state.state_is("airAttack", state.get_previous_state())) canAirAttack = false;
if (fsm.state_is("airAttack", fsm.get_previous_state())) canAirAttack = false;
else canAirAttack = true;

},
Expand All @@ -237,13 +237,13 @@ state
if (hasSword) {
// If attack key is pressed, go into airAttack1
if (input.attack && canAirAttack) {
state.change("airAttack1");
fsm.change("airAttack1");
return;
}

// Throw the sword
if (input.throwSword) {
state.change("throwSword");
fsm.change("throwSword");
return;
}
} else {
Expand All @@ -255,10 +255,10 @@ state
}

// Coyote time
if ((state.get_time() <= coyoteDuration) && input.jump) {
if ((fsm.get_time() <= coyoteDuration) && input.jump) {
// Apply only if we were running
if (state.get_previous_state() == "run") {
state.change("jump");
if (fsm.get_previous_state() == "run") {
fsm.change("jump");
return;
}
}
Expand All @@ -269,7 +269,7 @@ state

// Check when we land
if (on_ground()) {
state.change("idle");
fsm.change("idle");
return;
}
}
Expand All @@ -283,7 +283,7 @@ state
nextAttack = false;

// Create effect
var _sprite = effectSprites[$ state.get_current_state()];
var _sprite = effectSprites[$ fsm.get_current_state()];
var _face = face;
var _x = x + _face * 8;
with (instance_create_depth(_x, y, depth, oEffect)) {
Expand All @@ -304,7 +304,7 @@ state
.add_child("attack", "groundAttack", {
/// @override
enter: function() {
state.inherit();
fsm.inherit();

// Stop
hspd = 0;
Expand All @@ -313,18 +313,18 @@ state

/// @override
step: function() {
state.inherit();
fsm.inherit();

// When the animation ends, go to the next attack state if attack has been pressed
// Otherwise, just go idle
if (animation_end()) {
if (nextAttack) {
var _state = state.get_current_state();
var _state = fsm.get_current_state();
var _curr = real(string_digits(_state));
var _next = string_letters(_state) + string(_curr+1);
state.change(_next);
fsm.change(_next);
} else {
state.change("idle");
fsm.change("idle");
}
return;
}
Expand All @@ -337,44 +337,44 @@ state
step: function() {
// When the animation ends, go to idle state
if (animation_end()) {
state.change("idle");
fsm.change("idle");
return;
}
}
})
.add_child("attack", "airAttack", {
/// @override
enter: function() {
state.inherit();
fsm.inherit();

// Lower the gravity
grav = gravAttack;
vspd = 0;
},
/// @override
step: function() {
state.inherit();
fsm.inherit();

// Go down, slowly
apply_gravity();
move_and_collide();

// Check when we land
if (on_ground()) {
state.change("idle");
fsm.change("idle");
return;
}

// When the animation ends, go to the next attack state if attack has been pressed
// Otherwise, just back to falling again
if (animation_end()) {
if (nextAttack) {
var _state = state.get_current_state();
var _state = fsm.get_current_state();
var _curr = real(string_digits(_state));
var _next = string_letters(_state) + string(_curr+1);
state.change(_next);
fsm.change(_next);
} else {
state.change("fall");
fsm.change("fall");
}
return;
}
Expand All @@ -393,7 +393,7 @@ state

// When the animation ends, go to fall state again
if (animation_end()) {
state.change("fall");
fsm.change("fall");
return;
}
}
Expand All @@ -415,9 +415,9 @@ state
// Switch the state to idle or fall,
// depending on what the previous state was
var _state = "idle";
if (state.get_previous_state() == "jump") _state = "fall";
if (state.get_previous_state() == "fall") _state = "fall";
state.change(_state);
if (fsm.get_previous_state() == "jump") _state = "fall";
if (fsm.get_previous_state() == "fall") _state = "fall";
fsm.change(_state);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion objects/oPlayer/Draw_0.gml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
state.draw();
fsm.draw();
4 changes: 2 additions & 2 deletions objects/oPlayer/Other_25.gml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ init_effect_sprites = function() {
};

get_sprite = function() {
return sprites[$ state.get_current_state()][@ hasSword];
return sprites[$ fsm.get_current_state()][@ hasSword];
};

check_input = function() {
Expand Down Expand Up @@ -61,7 +61,7 @@ spawn_sword = function() {
with (instance_create_depth(x+6*face, y-14, depth, oSword)) {
owner = other.id;
face = owner.face;
state.change("spinning");
fsm.change("spinning");
}
};

Expand Down
2 changes: 1 addition & 1 deletion objects/oPlayer/Other_76.gml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
state.throwSword();
fsm.throwSword();
2 changes: 1 addition & 1 deletion objects/oPlayer/Step_0.gml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
state.step();
fsm.step();
6 changes: 3 additions & 3 deletions objects/oSword/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ hspd = 0;
face = 1;

// State Machine
state = new SnowState("NULL");
fsm = new SnowState("NULL");

state
fsm
.event_set_default_function("draw", function() {
// Draw this no matter what state we are in
// (Unless it is overridden, ofcourse)
Expand All @@ -32,7 +32,7 @@ state
},
step: function() {
if (place_meeting(x+hspd, y, oWall)) {
state.change("embedded");
fsm.change("embedded");
return;
}
x += hspd;
Expand Down
2 changes: 1 addition & 1 deletion objects/oSword/Draw_0.gml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
state.draw();
fsm.draw();
4 changes: 2 additions & 2 deletions objects/oSword/Other_25.gml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// @desc Methods

recall = function() {
if (instance_exists(owner) && state.state_is("embedded")) {
state.change("recall");
if (instance_exists(owner) && fsm.state_is("embedded")) {
fsm.change("recall");
}
};
2 changes: 1 addition & 1 deletion objects/oSword/Step_0.gml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
state.step();
fsm.step();
Loading

0 comments on commit 669bb9b

Please sign in to comment.