xxxxxxxxxx
108
function setup() {
createCanvas(600, 400);
angleMode(DEGREES) //Need to add
}
var angle = 0
var angleDirection = 1
var angleMoveOn = true
var ballX = 100
var ballY = 260
var goalX = 490
var goalY = 260
var goalWidth = 100
var goalHeight = 30
var goalFlag = false //no goal yet
function draw() {
background(220);
fill('black')
text("X: " + mouseX + " Y: " + mouseY, 300,20)
//displaying range ---Optional
noStroke()
fill(255,0,0,100)
arc(25,100+12.5,400,400,315,350)
fill(0,255,0,100)
arc(25,100+12.5,400,400,350,10)
fill(255,0,0,100)
arc(25,100+12.5,400,400,10,45)
stroke(0)
strokeWeight(1)
//goal
fill('yellow')
rect(goalX,goalY,goalWidth,goalHeight)
//drawing of ball
if(goalFlag == false)
{
fill('white')
ellipse(ballX,ballY,25,25) //ball
}
else{
//write code for when ball makes it to the goal
}
//move ball if space key pressed
if(angleMoveOn == false)
{
//perfect range
if(angle>=-10 && angle<=10)
{
ballX += 2
}
//up bad
if(angle<-10)
{
ballX += 2
ballY -= 2
}
//down bad
if(angle>10)
{
ballX += 2
ballY += 2
}
}
//Moving Arrow
push()
translate(25,100) //replace this with the x & y of your rectangle
rotate(angle)
rect(0,0,150,25) // make your x and y 0,0
translate(-25,-100) //to make the arrow aligned place the negative version of the first translate here
triangle(174,67,247,109,174,154)
pop()
//angle will only move until space key pressed
if(angleMoveOn == true)
{
angle = angle + 1 * angleDirection
}
//flip angle direction
if (angle == 45)
{
angleDirection = -1
}
else if(angle == -45){
angleDirection = 1
}
//if space key pressed
if(keyCode == 32)
{
angleMoveOn = false //turn off
}
//collison with ball and goal
if(ballX>=goalX && ballX <=goalX + width &&
ballY >= goalY && ballY <= goalY + height)
{
goalFlag = true //GOAL!!
}
}