From: unknown Date: Thu, 20 Jan 2011 16:59:49 +0000 (-0600) Subject: Collisions draw correctly centered on sprite (ish) X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=3ab77a0d1d4850a27cc8303b800214fec4eaf00a;p=IvanGame.git Collisions draw correctly centered on sprite (ish) --- diff --git a/Animation.cpp b/Animation.cpp index fca422c..85d590c 100644 --- a/Animation.cpp +++ b/Animation.cpp @@ -69,6 +69,7 @@ int Animation::loadAnimation(std::string animFile) double x=0.0, y=0.0; value>>x; value>>y; + /** Collision data */ char c; @@ -116,17 +117,16 @@ int Animation::loadAnimation(std::string animFile) /** sets frame delay and makes sure height and width are correct */ mAnim[count].pause = pause; - if(!mW) mW = mAnim[count].image->w; - if(!mH) mH = mAnim[count].image->h; + mW = mAnim[count].image->w; + mH = mAnim[count].image->h; /** Set the animation Peg*/ - mAnim[count].animationPeg = Point2D(x,y); + mAnim[count].animationPeg = Point2D(x + double(mW)/2, y + double(mH)/2); count++; } } } - /// \todo add collision info obtained from file. fin.close(); return 0; } diff --git a/ArtAssets/Sprites/sun.anim b/ArtAssets/Sprites/sun.anim index 29e9d82..b466db1 100644 --- a/ArtAssets/Sprites/sun.anim +++ b/ArtAssets/Sprites/sun.anim @@ -2,7 +2,7 @@ #ArtAssets/ milisec Transparency #filename pause r g b xOffset yOffset ( collisionType , ... ) NumFrames: 4 -sun1.bmp 20 0 0 255 0.0 0.0 ( c 0.0 0.0 0.0 ) -sun2.bmp 20 0 0 255 0.0 0.0 ( c 0.0 0.0 0.0 ) -sun3.bmp 20 0 0 255 0.0 0.0 ( c 0.0 0.0 0.0 ) -sun4.bmp 20 0 0 255 0.0 0.0 ( c 0.0 0.0 0.0 ) +sun1.bmp 20 0 0 255 0.0 0.0 ( c 0.0 0.0 10.0 ) +sun2.bmp 20 0 0 255 0.0 0.0 ( c 0.0 0.0 10.0 ) +sun3.bmp 20 0 0 255 0.0 0.0 ( c 0.0 0.0 10.0 ) +sun4.bmp 20 0 0 255 0.0 0.0 ( c 0.0 0.0 10.0 ) diff --git a/ArtAssets/Sprites/viking.anim b/ArtAssets/Sprites/viking.anim index 02056f4..56ad9a8 100644 --- a/ArtAssets/Sprites/viking.anim +++ b/ArtAssets/Sprites/viking.anim @@ -2,12 +2,12 @@ #ArtAssets/ milisec Transparency #filename pause r g b xOffset yOffset ( , ... ) NumFrames: 9 -viking1.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 ) -viking2.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 ) -viking3.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 ) -viking4.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 r -6.0 3.0 5.0 5.0 ) -viking5.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 ) -viking6.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 ) -viking7.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 ) -viking8.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 ) -viking9.bmp 50 0 255 0 0.0 0.0 ( r 0.0 0.0 150.0 100.0 ) +viking1.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0 ) +viking2.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0 ) +viking3.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0 ) +viking4.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0 c 0.0.0 5.0 ) +viking5.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0 ) +viking6.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0 ) +viking7.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0 ) +viking8.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0 ) +viking9.bmp 50 0 255 0 0.0 0.0 ( r -75 -50 150.0 100.0 ) diff --git a/Frame.h b/Frame.h index 5a574c3..e2628da 100644 --- a/Frame.h +++ b/Frame.h @@ -9,8 +9,8 @@ struct SpriteFrame{ SDL_Surface *image;/**< Pointer to an image. */ int pause;/**< Tells the amount of time to pause between this frame and the next. */ - int width;/**< Base width of the frame's image. */ - int height;/**< Base height of the frame's image. */ + int width;/**< Base width of the frame's image. \todo make this and animation's match or at least sync or delete*/ + int height;/**< Base height of the frame's image. \todo make this and animation's match or at least sync or delete*/ vector hotSpots;/**< Hot spots that can be used for locating objects on the sprite default is tagged to center of the sprite \todo implement default*/ Point2D animationPeg;/**< The offeset from position to place the image. Defaults to (0,0) \todo implement */ vector collisionData;/**< The collision data for this sprite */ diff --git a/Sprite.cpp b/Sprite.cpp index 98b528a..1899da9 100644 --- a/Sprite.cpp +++ b/Sprite.cpp @@ -44,5 +44,5 @@ void Sprite::draw() if(mVisible == true) SDL_BlitSurface(frame.image,NULL,mScreen,&dest); if(Game::game()->ShowCollisions) - drawCollisions(frame.collisionData, frame.animationPeg); + drawCollisions(frame.collisionData, mPos + frame.animationPeg); }