forked from MATF-RG19/RG41-s-machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths-machine.cpp
181 lines (143 loc) · 4.06 KB
/
s-machine.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <ctime>
#include <GL/glut.h>
#include "drawFunction.hpp"
#include "slotFunction.hpp"
#include "irrKlangLib/include/irrKlang.h"
using namespace std;
using namespace irrklang;
#pragma comment (lib, "irrKlangLib/lib");
ISoundEngine* engine;
vector<int> numImages;
static bool timerActive = false;
static double goCamX = 0;
static double goCamY = 0;
static double goCamZ = 0;
static bool programStarted = false;
static bool slotWorks = false;
static int stepForSlot = 0;
static int randomImage;
static void whileSlotWorks(int);
static int money;
static int bet;
static void on_display(void);
static void on_keyboard(unsigned char, int, int);
static void on_reshape(int, int);
static void on_timer(int);
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(600, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow("SLOT-MACHINE");
glutKeyboardFunc(on_keyboard);
glutReshapeFunc(on_reshape);
glutDisplayFunc(on_display);
glClearColor(0.05, 0.05, 0.05, 0);
glEnable(GL_DEPTH_TEST);
srand(time(NULL));
/*
cout << "Unesite iznos vaseg novca" << endl;
cin >> money;
cout << "Unesite zeljeni BET. Moguce vrednosti [1, 5, 10, 50, 100]" << endl;
cin >> bet;
if (bet != 1 && bet != 5 && bet != 10 && bet != 50 && bet != 100){
cout << "Nedozvoljene vrednosti za BET" << endl;
exit(EXIT_FAILURE);
}
setMoney(money);
setBet(bet);
obrisati linije 75-78 da bi program mogao da se prevede
*/
engine = createIrrKlangDevice(); //kreiranje zvuka
engine->play2D("irrKlangLib/media/music.mp3", true); //pustanje zvuka
money = 1000;
bet = 10;
setMoney(money);
setBet(bet);
glutMainLoop();
return 0;
}
void on_display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(12.0-goCamX,8.0-goCamY,9.0-goCamZ+1,0+goCamY,2+goCamY,0, 0,1,0);
lightInit();
drawMan();
drawSlotMachine(slotWorks);
if(!programStarted) pressS();
if(programStarted) writeMoney();
if(programStarted && !slotWorks) pressSpace();
if(slotWorks) postSlots(numImages);
glutSwapBuffers();
}
void on_keyboard(unsigned char c , int x , int y) {
switch (c){
case 27:
engine->drop(); //oslobadjanje zvuka
exit(0);
case 's':
/*Pokrecemo program, kamera se premesta u glavu igraca*/
if (!timerActive) {
glutTimerFunc(10, on_timer, 0);
timerActive = true;
}
break;
case 32:
/*Na space pokrecemo slot masinu ali tek nakon sto je program pokrenut*/
if(getMoney() < bet){
engine->drop();
exit(0);
}
if (programStarted && !slotWorks){
slotWorks = true;
stepForSlot = 0;
glutTimerFunc(50, whileSlotWorks, 0);
}
break;
case 'r':
/*Podizemo novac, i jedino sto nam preostaje jeste da izadjemo iz igrice*/
setMoney(0);
slotWorks = false;
glutPostRedisplay();
break;
}
}
void whileSlotWorks(int value){
if(value !=0)
return;
randomImage = rand() % 9;
numImages.push_back(randomImage);
glutPostRedisplay();
stepForSlot++;
if (stepForSlot <= 7)
glutTimerFunc(70, whileSlotWorks, 0);
else{
slotWorks = false;
numImages.clear();
}
}
void on_timer(int value) {
if(value != 0)
return;
goCamX += 0.5;
goCamZ += 0.33;
goCamY += 0.165;
glutPostRedisplay();
if (goCamX < 9)
glutTimerFunc(10, on_timer, 0);
else
programStarted = true;
}
static void on_reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (float) width / height, 1, 1500);
}