-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.js
106 lines (94 loc) · 3.17 KB
/
global.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
"use strict";
let SCREEN_WIDTH = 800;
let SCREEN_HEIGHT = 600;
let GET_MAX_X = SCREEN_WIDTH - 1;
let GET_MAX_Y = SCREEN_HEIGHT - 1;
let SCREEN_WIDTH_CENTER = Math.floor(GET_MAX_X / 2);
let SCREEN_HEIGHT_CENTER = Math.floor(GET_MAX_Y / 2);
let ArmourTypes = {
NoArmour: 0,
Light: 1,
Medium: 2,
Heavy: 3,
Titanium: 4
};
function line(graphics, color, x1, y1, x2, y2) {
graphics.beginStroke(color).moveTo(x1, y1).lineTo(x2, y2).endStroke();
}
function bar(graphics, color, x1, y1, x2, y2) {
let startX = Math.min(x1, x2);
let endX = Math.max(x1, x2);
let startY = Math.min(y1, y2);
let endY = Math.max(y1, y2);
let width = endX - startX;
let height = endY - startY;
if (width > 0 && height > 0) {
graphics.beginStroke(color).beginFill(color).drawRect(startX, startY, width, height).endFill().endStroke();
}
}
function barAsShape(color, x1, y1, x2, y2) {
let startX = Math.min(x1, x2);
let endX = Math.max(x1, x2);
let startY = Math.min(y1, y2);
let endY = Math.max(y1, y2);
let shape = new createjs.Shape();
bar(shape.graphics, color, 0, 0, endX - startX, endY - startY);
shape.x = startX;
shape.y = startY;
return shape;
}
function rectangle(graphics, color, x1, y1, x2, y2) {
let startX = Math.min(x1, x2);
let endX = Math.max(x1, x2);
let startY = Math.min(y1, y2);
let endY = Math.max(y1, y2);
let width = endX - startX;
let height = endY - startY;
if (width > 0 && height > 0) {
graphics.beginStroke(color).drawRect(startX, startY, width, height).endStroke();
}
}
function putPixel(graphics, color, x, y) {
graphics.beginStroke(color).drawRect(x, y, 0.001, 0.001).endStroke();
}
function circle(graphics, color, x, y, r, fillColor) {
graphics.beginStroke(color);
if (fillColor) {
graphics.beginFill(fillColor);
}
graphics.drawCircle(x, y, r);
if (fillColor) {
graphics.endFill();
}
graphics.endStroke();
}
function circleFilled(graphics, color, x, y, r) {
graphics.beginStroke(color).beginFill(color).drawCircle(x, y, r).endFill().endStroke();
}
function outTextXY(container, color, text, x, y, textAlign, shadowColor) {
// This is the closest approximation to the DOS font and size used in the original Mortar Mayhem (combined with the font style in style.css)
let textObj = outTextXYAsText(color, text, x, y, textAlign, shadowColor);
container.addChild(textObj);
}
function outTextXYAsText(color, text, x, y, textAlign, shadowColor) {
// This is the closest approximation to the DOS font and size used in the original Mortar Mayhem (combined with the font style in style.css)
let textObj = new createjs.Text(text, "11px TerminalVector", color);
if (textAlign) {
textObj.textAlign = textAlign;
}
textObj.scaleY = 0.84;
textObj.x = x - 0.5;
textObj.y = y - 1.5;
if (shadowColor) {
textObj.shadow = new createjs.Shadow(shadowColor, 2, 2, 0);
}
return textObj;
}
function showPCX(assets, container, name, x, y, width, height) {
let bitmap = new createjs.Bitmap(assets.getResult(name));
bitmap.x = x - 0.5;
bitmap.y = y - 0.5;
// crop bitmap
bitmap.sourceRect = new createjs.Rectangle(0, 0, width + 1, height + 1); // +1, because that's how Show_PCX() worked in MM.
container.addChild(bitmap);
}