Advertisement
mainland_china

Player Code

Dec 17th, 2023 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Game Maker 2.34 KB | Source Code | 0 0
  1. ~create
  2. xspd = 0;
  3. yspd = 0;
  4. walk_timer = 0;
  5. move_spd = 1
  6. frame_speed = 0.7;
  7. image_speed = 1;
  8.  
  9. flashlight = 25;
  10. flashlight_max = flashlight;
  11. flashlight_width = 295;
  12. flashlight_height = 100;
  13. flashlight_x = (1366/2) - (flashlight_width/2);
  14. flashlight_y = ystart - 100;
  15.  
  16. keys = 0;
  17.  
  18. image_angle_ = 0;
  19. audio_listener_orientation(0, 1, 0, 0, 0, 1);
  20.  
  21. depth = obj_player.depth - 1;
  22.  
  23. alarm[0] = 1;
  24.  
  25.  
  26. -------------
  27. ~step
  28. right_key = keyboard_check(ord("D"));
  29. left_key = keyboard_check(ord("A"));
  30. up_key = keyboard_check(ord("W"));
  31. down_key = keyboard_check(ord("S"));
  32.  
  33. if keyboard_check_pressed(vk_shift){
  34.     move_spd = 1.5;
  35.     frame_speed = 0.8;
  36.    
  37. }
  38. if keyboard_check_released(vk_shift){
  39.     move_spd = 1;
  40.     frame_speed = 0.7;
  41. }
  42. xspd = (right_key - left_key) * move_spd;
  43. yspd = (down_key - up_key) * move_spd;
  44.  
  45.  
  46. direction = point_direction(x, y, mouse_x, mouse_y);
  47. image_angle_ = direction;
  48.  
  49. //collision
  50. if place_meeting(x + xspd, y, obj_wall) == true {
  51.     xspd = 0;
  52. }
  53. if place_meeting(x, y + yspd, obj_wall) == true {
  54.     yspd = 0;
  55. }
  56.  
  57. x += xspd;
  58. y += yspd;
  59.  
  60. if (xprevious == x and yprevious == y){
  61.     image_speed = 0; walk_timer = 0;
  62. }
  63.  
  64. else{
  65.     image_speed = 1; walk_timer++;
  66. }
  67.  
  68. var target_x = x - cam_w()/2;
  69. var target_y = y - 150;
  70. var camX = lerp(cam_x(), target_x, .1);
  71. var camY = lerp(cam_y(), target_y, .1);
  72. cam_x = clamp(camX, 0, room_width-cam_w());
  73. cam_y = clamp(camY, 0, room_height-cam_h());
  74. cam_pos(camX, camY);
  75.  
  76. audio_listener_position(x, y, 0);
  77.  
  78. dist = point_distance(x, y, obj_enemy.x, obj_enemy.y);
  79.  
  80.  
  81. --------------------
  82. ~draw
  83.  
  84. if walk_timer > 5{
  85.     draw_sprite_ext(spr_legs, image_index, x + 0.01, y, image_xscale - 0.4, image_yscale - 0.3, image_angle_, image_blend, image_alpha);
  86.     image_index += frame_speed;
  87. }
  88. draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, image_angle_, image_blend, image_alpha);
  89.  
  90.  
  91. ---------------------
  92. ~draw gui
  93.  
  94. if instance_exists(obj_player){
  95.     for (i = 0; i < keys; i++){
  96.     draw_sprite_ext(spr_key, 0, 550 + (i*150), 600, 5, 5, 0, c_white, 1)
  97.     }
  98.    
  99.     draw_sprite(spr_fl_bg, 0, 500, flashlight_y);
  100.     draw_sprite_stretched(spr_fl_bar, 0, 500, flashlight_y, (flashlight/flashlight_max) * flashlight_width, flashlight_height);
  101.     draw_sprite(spr_fl_outline, 0, 500, flashlight_y);
  102. }
  103.  
  104.  
  105. --------------------
  106. ~alarm 0
  107. flashlight -= 1;
  108.  
  109.  
  110. alarm_set(0, 60);
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement