// I am trying to follow the instructions with the sign (/**) below using C prog
ID: 3690056 • Letter: #
Question
// I am trying to follow the instructions with the sign (/**) below using C program, but I am doing something wrong. Can you cerrect what I have using the arrow (->) operator. Thank you
#include "blob.h"
#include "mbed.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
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) {
// ***
b->posx=rand()%256+1 ;
b->posy=rand()%256+1 ;
b->vx=rand()%10+1 ;
b->vy=rand()%10+1 ;
b->rad=rand()%10+1 ;
b->color=rand()%3+1 ;
b->old_x=rand()%10+1;
b->old_y=rand()%10+1;
b->valid=1;
b->delete_now=0;
}
// 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) {
// ***
if(b->old_x>WORLD_HEIGHT || b->old_y>WORLD_HEIGHT){
b->old_x=-1*b->old_x;
b->old_y=-1*b->old_y;
}
if (b->posx> WORLD_HEIGHT || b->posx<WORLD_HEIGHT){
b->posx=-1*b->posx;
b->posy=-1*b->posy;
}
}
// Randomly initialize a blob. Then set the radius to the provided value.
void BLOB_init(BLOB* b, int rad1) {
// ***
BLOB *temp = b;
temp->rad = rad;
Explanation / Answer
in this question , BLOB is structure with posx,posy,vx,vy,rad,color,old_x,old_y,valid,delete_now as data items and to use this items we use . operator rather than -> arrow
in the given program, you uses -> arrow operator so it may leads toerror so use . opeartor
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.