fixed block push animation

This commit is contained in:
Michael Chen 2018-01-26 23:50:05 +01:00
parent 396c8f7ddc
commit 2c860c2f4b
2 changed files with 12 additions and 3 deletions

View File

@ -164,7 +164,7 @@ void BREAKOUT_PushNewRow(Scenery * scenery){
} }
for (size_t x = 0; x < (scenery->XBlocks); x++) { for (size_t x = 0; x < (scenery->XBlocks); x++) {
(scenery->blocks)[x + oldBlockCount] = BLOCK_CreateDefault(); (scenery->blocks)[x + oldBlockCount] = BLOCK_CreateDefault();
(scenery->blocks)[x + oldBlockCount].TargetRect = (SDL_Rect) {.x = ((128 * x) + 2), .y = 1, .w = 124, .h = 62 }; (scenery->blocks)[x + oldBlockCount].TargetRect = (SDL_Rect) {.x = ((128 * x) + 2), .y = -63, .w = 124, .h = 62 };
(scenery->blocks)[x + oldBlockCount].TextureIndex = (((scenery->TopLeftBlockColor) + x) % BLOCK_TextureCount); (scenery->blocks)[x + oldBlockCount].TextureIndex = (((scenery->TopLeftBlockColor) + x) % BLOCK_TextureCount);
(scenery->blocks)[x + oldBlockCount].DestYValue = 1; (scenery->blocks)[x + oldBlockCount].DestYValue = 1;
} }
@ -561,11 +561,17 @@ void PADDLE_MoveSmooth(Paddle * obj){
(obj->TargetRect).x = paddleXMid - (int)roundf((float)(paddleXMid - mouseX) * PADDLE_SmoothFactor) - halfPaddle; (obj->TargetRect).x = paddleXMid - (int)roundf((float)(paddleXMid - mouseX) * PADDLE_SmoothFactor) - halfPaddle;
} }
void PADDLE_MoveAuto(Scenery * scenery){
int paddleXMid, halfPaddle = (((scenery->paddle).TargetRect).w / 2);
paddleXMid = halfPaddle + ((scenery->paddle).TargetRect.x); // Current State
((scenery->paddle).TargetRect).x = paddleXMid - (int)roundf((float)(paddleXMid - (((scenery->ball).Location).x + (rand() % 30) + ((scenery->ball).Size))) * 0.2f) - halfPaddle;
}
void PADDLE_AdaptSpeedGradient(Paddle * obj, int FrameCount){ void PADDLE_AdaptSpeedGradient(Paddle * obj, int FrameCount){
if (FrameCount > PADDLE_AccelerationTime) if (FrameCount > PADDLE_AccelerationTime)
return; return;
(obj->TargetRect).w = PADDLE_MaxSize - (((double)FrameCount / (double)PADDLE_AccelerationTime) * (PADDLE_MaxSize - PADDLE_MinSize)); (obj->TargetRect).w = PADDLE_MaxSize - (((double)FrameCount / (double)PADDLE_AccelerationTime) * (PADDLE_MaxSize - PADDLE_MinSize));
} }
void PADDLE_Update(Paddle * obj, Scenery * scenery, const Uint8 * keystate){ void PADDLE_Update(Paddle * obj, Scenery * scenery, const Uint8 * keystate){
@ -586,6 +592,9 @@ void PADDLE_Update(Paddle * obj, Scenery * scenery, const Uint8 * keystate){
((obj->TargetRect).x) += (obj->Speed); ((obj->TargetRect).x) += (obj->Speed);
} }
break; break;
case Automatic:
PADDLE_MoveAuto(scenery);
break;
default: default:
printf("Unknown Paddle Control Mode: %d!\n", obj->Mode); printf("Unknown Paddle Control Mode: %d!\n", obj->Mode);
break; break;

View File

@ -10,7 +10,7 @@
#include "vector.h" #include "vector.h"
// Enums // Enums
typedef enum controlModeEnum {KeyboardControl = 0, MouseControl = 1} ControlMode; typedef enum controlModeEnum {KeyboardControl = 0, MouseControl = 1, Automatic = 2} ControlMode;
// End Enums // End Enums
// Structs // Structs