Skip to content

Commit c0948ca

Browse files
some tests
1 parent cb2c1d1 commit c0948ca

File tree

7 files changed

+85
-27
lines changed

7 files changed

+85
-27
lines changed

data/img/door.png

257 Bytes
Loading

data/img/floor.png

264 Bytes
Loading

data/img/human.png

245 Bytes
Loading

data/img/wall.png

240 Bytes
Loading

entrypoint.lua

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
-- Entry point if the game is run in a browser using fengari + p5js
2+
local js = require "js"
3+
local window = js.global
4+
local document = window.document
5+
local br = require "main"
6+
7+
function window.setup()
8+
window:createCanvas(400, 400)
9+
end
10+
11+
window.brout = window:Object();
12+
window.brout.room = window:Array()
13+
14+
local currentRoom = br.world.map[br.player.position["global"].x][br.player.position["global"].y]
15+
16+
for x = 0, #currentRoom.map-1 do
17+
window.brout.room:push(window:Array());
18+
for y = 0, #currentRoom.map[x+1]-1 do
19+
window.brout.room[x]:push(currentRoom.map[x+1][y+1])
20+
end
21+
end
22+
23+
window.brout.player = window:Object()
24+
window.brout.player.x = br.player.position["local"].x
25+
window.brout.player.y = br.player.position["local"].y
26+
27+
function window._redraw()
28+
window.brout = window:Object();
29+
window.brout.room = window:Array()
30+
31+
local currentRoom = br.world.map[br.player.position["global"].x][br.player.position["global"].y]
32+
33+
for x = 0, #currentRoom.map-1 do
34+
window.brout.room:push(window:Array());
35+
for y = 0, #currentRoom.map[x+1]-1 do
36+
window.brout.room[x]:push(currentRoom.map[x+1][y+1])
37+
end
38+
end
39+
40+
window.brout.player = window:Object()
41+
window.brout.player.x = br.player.position["local"].x
42+
window.brout.player.y = br.player.position["local"].y
43+
end

index.html

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,50 @@
66
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.2/p5.min.js" integrity="sha512-eu9vkh+EbAsW3fMmPTj/DP5W3UegIdu0Z/OABMocvoofx43MYBkcQ9hRIVxZndV1vcCYQwBg+U1PkWl04TD0Jg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
77
<script src='lib/fengari-web.js' type="text/javascript"></script>
88
<script type="text/javascript">
9+
let imgs = {}
10+
11+
preload = function()
12+
{
13+
imgs.human = loadImage("data/img/human.png")
14+
imgs.floor = loadImage("data/img/floor.png")
15+
imgs.wall = loadImage("data/img/wall.png")
16+
imgs.door = loadImage("data/img/door.png")
17+
console.log("aoba")
18+
}
19+
20+
setup = function()
21+
{
22+
createCanvas(400, 400)
23+
}
24+
925
async function main()
1026
{
1127
//brutopolis code
12-
//let code = await fetch("main.lua").then(response => response.text());
13-
//fengari.load(code)();
14-
15-
/*fengari.load(`
16-
local js = require "js"
17-
local window = js.global
18-
local document = window.document
19-
window.bruter = br
20-
`)()*/
21-
22-
fengari.load(`
23-
local js = require "js"
24-
local window = js.global
25-
local document = window.document
28+
fengari.load(await fetch("entrypoint.lua").then(response => response.text()))()
2629

27-
function window.setup()
28-
window:createCanvas(400, 400)
29-
end
30-
31-
function window.draw()
32-
window:background(220)
33-
window:fill(255, 0, 0)
34-
window:ellipse(200, 200, 50, 50)
35-
end`)()
36-
37-
setup = window.setup
38-
draw = window.draw
39-
console.log(window.bruter)
30+
draw = function()
31+
{
32+
background(220)
33+
for (let x = 0; x < window.brout.room.length; x++)
34+
{
35+
for (let y = 0; y < window.brout.room[x].length; y++)
36+
{
37+
if (window.brout.room[x][y] == 32)
38+
{
39+
image(imgs.floor, x * 11, y * 11, 12, 12)
40+
}
41+
else if (window.brout.room[x][y] == 35)
42+
{
43+
image(imgs.wall, x * 11, y * 11, 12, 12)
44+
}
45+
else if (window.brout.room[x][y] == 48)
46+
{
47+
image(imgs.door, x * 11, y * 11, 12, 12)
48+
}
49+
}
50+
}
51+
image(imgs.human, brout.player.x * 11, brout.player.y * 11, 12, 12)
52+
}
4053
}
4154
main()
4255
</script>

main.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,6 @@ end
240240

241241
if io then -- if not on fengari-web(only works on nodejs fengari and lua)
242242
br.repl();
243+
else
244+
return br;
243245
end

0 commit comments

Comments
 (0)