Advertisement
SteelGolem

Untitled

Jul 18th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.02 KB | None | 0 0
  1.         void UpdatePlayer()
  2.         {
  3.             if (player.state == "waiting")
  4.             {
  5.                 string dpad = "";
  6.                 if (keyboard.IsKeyDown(Keys.Up) || gamepad.IsButtonDown(Buttons.DPadUp)) dpad = "u";
  7.                 if (keyboard.IsKeyDown(Keys.Down) || gamepad.IsButtonDown(Buttons.DPadDown)) dpad = "d";
  8.                 if (keyboard.IsKeyDown(Keys.Left) || gamepad.IsButtonDown(Buttons.DPadLeft)) dpad = "l";
  9.                 if (keyboard.IsKeyDown(Keys.Right) || gamepad.IsButtonDown(Buttons.DPadRight)) dpad = "r";
  10.  
  11.                 if (attackQueued ||
  12.                     (keyboard.IsKeyDown(Keys.X) && !lastKeyboard.IsKeyDown(Keys.X)) ||
  13.                     (gamepad.IsButtonDown(Buttons.A) && !lastGamepad.IsButtonDown(Buttons.A)))
  14.                 {
  15.                     if (dpad == "")
  16.                     {
  17.                         player.state = "swinging_sword";
  18.                         player.stateFrames = 0;
  19.                         sword = new Sprite();
  20.                         sword.state = "swinging";
  21.                         sword.dir = player.dir;
  22.                         sword.stateFrames = 0;
  23.                         attackQueued = false;
  24.                         goto PLAYER_SWINGING_SWORD;
  25.                     }
  26.                     else
  27.                     {
  28.                         player.state = "stabbing_sword";
  29.                         player.stateFrames = 0;
  30.                         sword = new Sprite();
  31.                         sword.state = "stabbing";
  32.                         sword.dir = player.dir;
  33.                         sword.stateFrames = 0;
  34.                         attackQueued = false;
  35.                         goto PLAYER_STABBING_SWORD;
  36.                     }
  37.                 }
  38.  
  39.                 if (dpad != "")
  40.                 {
  41.                     player.state = "walking";
  42.                     player.stateFrames = 0;
  43.                     player.dir = dpad;
  44.                 }
  45.             }
  46.  
  47.             if (player.state == "walking")
  48.             {
  49.                 if (player.dir == "u") player.y--;
  50.                 if (player.dir == "d") player.y++;
  51.                 if (player.dir == "l") player.x--;
  52.                 if (player.dir == "r") player.x++;
  53.                 if ((keyboard.IsKeyDown(Keys.X) && !lastKeyboard.IsKeyDown(Keys.X)) ||
  54.                     (gamepad.IsButtonDown(Buttons.A) && !lastGamepad.IsButtonDown(Buttons.A))) attackQueued = true;
  55.                 int frame = 1;
  56.                 if (player.stateFrames >= 4) frame = 2;
  57.                 player.srcRect = "hero_walking_" + player.dir + frame;
  58.                 player.stateFrames++;
  59.                 if (player.stateFrames == 8)
  60.                 {
  61.                     player.state = "waiting";
  62.                     player.srcRect = "hero_walking_" + player.dir + "1";
  63.                 }
  64.                 return;
  65.             }
  66.  
  67.             PLAYER_SWINGING_SWORD:
  68.             if (player.state == "swinging_sword")
  69.             {
  70.                 int frame = 1;
  71.                 if (player.stateFrames >= 8) frame = 2;
  72.                 player.srcRect = "hero_attacking_" + player.dir + frame;
  73.                 if (player.stateFrames == 16)
  74.                 {
  75.                     player.state = "waiting";
  76.                     player.srcRect = "hero_walking_" + player.dir + "1";
  77.                 }
  78.                 player.stateFrames++;
  79.                 return;
  80.             }
  81.  
  82.             PLAYER_STABBING_SWORD:
  83.             if (player.state == "stabbing_sword")
  84.             {
  85.                 player.srcRect = "hero_attacking_" + player.dir + "2";
  86.                 if (player.stateFrames == 12)
  87.                 {
  88.                     player.state = "waiting";
  89.                     player.srcRect = "hero_walking_" + player.dir + "1";
  90.                 }
  91.                 player.stateFrames++;
  92.                 return;
  93.             }
  94.         }
  95.  
  96.         void UpdateSword()
  97.         {
  98.             if (sword.state == "swinging")
  99.             {
  100.                 if (sword.dir == "u")
  101.                 {
  102.                     if (sword.stateFrames >= 0 && sword.stateFrames < 4)
  103.                     {
  104.                         sword.srcRect = "sword_se";
  105.                         sword.x = player.x + 16;
  106.                         sword.y = player.y + 10;
  107.                     }
  108.                     if (sword.stateFrames >= 4 && sword.stateFrames < 8)
  109.                     {
  110.                         sword.srcRect = "sword_e";
  111.                         sword.x = player.x + 16;
  112.                         sword.y = player.y + 2;
  113.                     }
  114.                     if (sword.stateFrames >= 8 && sword.stateFrames < 12)
  115.                     {
  116.                         sword.srcRect = "sword_ne";
  117.                         sword.x = player.x + 10;
  118.                         sword.y = player.y - 10;
  119.                     }
  120.                     if (sword.stateFrames >= 12 && sword.stateFrames < 16)
  121.                     {
  122.                         sword.srcRect = "sword_n";
  123.                         sword.x = player.x;
  124.                         sword.y = player.y - 16;
  125.                     }
  126.                 }
  127.                 if (sword.dir == "d")
  128.                 {
  129.                     if (sword.stateFrames >= 0 && sword.stateFrames < 4)
  130.                     {
  131.                         sword.srcRect = "sword_nw";
  132.                         sword.x = player.x - 14;
  133.                         sword.y = player.y - 9;
  134.                     }
  135.                     if (sword.stateFrames >= 4 && sword.stateFrames < 8)
  136.                     {
  137.                         sword.srcRect = "sword_w";
  138.                         sword.x = player.x - 16;
  139.                         sword.y = player.y;
  140.                     }
  141.                     if (sword.stateFrames >= 8 && sword.stateFrames < 12)
  142.                     {
  143.                         sword.srcRect = "sword_sw";
  144.                         sword.x = player.x - 11;
  145.                         sword.y = player.y + 12;
  146.                     }
  147.                     if (sword.stateFrames >= 12 && sword.stateFrames < 16)
  148.                     {
  149.                         sword.srcRect = "sword_s";
  150.                         sword.x = player.x;
  151.                         sword.y = player.y + 16;
  152.                     }
  153.                 }
  154.                 if (sword.dir == "l")
  155.                 {
  156.                     if (sword.stateFrames >= 0 && sword.stateFrames < 4)
  157.                     {
  158.                         sword.srcRect = "sword_ne";
  159.                         sword.x = player.x + 10;
  160.                         sword.y = player.y - 8;
  161.                     }
  162.                     if (sword.stateFrames >= 4 && sword.stateFrames < 8)
  163.                     {
  164.                         sword.srcRect = "sword_n";
  165.                         sword.x = player.x;
  166.                         sword.y = player.y - 11;
  167.                     }
  168.                     if (sword.stateFrames >= 8 && sword.stateFrames < 12)
  169.                     {
  170.                         sword.srcRect = "sword_nw";
  171.                         sword.x = player.x - 14;
  172.                         sword.y = player.y - 5;
  173.                     }
  174.                     if (sword.stateFrames >= 12 && sword.stateFrames < 16)
  175.                     {
  176.                         sword.srcRect = "sword_w";
  177.                         sword.x = player.x - 16;
  178.                         sword.y = player.y + 3;
  179.                     }
  180.                 }
  181.                 if (sword.dir == "r")
  182.                 {
  183.                     if (sword.stateFrames >= 0 && sword.stateFrames < 4)
  184.                     {
  185.                         sword.srcRect = "sword_nw";
  186.                         sword.x = player.x - 10;
  187.                         sword.y = player.y - 8;
  188.                     }
  189.                     if (sword.stateFrames >= 4 && sword.stateFrames < 8)
  190.                     {
  191.                         sword.srcRect = "sword_n";
  192.                         sword.x = player.x;
  193.                         sword.y = player.y - 11;
  194.                     }
  195.                     if (sword.stateFrames >= 8 && sword.stateFrames < 12)
  196.                     {
  197.                         sword.srcRect = "sword_ne";
  198.                         sword.x = player.x + 14;
  199.                         sword.y = player.y - 5;
  200.                     }
  201.                     if (sword.stateFrames >= 12 && sword.stateFrames < 16)
  202.                     {
  203.                         sword.srcRect = "sword_e";
  204.                         sword.x = player.x + 16;
  205.                         sword.y = player.y + 3;
  206.                     }
  207.                 }
  208.  
  209.                 if (sword.stateFrames == 16)
  210.                 {
  211.                     sword = null;
  212.                     return;
  213.                 }
  214.                
  215.                 sword.stateFrames++;
  216.             }
  217.  
  218.             if (sword.state == "stabbing")
  219.             {
  220.                 if (sword.dir == "u")
  221.                 {
  222.                     sword.srcRect = "sword_n";
  223.                     if (sword.stateFrames >= 0 && sword.stateFrames < 4)
  224.                     {
  225.                         sword.x = player.x + 2;
  226.                         sword.y = player.y - 8;
  227.                     }
  228.                     if (sword.stateFrames >= 6 && sword.stateFrames < 9)
  229.                     {
  230.                         sword.x = player.x + 2;
  231.                         sword.y = player.y - 16;
  232.                     }
  233.                     if (sword.stateFrames >= 10 && sword.stateFrames < 13)
  234.                     {
  235.                         sword.x = player.x + 2;
  236.                         sword.y = player.y - 8;
  237.                     }
  238.                 }
  239.                 if (sword.dir == "d")
  240.                 {
  241.                     sword.srcRect = "sword_s";
  242.                     if (sword.stateFrames >= 0 && sword.stateFrames < 4)
  243.                     {
  244.                         sword.x = player.x - 2;
  245.                         sword.y = player.y + 8;
  246.                     }
  247.                     if (sword.stateFrames >= 6 && sword.stateFrames < 9)
  248.                     {
  249.                         sword.x = player.x - 2;
  250.                         sword.y = player.y + 16;
  251.                     }
  252.                     if (sword.stateFrames >= 10 && sword.stateFrames < 13)
  253.                     {
  254.                         sword.x = player.x - 2;
  255.                         sword.y = player.y + 8;
  256.                     }
  257.                 }
  258.                 if (sword.dir == "l")
  259.                 {
  260.                     sword.srcRect = "sword_w";
  261.                     if (sword.stateFrames >= 0 && sword.stateFrames < 4)
  262.                     {
  263.                         sword.x = player.x - 8;
  264.                         sword.y = player.y + 3;
  265.                     }
  266.                     if (sword.stateFrames >= 6 && sword.stateFrames < 9)
  267.                     {
  268.                         sword.x = player.x - 16;
  269.                         sword.y = player.y + 3;
  270.                     }
  271.                     if (sword.stateFrames >= 10 && sword.stateFrames < 13)
  272.                     {
  273.                         sword.x = player.x - 8;
  274.                         sword.y = player.y + 3;
  275.                     }
  276.                 }
  277.                 if (sword.dir == "r")
  278.                 {
  279.                     sword.srcRect = "sword_e";
  280.                     if (sword.stateFrames >= 0 && sword.stateFrames < 4)
  281.                     {
  282.                         sword.x = player.x + 8;
  283.                         sword.y = player.y + 3;
  284.                     }
  285.                     if (sword.stateFrames >= 6 && sword.stateFrames < 9)
  286.                     {
  287.                         sword.x = player.x + 16;
  288.                         sword.y = player.y + 3;
  289.                     }
  290.                     if (sword.stateFrames >= 10 && sword.stateFrames < 13)
  291.                     {
  292.                         sword.x = player.x + 8;
  293.                         sword.y = player.y + 3;
  294.                     }
  295.                 }
  296.  
  297.                 if (sword.stateFrames == 12)
  298.                 {
  299.                     sword = null;
  300.                     return;
  301.                 }
  302.  
  303.                 sword.stateFrames++;
  304.             }
  305.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement