-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.js
78 lines (66 loc) · 1.99 KB
/
events.js
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
/* This is the event library.
* Going to simulate some OOP up in here. */
// Coordinate boundaries of acceptable events.
var min_x = 30;
var max_x = 800;
var min_y = 30;
var max_y = 400;
/** BASE EVENT **/
// Returns a new and most generic event.
function create_base_event(counter) {
var x_bonus = Math.round(Math.random()*(max_x - min_x));
var y_bonus = Math.round(Math.random()*(max_y - min_y));
return {x: min_x + x_bonus,
y: min_y + y_bonus,
duration: 50,
difficulty: 1,
reward: 5,
type: "base",
diffuse: false};
}
// Base event:
// If the robot is more than the event, it is over.
// If the robot is less than the event, no more robot.
function click_base_event(event, robot) {
if (robot.level > event.difficulty) {
event.diffuse = true;
event.duration = 10; // Duration of a diffused event is how long it takes to fix.
} else {
robot.dead = true; // Might be too harsh!
}
}
// Progress base event by whittling down timer.
function progress_base_event(event) {
event.duration--;
}
// Ends the event.
function end_base_event(event, game_state) {
if (event.diffuse) {
game_state.budget = game_state.budget + event.reward;
} else {
game_state.budget = game_state.budget - event.reward;
}
}
/***********************************/
/* Incremental Event: Gets worse. */
// Returns an 'incremental' event.
function create_incremental_event(counter) {
var event = create_base_event(counter);
event.type = "inc";
return event;
}
// Every time you fail, it gets worse.
function click_incremental_event(event, robot) {
var old_diff = event.difficulty;
event.difficulty = Math.round(event.difficulty);
click_base_event(event, robot);
if (robot.dead) {
event.difficulty = old_diff + 0.2;
}
}
// When you do nothing, it gets worse.
function progress_incremental_event(event) {
event.difficulty = event.difficulty + 0.1;
progress_base_event(event);
}
/***********************************/