Guest User

Untitled

a guest
Nov 18th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. void update() {
  2.  
  3. // Physics
  4. survivor.y += world.gravity;
  5.  
  6. // Platform collision
  7. if (survivor.y + survivor.h > platform.y &&
  8. survivor.x + 48 >= platform.x &&
  9. survivor.x + survivor.w - 48 <= platform.x + platform.w &&
  10. survivor.y + (survivor.h/2) < platform.y) {
  11. survivor.y = platform.y - survivor.h;
  12. }
  13.  
  14. // Input processing
  15. const Uint8* keys = SDL_GetKeyboardState(NULL);
  16. if (survivor.state != "state_shoot") {
  17. if (keys[SDL_SCANCODE_D]) {
  18. survivor.x += survivor.speed;
  19. survivor.scaleX = 1;
  20. survivor.frameY = 1;
  21. survivor.state = "state_walk";
  22. } else if (keys[SDL_SCANCODE_A]) {
  23. survivor.x -= survivor.speed;
  24. survivor.scaleX = -1;
  25. survivor.frameY = 1;
  26. survivor.state = "state_walk";
  27. } else if (keys[SDL_SCANCODE_J]) {
  28. survivor.frameX = 0;
  29. survivor.frameY = 2;
  30. survivor.animCompleted = false;
  31. survivor.shot = false;
  32. survivor.state = "state_shoot";
  33. } else {
  34. survivor.frameX = 0;
  35. survivor.frameY = 0;
  36. survivor.state = "state_idle";
  37. }
  38. }
  39.  
  40. // Player states
  41. if (survivor.state == "state_shoot") {
  42.  
  43. if (survivor.frameX / survivor.animSpeed == 2 && !survivor.shot) {
  44. survivor.shot = true;
  45. shootBullet();
  46. }
  47.  
  48. if (survivor.animCompleted) {
  49. survivor.frameY = 0;
  50. survivor.state = "state_idle";
  51. }
  52. }
  53. }
Add Comment
Please, Sign In to add comment