Skip to content

Commit

Permalink
Improving combat system
Browse files Browse the repository at this point in the history
  • Loading branch information
Batora07 committed Jul 20, 2017
1 parent 0c978ff commit 1a15b5a
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 5 deletions.
10 changes: 9 additions & 1 deletion README.md
Expand Up @@ -31,4 +31,12 @@ Here are a few examples of what I'm trying to achieve with this project :

> **Data created with JSON**
[![PLG05](img/img05.png)](img/img05.png)
[![PLG05](img/img05.png)](img/img05.png)

> **Multiple choices during fights**
[![PLG07](img/img07.png)](img/img07.png)

> **The player can fight and use items in combat**
[![PLG06](img/img06.png)](img/img06.png)
4 changes: 4 additions & 0 deletions Westwick Beta.gmx/Westwick Beta.project.gmx
Expand Up @@ -243,9 +243,13 @@
<script>scripts\battle_idle_state.gml</script>
<script>scripts\battle_approach_state.gml</script>
<script>scripts\battle_use_item_state.gml</script>
<script>scripts\battle_wait_state.gml</script>
<script>scripts\battle_hit_state.gml</script>
<script>scripts\battle_death_state.gml</script>
</scripts>
<script>scripts\get_stats_from_class.gml</script>
<script>scripts\calculate_health.gml</script>
<script>scripts\set_hitflash.gml</script>
</scripts>
<script>scripts\battle_set_sprite.gml</script>
</scripts>
Expand Down
29 changes: 29 additions & 0 deletions Westwick Beta.gmx/objects/o_battle.object.gmx
Expand Up @@ -26,6 +26,35 @@
<argument>
<kind>1</kind>
<string>play = true;
</string>
</argument>
</arguments>
</action>
</event>
<event eventtype="3" enumb="0">
<action>
<libid>1</libid>
<id>603</id>
<kind>7</kind>
<userelative>0</userelative>
<isquestion>0</isquestion>
<useapplyto>-1</useapplyto>
<exetype>2</exetype>
<functionname></functionname>
<codestring></codestring>
<whoName>self</whoName>
<relative>0</relative>
<isnot>0</isnot>
<arguments>
<argument>
<kind>1</kind>
<string>/// check for play
if (instance_exists(o_player_battle_unit) &amp;&amp; instance_exists(o_enemy_battle_unit)){
if (o_player_battle_unit.state == battle_wait_state &amp;&amp; o_enemy_battle_unit.state = battle_wait_state) {
with (o_battle_unit) state = battle_idle_state;
play = true;
}
}
</string>
</argument>
</arguments>
Expand Down
58 changes: 58 additions & 0 deletions Westwick Beta.gmx/objects/o_battle_unit.object.gmx
Expand Up @@ -29,6 +29,7 @@
action_meter = 0;
max_action_meter = 100;
item_index = 0;
hitflash = false;

// Set up the state
state = battle_idle_state;
Expand Down Expand Up @@ -72,6 +73,30 @@ if (object_index == o_enemy_battle_unit) {
// Stop the play and view stats
o_battle.play = false;
o_battle_view.state = battle_view_idle_state;
</string>
</argument>
</arguments>
</action>
</event>
<event eventtype="2" enumb="0">
<action>
<libid>1</libid>
<id>603</id>
<kind>7</kind>
<userelative>0</userelative>
<isquestion>0</isquestion>
<useapplyto>-1</useapplyto>
<exetype>2</exetype>
<functionname></functionname>
<codestring></codestring>
<whoName>self</whoName>
<relative>0</relative>
<isnot>0</isnot>
<arguments>
<argument>
<kind>1</kind>
<string>/// Set hitflash to false
hitflash = false;
</string>
</argument>
</arguments>
Expand Down Expand Up @@ -127,6 +152,39 @@ with (stats_object) {
<kind>1</kind>
<string>/// Execute the current state
script_execute(state);
</string>
</argument>
</arguments>
</action>
</event>
<event eventtype="8" enumb="0">
<action>
<libid>1</libid>
<id>603</id>
<kind>7</kind>
<userelative>0</userelative>
<isquestion>0</isquestion>
<useapplyto>-1</useapplyto>
<exetype>2</exetype>
<functionname></functionname>
<codestring></codestring>
<whoName>self</whoName>
<relative>0</relative>
<isnot>0</isnot>
<arguments>
<argument>
<kind>1</kind>
<string>/// Draw the character
draw_self();
if (hitflash) {
draw_set_blend_mode(bm_add);
d3d_set_fog(true, c_red, 0, 0);
draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, image_angle, image_blend, .75*image_alpha);
d3d_set_fog(true, c_yellow, 0, 0);
draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, image_angle, image_blend, .25*image_alpha);
d3d_set_fog(false, c_white, 0, 0);
draw_set_blend_mode(bm_normal);
}
</string>
</argument>
</arguments>
Expand Down
3 changes: 2 additions & 1 deletion Westwick Beta.gmx/scripts/battle_attack_state.gml
Expand Up @@ -6,7 +6,8 @@ if (animation_hit_frame(1)) {
var foe = instance_place(x+32 * image_xscale, y, o_battle_unit);
if (foe) {
deal_damage(id, foe, chance(stats_object.stats[? "critical"]/100), 1);
state = battle_return_state;
set_hitflash(foe, room_speed/2);
foe.state = battle_hit_state;
}
}

Expand Down
8 changes: 8 additions & 0 deletions Westwick Beta.gmx/scripts/battle_death_state.gml
@@ -0,0 +1,8 @@
/// battle_death_state
image_speed = 0;
hitflash = true;
if (image_alpha > 0) {
image_alpha -= .04;
} else {
instance_destroy();
}
17 changes: 17 additions & 0 deletions Westwick Beta.gmx/scripts/battle_hit_state.gml
@@ -0,0 +1,17 @@
/// battle_hit_state
battle_set_sprite(HIT, 0);

// Move the player based on the position in the animation
var input = (image_index/image_number) * pi;
x = xstart-sin(input) * 32 * image_xscale;

// check for death
if (x - xstart > 24 && stats_object.stats[? "health"] <= 0) {
state = battle_death_state;
}

// return to the wait state
if (animation_end()) {
state = battle_wait_state;
x = xstart;
}
2 changes: 1 addition & 1 deletion Westwick Beta.gmx/scripts/battle_return_state.gml
Expand Up @@ -9,6 +9,6 @@ image_speed = get_image_speed_from_frames(frames, image_number);

x = approach(x, targetx, spd);
if (x == targetx) {
state = battle_idle_state;
state = battle_wait_state;
o_battle.play = true;
}
4 changes: 2 additions & 2 deletions Westwick Beta.gmx/scripts/battle_use_item_state.gml
@@ -1,7 +1,7 @@
///battle_use_item_state()
// enemies can't use items
if (object_index != o_player_battle_unit) {
state = battle_idle_state;
state = battle_wait_state;
exit;
}

Expand All @@ -16,6 +16,6 @@ if (animation_hit_frame(5)) {
// return to the idle state
if (animation_end()) {
with (o_battle_unit) {
state = battle_idle_state;
state = battle_wait_state;
}
}
3 changes: 3 additions & 0 deletions Westwick Beta.gmx/scripts/battle_wait_state.gml
@@ -0,0 +1,3 @@
///battle_wait_state
battle_set_sprite(IDLE, 0);
depth = 0;
7 changes: 7 additions & 0 deletions Westwick Beta.gmx/scripts/set_hitflash.gml
@@ -0,0 +1,7 @@
///set_hitflash(target, duration)
var target = argument0;
var duration = argument1;
with (target) {
hitflash = true;
alarm[0] = duration;
}
Binary file modified img/img06.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/img07.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1a15b5a

Please sign in to comment.