Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Cole Anderson
- // 4/22/17
- // ETEC-2110
- // Assignment 8 - Program 1
- // Yost
- #include <SDL2/SDL.h>
- #include <stdio.h>
- //Screen dimension constants
- int SCREEN_WIDTH = 800;
- int SCREEN_HEIGHT = 600;
- struct BLOCKHEAD_NODE
- {
- float x,y; // position
- float dx,dy; // movement component
- long color;
- int size;
- struct BLOCKHEAD_NODE * next;
- };
- void renderBlockHead(struct BLOCKHEAD_NODE * blockhead, SDL_Renderer *renderer)
- {
- // if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) {
- // Uint32 SDL_GetMouseState(int* x,int* y);
- // printf("%f %f %i", blockhead->x, blockhead->y, blockhead->size);
- SDL_Rect fillRect = { (int)blockhead->x, (int)blockhead->y, 10, 10};
- SDL_SetRenderDrawColor( renderer, 0, blockhead->color, 0, 0);
- SDL_RenderFillRect( renderer, &fillRect );
- // }
- //this function should draw the blockhead according that is appropriate for the structure elements.
- }
- void moveBlockHead(struct BLOCKHEAD_NODE * blockhead, float elapsed)
- {
- //this function should use the displacement vector to move the blockhead to a new position..
- //Be sure to handle bouncing off of the window borders.
- //bottom case:
- if((int)blockhead->y+blockhead->size>=SCREEN_HEIGHT && blockhead->dy>=0){blockhead->dy*=-1;printf("bounce\n");} // bottom border - done
- if((int)blockhead->x+blockhead->size>=SCREEN_WIDTH && blockhead->dx<=800){blockhead->dx*=-1;printf("bounce\n");} // right border - done
- if((int)blockhead->y-blockhead->size>=SCREEN_HEIGHT && blockhead->dy>=600){blockhead->dy*=-1;printf("bounce\n");} // top border
- // if((int)blockhead->x-blockhead->size>=SCREEN_WIDTH && blockhead->dx<=0){blockhead->dx*=-1;printf("bounce\n");} // left border
- blockhead->x += blockhead->dx*elapsed;
- blockhead->y += blockhead->dy*elapsed;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement