Hello,
I am taking up @Ignatz “learn codea” pdf guide.
I would like to know what exactly I am doing wrong.
The purpose of this code @Ignatz produced, was to demonstrate once the red line (aka: the arrow) hits a yellow floating ball, we get a score.
I did not paste his code, instead I typed it. I’m a beginner, so for me typing in the code allows it to sink in.
I compared our codes - and I cannot find what is causing the error on my side, but his code is working fine.
Please just let me know what I did wrong
(over explaining with examples that have nothing to do with this code - - will confuse me)
It’s been a couple years since I’ve been on this forum - and when I was on here, I was a beginner grappling with the concepts of variables.
Here is @Ignatz working code:
function setup()
balloonWidth=50
balloonHeight=60
balloonX=WIDTH/2
balloonY=0
balloonSpeed=1
arrowWidth=40
arrowStartX=50
arrowX=arrowStartX
arrowY=HEIGHT/2
arrowSpeed=3
score=0
end
function draw()
background(0)
pushStyle()
fill(255,255,0,150)
balloonY=balloonY+balloonSpeed
if balloonY-balloonHeight/2>HEIGHT
then balloonY=0
end
ellipse(balloonX,balloonY,balloonWidth,balloonHeight)
arrowX=arrowX+arrowSpeed
if arrowX>WIDTH
then arrowX=arrowStartX
end
if arrowX>balloonX-balloonWidth/2
and arrowX<=balloonX+balloonWidth/2
and arrowY>balloonY-balloonHeight/2
and arrowY<=balloonY+balloonHeight/2
then score=score+1
print("Hit!",score)
balloonY=0 arrowX=arrowStartX --reset balloon and arrow
end
stroke(245, 30, 55)
strokeWidth(5) line(arrowX,arrowY,arrowX+arrowWidth,arrowY) popStyle()
end
My code (what did I do wrong?) please POINT out the specific code line or code lines —Thank You
function setup()
balloonWidth=50
balloonHeight=60
balloonX=WIDTH/2 --sets (x axis) position to mid screen.
balloonY=0 --sets y axis position
balloonSpeed=1 --sets speed
--ARROWS
arrowWidth=40
arrowStartX=50 --where arrow starts from left
arrowX=arrowStartX --current x value of arrow
arrowY=HEIGHT/2 --later this will be touch
arrowSpeed=3
score=0
end
function draw()
background(4)
pushStyle()
fill(255,255,0,150)
--adjust vertical (y axis) position
balloonY=balloonY+balloonSpeed
--checks if ball at top of screen, restarts draw bottom if ball at top of screen
if balloonY-balloonHeight/2>HEIGHT
then balloonY=0
end
ellipse(balloonX,balloonY,balloonWidth,balloonHeight)
--ARROWS
arrowX=arrowX+arrowSpeed --similiar to balloon
if arrowX>WIDTH
then arrowX=arrowStartX
end
--Collision Detect
if arrowX>balloonX-balloonWidth/2
and arrowX<=balloonX+balloonWidth/2
and arrowY>balloonY-balloonHeight/2
and arrowY<=balloonY+balloonHeight/2
then score=score+1
print("Hit!",score)
balloonY=0 arrowX=arrowStart --reset balloon and arrow
end
--STROKE
stroke(239, 52, 57) --arrow color
strokeWidth(5) --pixels wide
line(arrowX,arrowY,arrowX+arrowWidth,arrowY) --draw arrow
popStyle()
end