Advertisement
Guest User

Untitled

a guest
Feb 27th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Animation example using sprite image indexes to handle animation transitions
  2. // NB Every image has to be same size to use this approach. Else sprite_index is more suiting
  3. // -- Due to free license of GM2 the number of sprites available in project is limited.
  4. // -- Therefore we use this approach.
  5.  
  6.  
  7. // Check if should play death animation
  8. if (Health <= 0 && !isDead) {
  9.     alarm[0] = 5 * room_speed // Alarm for handling gameover
  10.     image_index = 30
  11.     isDead = true
  12.     isHit = false
  13.     isAttacking = false
  14.     isJumping = false
  15. }
  16.  
  17. // Check if death animation ended
  18. if (isDead && image_index >= 34) {
  19.     image_speed = 0
  20.     hsp = 0
  21. }
  22.  
  23. // Reset isHit when hit animation has ended
  24. if (isHit && image_index > 30) {
  25.     image_index = 0
  26.     isHit = false
  27.     hsp = 0
  28. }
  29.  
  30. // Reset isAttacking when animation has ended
  31. if (isAttacking && !isHit && image_index >= 25) {
  32.     //image_speed = 0
  33.     isAttacking = false
  34.     image_index = 0;
  35.     image_speed = movement_speed / 3
  36.     //alarm[2] = 0.2 * room_speed
  37. }
  38.  
  39. // Reset isJumping when animation has ended
  40. if (isJumping && !isAttacking && !isHit && image_index > 20) {
  41.     image_index = 0
  42.     isJumping = false
  43. }
  44.  
  45. // Flip image on sprite, depending on looking direction
  46. if (!isHit && !isAttacking) {
  47.     if (hsp < 0) {
  48.         image_xscale = -scale_x;
  49.     } else if (hsp > 0) {
  50.         image_xscale = scale_x;
  51.     }
  52. }
  53.  
  54.  
  55. // If we are not attacking, taking damage, or dead
  56. if (!isAttacking && !isHit && !isDead && !isJumping) {
  57.     // Check for attack input // Animate attack
  58.     if (keyboard_check(vk_space) && canAttack) {
  59.         image_index = 20
  60.         image_speed = 1 + (1 - atk_speed)
  61.         isAttacking = true
  62.         hasHit = false
  63.         canAttack = false
  64.         alarm[1] = atk_speed * room_speed
  65.     }
  66.     else {
  67.         // Do walk/run animations
  68.         if (hsp != 0) {
  69.             if (keyboard_check(vk_shift)) {
  70.                 if (image_index < 10 || image_index >= 15)
  71.                     image_index = 10
  72.             } else if (image_index < 5 || image_index >= 10) {
  73.                 image_index = 5
  74.             }
  75.         }
  76.         // Do idle animations
  77.         else {
  78.             if (image_index >= 5) {
  79.                 image_index = 0
  80.             }
  81.         }
  82.     }
  83. }
  84.  
  85. // Move by input if not dead or taking damage
  86. if (!isDead && !isHit) {
  87.     // Horizontal movement
  88.     var input = keyboard_check(ord("D")) - keyboard_check(ord("A"))
  89.     if ((input != 0 && jump_current < jump_number) || jump_current == jump_number) {
  90.         hsp = input
  91.         hsp *= movement_speed;
  92.         if (keyboard_check(vk_shift)) {
  93.             hsp *= run_speed;
  94.         }
  95.     }
  96.     // Vertical movement
  97.     if(keyboard_check_pressed(ord("W")) && jump_current > 0){
  98.         if (jump_current != jump_number) {
  99.             vsp = -jump_force * 1
  100.         }
  101.         else vsp = -jump_force;
  102.         jump_current--;
  103.         isJumping = true
  104.         isAttacking = false
  105.         image_index = 15
  106.         image_speed = movement_speed / 3
  107.     }
  108. } else if (!isHit && !isDead) {
  109.     hsp = 0;
  110. }
  111.  
  112. var bbox_side
  113.  
  114. // Horizontal tile colission check
  115. if (hsp > 0) bbox_side = bbox_right else bbox_side = bbox_left
  116. if  (tilemap_get_at_pixel(tilemap, bbox_side + hsp, bbox_top + 1) != 0) ||
  117.     (tilemap_get_at_pixel(tilemap, bbox_side + hsp, bbox_bottom - 1) != 0) ||
  118.     (tilemap_get_at_pixel(tilemap, bbox_side + hsp, y) != 0) {
  119.     if (hsp > 0) x = x - x % 128 + 127 - (bbox_right - x)
  120.     else x = x - x % 128 - (bbox_left - x)
  121.     hsp = 0
  122. }
  123. x += hsp
  124.  
  125. // Vertical tile colission check
  126. vsp += grav;
  127. if (vsp > 0) bbox_side = bbox_bottom else bbox_side = bbox_top
  128. if  (tilemap_get_at_pixel(tilemap, bbox_left + 1, bbox_side + vsp) != 0) ||
  129.     (tilemap_get_at_pixel(tilemap, bbox_right - 1, bbox_side + vsp) != 0) ||
  130.     (tilemap_get_at_pixel(tilemap, x, bbox_side + vsp) != 0) {
  131.     if (vsp > 0) {  y =  y - y % 128 + 127 - (bbox_bottom - y)
  132.                     jump_current = jump_number}
  133.     else y = y - y % 128 - (bbox_top - y)
  134.     vsp = 0
  135. }
  136.  
  137. y += vsp
  138.  
  139.  
  140. //// Handle colliding with solid ground
  141. //if(place_meeting(x, y + vsp, obj_Ground))
  142. //{
  143. //    while(!place_meeting(x, y + sign(vsp), obj_Ground))
  144. //    {
  145. //        y += sign(vsp);
  146. //    }
  147. //    if(vsp > 0)
  148. //    {
  149. //        jump_current = jump_number;
  150. //    }
  151. //    vsp = 0;
  152. //}
  153.  
  154. //
  155.  
  156. if (Experience >= ToNextLevel) {
  157.     Level++
  158.     StatPoints += 5
  159.     MaxHealth = 5 * Level * Vitality
  160.     Health = MaxHealth
  161.     ToNextLevel = Experience + 100 * (power(2, Level) - 1)
  162.     show_debug_message("Level up!")
  163.     show_debug_message("Level: " + string(Level))
  164.     show_debug_message("Health: " + string(Health) + "/" + string(MaxHealth))
  165.     show_debug_message("Unspend stat points: " + string(StatPoints))
  166.     show_debug_message("Exp to next level: " + string(ToNextLevel))
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement