Example #1
0
void kissSimInBgd()
{
	int r,g,b,help=0;
	static int PenPrevious=0;
	while(!kiss_get_key('Q')){
		if(!kiss_get_key('P')){
			if(PenPrevious){
				PenPrevious=0;
				robot.pen=!robot.pen;
				if(robot.pen && robot.pixelCount==0){
					robot.pixel[0].x=robot.x;
					robot.pixel[0].y=robot.y;
					robot.pixelCount=1;
				}
			}
			PenPrevious=0;
		}
		else PenPrevious=1;
		if(kiss_get_key('H'))help=1;
		else help=0;
		kissSimRobotUpdate();
		kissSimComputerUpdate();
		if(!help && _world.simPaused)graphics_rectangle_fill(0,0,ksWindow.simWidth-1,ksWindow.simHeight-1,GRAY);
		else { 
			if(!help){
				kissSimComputerTone(&r,&g,&b);
				graphics_rectangle_fill(0,0,ksWindow.simWidth-1,ksWindow.simHeight-1,r,g,b);
			}
		}
		kissSimDrawObst();
		kissSimRobotDraw();
		kissSimComputerDraw();
		if(help){//print help screen
			graphics_rectangle_fill(0,0,ksWindow.simWidth-1,ksWindow.simHeight-1,255,200,200);// instruction background is light pink
			kissSimPrintInstructions();
		}
		graphics_update();
		msleep(20);
	}
	kissSim_end();
}
Example #2
0
void kissSimDrawButton(struct __button *b, int r, int g, int bb, int rd, int gd, int bd, int rl, int gl, int bl)
{
int x,y;
kiss_get_mouse_position(&x,&y);
b->prevPushState=b->pushState;
b->pushState = kiss_get_mouse_button(0);	
if(x>=b->x1 && x<=b->x2 && y>=b->y1 && y<=b->y2) {
if(!b->prevPushState && b->pushState){
if(b->sticky)b->state=!b->state;
else b->state = 1;
}
}
if(!b->sticky && !b->pushState) b->state=0;
if(b->state){
//		graphics_rectangle_fill(b->x1,b->y1,b->x2-1,b->y2-1,SHADOW);
//		graphics_rectangle_fill(b->x1+1,b->y1+1,b->x2-2,b->y2-2,SHADOW);
graphics_rectangle_fill(b->x1+1,b->y1+1,b->x2+1,b->y2+1,WHITE);
graphics_rectangle_fill(b->x1+2,b->y1+2,b->x2+2,b->y2+2,WHITE);
graphics_rectangle_fill(b->x1+2,b->y1+2,b->x2,b->y2,rd,gd,bd);
}
else {
graphics_rectangle_fill(b->x1+1,b->y1+1,b->x2+1,b->y2+1,SHADOW);
graphics_rectangle_fill(b->x1+2,b->y1+2,b->x2+2,b->y2+2,SHADOW);
graphics_rectangle_fill(b->x1,b->y1,b->x2,b->y2,r,g,bb);
}
BOLD g_printCharacter(b->ltr, b->x1+(b->x2-b->x1)/3, b->y1+(b->y2-b->y1)/4, rl, gl, bl, ((float)(b->y2-b->y1)/11.0));
}
void get_bgal_pod_positions()
{
	// screen size (scols,srows), box size (bxcols,bxcols), separator m pixels
	// random block positions p1, p2 set by function picks
	int srows=120,scols=160, bpos, ppos;
	graphics_close(); // close any existing graphics window
	display_clear();  // prep screen
	set_a_button_text("COUNTDOWN");	set_b_button_text("-"); set_c_button_text("-");
	graphics_open(scols,srows);
	graphics_fill(WHITE);
	bpos=rand()%2;
	if (bpos==0) ppos=1;
	else ppos=0;	
	// draw field
	graphics_rectangle(3,3,157,117,BLACK);        // outline
	graphics_rectangle(3,3,70,50,BLACK);          // quads
	graphics_rectangle(90,3,157,50,BLACK);
	graphics_rectangle(3,70,70,117,BLACK);
	graphics_rectangle(90,70,157,117,BLACK);
	graphics_rectangle_fill(70,3,90,50,LTBROWN);         // mesa
	graphics_rectangle(70,3,90,50,BLACK);
	graphics_rectangle_fill(70,70,90,117,LTBROWN);
	graphics_rectangle(70,70,90,117,BLACK); 
	graphics_rectangle_fill(72,50,88,70,LTGRAY);  // caldera
	graphics_rectangle(72,50,88,70,BLACK);
	graphics_rectangle_fill(20,3,25,50,TEAL);     // lines
	graphics_rectangle_fill(135,3,140,50,TEAL);
	graphics_rectangle_fill(20,70,25,117,PINK);
	graphics_rectangle_fill(135,70,140,117,PINK);	
	if (bpos==0) { 
		draw_bg(73,13,0.2);
		graphics_rectangle_fill(74,87,86,102,GREEN);
	}
	else {
		draw_bg(73,82,0.2);
		graphics_rectangle_fill(74,18,86,32,GREEN);
	}
	graphics_update();
	
	display_printf(2,0,"Set Botgal and Botpod ");
	
	while(a_button()==0);
	while(a_button()==1); // debounce
}
Example #4
0
void kissSim_init(int world, int rx, int ry, float rt)
{
  int i,splash=1;
  if(world<0){world=-world; splash=0;}//a negative world means no splash screen
	kissSimLoadWorld(world);//sets .world, .simHeight & .simWidth (leaving default values if sim is smaller)
	kissSimRobotDim(&ksWindow.rWidth, &ksWindow.rHeight);//set robot window dimensions
	ksWindow.height=ksWindow.simHeight+ksWindow.rHeight;//set overall window height
	kissSimComputerDim(&ksWindow.cWidth, &ksWindow.cHeight);//set computer window dimentsions
	ksWindow.width=ksWindow.simWidth+ksWindow.cWidth;//set overall window width
	graphics_init(ksWindow.width, ksWindow.height);
	graphics_fill(255,255,255);
	glfwSetWindowTitle(_world.title);
	// Draw the spash screen
	if(splash)kissSplashBG(ksWindow.width, ksWindow.height);
	robot.x=rx; robot.y=ry; robot.theta=rt;
	kissSimRobotInit();
	kissSimComputerInit();
	graphics_rectangle_fill(0,0,ksWindow.simWidth-1,ksWindow.simHeight-1,255,200,200);// instruction background is light pink
	kissSimPrintInstructions();
	graphics_update();
	while(!kiss_get_key(' '));while(kiss_get_key(' '));//pause until space bar is hit
	start_process(kissSimInBgd);
	kissSimPause();
}
Example #5
0
void kissSimComputerDraw()
{
	int oriX=ksWindow.simWidth, oriY=0, i;
	static char digitals[]="0 0 0 0 0 0 0 0";
	static char buttons[]="0 0 0 0 0 0 0";
	static char analogs[11][10]={"         ","         ","         ","         ","         ","         ","         ","         ","         ","         ","         "};
	static char actuators[4][25]={"                        ","                        ","                        ","                        "};
	static char servos[4][25]={"                        ","                        ","                        ","                        "};
	if(!glfwGetWindowParam(GLFW_OPENED)) return;
	graphics_rectangle_fill(oriX,oriY,oriX+1,ksWindow.height,BLACK); // draw left border
	draw_bg(oriX+5,oriY+9,0.36); // Botguy
	NOBOLD g_printString(" CBC SIMULATOR",oriX+25, oriY+10,TEAL,1.0);
	NOBOLD g_printString("    DIGITALS  ",oriX+25, oriY+40,TEAL,1.0);
	NOBOLD g_printString("0 1 2 3 4 5 6 7",oriX+25, oriY+55,TEAL,1.0);
	NOBOLD g_printString("    BUTTONS  ",oriX+25, oriY+90,TEAL,1.0);
	//NOBOLD g_printString("< ^ V > A B .",oriX+30, oriY+105,TEAL,1.0);
	NOBOLD g_printString("\xb \xd \xe \xc A B .",oriX+30, oriY+105,TEAL,1.0);
    // hex b, c, d, e are left, right, up, and down arrows
	NOBOLD g_printString(digitals,oriX+25, oriY+70,WHITE,1.0); // erase old digital values
	NOBOLD g_printString("    ANALOGS  ",oriX+25, oriY+140,TEAL,1.0);
	for(i=0;i<8;i++){
		digitals[2*i]=48+digital(i);
	}
	NOBOLD g_printString(digitals,oriX+25, oriY+70,BLACK,1.0); // write new digital values
	NOBOLD g_printString(buttons,oriX+30, oriY+120,WHITE,1.0); // erase old button values
	buttons[0]=48+!!left_button();
	buttons[2]=48+!!up_button();
	buttons[4]=48+!!down_button();
	buttons[6]=48+!!right_button();
	buttons[8]=48+!!a_button();
	buttons[10]=48+!!b_button();
	_bob.button=!!kiss_get_key('.');
	buttons[12]=48+black_button();
	NOBOLD g_printString(buttons,oriX+30, oriY+120,BLACK,1.0); // erase old button values
	for(i=8;i<16;i++){//print out analogs
		analogs[i-8][1]=(i<10)?48+i:48+i-10;
		analogs[i-8][0]=(i<10)?32:49;
		analogs[i-8][2]=':';
		analogs[i-8][3]=' ';
		NOBOLD g_printString(analogs[i-8],oriX+5, oriY+155+(15*(i-8)),WHITE,1.0);
		convertNumToString(analog10(i),4,*analogs,10,i-8,3);
		graphics_rectangle_fill(oriX+30,oriY+155+(15*(i-8)),oriX+157, oriY+165+(15*(i-8)),GRAY);
		graphics_line(oriX+30+analog(i)/2, oriY+155+(15*(i-8)),oriX+30+analog(i)/2,oriY+165+(15*(i-8)),RED);
		NOBOLD g_printString(analogs[i-8],oriX+5, oriY+155+(15*(i-8)),BLACK,1.0);

	}
	analogs[8][1]='X';
	analogs[8][0]='A';
	analogs[8][2]=':';
	analogs[8][3]=' ';
	NOBOLD g_printString(analogs[8],oriX+5, oriY+155+(15*(8)),WHITE,1.0);
	convertNumToString(accel_x(),5,*analogs,10,8,3);
	graphics_rectangle_fill(oriX+30,oriY+155+(15*(8)),oriX+157, oriY+165+(15*(8)),GRAY);
	graphics_line(oriX+30+(accel_x()+2048)/32, oriY+155+(15*(8)),oriX+30+(accel_x()+2048)/32,oriY+165+(15*(8)),RED);
	NOBOLD g_printString(analogs[8],oriX+5, oriY+155+(15*(8)),BLACK,1.0);
	analogs[9][1]='Y';
	analogs[9][0]='A';
	analogs[9][2]=':';
	analogs[9][3]=' ';
	NOBOLD g_printString(analogs[9],oriX+5, oriY+155+(15*(9)),WHITE,1.0);
	convertNumToString(accel_y(),5,*analogs,10,9,3);
	graphics_rectangle_fill(oriX+30,oriY+155+(15*(9)),oriX+157, oriY+165+(15*(9)),GRAY);
	graphics_line(oriX+30+(accel_y()+2048)/32, oriY+155+(15*(9)),oriX+30+(accel_y()+2048)/32,oriY+165+(15*(9)),RED);
	NOBOLD g_printString(analogs[9],oriX+5, oriY+155+(15*(9)),BLACK,1.0);
	analogs[10][1]='Z';
	analogs[10][0]='A';
	analogs[10][2]=':';
	analogs[10][3]=' ';
	NOBOLD g_printString(analogs[10],oriX+5, oriY+155+(15*(10)),WHITE,1.0);
	convertNumToString(accel_z(),5,*analogs,10,10,3);
	graphics_rectangle_fill(oriX+30,oriY+155+(15*(10)),oriX+157, oriY+165+(15*(10)),GRAY);
	graphics_line(oriX+30+(accel_z()+2048)/32, oriY+155+(15*(10)),oriX+30+(accel_z()+2048)/32,oriY+165+(15*(10)),RED);
	NOBOLD g_printString(analogs[10],oriX+5, oriY+155+(15*(10)),BLACK,1.0);

	NOBOLD g_printString("MOT PWM TPS  ENCODER VAL",oriX+5, oriY+330,TEAL,1.0);
	for(i=0;i<4;i++){
		actuators[i][0]=48+i;
		actuators[i][1]=':';
		actuators[i][2]=' ';
		NOBOLD g_printString(actuators[i],oriX+5, oriY+345+(15*(i)),WHITE,1.0);
		convertNumToString(_bob.motor_pwm[i],4,*actuators,25,i,2);
		convertNumToString(_bob.motor_tps[i],4,*actuators,25,i,7);
		convertNumToString(_bob.motor_counter[i],10,*actuators,25,i,12);
		NOBOLD g_printString(actuators[i],oriX+5, oriY+345+(15*(i)),BLACK,1.0);
	}
	if(_bob.enable_servos){
		NOBOLD g_printString("SERVO TARGET DISABLED",oriX+5, oriY+410,WHITE,1.0);
		NOBOLD g_printString("SERVO TARGET ENABLED",oriX+5, oriY+410,TEAL,1.0);
	}
	else {
		NOBOLD g_printString("SERVO TARGET ENABLED",oriX+5, oriY+410,WHITE,1.0);
		NOBOLD g_printString("SERVO TARGET DISABLED",oriX+5, oriY+410,TEAL,1.0);
	}
	for(i=0;i<4;i++){
		servos[i][2]=49+i;//servos are 1 indexed!!
		servos[i][3]=':';
		servos[i][4]=' ';
		NOBOLD g_printString(servos[i],oriX+5, oriY+425+(15*(i)),WHITE,1.0);
		convertNumToString(_bob.servo_targets[i],4,*servos,25,i,6);
		NOBOLD g_printString(servos[i],oriX+5, oriY+425+(15*(i)),BLACK,1.0);
	}

}