Geep5

player cast

Sep 21st, 2020
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1.  
  2. <script>
  3. import firebase from './stores/DB.js'
  4. // console.log('DB', DB);
  5.  
  6. let playercast = [0,0,50,0,0]
  7.  
  8. let players = firebase.database().ref('Fight/');
  9. console.log('players', players);
  10. let playerlist = []
  11. players.on('value', function(snapshot) {
  12. playerlist = Object.values(snapshot.val())
  13. console.log('playerlist', playerlist);
  14. for (let i of playerlist) {
  15. console.log('cast', i.cast)
  16. }
  17. });
  18.  
  19. firebase.database().ref('Fight/' + 'player1/health').set({
  20. hp : 57,
  21. });
  22.  
  23. const countdown = async () => {
  24. if (playercast[1] > 0) setTimeout(castdown, 20)
  25. else firebase.database()
  26. .ref('Fight')
  27. .child('Dor')
  28. .child('health')
  29. .child('hp')
  30. .set(firebase.database.ServerValue.increment(-1))
  31. return
  32. }
  33.  
  34. const castdown = async () => {
  35. playercast[1]--
  36. countdown()
  37. }
  38.  
  39. const resetDor = async () => {
  40. firebase.database().ref('Fight/' + 'Dor/health').set({
  41. hp : 100,
  42. });
  43. }
  44.  
  45. </script>
  46.  
  47. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
  48.  
  49. <main>
  50. hello from app.svelte
  51.  
  52. <!-- {$DB} -->
  53. {#each playerlist as player, i}
  54. <div class="health-background">
  55. <div class="health-bar" style="width: {player.health.hp}%">
  56. {player.name}
  57. {player.health.hp}
  58. </div>
  59. </div>
  60. <div class="cast-background">
  61. <div class="cast-bar" style="width: {playercast[i]}%">
  62. {player.spell}
  63. </div>
  64. </div>
  65. <div class="target-position">
  66. <i class="fa fa-user target-icon playericon1"></i>
  67. </div>
  68. {/each}
  69.  
  70. <button on:click={countdown}>☄️Frost Bolt</button>
  71. <button on:click={resetDor}>🔄Reset Dor</button>
  72.  
  73. </main>
  74.  
  75. <style>
  76.  
  77. .playericon1 {
  78. color: red;
  79.  
  80. }
  81.  
  82. .target-icon {
  83. margin-left: 515px;
  84. margin-top: -73px;
  85. position: absolute;
  86. font-size: 38px;
  87. }
  88.  
  89. .cast-bar {
  90. /* width: 30%; */
  91. background-color:#e0d774;
  92. color: white;
  93. text-shadow: 1px 1px #202020;
  94. height: 30px;
  95. }
  96.  
  97. .cast-background {
  98. width: 50%;
  99. background-color:#cacaca;
  100. margin-bottom: 20px;
  101. }
  102.  
  103. .health-bar {
  104. background-color: rgb(60, 80, 255);
  105. color: white;
  106. text-shadow: 1px 1px #202020;
  107. height: 40px;
  108. }
  109.  
  110. .health-background {
  111. width: 50%;
  112. background-color:#cecece;
  113. }
  114.  
  115. </style>
Add Comment
Please, Sign In to add comment