-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplay.html
More file actions
99 lines (99 loc) · 3.44 KB
/
Copy pathplay.html
File metadata and controls
99 lines (99 loc) · 3.44 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
<html>
<head>
<link type = "text/css" href="play.css" rel="stylesheet">
<script src = "jsgame_0.0.3.js"></script>
<script src = "jquery.js"></script>
<script>
const { dialog } = require('electron').remote
const fs = require("fs")
let files = []
let users = [{},{}]
let context = {
"resource" : {
"ore" : []
}
}
let ctx
let init
let enemy
$(window).ready(function(){
game()
resize()
$("#load").click(function(){
if (files.length >= 2){ return }
dialog.showOpenDialog({ properties: ['openFile','multiSelections']})
.then(function(filepath){
//console.log(filepath)
fs.readFile(filepath.filePaths[0],function(err,data){
files.push(data.toString())
})
})
})
$("#run").click(function(){
init = true
})
$(window).resize(function(){
resize()
})
})
function game(){
ctx = jsgame.createCanvas($(".canvas").get(0))
setTimeout(function(){
process()
},16)
}
function process(){
ctx.screen.bgcolor()
if (init){
jsgame.sprites.clear()
init = false
getEval()
for (let i in users){
users[i].setup()
}
}
for (let i in users){
enemy = enemyUpdate(i)
try { users[i].update() }
catch {}
}
jsgame.sprites.draw()
setTimeout(process,16)
}
function getEval(){
let map = mapInit(ctx,"default")
let that
for (let i in files){
that = users[i]
eval(files[i])
users[i]["building"] = []
map.home[i].user = users[i]
users[i]["building"][0] = map.home[i]
users[i]["unit"] = {}
users[i]["unit"].worker = []
users[i]["unit"].melee = []
}
context.resource = map.resource
}
function resize(){
let canvas = $(".canvas").get(0)
canvas.height = window.innerHeight
canvas.width = window.innerWidth
ctx.resize(canvas.width,canvas.height)
}
function enemyUpdate(user){
let enemyList = []
for (let i in users){
if (i == user){ continue }
enemyList.push(users[i])
}
return enemyList
}
</script>
</head>
<body>
<button id = "run" class = "button">run</button>
<button id = "load" class = "button">load</button>
<canvas class = "canvas"></canvas>
</body>
</html>