Skip to main content

How many Struckd Coins do I receive from each purchase?

Comments

3 comments

  • Pratap Chandra Dhir

     

    <!DOCTYPE html><html lang="en">

    <head>

      <meta charset="UTF-8">

      <title>Fishing Man Game</title>

      <style>

        body {

          margin: 0;

          overflow: hidden;

          background: skyblue;

        }

        canvas {

          display: block;

          margin: auto;

          background: #4da6ff;

        }

      </style>

    </head>

    <body>

    <canvas id="gameCanvas" width="480" height="640"></canvas><script>

    const canvas = document.getElementById("gameCanvas");

    const ctx = canvas.getContext("2d");

    let boat = { x: 200, y: 50, width: 80, height: 40 };

    let hook = { x: boat.x + 40, y: boat.y + 40, width: 5, height: 20, moving: false, down: true };

    let fishes = [];

    let score = 0;

    // create fishes

    function spawnFish() {

      let fish = {

        x: Math.random() * (canvas.width - 40),

        y: Math.random() * (canvas.height - 200) + 200,

        width: 40,

        height: 20,

        speed: (Math.random() * 2) + 1,

        dir: Math.random() < 0.5 ? 1 : -1

      };

      fishes.push(fish);

    }

    setInterval(spawnFish, 2000);

    // draw boat

    function drawBoat() {

      ctx.fillStyle = "brown";

      ctx.fillRect(boat.x, boat.y, boat.width, boat.height);

    }

    // draw hook

    function drawHook() {

      ctx.fillStyle = "black";

      ctx.fillRect(hook.x, hook.y, hook.width, hook.height);

      ctx.beginPath();

      ctx.moveTo(boat.x + boat.width/2, boat.y + boat.height);

      ctx.lineTo(hook.x + hook.width/2, hook.y);

      ctx.stroke();

    }

    // draw fishes

    function drawFishes() {

      ctx.fillStyle = "orange";

      for (let f of fishes) {

        ctx.fillRect(f.x, f.y, f.width, f.height);

      }

    }

    // move fishes

    function moveFishes() {

      for (let f of fishes) {

        f.x += f.speed * f.dir;

        if (f.x <= 0 || f.x + f.width >= canvas.width) {

          f.dir *= -1;

        }

      }

    }

    // move hook

    function moveHook() {

      if (hook.moving) {

        if (hook.down) {

          hook.y += 4;

          if (hook.y > canvas.height - 10) hook.down = false;

        } else {

          hook.y -= 4;

          if (hook.y <= boat.y + boat.height) {

            hook.moving = false;

            hook.down = true;

            hook.y = boat.y + boat.height;

          }

        }

      }

    }

    // collision detection

    function checkCatch() {

      for (let i = 0; i < fishes.length; i++) {

        let f = fishes[i];

        if (hook.x < f.x + f.width && hook.x + hook.width > f.x &&

            hook.y < f.y + f.height && hook.y + hook.height > f.y) {

          score++;

          fishes.splice(i, 1);

          hook.down = false;

          break;

        }

      }

    }

    // controls

    window.addEventListener("keydown", e => {

      if (e.key === "ArrowLeft") boat.x -= 15;

      if (e.key === "ArrowRight") boat.x += 15;

      if (e.key === " " && !hook.moving) {

        hook.moving = true;

        hook.x = boat.x + boat.width/2;

    0
  • Pratap Chandra Dhir

    <!DOCTYPE html><html lang="en">

    <head>

      <meta charset="UTF-8">

      <title>Fishing Man Game</title>

      <style>

        body {

          margin: 0;

          overflow: hidden;

          background: skyblue;

        }

        canvas {

          display: block;

          margin: auto;

          background: #4da6ff;

        }

      </style>

    </head>

    <body>

    <canvas id="gameCanvas" width="480" height="640"></canvas><script>

    const canvas = document.getElementById("gameCanvas");

    const ctx = canvas.getContext("2d");

    let boat = { x: 200, y: 50, width: 80, height: 40 };

    let hook = { x: boat.x + 40, y: boat.y + 40, width: 5, height: 20, moving: false, down: true };

    let fishes = [];

    let score = 0;

    // create fishes

    function spawnFish() {

      let fish = {

        x: Math.random() * (canvas.width - 40),

        y: Math.random() * (canvas.height - 200) + 200,

        width: 40,

        height: 20,

        speed: (Math.random() * 2) + 1,

        dir: Math.random() < 0.5 ? 1 : -1

      };

      fishes.push(fish);

    }

    setInterval(spawnFish, 2000);

    // draw boat

    function drawBoat() {

      ctx.fillStyle = "brown";

      ctx.fillRect(boat.x, boat.y, boat.width, boat.height);

    }

    // draw hook

    function drawHook() {

      ctx.fillStyle = "black";

      ctx.fillRect(hook.x, hook.y, hook.width, hook.height);

      ctx.beginPath();

      ctx.moveTo(boat.x + boat.width/2, boat.y + boat.height);

      ctx.lineTo(hook.x + hook.width/2, hook.y);

      ctx.stroke();

    }

    // draw fishes

    function drawFishes() {

      ctx.fillStyle = "orange";

      for (let f of fishes) {

        ctx.fillRect(f.x, f.y, f.width, f.height);

      }

    }

    // move fishes

    function moveFishes() {

      for (let f of fishes) {

        f.x += f.speed * f.dir;

        if (f.x <= 0 || f.x + f.width >= canvas.width) {

          f.dir *= -1;

        }

      }

    }

    // move hook

    function moveHook() {

      if (hook.moving) {

        if (hook.down) {

          hook.y += 4;

          if (hook.y > canvas.height - 10) hook.down = false;

        } else {

          hook.y -= 4;

          if (hook.y <= boat.y + boat.height) {

            hook.moving = false;

            hook.down = true;

            hook.y = boat.y + boat.height;

          }

        }

      }

    }

    // collision detection

    function checkCatch() {

      for (let i = 0; i < fishes.length; i++) {

        let f = fishes[i];

        if (hook.x < f.x + f.width && hook.x + hook.width > f.x &&

            hook.y < f.y + f.height && hook.y + hook.height > f.y) {

          score++;

          fishes.splice(i, 1);

          hook.down = false;

          break;

        }

      }

    }

    // controls

    window.addEventListener("keydown", e => {

      if (e.key === "ArrowLeft") boat.x -= 15;

      if (e.key === "ArrowRight") boat.x += 15;

      if (e.key === " " && !hook.moving) {

        hook.moving = true;

        hook.x = boat.x + boat.width/2;

    0
  • Dhruvi Parekh

    /e dance2

     

    0

Please sign in to leave a comment.

Powered by Zendesk