Basic Ball functionality

This commit is contained in:
Michael Chen 2018-01-10 23:56:47 +01:00
parent 71b4993a6b
commit f136e07b43
2 changed files with 10 additions and 4 deletions

View File

@ -24,7 +24,7 @@ void BREAKOUT_INITIALIZE(SDL_Renderer * renderer, int width, int height){
srand(time(NULL));
BREAKOUT_BoxWidth = width;
BREAKOUT_BoxHeight = height;
if (!BALL_Texture) printf("Ball texture cannot be loaded!\n");
BALL_Initialize(renderer);
printf("Game initialized!\n");
}
@ -57,7 +57,7 @@ Ball BALL_CreateDefault(){
return (Ball) {
.Location = (Vector) {.x = BREAKOUT_BoxWidth / 2, .y = BREAKOUT_BoxHeight / 2 },
.Momentum = getScaledDirectionalUnitVector(rotation, 5),
.Momentum = (Vector) {.x = 0.0f, .y = 6.0f },
.TargetRect = (SDL_Rect) {.x = BREAKOUT_BoxWidth / 2, .y = BREAKOUT_BoxHeight / 2, .w = 50, .h = 50 },
.Size = 50.0f,
.Rotation = rotation,
@ -67,6 +67,7 @@ Ball BALL_CreateDefault(){
}
void BALL_Draw(SDL_Renderer * renderer, Ball * obj){
printf("Ball drawn at (%d|%d)!\n", (obj->TargetRect).x, (obj->TargetRect).x);
SDL_RenderCopyEx(renderer, BALL_Texture, BALL_SourceRects + (obj->TextureIndex), &(obj->TargetRect), obj->Rotation, NULL, SDL_FLIP_NONE);
}
@ -74,6 +75,9 @@ void BALL_Update(Ball * obj){
obj->Location = vectorAdd(obj->Location, obj->Momentum);
(obj->TargetRect).x = (int)round((obj->Location).x);
(obj->TargetRect).y = (int)round((obj->Location).y);
obj->Rotation += obj->RotationValue;
if ((obj->Location).y > BREAKOUT_BoxHeight)
obj->Location = (Vector) {.x = BREAKOUT_BoxWidth / 2, .y = BREAKOUT_BoxHeight / 2 };
}
void BALL_DestroyObject(Ball * obj){
}

6
main.c
View File

@ -38,8 +38,6 @@ int main(int argc, char * args[]){
// system("bhi.exe");
INITIALIZE();
while (running) { // Gameloop
GAMELOOP();
DrawFrame();
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
@ -57,6 +55,8 @@ int main(int argc, char * args[]){
break;
}
}
GAMELOOP();
DrawFrame();
}
QUIT();
return 0;
@ -121,10 +121,12 @@ void INITIALIZE() {
printf("Window was created!\n");
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
printf("Renderer was created!\n");
BREAKOUT_INITIALIZE(renderer, width, height);
} /* INITIALIZE */
void QUIT(){
printf("De-initializing started...\n");
BREAKOUT_DEINITIALIZE();
free(keystate);
TTF_Quit();
IMG_Quit();