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

opörationnel

parent b2bdd29a
Branches
No related tags found
No related merge requests found
......@@ -64,7 +64,12 @@ void *display_func(void *param){
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++){
for (int i=0; i<mas->machine_wallet; i++){
SDL_Rect coin_rect_pos={700, 1010-10*i, coin_rect.w, coin_rect.h};
SDL_RenderCopy(renderer, coin_texture, NULL, &coin_rect_pos);
}
for (int i=0; i<mas->player_wallet; 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);
}
......
......@@ -23,8 +23,10 @@ wheel create_wheel(int pixel,int speed){
}
void new_machine(machine* mas, int nb_wheels){
void new_machine(machine* mas, int nb_wheels,int player, int machine){
for (int i = 0; i < nb_wheels; i++) {
mas->wheels[i] = create_wheel(96,nb_wheels-i);
mas->wheels[i] = create_wheel(96,0);
mas->player_wallet = player;
mas->machine_wallet = machine;
}
}
......@@ -21,6 +21,6 @@ int insert_coin();
int set_wheel_speed(int index);
int next_wheel();
wheel create_wheel(int pixel,int speed);
void new_machine(machine* mas, int nb_wheels);
void new_machine(machine* mas, int nb_wheels,int player, int machine);
#endif
......@@ -17,13 +17,26 @@
int how_many_points(machine mas){
int count = 0;
int bubble = mas.wheels[0].current_px;
for(int i =0; i<WHEEL_NB; i++){
if(bubble == mas.wheels[i].current_px) count += 1;
}
if(mas.wheels[1].current_px == mas.wheels[2].current_px) count += 1;
return count;
}
int main()
{
int wheel_turn = 0;
int wheel_turn = 4;
bool paid = false;
pthread_t threads[4];
machine mas;
new_machine(&mas, 3);
new_machine(&mas, 3,10,30);
for(int i = 0; i<3; i++){
run_thread(&threads[i],wheel_func,&mas.wheels[i]);
......@@ -59,16 +72,33 @@ int main()
break;
case SDLK_SPACE:
wait_key_release();
if(wheel_turn <3){
if(wheel_turn <WHEEL_NB){
stop_wheel(&mas.wheels[wheel_turn]);
wheel_turn += 1;
}
if(wheel_turn == WHEEL_NB && paid == false){
paid = true;
int howmany = how_many_points(mas);
if(howmany == 2){
mas.player_wallet += 2;
mas.machine_wallet -= 2;
}
else if(howmany > 2){
mas.player_wallet += mas.machine_wallet/2;
mas.machine_wallet -= mas.machine_wallet/2;
}
}
break;
case SDLK_s:
wait_key_release();
if(mas.player_wallet > 0){
paid = false;
mas.player_wallet -= 1;
mas.machine_wallet += 1;
wheel_turn =0;
for(int i = 0; i<3; i++){
mas.wheels[i].speed = 3-i;
for(int i = 0; i<WHEEL_NB; i++){
mas.wheels[i].speed = WHEEL_NB-i;
}
}
break;
}
......
......@@ -64,7 +64,7 @@ void wait_key_release()
if (SDL_PollEvent(&event)) {
if (event.type==SDL_KEYUP)
{
printf("key released\n");
//printf("key released\n");
break;
}
}
......
......@@ -38,8 +38,8 @@ int wheel_delay_ms(wheel this){
}
int stop_wheel(wheel* this){
while (this->current_px % 128 != 128-32) { // 32 is the offset to center the item
wheel_spin_1_tick(this);
while (this->current_px % 128 != 96) { // 32 is the offset to center the item
//wheel_spin_1_tick(this);
wait_until(wheel_delay_ms(*this));
}
this->speed = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment