Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void UpdatePlayer()
- {
- if (player.state == "waiting")
- {
- string dpad = "";
- if (keyboard.IsKeyDown(Keys.Up) || gamepad.IsButtonDown(Buttons.DPadUp)) dpad = "u";
- if (keyboard.IsKeyDown(Keys.Down) || gamepad.IsButtonDown(Buttons.DPadDown)) dpad = "d";
- if (keyboard.IsKeyDown(Keys.Left) || gamepad.IsButtonDown(Buttons.DPadLeft)) dpad = "l";
- if (keyboard.IsKeyDown(Keys.Right) || gamepad.IsButtonDown(Buttons.DPadRight)) dpad = "r";
- if (attackQueued ||
- (keyboard.IsKeyDown(Keys.X) && !lastKeyboard.IsKeyDown(Keys.X)) ||
- (gamepad.IsButtonDown(Buttons.A) && !lastGamepad.IsButtonDown(Buttons.A)))
- {
- if (dpad == "")
- {
- player.state = "swinging_sword";
- player.stateFrames = 0;
- sword = new Sprite();
- sword.state = "swinging";
- sword.dir = player.dir;
- sword.stateFrames = 0;
- attackQueued = false;
- goto PLAYER_SWINGING_SWORD;
- }
- else
- {
- player.state = "stabbing_sword";
- player.stateFrames = 0;
- sword = new Sprite();
- sword.state = "stabbing";
- sword.dir = player.dir;
- sword.stateFrames = 0;
- attackQueued = false;
- goto PLAYER_STABBING_SWORD;
- }
- }
- if (dpad != "")
- {
- player.state = "walking";
- player.stateFrames = 0;
- player.dir = dpad;
- }
- }
- if (player.state == "walking")
- {
- if (player.dir == "u") player.y--;
- if (player.dir == "d") player.y++;
- if (player.dir == "l") player.x--;
- if (player.dir == "r") player.x++;
- if ((keyboard.IsKeyDown(Keys.X) && !lastKeyboard.IsKeyDown(Keys.X)) ||
- (gamepad.IsButtonDown(Buttons.A) && !lastGamepad.IsButtonDown(Buttons.A))) attackQueued = true;
- int frame = 1;
- if (player.stateFrames >= 4) frame = 2;
- player.srcRect = "hero_walking_" + player.dir + frame;
- player.stateFrames++;
- if (player.stateFrames == 8)
- {
- player.state = "waiting";
- player.srcRect = "hero_walking_" + player.dir + "1";
- }
- return;
- }
- PLAYER_SWINGING_SWORD:
- if (player.state == "swinging_sword")
- {
- int frame = 1;
- if (player.stateFrames >= 8) frame = 2;
- player.srcRect = "hero_attacking_" + player.dir + frame;
- if (player.stateFrames == 16)
- {
- player.state = "waiting";
- player.srcRect = "hero_walking_" + player.dir + "1";
- }
- player.stateFrames++;
- return;
- }
- PLAYER_STABBING_SWORD:
- if (player.state == "stabbing_sword")
- {
- player.srcRect = "hero_attacking_" + player.dir + "2";
- if (player.stateFrames == 12)
- {
- player.state = "waiting";
- player.srcRect = "hero_walking_" + player.dir + "1";
- }
- player.stateFrames++;
- return;
- }
- }
- void UpdateSword()
- {
- if (sword.state == "swinging")
- {
- if (sword.dir == "u")
- {
- if (sword.stateFrames >= 0 && sword.stateFrames < 4)
- {
- sword.srcRect = "sword_se";
- sword.x = player.x + 16;
- sword.y = player.y + 10;
- }
- if (sword.stateFrames >= 4 && sword.stateFrames < 8)
- {
- sword.srcRect = "sword_e";
- sword.x = player.x + 16;
- sword.y = player.y + 2;
- }
- if (sword.stateFrames >= 8 && sword.stateFrames < 12)
- {
- sword.srcRect = "sword_ne";
- sword.x = player.x + 10;
- sword.y = player.y - 10;
- }
- if (sword.stateFrames >= 12 && sword.stateFrames < 16)
- {
- sword.srcRect = "sword_n";
- sword.x = player.x;
- sword.y = player.y - 16;
- }
- }
- if (sword.dir == "d")
- {
- if (sword.stateFrames >= 0 && sword.stateFrames < 4)
- {
- sword.srcRect = "sword_nw";
- sword.x = player.x - 14;
- sword.y = player.y - 9;
- }
- if (sword.stateFrames >= 4 && sword.stateFrames < 8)
- {
- sword.srcRect = "sword_w";
- sword.x = player.x - 16;
- sword.y = player.y;
- }
- if (sword.stateFrames >= 8 && sword.stateFrames < 12)
- {
- sword.srcRect = "sword_sw";
- sword.x = player.x - 11;
- sword.y = player.y + 12;
- }
- if (sword.stateFrames >= 12 && sword.stateFrames < 16)
- {
- sword.srcRect = "sword_s";
- sword.x = player.x;
- sword.y = player.y + 16;
- }
- }
- if (sword.dir == "l")
- {
- if (sword.stateFrames >= 0 && sword.stateFrames < 4)
- {
- sword.srcRect = "sword_ne";
- sword.x = player.x + 10;
- sword.y = player.y - 8;
- }
- if (sword.stateFrames >= 4 && sword.stateFrames < 8)
- {
- sword.srcRect = "sword_n";
- sword.x = player.x;
- sword.y = player.y - 11;
- }
- if (sword.stateFrames >= 8 && sword.stateFrames < 12)
- {
- sword.srcRect = "sword_nw";
- sword.x = player.x - 14;
- sword.y = player.y - 5;
- }
- if (sword.stateFrames >= 12 && sword.stateFrames < 16)
- {
- sword.srcRect = "sword_w";
- sword.x = player.x - 16;
- sword.y = player.y + 3;
- }
- }
- if (sword.dir == "r")
- {
- if (sword.stateFrames >= 0 && sword.stateFrames < 4)
- {
- sword.srcRect = "sword_nw";
- sword.x = player.x - 10;
- sword.y = player.y - 8;
- }
- if (sword.stateFrames >= 4 && sword.stateFrames < 8)
- {
- sword.srcRect = "sword_n";
- sword.x = player.x;
- sword.y = player.y - 11;
- }
- if (sword.stateFrames >= 8 && sword.stateFrames < 12)
- {
- sword.srcRect = "sword_ne";
- sword.x = player.x + 14;
- sword.y = player.y - 5;
- }
- if (sword.stateFrames >= 12 && sword.stateFrames < 16)
- {
- sword.srcRect = "sword_e";
- sword.x = player.x + 16;
- sword.y = player.y + 3;
- }
- }
- if (sword.stateFrames == 16)
- {
- sword = null;
- return;
- }
- sword.stateFrames++;
- }
- if (sword.state == "stabbing")
- {
- if (sword.dir == "u")
- {
- sword.srcRect = "sword_n";
- if (sword.stateFrames >= 0 && sword.stateFrames < 4)
- {
- sword.x = player.x + 2;
- sword.y = player.y - 8;
- }
- if (sword.stateFrames >= 6 && sword.stateFrames < 9)
- {
- sword.x = player.x + 2;
- sword.y = player.y - 16;
- }
- if (sword.stateFrames >= 10 && sword.stateFrames < 13)
- {
- sword.x = player.x + 2;
- sword.y = player.y - 8;
- }
- }
- if (sword.dir == "d")
- {
- sword.srcRect = "sword_s";
- if (sword.stateFrames >= 0 && sword.stateFrames < 4)
- {
- sword.x = player.x - 2;
- sword.y = player.y + 8;
- }
- if (sword.stateFrames >= 6 && sword.stateFrames < 9)
- {
- sword.x = player.x - 2;
- sword.y = player.y + 16;
- }
- if (sword.stateFrames >= 10 && sword.stateFrames < 13)
- {
- sword.x = player.x - 2;
- sword.y = player.y + 8;
- }
- }
- if (sword.dir == "l")
- {
- sword.srcRect = "sword_w";
- if (sword.stateFrames >= 0 && sword.stateFrames < 4)
- {
- sword.x = player.x - 8;
- sword.y = player.y + 3;
- }
- if (sword.stateFrames >= 6 && sword.stateFrames < 9)
- {
- sword.x = player.x - 16;
- sword.y = player.y + 3;
- }
- if (sword.stateFrames >= 10 && sword.stateFrames < 13)
- {
- sword.x = player.x - 8;
- sword.y = player.y + 3;
- }
- }
- if (sword.dir == "r")
- {
- sword.srcRect = "sword_e";
- if (sword.stateFrames >= 0 && sword.stateFrames < 4)
- {
- sword.x = player.x + 8;
- sword.y = player.y + 3;
- }
- if (sword.stateFrames >= 6 && sword.stateFrames < 9)
- {
- sword.x = player.x + 16;
- sword.y = player.y + 3;
- }
- if (sword.stateFrames >= 10 && sword.stateFrames < 13)
- {
- sword.x = player.x + 8;
- sword.y = player.y + 3;
- }
- }
- if (sword.stateFrames == 12)
- {
- sword = null;
- return;
- }
- sword.stateFrames++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement