all repos — katbugjs @ bcbe4dc003995c9af89c0151245f7e2a1bfd9dd9

side-scrolling infinite arcade game in Javascript with HTML5 Canvas

Catbug.js (raw)

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
var catbug = {
  x: 45,
  y: 90,
  vX: 0,
  vY: 0,
  frame: 0,
  HP: 3,
  maxHP: 3
};

catbug.move = function()
{
  this.x += this.vX;
  this.y += this.vY;

  if (this.x <= 0 || this.x >= 320)
  {
    this.x -= this.vX;
  }
  if (this.y <= 0 || this.y >= 180)
  {
    this.y -= this.vY;
  }
}
catbug.isInRect = function(box)
{
  if (this.x >= box.x && this.x <= box.x + box.w
      && this.y >= box.y && this.y <= box.y + box.h)
  {
    return true;
  }
  return false;
}