Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. // Cole Anderson
  2. // 4/22/17
  3. // ETEC-2110
  4. // Assignment 8 - Program 1
  5. // Yost
  6.  
  7. #include <SDL2/SDL.h>
  8. #include <stdio.h>
  9. //Screen dimension constants
  10. int SCREEN_WIDTH = 800;
  11. int SCREEN_HEIGHT = 600;
  12.  
  13. struct BLOCKHEAD_NODE
  14. {
  15. float x,y; // position
  16. float dx,dy; // movement component
  17. long color;
  18. int size;
  19. struct BLOCKHEAD_NODE * next;
  20. };
  21.  
  22.  
  23. void renderBlockHead(struct BLOCKHEAD_NODE * blockhead, SDL_Renderer *renderer)
  24. {
  25.  
  26. // if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) {
  27. // Uint32 SDL_GetMouseState(int* x,int* y);
  28. // printf("%f %f %i", blockhead->x, blockhead->y, blockhead->size);
  29. SDL_Rect fillRect = { (int)blockhead->x, (int)blockhead->y, 10, 10};
  30.  
  31. SDL_SetRenderDrawColor( renderer, 0, blockhead->color, 0, 0);
  32. SDL_RenderFillRect( renderer, &fillRect );
  33. // }
  34.  
  35. //this function should draw the blockhead according that is appropriate for the structure elements.
  36. }
  37. void moveBlockHead(struct BLOCKHEAD_NODE * blockhead, float elapsed)
  38. {
  39. //this function should use the displacement vector to move the blockhead to a new position..
  40. //Be sure to handle bouncing off of the window borders.
  41. //bottom case:
  42. if((int)blockhead->y+blockhead->size>=SCREEN_HEIGHT && blockhead->dy>=0){blockhead->dy*=-1;printf("bounce\n");} // bottom border - done
  43. if((int)blockhead->x+blockhead->size>=SCREEN_WIDTH && blockhead->dx<=800){blockhead->dx*=-1;printf("bounce\n");} // right border - done
  44. if((int)blockhead->y-blockhead->size>=SCREEN_HEIGHT && blockhead->dy>=600){blockhead->dy*=-1;printf("bounce\n");} // top border
  45. // if((int)blockhead->x-blockhead->size>=SCREEN_WIDTH && blockhead->dx<=0){blockhead->dx*=-1;printf("bounce\n");} // left border
  46. blockhead->x += blockhead->dx*elapsed;
  47. blockhead->y += blockhead->dy*elapsed;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement