Permalink
Browse files

Update ship.c(h) for new naming convention and error usage

  • Loading branch information...
1 parent 7c7f093 commit fe342a87c9da624d895f9a1b57b175459172345c @vimalloc committed Nov 24, 2011
Showing with 16 additions and 28 deletions.
  1. +9 −20 src/ship.c
  2. +7 −8 src/ship.h
View
@@ -4,51 +4,40 @@
#include "ship.h"
#include "errors.h"
-int ship_init(ship **s, sprite *sprite, int ship_speed, int gun_recharge)
-{
- int error;
-
+void ship_init(ship **s, sprite *sprite, int ship_speed, int gun_recharge) {
assert(sprite);
*s = malloc(sizeof(ship));
if(!s)
- return ERR_MALLOC;
+ system_error("malloc error in ship_init");
/* Create the gun this ship will use */
- error = gun_init(&((**s).gun), gun_recharge);
- if(error != HUGE_SUCCESS) {
- free(*s);
- return error;
- }
+ gun_init(&((**s).gun), gun_recharge);
/* Set the values for this ship */
(**s).sprite = sprite;
(**s).speed = ship_speed;
(**s).xpos = 0;
(**s).ypos = 0;
-
- return HUGE_SUCCESS;
}
-void ship_free(ship *s)
-{
+void ship_free(ship *s) {
assert(s);
gun_free(s->gun);
free(s);
}
-int ship_get_speed(ship *s)
-{
+int ship_get_speed(ship *s) {
assert(s);
return s->speed;
}
-int ship_get_width(ship *s)
-{
+int ship_get_width(ship *s) {
+ assert(s);
return sprite_width(s->sprite);
}
-int ship_get_height(ship *s)
-{
+int ship_get_height(ship *s) {
+ assert(s);
return sprite_height(s->sprite);
}
View
@@ -17,7 +17,7 @@ typedef struct {
int speed;
sprite *sprite;
gun *gun;
-} ship;
+} ship_t;
/**
* Initializes a ship object
@@ -30,7 +30,7 @@ typedef struct {
* @param gun_recharge How fast the gun on this ship will recharge
* @return 0 on success, error (< 0) if failure
*/
-int ship_init(ship **s, sprite *sprite, int ship_speed, int gun_recharge);
+void ship_init(ship_t **s, sprite *sprite, int ship_speed, int gun_recharge);
/**
* Frees all the memory used by a ship
@@ -42,19 +42,18 @@ int ship_init(ship **s, sprite *sprite, int ship_speed, int gun_recharge);
*
* @param s The ship to free
*/
-void ship_free(ship *s);
+void ship_free(ship_t *s);
/**
* @brief Returns the movement speed of a ship
*
* @param s The ship to get the speed of
* @return The speed of the passed in ship
*/
-int ship_get_speed(ship *s);
-
-int ship_get_height(ship *s);
-int ship_get_width(ship *s);
-
+int ship_get_speed(ship_t *s);
+int ship_get_height(ship_t *s);
+int ship_get_width(ship_t *s);
#endif
+

0 comments on commit fe342a8

Please sign in to comment.