-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
97 lines (70 loc) · 1.67 KB
/
Copy pathutils.cpp
File metadata and controls
97 lines (70 loc) · 1.67 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
/*
* utils.h
*
* Various useful things and utility functions, like easy access to random numbers in various ways.
*/
#include <stdlib.h>
#include <string>
#include <cctype>
#include <iostream>
#include <algorithm>
using namespace std;
#include "utils.h"
#include "common.h"
#include "console.h"
u64 ri(u64 a, u64 b)
{
std::uniform_int_distribution<int> dist(a, b);
return dist(rng);
}
bool fiftyfifty()
{
u64 i;
std::uniform_int_distribution<> dist(1, 100);
i = dist(rng);
if(i <= 50)
return true;
else
return false;
}
bool x_in_y(u64 x, u64 y)
{
u64 i;
std::uniform_int_distribution<> dist(1, y);
i = dist(rng);
if(i <= x)
return true;
else
return false;
}
bool one_in(int chance)
{
return x_in_y(1, chance);
}
int roll_die() {
return ri(1, 6);
}
int dice(int num, int sides, signed int modifier) {
int min, max;
min = num;
max = num * sides;
std::uniform_int_distribution<> dist(min, max);
return (dist(rng) + modifier);
}
// Again, credits to PT_Console - https://github.com/pdetagyos/RoguelikeTutorial/blob/tutorial-step-01/pt_console.c
u32 PT_ColorizePixel(u32 dest, u32 src)
{
// Colorize the destination pixel using the source color
if (ALPHA(dest) == 255) {
return src;
} else if (ALPHA(dest) > 0) {
// Scale the final alpha based on both dest & src alphas
return COLOR_FROM_RGBA(RED(src),
GREEN(src),
BLUE(src),
(u8)(ALPHA(src) * (ALPHA(dest) / 255.0)));
} else {
return dest;
}
}
// vim: fdm=syntax ft=cpp