Skip to content
Snippets Groups Projects
Select Git revision
  • c5f2460fc82ca95170fc1568a5097f4f2dda4c90
  • master default protected
  • 1.1.1
  • 1.1
  • 1.0
5 results

display.c

Blame
  • display.c 2.59 KiB
    #include "display.h"
    #include "one_armed_bandit.h"
    
    // the following global variables are defined for graphical objects only:
    // the images size is 104x128 pixels
    
    
    SDL_Window* init_display(){
    	int one_arm_width, one_arm_height;
    	SDL_Window *window;
    
    	// -------------------------
      	// Graphic initialization
    	// -------------------------
    	assert(SDL_Init(SDL_INIT_VIDEO) == 0);
    	get_image_file_size("./one_armed_bandit.png", &one_arm_width, &one_arm_height);
    	assert((window = SDL_CreateWindow("one_armed_bandit", SDL_WINDOWPOS_UNDEFINED,
    	                          SDL_WINDOWPOS_UNDEFINED, one_arm_width,
    	                          one_arm_height, SDL_WINDOW_OPENGL))!=NULL);
    	assert((renderer = SDL_CreateRenderer(window, -1, 0))!=NULL);
    	SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);   // allow transparent mode!
    	assert((one_arm_texture=create_texture_from_image_file(renderer, "one_armed_bandit.png",
    	                                                       &one_arm_rect))!=NULL);
    	assert((coin_texture=create_texture_from_image_file(renderer, "coin.png",
    	                                                    &coin_rect))!=NULL);
    	// create the global texture containing all objects:
    	assert((objects_texture=create_texture_from_image_file(renderer, "objects.png",
    			                                                   &object_rect))!=NULL);
      	object_height=object_rect.h/9;
    
    	return window;
    }
    
    display_wheel(int pixel,int offset){
        // -------------------------
    	// example of board display:
    	// -------------------------
    	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
        //85 + index*104  + 1
    	src_rect.y=object_height*offset;
    	dst_rect.x= pixel;
    	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);
    }
    
    
    
    void *display_func(void *param){
    	printf("\ndisplay_func");
    	machine mas = *((machine *) param); 
    
    	while(1){
    
    		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);
    		}
    
    		for(int i=0; i<3; i++){
    			display_wheel(85+104*i + 1,mas.wheels[i].current_px);
    		}