]> git.lizzy.rs Git - dragonblocks.git/blob - game/fire/init.js
Reset file permissions to defaults
[dragonblocks.git] / game / fire / init.js
1 fire = {};
2 fire.playingBurnSounds = 0;
3 fire.playBurnSound = function(){
4         if(fire.playingBurnSounds > 2)
5                 return;
6         fire.playingBurnSounds++;
7         let audio = new Audio(dragonblocks.getSound("fire_burn.ogg"));
8         audio.onended = _ => {
9                 fire.playingBurnSounds--;
10         };
11         audio.play();
12 }
13 fire.catchfire = function(x, y){
14         let mapNode = dragonblocks.getNode(x, y);
15         if(mapNode && mapNode.toNode().flammable){
16                 if(mapNode.toNode().onfire && mapNode.toNode().onfire(x, y) == false)
17                         return;
18                 dragonblocks.player.place(x, y - 1, "fire:fire");
19         }
20 }
21 dragonblocks.registerGroup({
22         name: "flammable",
23 });
24 dragonblocks.registerNode({
25         name: "fire:fire",
26         stable: false,
27         texture: "fire_fire.png",
28         groups: [],
29         hardness: 1,
30         desc: "Fire",
31         drops: "",
32         sounds: {
33                 dug: "fire_dug.ogg",
34                 place: "",
35         },
36         onset : (x, y) => {
37                 let meta = dragonblocks.getNode(x, y).meta;
38                 meta.fireInterval = setInterval(_ => {
39                         if(dblib.random(0, 6) == 0);
40                                 fire.playBurnSound();
41                         for(let ix = x - 1; ix <= x + 1; ix++){
42                                 for(let iy = y - 1; iy <= y + 2; iy++){
43                                         if(dblib.random(0, 3) == 0)
44                                                 fire.catchfire(ix, iy);
45                                 }
46                         }
47                         if(! dragonblocks.getNode(x, y + 1) || ! dragonblocks.getNode(x, y + 1).toNode().inGroup("flammable")){
48                                 if(dblib.random(0, 20) == 0)
49                                         dragonblocks.setNode(x, y, "air");
50                         }
51                         else if(dblib.random(0, dragonblocks.getNode(x, y + 1).toNode().hardness * 2) == 0)
52                                 dragonblocks.player.dig(x, y + 1);
53                 }, 1000);
54         },
55         onremove : (x, y) => {
56                 clearInterval(dragonblocks.getNode(x, y).meta.fireInterval);
57         }
58 });