Skip to content
Snippets Groups Projects
Commit 2908038c authored by benjamin.sitbon's avatar benjamin.sitbon
Browse files

un push sans les .o

parent 705d26b4
No related branches found
No related tags found
No related merge requests found
#include <stdio.h>
#include <stdbool.h>
#include <assert.h>
#include <unistd.h>
#include <pthread.h>
#include "utilities.h"
#include "display.h" #include "display.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
// the following global variables are defined for graphical objects only: // the following global variables are defined for graphical objects only:
// the images size is 104x128 pixels // the images size is 104x128 pixels
static SDL_Renderer *renderer;
static SDL_Texture *one_arm_texture, *objects_texture, *coin_texture;
static SDL_Rect one_arm_rect, coin_rect;
static SDL_Rect object_rect;
int object_height; // global for convenience
void *display_func(void *param)
{ void *display_func(void *param){
int one_arm_width, one_arm_height; int one_arm_width, one_arm_height;
SDL_Window *window; SDL_Window *window;
...@@ -42,17 +29,21 @@ void *display_func(void *param) ...@@ -42,17 +29,21 @@ void *display_func(void *param)
object_height=object_rect.h/9; object_height=object_rect.h/9;
while(1){
for(double a = 0; a<8.0; a +=0.1){
wheel_func(a); 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_RenderPresent(renderer);
wait_until(20);
// ------------------------- // -------------------------
// managing events: // managing events:
// ------------------------- // -------------------------
...@@ -68,37 +59,7 @@ void *display_func(void *param) ...@@ -68,37 +59,7 @@ void *display_func(void *param)
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;
}
...@@ -2,9 +2,24 @@ ...@@ -2,9 +2,24 @@
#define DISPLAY_H #define DISPLAY_H
#include <time.h> #include <time.h>
#include <stdio.h>
#include <stdbool.h>
#include <assert.h>
#include <unistd.h>
#include <pthread.h>
#include "utilities.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
static SDL_Renderer *renderer;
static SDL_Texture *one_arm_texture, *objects_texture, *coin_texture;
static SDL_Rect one_arm_rect, coin_rect;
static SDL_Rect object_rect;
int object_height; // global for convenience
void *display_func(void *param); void *display_func(void *param);
int wheel_func(double index); int wheel_spin(double offset,int pixel,int time);
// height of one single object // height of one single object
extern int object_height; // global for convenience extern int object_height; // global for convenience
......
File deleted
File deleted
...@@ -7,24 +7,36 @@ ...@@ -7,24 +7,36 @@
#include <pthread.h> #include <pthread.h>
#include <semaphore.h> #include <semaphore.h>
#include "utilities.h" #include "utilities.h"
#include "display.h"
#include "one_armed_bandit.h" #include "one_armed_bandit.h"
int insert_coin(){ int insert_coin(){
return -1;
} }
int set_wheel_speed(int index){ int set_wheel_speed(int index){
return -1;
} }
int next_wheel(){ int next_wheel(){
return -1;
}
wheel create_wheel(int pixel,int speed){
wheel ret;
ret.current_px = pixel;
ret.speed = speed;
return ret;
} }
int main() int main()
{ {
pthread_t threads[5];
display_func(NULL); display_func(NULL);
SDL_Event event; SDL_Event event;
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#define OBJECT_NB 7 #define OBJECT_NB 7
#define WHEEL_NB 3 #define WHEEL_NB 3
#include "wheel.h";
typedef struct machine_a_sous{ typedef struct machine_a_sous{
wheel* wheels; wheel* wheels;
int player_wallet; int player_wallet;
......
File deleted
...@@ -75,8 +75,11 @@ void wait_key_release() ...@@ -75,8 +75,11 @@ void wait_key_release()
/* return updated value: time_start + offset_ms. wait until current time reaches /* return updated value: time_start + offset_ms. wait until current time reaches
the time value returned. If delta time is negative, do not wait. */ the time value returned. If delta time is negative, do not wait. */
struct timespec wait_until(struct timespec time_start, unsigned long offset_ms) struct timespec wait_until( unsigned long offset_ms)
{ {
struct timespec time_start;
clock_gettime(CLOCK_MONOTONIC, &time_start);
struct timespec current_time, ret_time; struct timespec current_time, ret_time;
LL end_ns, delay_ns; LL end_ns, delay_ns;
......
...@@ -26,7 +26,7 @@ void wait_key_release(); ...@@ -26,7 +26,7 @@ void wait_key_release();
* Parameters: time_start: start timestamp. Can be get at first with clock_gettime(CLOCK_MONOTONIC, &time_start) * Parameters: time_start: start timestamp. Can be get at first with clock_gettime(CLOCK_MONOTONIC, &time_start)
offset_ms: duration of the passive waiting [ms] offset_ms: duration of the passive waiting [ms]
*/ */
struct timespec wait_until(struct timespec time_start, unsigned long offset_ms); struct timespec wait_until(unsigned long offset_ms);
/* Description: calculate the difference of time between a timestamp and present time /* Description: calculate the difference of time between a timestamp and present time
* Parameters: time_start: past start timestamp. Can be get at first with clock_gettime(CLOCK_MONOTONIC, &time_start) * Parameters: time_start: past start timestamp. Can be get at first with clock_gettime(CLOCK_MONOTONIC, &time_start)
......
File deleted
int set_speed(int s){ #include "display.h"
#include "utilities.h"
#include "wheel.h";
int set_speed(int s){
return -1;
} }
int get_current_px(){ int get_current_px(){
return -1;
}
int wheel_spin(double offset, int pixel,int time){
// -------------------------
// 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);
wait_until(time);
return 0;
}
void *wheel_func(void *param){
wheel id = *((wheel *) param);
while(1){
for(double a = 0; a<8.0; a +=0.1){
wheel_spin(a,id.current_px,id.speed);
}
}
} }
\ No newline at end of file
...@@ -3,5 +3,7 @@ typedef struct roue{ ...@@ -3,5 +3,7 @@ typedef struct roue{
int current_px; int current_px;
} wheel; } wheel;
int wheel_spin(double offset, int pixel,int time);
int set_speed(int s); int set_speed(int s);
int get_current_px(); int get_current_px();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment