-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobot.h
More file actions
121 lines (103 loc) · 2.23 KB
/
Robot.h
File metadata and controls
121 lines (103 loc) · 2.23 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
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
#pragma once
#include "PhysicsObject.h"
#include "Emote.h"
#include <cmath>
#include <iostream>
/// <summary>
/// Represents a Robot that can accomplish simple functions
/// </summary>
class Robot : public PhysicsObject
{
public:
Robot();
Robot(float x, float y);
Robot(float x, float y, std::string spriteName);
Robot(float x, float y, std::string spriteName, bool lockRotation);
Robot(const Robot& other);
void Act(sf::RenderWindow& screen) {
// Moves the robot consistently
if (isMoving) {
if (movingTime > 0) {
Accelerate((face == left) ? -0.75f : 0.75f, 0);
movingTime--;
}
else
isMoving = false;
}
// Performs a random action
if (timer <= 0 && !isMoving) {
unsigned int choice = static_cast<unsigned int>((rand() % 3) + 1);
// Chooses what action the robot decides to do
switch (choice) {
case 1:
movingTime = (rand() % 95) + 5;
isMoving = true;
face = left;
break;
case 2:
movingTime = (rand() % 495) + 5;
isMoving = true;
face = right;
break;
default:
if (emote == none) {
unsigned int emoteChoice = (rand() % 4) + 1;
switch (emoteChoice) {
case 1:
emote = happy;
break;
case 2:
emote = awkward;
break;
case 3:
emote = suprised;
break;
default:
emote = unsure;
break;
}
e->SelectEmote(emote);
break;
}
}
timer = (rand() % 500) + 50; // Resets timer
}
timer--;
// Plays a random sound
if (soundTimer <= 0) {
int index = rand() % 16;
PlaySound(index);
soundTimer = (rand() % 500) + 50; // Resets timer
}
soundTimer--;
PhysicsObject::Act(screen);
}
void Render(sf::RenderWindow& screen) override;
protected:
void SetUpValues(float x = 0, float y = 0, std::string spriteName = "DefaultTexture.png");
private:
// Timers for when a robot and perform actions
unsigned int timer = 100;
unsigned int soundTimer = 100;
bool isMoving = false;
int movingTime;
// Direction the robot is facing
enum direction {
right,
left
};
direction face;
// Sprite properties
sf::IntRect dir[2];
sf::Vector2f spriteSize;
// The robots emotes
Emote* e;
enum emotions {
happy,
awkward,
suprised,
unsure,
none
};
emotions emote;
};