diff --git a/display.c b/display.c index a2154eeed29d45bd59285c56225bd49b5d78088a..492270a5a7a8a04e9a4a70f2ec48cd36ed81734f 100644 --- a/display.c +++ b/display.c @@ -21,10 +21,9 @@ void *display_func(void *param) { int one_arm_width, one_arm_height; SDL_Window *window; - int i; // ------------------------- - // Graphic initialization + // Graphic initialization // ------------------------- assert(SDL_Init(SDL_INIT_VIDEO) == 0); get_image_file_size("./one_armed_bandit.png", &one_arm_width, &one_arm_height); @@ -43,48 +42,19 @@ void *display_func(void *param) object_height=object_rect.h/9; - - // ------------------------- - // example of board display: - // ------------------------- - SDL_RenderCopy(renderer, one_arm_texture, NULL, &one_arm_rect); + while(1){ + for(double a = 0; a<8.0; a +=0.1){ - SDL_Rect coin_rect_pos={700, 1020, coin_rect.w, coin_rect.h}; - SDL_RenderCopy(renderer, coin_texture, NULL, &coin_rect_pos); - for (i=0; i<4; i++){ - SDL_Rect coin_rect_pos={700, 400-10*i, coin_rect.w, coin_rect.h}; - SDL_RenderCopy(renderer, coin_texture, NULL, &coin_rect_pos); - } - - SDL_Rect src_rect, dst_rect=object_rect; - dst_rect.h=object_height*1.5; // display 1.5 object on screen for a wheel - src_rect=dst_rect; - src_rect.x=0; - - // src_rect.y is positionned here on the 2nd object of objects.png - src_rect.y=object_height; - dst_rect.x=85; - dst_rect.y=410-object_height/2; // setup the coord. of the icon in the global renderer - SDL_RenderCopy(renderer, objects_texture, &src_rect, &dst_rect); - - - // src_rect.y is positionned here on the 2nd object of objects.png - src_rect.y=object_height; - dst_rect.x=190; - dst_rect.y=410-object_height/2; // setup the coord. of the icon in the global renderer - SDL_RenderCopy(renderer, objects_texture, &src_rect, &dst_rect); + wheel_func(a); + } + } + - // src_rect.y is positionned here on the 2nd object of objects.png - src_rect.y=object_height; - dst_rect.x=295; - dst_rect.y=410-object_height/2; // setup the coord. of the icon in the global renderer - SDL_RenderCopy(renderer, objects_texture, &src_rect, &dst_rect); - - SDL_RenderPresent(renderer); + // ------------------------- - // managing events: + // managing events: // ------------------------- SDL_Event event; bool quit=false; @@ -127,3 +97,40 @@ void *display_func(void *param) SDL_Quit(); return NULL; } + + + +int wheel_func(double index){ + + + // ------------------------- + // example of board display: + // ------------------------- + + SDL_RenderCopy(renderer, one_arm_texture, NULL, &one_arm_rect); + + SDL_Rect coin_rect_pos={700, 1020, coin_rect.w, coin_rect.h}; + SDL_RenderCopy(renderer, coin_texture, NULL, &coin_rect_pos); + for (int i=0; i<4; i++){ + SDL_Rect coin_rect_pos={700, 400-10*i, coin_rect.w, coin_rect.h}; + SDL_RenderCopy(renderer, coin_texture, NULL, &coin_rect_pos); + } + + SDL_Rect src_rect, dst_rect=object_rect; + dst_rect.h=object_height*1.5; // display 1.5 object on screen for a wheel + src_rect=dst_rect; + src_rect.x=0; + + + for(int i=0; i<3; i++){ + // src_rect.y is positionned here on the 2nd object of objects.png + src_rect.y=object_height*index; + dst_rect.x=85 + i*104 + 1; + dst_rect.y=410-object_height/2; // setup the coord. of the icon in the global renderer + SDL_RenderCopy(renderer, objects_texture, &src_rect, &dst_rect); + } + + SDL_RenderPresent(renderer); + sleep(0.1); + return 0; +} diff --git a/display.h b/display.h index e702a3cb02db4bda5ee11680b593f52fe03bdd7d..8f08a0d9c8e4cf84c0300f90228cfe4fdac434ac 100644 --- a/display.h +++ b/display.h @@ -1,10 +1,13 @@ #ifndef DISPLAY_H #define DISPLAY_H +#include <time.h> + void *display_func(void *param); +int wheel_func(double index); // height of one single object -extern int object_height; // global for convenience +extern int object_height; // global for convenience #endif \ No newline at end of file diff --git a/display.o b/display.o index e2b494507865d56c3ae5ac14cf19bd80377373b5..c70f3a8922462cb97750d7361c5d1b6518643b02 100644 Binary files a/display.o and b/display.o differ diff --git a/one_armed_bandit b/one_armed_bandit index 3cfef48cae541c4dca89c21f1509a6acc15ad6c1..5f449a5a9e3c854950b6e70bde110117ea52a8e5 100755 Binary files a/one_armed_bandit and b/one_armed_bandit differ diff --git a/one_armed_bandit.c b/one_armed_bandit.c index 368f0d476066fdfaa9e6f372f5cd31b2cd01ac4a..11028d5938422dacbb238f783943a0dbca24200c 100644 --- a/one_armed_bandit.c +++ b/one_armed_bandit.c @@ -11,6 +11,7 @@ #include "one_armed_bandit.h" + int main() { display_func(NULL); diff --git a/one_armed_bandit.o b/one_armed_bandit.o index 65534fb410f070b6bbe75b5e0a54595a0b639fea..3befc5d830bdc07e6e9109c566c5e2ca22f21591 100644 Binary files a/one_armed_bandit.o and b/one_armed_bandit.o differ diff --git a/utilities.o b/utilities.o index 23976ef35f344ef38ae203f4d94abf264170a443..2428ff3883394c0af87942959a341e1fe4796001 100644 Binary files a/utilities.o and b/utilities.o differ