Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//How can I complete the parts with this symbol /*** using C code. I need to cre

ID: 3689909 • Letter: #

Question

//How can I complete the parts with this symbol /*** using C code. I need to create a blob for a game and I have not gotten the right results. I need to use the arrow operator (->) and I need to follow the steps below.

#include "blob.h"
#include "mbed.h"
#include "misc.h"
#define BGRD_COL 0x0F0066
#define FOOD_COL 0xFFFFFF
#define P1_COL 0xBB0CE8
#define P2_COL 0xFF0030
#define BORDER_COL 0xFFFFFF
#define WORLD_WIDTH 256
#define WORLD_HEIGHT 256

typedef struct blob {
float old_x, old_y;
float posx, posy;
float vx, vy;
float rad;
int color;
bool valid;
bool delete_now;
} BLOB;

void BLOB_init(BLOB* b);
void BLOB_init(BLOB* b, int rad);
void BLOB_init(BLOB* b, int rad, int color);

void BLOB_constrain2world(BLOB* b);
void BLOB_print(BLOB b);
float BLOB_dist2(BLOB b1, BLOB b2);

extern Serial pc;


// Randomly initialize a blob's position, velocity, color, radius, etc.
// Set the valid flag to true and the delete_now flag to false.
// delete_now is basically the derivative of valid. It goes true for one
// fram when the blob is deleted, and then it is reset to false in the next frame
// when that blob is deleted.
void BLOB_init(BLOB* b) {
// ***
}


// Take in a blob and determine whether it is inside the world.
// If the blob has escaped the world, put it back on the edge
// of the world and negate its velocity so that it bounces off
// the boundary. Use WORLD_WIDTH and WORLD_HEIGHT defined in "misc.h"
void BLOB_constrain2world(BLOB* b) {
// ***
}

// Randomly initialize a blob. Then set the radius to the provided value.
void BLOB_init(BLOB* b, int rad) {
// ***
}

// Randomly initialize a blob. Then set the radius and color to the
// provided values.
void BLOB_init(BLOB* b, int rad, int color) {
// ***
}

// For debug purposes, you can use this to print a blob's properties to your computer's serial monitor.
void BLOB_print(BLOB b) {
pc.printf("(%f, %f) <%f, %f> Color: 0x%x ", b.posx, b.posy, b.vx, b.vy, b.color);
}

// Return the square of the distance from b1 to b2
float BLOB_dist2(BLOB b1, BLOB b2) {
// ***
}

Explanation / Answer

Answer:)

// Randomly initialize a blob. Then set the radius to the provided value.
void BLOB_init(BLOB* b, int rad) {
// ***
   BLOB *temp = b;
   temp->rad = rad;
}

// Randomly initialize a blob. Then set the radius and color to // the provided values.
void BLOB_init(BLOB* b, int rad, int color) {
// ***
   BLOB *temp = b;
   temp->rad = rad;
   temp->color = color;
}

// Return the square of the distance from b1 to b2
float BLOB_dist2(BLOB b1, BLOB b2) {
// ***
   float dist = 0.0;
   dist = ((b1->posx - b2->posx)*(b1->posx - b2->posx))+((b1->posy - b2->posy)*(b1->posy - b2->posy));
   return dist;
}