# Food Drop from an Airplane

**URL:** <https://discourse.processing.org/t/food-drop-from-an-airplane/25782>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [November 28, 2020, 5:20am UTC](https://discourse.processing.org/t/food-drop-from-an-airplane/25782 "2020-11-28T05:20:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/elo/32/11154_2.png) [@Elo](https://discourse.processing.org/u/Elo)\
**Post date:** [November 28, 2020, 5:20am UTC](https://discourse.processing.org/t/food-drop-from-an-airplane/25782/1 "2020-11-28T05:20:48Z")

</div>

I don’t know what I’m doing wrong and I don’t understand processing that well; Can Someone help me fix the issues and bugs in my program

 ![Screenshot (34)](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8ce0e92a644e771d508d0f739eb03f71f5e306b4.png) ![Screenshot (35)](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/ce406d2160b3619df18847f2a68d99874ca350d8.png) ![Screenshot (36)](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f342484114bbdd87845eb18037490fc91eb105d7.png)

[details=“Summary”]  
This text will be hidden

//plane coordinates  
int planeX = 50, planeY = 50;//plane initaial position  
int planeWidth = 60, planeHeight = 20;//plane size  
int cockpitX = planeX + 60, cockpitY = 60;//cockpit position of the plane  
int cockpitWidth = 45, cockpitHeight = planeHeight;// size of the cockpit  
int wingX1 = planeX, wingX2 = planeX + 30, wingY1 = 30, wingY2 = 70;//wing position and size

//position of the food;  
int x = planeX;  
int y = planeY ;

boolean onlyOneDrops = true; //so another package doesn’t drop  
boolean foodReleased = true;

void setup()  
size(500, 500);

void draw()  
background(#C5D7FA);//blue  
drawBackground();  
movePlane();  
drawPlane();  
dropFood();

if (keyCode == ENTER)  
textSize(30);  
fill(0);  
text(“FOOD RELEASED”, width_0.25, height_0.4);  
else  
foodReleased = !foodReleased;

target();

void drawBackground() {  
final float HORIZON\_Y = height \* 0.9;//height of the horizon  
final float HORIZON\_X = width;//end of the horizon

noStroke();  
fill(#2C673D);//forest green  
rect(0, HORIZON\_Y, HORIZON\_X, height);//horizon

treeLocation(0, height_0.8, height_0.9, 25);

void treeLocation(float treeX, float treePostY, float treeY, final float TREE\_SIZE)  
final float SPACING= 30;  
for (int i=0; i\<=width; i++)

```
treeX = SPACING * i; 
treeX+= SPACING/5;

stroke(#6C482C);//brown
strokeWeight(4);
line(treeX, treePostY, treeX, treeY);

noStroke();
fill(#35C958);//light green
circle(treeX, treePostY, TREE_SIZE);

```

void drawPlane()

noStroke();  
fill(#7275FA);  
rect(planeX, planeY, planeWidth, planeHeight);  
ellipse(cockpitX, cockpitY, cockpitWidth, cockpitHeight);  
triangle(wingX1, wingY2, wingX1, wingY1, wingX2, wingY2);

void movePlane()

final float SPEED = 2.0;

planeX+=SPEED;  
cockpitX+=SPEED;  
wingX1+=SPEED;  
wingX2+=SPEED;  
if (planeX\>width && cockpitX\>width+20 && wingX1\>width && wingX2\>width && wingX2\>width)

```
planeX = -20;
cockpitX = 40;
wingX1 = -20;
wingX2 = -20;
wingX2 = 20;

```

float calcTimeSinceDropped(float time)

time = ENTER;

return time;

float calcFoodX(float flightTime, float initX, float initV)

initX = initX + initV \* flightTime;  
x += initX;  
return x;

float calcFoodY(float flightTime, float initY)  
final float GRAVITY = 0.25;//gravity to move the food  
initY = initY + 0.5 \* GRAVITY \* (flightTime\*flightTime);  
y += initY;  
return y;

void dropFood() {

if (keyCode==ENTER && onlyOneDrops)  
x += calcFoodX(0, 0, 0);  
y += calcFoodY(0, 0);

```
final int FOOD_SIZE = 10;
strokeWeight(1);
stroke(0);
fill(#FF05AC);
rect (x, y, FOOD_SIZE, FOOD_SIZE);

```

fill(#F01657);  
textSize(18);  
text(“FoodX:”+" “+ (int)x, width \* 0.02, height \* 0.1);  
text(“FoodY:”+” "+ (int)y, width\* 0.02, height\* 0.14);

boolean foodInObject(float objectX, float objectY, float objectDiameter, float foodX, float foodY)

int score = 0;  
if (foodX == objectX || foodY == objectY )  
score++;  
text(“shots”+" " + score, width_4/5, height_1/5);  
text(“TARGET HIT”, width/2, height/2);  
return true;  
else  
score = 0;  
text(“MISS!”, width/2, height/2);  
return false;

boolean belowGround(float y)  
if (y\>height)  
return true;  
else  
return false;

boolean outOfView(float x)  
if ( x\>width)  
return true;  
else  
return false;

void target()  
float circleX = 300;  
float circleY = height \* 0.95;  
float targetSize = 40;

strokeWeight(1);  
stroke(0);  
fill(#CB792B);

circle( circleX, circleY, targetSize);

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [November 28, 2020, 5:36pm UTC](https://discourse.processing.org/t/food-drop-from-an-airplane/25782/2 "2020-11-28T17:36:43Z")

</div>

Please edit your code above to make it copyable. When you copy it as is, it’s full of curly quotes like “ which don’t work. But I already saw that you used `time = ENTER;` while time was declared as float, and enter isn’t a float;
