Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Animation example using sprite image indexes to handle animation transitions
- // NB Every image has to be same size to use this approach. Else sprite_index is more suiting
- // -- Due to free license of GM2 the number of sprites available in project is limited.
- // -- Therefore we use this approach.
- // Check if should play death animation
- if (Health <= 0 && !isDead) {
- alarm[0] = 5 * room_speed // Alarm for handling gameover
- image_index = 30
- isDead = true
- isHit = false
- isAttacking = false
- isJumping = false
- }
- // Check if death animation ended
- if (isDead && image_index >= 34) {
- image_speed = 0
- hsp = 0
- }
- // Reset isHit when hit animation has ended
- if (isHit && image_index > 30) {
- image_index = 0
- isHit = false
- hsp = 0
- }
- // Reset isAttacking when animation has ended
- if (isAttacking && !isHit && image_index >= 25) {
- //image_speed = 0
- isAttacking = false
- image_index = 0;
- image_speed = movement_speed / 3
- //alarm[2] = 0.2 * room_speed
- }
- // Reset isJumping when animation has ended
- if (isJumping && !isAttacking && !isHit && image_index > 20) {
- image_index = 0
- isJumping = false
- }
- // Flip image on sprite, depending on looking direction
- if (!isHit && !isAttacking) {
- if (hsp < 0) {
- image_xscale = -scale_x;
- } else if (hsp > 0) {
- image_xscale = scale_x;
- }
- }
- // If we are not attacking, taking damage, or dead
- if (!isAttacking && !isHit && !isDead && !isJumping) {
- // Check for attack input // Animate attack
- if (keyboard_check(vk_space) && canAttack) {
- image_index = 20
- image_speed = 1 + (1 - atk_speed)
- isAttacking = true
- hasHit = false
- canAttack = false
- alarm[1] = atk_speed * room_speed
- }
- else {
- // Do walk/run animations
- if (hsp != 0) {
- if (keyboard_check(vk_shift)) {
- if (image_index < 10 || image_index >= 15)
- image_index = 10
- } else if (image_index < 5 || image_index >= 10) {
- image_index = 5
- }
- }
- // Do idle animations
- else {
- if (image_index >= 5) {
- image_index = 0
- }
- }
- }
- }
- // Move by input if not dead or taking damage
- if (!isDead && !isHit) {
- // Horizontal movement
- var input = keyboard_check(ord("D")) - keyboard_check(ord("A"))
- if ((input != 0 && jump_current < jump_number) || jump_current == jump_number) {
- hsp = input
- hsp *= movement_speed;
- if (keyboard_check(vk_shift)) {
- hsp *= run_speed;
- }
- }
- // Vertical movement
- if(keyboard_check_pressed(ord("W")) && jump_current > 0){
- if (jump_current != jump_number) {
- vsp = -jump_force * 1
- }
- else vsp = -jump_force;
- jump_current--;
- isJumping = true
- isAttacking = false
- image_index = 15
- image_speed = movement_speed / 3
- }
- } else if (!isHit && !isDead) {
- hsp = 0;
- }
- var bbox_side
- // Horizontal tile colission check
- if (hsp > 0) bbox_side = bbox_right else bbox_side = bbox_left
- if (tilemap_get_at_pixel(tilemap, bbox_side + hsp, bbox_top + 1) != 0) ||
- (tilemap_get_at_pixel(tilemap, bbox_side + hsp, bbox_bottom - 1) != 0) ||
- (tilemap_get_at_pixel(tilemap, bbox_side + hsp, y) != 0) {
- if (hsp > 0) x = x - x % 128 + 127 - (bbox_right - x)
- else x = x - x % 128 - (bbox_left - x)
- hsp = 0
- }
- x += hsp
- // Vertical tile colission check
- vsp += grav;
- if (vsp > 0) bbox_side = bbox_bottom else bbox_side = bbox_top
- if (tilemap_get_at_pixel(tilemap, bbox_left + 1, bbox_side + vsp) != 0) ||
- (tilemap_get_at_pixel(tilemap, bbox_right - 1, bbox_side + vsp) != 0) ||
- (tilemap_get_at_pixel(tilemap, x, bbox_side + vsp) != 0) {
- if (vsp > 0) { y = y - y % 128 + 127 - (bbox_bottom - y)
- jump_current = jump_number}
- else y = y - y % 128 - (bbox_top - y)
- vsp = 0
- }
- y += vsp
- //// Handle colliding with solid ground
- //if(place_meeting(x, y + vsp, obj_Ground))
- //{
- // while(!place_meeting(x, y + sign(vsp), obj_Ground))
- // {
- // y += sign(vsp);
- // }
- // if(vsp > 0)
- // {
- // jump_current = jump_number;
- // }
- // vsp = 0;
- //}
- //
- if (Experience >= ToNextLevel) {
- Level++
- StatPoints += 5
- MaxHealth = 5 * Level * Vitality
- Health = MaxHealth
- ToNextLevel = Experience + 100 * (power(2, Level) - 1)
- show_debug_message("Level up!")
- show_debug_message("Level: " + string(Level))
- show_debug_message("Health: " + string(Health) + "/" + string(MaxHealth))
- show_debug_message("Unspend stat points: " + string(StatPoints))
- show_debug_message("Exp to next level: " + string(ToNextLevel))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement