-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.js
121 lines (96 loc) · 2.93 KB
/
game.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
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
// Setting up game global variables
var game_started = false; // Should not change after made true
var can_move = true;
var develop_manager = new DevelopManager();
//localStorage.clear();
var default_equipment = {weapon:{name:"Fists", use:"weapon", damage:10}, armour:{name:"Cloth", use:"armour", resistance:1}};
var max_health = 200;
var environment;
ClearEnvironment(); // Initialize environment
var world_environments = [];
var world_map = "" +
"^^^^^^^^^^^^^^<br>" +
"^#######~~~~~~<br>" +
"^#..###~~~~~~~<br>" +
"^#...##~~~~~~~<br>" +
"^....###~~~~~~<br>" +
"^........~~~~~<br>" +
"^.........~~~~<br>" +
"^..........~~~<br>" +
"^........../~~<br>" +
"^###....///.~~<br>" +
"^#####//.....~<br>";
var map;
var move_speed = 100;
var character = {x:null, y:null};
var interact_place = {x:null, y:null};
// Movement Variables
var move = {up:null, left:null, right:null, down:null};
var move_direction = {up:false, left:false, right:false, down:false};
var box = {title:"", list:[], body:"", current_interaction:null};
var previous_symbol = "";
function Play(){
if (!game_started){
game_started = true;
develop_manager.Deactivate();
SetupEnvironment();
}
}
function Develop(){
develop_manager.Activate();
//develop_mode = true;
//document.getElementById("myNav").style.width = "100%";
var new_world = new World("Test");
develop_manager.InitializeWorld(new_world);
}
function Inherits(Parent, Child){
Child.prototype = new Parent();
return Child;
}
function IsClass(Constructor, class_name){
var temp_obj = new Constructor();
if (temp_obj.class == class_name){
return true;
}
return false;
}
function GetClass(Constructor){
var temp_obj = new Constructor();
return temp_obj.class;
}
function GetConstructor(class_name){
return window[class_name];
}
//Basic Game Functions
Storage.prototype.setObj = function(key, obj) {
var o = obj || 'Null';
return this.setItem(key, JSON.stringify(o))
}
Storage.prototype.getObj = function(key) {
return JSON.parse(this.getItem(key))
}
String.prototype.capFirst = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
function partial(func /*, 0..n args */) {
var args = Array.prototype.slice.call(arguments, 1);
return function() {
var allArguments = args.concat(Array.prototype.slice.call(arguments));
return func.apply(this, allArguments);
};
}
if (localStorage.getObj("player") === null){
var player = {health:max_health, level:3, strength:0, speed:0, gold:10, items:[], equipment:default_equipment, quests:[], discovered:[], last_save:{world_loc:{x:2, y:2}, loc:{x:10, y:10}}};
localStorage.setObj("player", player);
}
// Use when loading new environment
function EmptyEnv(){
return {name:"", map:"", world_loc:null, ch:"", stores:[], NPCs:[], chests:[], gates:[]};
}
function ClearEnvironment(){
environment = EmptyEnv();
}
String.prototype.replaceAt=function(index, ch) {
return this.substr(0, index) + ch + this.substr(index+ch.length);
}
function NullFunction(){}