Need help with simple JS game :)


#1

I’m having some trouble writing a simple code about a g

ame, similar to “!osu”, where you click in a moving target – a square – and if you hit the target, you get a point (score += 1). Every time you click, hitting the target or not, the target gets smaller and faster, yet, something’s off in my code, so it doesn’t counts as a hit when i hit the target, I believe the issue is in line 22 - 23.
If you can, please take a look:
[Take in consideration that the var “tamanho” would be the square size, and the var “freimeRate” is the frameRate, or the difficulty level]



var tamanho = 50;
var score = 0
var freimeRate
freimeRate = 0.5
function setup() { 
  createCanvas(400, 400);
} 
function draw() { 
  var x = random(1, 370);
	var y = random(1, 370);
  frameRate(freimeRate);
  background(220);
  rect (x, y, tamanho, tamanho);
  textSize(25);
  text("SCORE = " + score, 10, 30);
  }
function mouseClicked(){
freimeRate +=0.3;
tamanho -=0.5;
  var x = random(1, 370);
	var y = random(1, 370);
  if(mouseX >= x && mouseX <= x + tamanho){
    if(mouseY >=y && mouseY <= y + tamanho){
      score +=1
    }
  }
}



#2

nothing happens? Is there also html code involved? Please provide a running/working example (sites like jsfiddle, jsbin, codepen and repl.it are good sites where you can place such code snippets

i feel like html code or something might be missing, the function are never called thus never executed


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.