forked from AASF-IIITM/oops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobs.cpp
More file actions
59 lines (50 loc) · 1.22 KB
/
Copy pathobs.cpp
File metadata and controls
59 lines (50 loc) · 1.22 KB
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
#include "obs.h"
#include <cstdlib>
int get_random_num(int a, int b)
{
static bool first = true; if (first){srand( time(NULL) );first = false;}
int result=a + rand() % (( b + 1 ) - a);
result=(result/10)*10;
return result;
}
float obS :: obs_speed = 0.10f;
obS :: obS()
{ static int st=0;
obs_posn.x = get_random_num(borderLeft, borderRight);
if(st == 0)
obs_posn.y = 0;
else if(st == 1)obs_posn.y = -200;
else if(st == 2) obs_posn.y = -300;
else obs_posn.y = -100;
obtxt.loadFromFile("obs.png");
obsprt.setTexture(obtxt);
st++;
}
Sprite obS :: getSprite()
{
return obsprt;
}
int obS :: update()
{ static int scr=0;
if(obs_posn.y < low)
obs_posn.y += obs_speed;
else{
scr++;
obs_posn.y = 0;
obs_posn.x = get_random_num(borderLeft,borderRight);
}
obsprt.setPosition(obs_posn);
return scr;
}
void obS :: resetX()
{ static int gt=0;
obs_posn.x = get_random_num(borderLeft, borderRight);
if(gt == 0)
obs_posn.y = 0;
else if(gt == 1)obs_posn.y = -200;
else if(gt == 2) obs_posn.y = -300;
else obs_posn.y = -100;
gt = (gt+1)%4;
}
void obS :: obspd(){
obs_speed += 0.06f;}