breakout

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit e95bd82deff056b86640f0815a6e20f56837432a
parent 4dc9ca85df53bd3f9f82c78e7db28f4651d03e58
Author: Christopher Ray Langford <chris@hellocld.com>
Date:   Sun, 25 Aug 2019 21:19:41 -0400

Error was caused by editing data_path inadvertantly

FUN FACT: strcat manipulates the source string provided

Diffstat:
Massets/gfx/ball.aseprite | 0
Massets/gfx/ball.bmp | 0
Msrc/main.c | 28++++++++++++++++++----------
3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/assets/gfx/ball.aseprite b/assets/gfx/ball.aseprite Binary files differ. diff --git a/assets/gfx/ball.bmp b/assets/gfx/ball.bmp Binary files differ. diff --git a/src/main.c b/src/main.c @@ -1,11 +1,12 @@ #include "SDL.h" +#include <stdlib.h> #define WINDOW_W 320 #define WINDOW_H 240 int CreateSprite(void); void MoveSprite(void); -void Quit(int); +void myquit(int); SDL_Window *window; SDL_Renderer *renderer; @@ -60,7 +61,7 @@ int main(int argc, char *argv[]) int temp; temp = CreateSprite(); if(temp != 0) { - Quit(temp); + myquit(temp); } SDL_Event event; @@ -71,25 +72,27 @@ int main(int argc, char *argv[]) if(event.type == SDL_QUIT) done = 1; MoveSprite(); - SDL_Delay(100); + SDL_Delay(10); } - Quit(0); + myquit(0); return 0; } -void Quit(int i) +void myquit(int i) { + SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); SDL_free(data_path); SDL_Quit(); - exit(i); } int CreateSprite() { SDL_Surface *temp; - char* path = strcat(data_path, "assets/gfx/ball.bmp"); + char path[1000]; + strcpy(path, data_path); + strcat(path, "assets/gfx/ball.bmp"); temp = SDL_LoadBMP(path); if(temp == NULL) @@ -104,12 +107,12 @@ int CreateSprite() SDL_Log("Failed to create texture from surface: %s\n", SDL_GetError()); return 2; } - ball.position.x = 0; - ball.position.y = 0; + ball.position.x = 10; + ball.position.y = 13; ball.position.w = temp->w; ball.position.h = temp->h; ball.velocity.x = 1; - ball.velocity.y = 0; + ball.velocity.y = 1; SDL_FreeSurface(temp); SDL_Log("Successfully created sprite!\n"); @@ -129,6 +132,11 @@ void MoveSprite() ball.velocity.x = -ball.velocity.x; ball.position.x += ball.velocity.x; } + ball.position.y += ball.velocity.y; + if(ball.position.y < 0 || ball.position.y > WINDOW_H - ball.position.h) { + ball.velocity.y = -ball.velocity.y; + ball.position.y += ball.velocity.y; + } SDL_RenderCopy( renderer,