Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update sprite.c(h) for new naming convention and error handling

  • Loading branch information...
commit b4dc4af3548d77f91d8d3b0eedbba6e0f80d3538 1 parent ffc5efc
@vimalloc authored
Showing with 14 additions and 19 deletions.
  1. +1 −1  src/game_state.c
  2. +8 −13 src/sprite.c
  3. +5 −5 src/sprite.h
View
2  src/game_state.c
@@ -21,7 +21,7 @@
void game_state_init(game_state_t **state) {
int ship_height;
int ship_width;
- sprite *player_sprite; /* owned by this game_state struct */
+ sprite_t *player_sprite; /* owned by this game_state struct */
*state = malloc(sizeof(game_state));
if(!*state)
View
21 src/sprite.c
@@ -4,32 +4,27 @@
#include <assert.h>
#include <stdlib.h>
-int sprite_load_bmp(sprite **s, char *file)
-{
+void sprite_load_bmp(sprite_t **s, char *file) {
*s = malloc(sizeof(sprite));
if(!s)
- return ERR_MALLOC;
+ system_error("malloc error in sprite_load_bmp");
- if(((*s)->pic = SDL_LoadBMP(file)) == NULL)
- return ERR_SPRITE;
-
- return HUGE_SUCCESS;
+ (**s).pic== SDL_LoadBMP(file);
+ if(!(**s).pic)
+ app_error(strcat(file, ": Couldn't be loaded into a sprite"));
}
-void sprite_free(sprite* s)
-{
+void sprite_free(sprite* s) {
assert(s);
free(s->pic);
free(s);
}
-int sprite_width(sprite *s)
-{
+int sprite_width(sprite *s) {
return s->pic->w;
}
-int sprite_height(sprite *s)
-{
+int sprite_height(sprite *s) {
return s->pic->h;
}
View
10 src/sprite.h
@@ -6,7 +6,7 @@
/* Handle for a sprite */
typedef struct {
SDL_Surface *pic;
-} sprite;
+} sprite_t;
/**
* Load a bmp file into a sprite
@@ -15,19 +15,19 @@ typedef struct {
* @param file The file path of the bmp image to load
* @return 0 on success, error (< 0) on failure
*/
-int sprite_load_bmp(sprite** s, char* file);
+void sprite_load_bmp(sprite_t **s, char *file);
/**
* Frees all the memory used by this sprite.
*
* @param s The sprite to free
*/
-void sprite_free(sprite* s);
+void sprite_free(sprite_t *s);
/* Returns the width of this sprite */
-int sprite_width(sprite *s);
+int sprite_width(sprite_t *s);
/* Returns the height of this sprite */
-int sprite_height(sprite *s);
+int sprite_height(sprite_t *s);
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.