Beispiel #1
0
int main(int argc, char **argv) {
    int w, h, fontsize;
    VGint x, cx, cy, cw, ch, midy, speed;
    char *message = "Now is the time for all good men to come to the aid of the party";
    char done[3];

    init(&w, &h);
    speed = 15;
    midy = (VGfloat) h / 2;
    fontsize = w / 50;
    cx = 0.0;
    ch = fontsize * 2;
    cw = w;
    cy = midy - (ch / 2);

    // scroll the text, only in the clipping rectangle
    for (x = 0; x < cw+speed; x += speed) {
        Start(w, h);
        Background(255, 255, 255);
        Fill(0,0,0,.2);
        Rect(cx, cy, cw, ch);
        ClipRect(cx, cy, cw, ch);
        Translate(x, cy + (fontsize / 2));
        Fill(0, 0, 0, 1);
        Text(0, 0, message, SansTypeface, fontsize);
        ClipEnd();
        End();
    }
    fgets(done, 2, stdin); // press [Return] when done
    finish();
    exit(0);
}
Beispiel #2
0
double FitFunction::operator()(const double* x, const double* par) {
    const double hist_val = par[0] * histogram_.GetBinContent(histogram_.FindBin(x[0]));
    const double bg = Background(x[0], par[1], par[2], par[3]);
    const double func_val = par[4] * bg;

    return hist_val + func_val;
}
void Animation::Draw(int x, int y, int angle, bool more, SDL_Renderer* render)
{
    if(m_animation_type=="background")
    {
        Background(x, y, angle, more,render);
    }
    else if(m_animation_type=="loop")
    {
        LOOP(x, y, angle, more, render);
    }
    else if(m_animation_type=="linear")
    {
        Linear(x, y, angle, more, render);
    }
    else if(m_animation_type=="repeat middle")
    {
        Repeat_middle(x, y, angle, more, render);
    }
    else if(m_animation_type=="return from end")
    {
        Return_end(x, y, angle, more, render);
    }
    else if(m_animation_type=="random")
    {
        Random(x, y, angle, more, render);
    }
    else if(m_animation_type=="hpbarbody")
    {
        HP_Bar_body(x, y, angle, more, render);
    }
    else if(m_animation_type=="draw image")
    {
        Draw_Image(x, y, angle, more, render);
    }
}
Beispiel #4
0
		void Update ()
			{
			ForegroundFLD->Int (OrigREC,Foreground ());
			BackgroundFLD->Int (OrigREC,Background ());
			StyleFLD->Int (OrigREC,Style ());
			OrigREC->Name (Name ());
			}
Beispiel #5
0
 DBInt IsChanged() {
     if (Foreground() != ForegroundFLD->Int(OrigREC)) return (true);
     if (Background() != BackgroundFLD->Int(OrigREC)) return (true);
     if (Style() != StyleFLD->Int(OrigREC)) return (true);
     if (strcmp(Name(), OrigREC->Name()) != 0) return (true);
     return (false);
 }
Beispiel #6
0
int drawScreen() {
	int width, height;
	char s[3];
	
	init(&width, &height);                  // Graphics initialization
	width = height;
	Start(width, height);                   // Start the picture
	Background(255, 255, 255);                    // Black background
	
	Fill(44, 77, 232, 1);
	
	//Circle(x,y,r) 
	Circle(width/2, height/2, height/10);	// Circle in middle
	
	//Rect(x1,y1,x2,y2)
	Fill(44, 77, 232, 1);
	Rect(0,0,width,height/50);	// Bottom Boarder
	Rect(0,height-height/50,width,height);	// Top Boarder
	Rect(0,0,width/50,height);	// Left Boarder
	Rect(width-width/50,0,width,height);	// Right Boarder

	drawLine(width, height);

	End();                                  // End the picture
	
	fgets(s, 2, stdin);                     // look at the pic, end with [RETURN]
	finish();                               // Graphics cleanup
	exit(0);
}
// -----------------------------------------------------------------------------
// AknsDrawUtils::Background()
// (commented in the header).
// -----------------------------------------------------------------------------
//
EXPORT_C TBool AknsDrawUtils::Background( MAknsSkinInstance* aInstance,
    MAknsControlContext* aContext, const CCoeControl* aControl,
    CWindowGc& aGc, const TRect& aRect )
    {
    return Background( aInstance, aContext, aControl, aGc, aRect,
        KAknsDrawParamDefault );
    }
Beispiel #8
0
///////////////////////// OpenGL ////////////////////////////////////
void DataLoad::renderScence(void)
{
	glClear(GL_COLOR_BUFFER_BIT || GL_DEPTH_TEST);

	glViewport(0, 0, 800, 800);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f);

	//gluPerspective(45, 1, 0.01, 1000);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	// 버텍스 버퍼 사용

	//glEnableClientState(GL_VERTEX_ARRAY);
	//glVertexPointer()
	//glDrawArrays();
	//glDisableClientState(GL_VERTEX_ARRAY);

	Background();
	//	DrawQuad();
	DrawGraph();
	DrawData();

	glutSwapBuffers();

}
Beispiel #9
0
// fontrange shows a range of fonts
void fontrange(int w, int h) {
	int *s, sizes[] = { 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 21, 24, 36, 48, 60, 72, 96, 0 };
	VGfloat x, y = h / 2, spacing = 50, s2 = spacing / 2, len, lx;
	char num[4];

	Start(w, h);
	Background(255, 255, 255);

	// compute the length so we can center
	for (len = 0, s = sizes; *s; s++) {
		len += *s + spacing;
	}
	len -= spacing;
	lx = (w / 2) - (len / 2);			   // center point

	// for each size, display a character and label
	for (x = lx, s = sizes; *s; s++) {
		Fill(128, 0, 0, 1);
		TextMid(x, y, "a", *s);
		Fill(128, 128, 128, 1);
		snprintf(num, 3, "%d", *s);
		TextMid(x, y - spacing, num, 16);
		x += *s + spacing;
	}
	// draw a line below the characters, a curve above
	x -= spacing;
	Stroke(150, 150, 150, 0.5);
	StrokeWidth(2);
	Line(lx, y - s2, x, y - s2);
	Fill(255, 255, 255, 1);
	Qbezier(lx, y + s2, x, y + s2, x, y + (spacing * 3));
	End();
}
Beispiel #10
0
RichTextCtrl::RichTextCtrl()
{
	SetZoom(Zoom(1, 1));
	Transparent();
	Background(Null);
	SetFrame(NullFrame());
	AutoHideSb();
}
void displayLogo(void) {
    Start(width, height);                   // Start the picture
    Background(0, 0, 0);                    // Black background

    Image((width / 2)-(logo_w / 2), (3 * height / 5) - (logo_h / 2), logo_w, logo_h, logo_path);

    End();
}
Beispiel #12
0
void HScroller::Redraw(IntCoord x1, IntCoord y1, IntCoord x2, IntCoord y2) {
    IntCoord left;
    int width;

    Background(x1, y1, x2, y2);
    GetBarInfo(shown, left, width);
    Bar(left, width);
    Outline(left, width);
}
Beispiel #13
0
void
Console::ResetAttributes()
{
	SetBold(false);
	SetBlink(false);
	SetReverseVideo(false);
	Background(BLACK);
	Foreground(WHITE);
}
Beispiel #14
0
void VScroller::Redraw(IntCoord x1, IntCoord y1, IntCoord x2, IntCoord y2) {
    IntCoord bot;
    int height;

    Background(x1, y1, x2, y2);
    GetBarInfo(shown, bot, height);
    Bar(bot, height);
    Outline(bot, height);
}
Beispiel #15
0
// gradient demos linear and radial gradients
void gradient(int width, int height) {
	VGfloat x1, y1, x2, y2, cx, cy, fx, fy, r;
	VGfloat w = (VGfloat)width;
	VGfloat h = (VGfloat)height;
	VGfloat dotcolor[4] = {0, 0, 0, 0.3};
	
	
	VGfloat stops[] = {
		0.0, 1.0, 1.0, 1.0, 1.0,
		0.5, 0.5, 0.5, 0.5, 1.0,
		1.0, 0.0, 0.0, 0.0, 1.0
	};
				
	
	x1 = w/8;
	x2 = (w*3)/8;
	y1 = h/3;
	y2 = (h*2)/3;
	cx = (w*3)/4;
	cy = (h/2);
	r = (x2-x1);
	fx = cx + (r/4);
	fy = cy + (r/4);
	Start(w, h);
	Background(128, 128, 128);
	

	FillLinearGradient(x1, y1, x2, y2, stops, 3);
	Rect(x1, y1, x2-x1, y2-y1);
	FillRadialGradient(cx, cy, fx, fy, r, stops, 3);
	Circle(cx, cy, r);
	
	RGBA(.5, 0, 0, 0.3, dotcolor);
	setfill(dotcolor);
	Circle(x1, y1, 10);
	Circle(x2, y2, 10);
	Circle(cx, cy, 10);
	Circle(cx+r/2, cy, 10);
	Circle(fx, fy, 10);
	
	RGB(0,0,0,dotcolor);
	setfill(dotcolor);
	TextMid(x1, y1-20, "(x1, y1)", 18);
	TextMid(x2, y2+10, "(x2, y2)", 18);
	TextMid(cx, cy, "(cx, cy)", 18);
	TextMid(fx, fy, "(fx, fy)", 18);
	TextEnd(cx+(r/2)+20, cy, "r", 18);
	
	
	TextMid(x1+((x2-x1)/2), h/6, "Linear Gradient", 36);
	TextMid(cx, h/6, "Radial Gradient", 36);
	
	
	End();

}
void displayLogoConnecting(void) {
    Start(width, height);                   // Start the picture
    Background(0, 0, 0);                    // Black background

    Image((width / 2)-(logo_w / 2), (3 * height / 5) - (logo_h / 2), logo_w, logo_h, logo_path);

    Fill(255, 255, 255, 1);                 // White text
    TextMid(width / 2, 3* height / 20, "Connecting..", SansTypeface, width / 30);  // Greetings
    End();
}
Beispiel #17
0
// raspi draws the raspberry pi, scaled to the screen dimensions
void raspi(int w, int h, char *s) {
	VGfloat midx = w / 2, midy = h / 2;
	int rw = midx, rh = (rw * 2) / 3, fontsize = w * 0.03;

	Start(w, h);
	Background(255, 255, 255);
	makepi(midx - (rw / 2), midy - (rh / 2), rw, rh);
	Fill(128, 0, 0, 1);
	TextMid(midx, midy - (rh / 2) - (fontsize * 2), s, fontsize);
	End();
}
Beispiel #18
0
void HScroller::Update() {
    IntCoord oldleft, oldright, newleft, newright;
    int oldwidth, newwidth;
    Perspective* p;

    if (canvas == nil) {
	return;
    }
    p = view;
    GetBarInfo(shown, oldleft, oldwidth);
    GetBarInfo(p, newleft, newwidth);
    if (oldleft != newleft || oldwidth != newwidth) {
	oldright = oldleft+oldwidth-1;
	newright = newleft+newwidth-1;
	if (oldright >= newleft && newright >= oldleft) {
	    if (oldright > newright) {
		Background(newright+1, inset, oldright, ymax-inset);
		Border(newright);
	    } else if (oldright < newright) {
		Bar(oldright, newright-oldright);
		Sides(oldright, newright);
		Border(newright);
	    }
	    if (oldleft > newleft) {
		Bar(newleft+1, oldleft-newleft);
		Sides(newleft, oldleft);
		Border(newleft);
	    } else if (oldleft < newleft) {
		Background(oldleft, inset, newleft-1, ymax-inset);
		Border(newleft);
	    }
	} else {
	    Background(oldleft, inset, oldright, ymax-inset);
	    Bar(newleft, newwidth);
	    Outline(newleft, newwidth);
	}
    }
    *shown = *p;
}
Beispiel #19
0
void VScroller::Update() {
    IntCoord oldbottom, oldtop, newbottom, newtop;
    int oldheight, newheight;
    Perspective* p;

    if (canvas == nil) {
	return;
    }
    p = view;
    GetBarInfo(shown, oldbottom, oldheight);
    GetBarInfo(p, newbottom, newheight);
    if (oldbottom != newbottom || oldheight != newheight) {
	oldtop = oldbottom+oldheight-1;
	newtop = newbottom+newheight-1;
	if (oldtop >= newbottom && newtop >= oldbottom) {
	    if (oldtop > newtop) {
		Background(inset, newtop+1, xmax-inset, oldtop);
		Border(newtop);
	    } else if (oldtop < newtop) {
		Bar(oldtop, newtop-oldtop);
		Sides(oldtop, newtop);
		Border(newtop);
	    }
	    if (oldbottom > newbottom) {
		Bar(newbottom+1, oldbottom-newbottom);
		Sides(newbottom, oldbottom);
		Border(newbottom);
	    } else if (oldbottom < newbottom) {
		Background(inset, oldbottom, xmax-inset, newbottom-1);
		Border(newbottom);
	    }
	} else {
	    Background(inset, oldbottom, xmax-inset, oldtop);
	    Bar(newbottom, newheight);
	    Outline(newbottom, newheight);
	}
    }
    *shown = *p;
}
Beispiel #20
0
QVariant editorModel::data(const QModelIndex &index, int role) const
{
    if ((role == Qt::DisplayRole) || (role == Qt::EditRole))
    {
        return getDataValue(index.row(),index.column()); //dataList[index.row()].fields[index.column()].value;
    }
    if (role == Qt::BackgroundRole)
    {

        //if (!dataList[index.row()].fields[index.column()].modified)
        if (!isDataModified(index.row(),index.column()))
        {
            QBrush Background(QColor(255,255,255));
            Background.setStyle(Qt::SolidPattern);
            return Background;
        }
        else
        {
            QBrush Background(QColor(255,0,0));
            Background.setStyle(Qt::SolidPattern);
            return Background;
        }

    }
    if (role == Qt::ForegroundRole)
    {

        //if (dataList[index.row()].fields[index.column()].ignore)
        if (isDataIgnored(index.row(),index.column()))
        {
            QBrush FontColor(QColor(191,184,181));
            return FontColor;
        }

    }
    return QVariant();
}
Beispiel #21
0
	AboutDlg() {
		Size isz = MakeLogo(*this, ctrl);
		int cx = min(isz.cx * 2, GetWorkArea().GetWidth());
		SetRect(0, 0, cx, isz.cy);
		about.SetQTF(GetTopic("ide/app/About$en-us"), Zoom(DPI(120), 1024));
		about.SetZoom(Zoom(1, 1));
		about.RightPos(0, cx - isz.cx - DPI(1)).VSizePos();
		about.HMargins(Zx(4));
		about.SetFrame(NullFrame());
		about.NoLazy();
		Background(PaintRect(ColorDisplay(), SColorPaper()));
		Add(about);
//		separator.Color(Gray());
//		Add(separator.RightPos(cx - isz.cx, DPI(1)).VSizePos());
		Title("About TheIDE");
	}
Beispiel #22
0
void imagetest(int w, int h) {
	int imgw = 422, imgh = 238;
	VGfloat cx = (w / 2) - (imgw / 2), cy = (h / 2) - (imgh / 2);
	VGfloat ulx = 0, uly = h - imgh;
	VGfloat urx = w - imgw, ury = uly;
	VGfloat llx = 0, lly = 0;
	VGfloat lrx = urx, lry = lly;
	Start(w, h);
	Background(0, 0, 0);
	Image(cx, cy, imgw, imgh, "desert1.jpg");
	Image(ulx, uly, imgw, imgh, "desert2.jpg");
	Image(urx, ury, imgw, imgh, "desert3.jpg");
	Image(llx, lly, imgw, imgh, "desert4.jpg");
	Image(lrx, lry, imgw, imgh, "desert5.jpg");
	End();
}
Beispiel #23
0
// rotext draws text, rotated around the center of the screen, progressively faded
void rotext(int w, int h, int n, char *s) {
	VGfloat fade = (100.0 / (VGfloat) n) / 100.0;
	VGfloat deg = 360.0 / n;
	VGfloat x = w / 2, y = h / 2;
	VGfloat alpha = 1.0;	// start solid
	int i, size = w / 8;

	Start(w, h);
	Background(0, 0, 0);
	Translate(x, y);
	for (i = 0; i < n; i++) {
		Fill(255, 255, 255, alpha);
		Text(0, 0, s, size);
		alpha -= fade;				   // fade
		size += n;				   // enlarge
		Rotate(deg);
	}
	End();
}
Beispiel #24
0
// sunearth shows the relative sizes of the sun and the earth
void sunearth(int w, int h) {
	VGfloat sun, earth, x, y;
	int i;

	rseed();
	Start(w, h);
	Background(0, 0, 0);
	Fill(255, 255, 255, 1);
	for (i = 0; i < w / 4; i++) {
		x = randf(w);
		y = randf(h);
		Circle(x, y, 2);
	}
	earth = (VGfloat) w *0.010;
	sun = earth * 109;
	Fill(0, 0, 255, 1);
	Circle(w / 3, h - (h / 10), earth);
	Fill(255, 255, 224, 1);
	Circle(w, 0, sun);
	End();
}
Beispiel #25
0
void imagetable(int w, int h) {
	int imgw = 422, imgh = 238;
	char *itable[] = {
		"desert0.jpg",
		"desert1.jpg",
		"desert2.jpg",
		"desert3.jpg",
		"desert4.jpg",
		"desert5.jpg",
		"desert6.jpg",
		"desert7.jpg",
		NULL
	};
	VGfloat left = 50.0;
	VGfloat bot = h - imgh - 50.0;
	VGfloat gutter = 50.0;

	VGfloat x = left;
	VGfloat y = bot;
	int i;
	Start(w, h);
	Background(0, 0, 0);
	for (i = 0; itable[i] != NULL; i++) {
		Image(x, y, imgw, imgh, itable[i]);
		Fill(255, 255, 255, 0.3);
		Rect(x, y, imgw, 32);
		Fill(0, 0, 0, 1);
		TextMid(x + (imgw / 2), y + 10, itable[i], 16);

		x += imgw + gutter;
		if (x > w) {
			x = left;
			y -= imgh + gutter;
		}
	}
	y = h * 0.1;
	Fill(128, 128, 128, 1);
	TextMid(w / 2, 100, "Joshua Tree National Park", 48);
	End();
}
Beispiel #26
0
int main() {
	int width, height, cursorx, cursory, cbsize;

	init(&width, &height);				   // Graphics initialization
	cursorx = width / 2;
	cursory = height / 2;
	cbsize = (CUR_SIZ * 2) + 1;
	VGImage CursorBuffer = vgCreateImage(VG_sABGR_8888, cbsize, cbsize, VG_IMAGE_QUALITY_BETTER);

	if (mouseinit(width, height) != 0) {
		fprintf(stderr, "Unable to initialize the mouse\n");
		exit(1);
	}
	Start(width, height);				   // Start the picture
	Background(0, 0, 0);				   // Black background
	Fill(44, 77, 232, 1);				   // Big blue marble
	Circle(width / 2, 0, width);			   // The "world"
	Fill(255, 255, 255, 1);				   // White text
	TextMid(width / 2, height / 2, "hello, world", SerifTypeface, width / 10);	// Greetings 
	End();						   // update picture

	// MAIN LOOP
	while (left_count < 2) {			   // Loop until the left mouse button pressed & released
		// if the mouse moved...
		if (mouse.x != cursorx || mouse.y != cursory) {
			restoreCursor(CursorBuffer);
			cursorx = mouse.x;
			cursory = mouse.y;
			saveCursor(CursorBuffer, cursorx, cursory, width, height, CUR_SIZ);
			circleCursor(cursorx, cursory, width, height, CUR_SIZ);
			End();				   // update picture
		}
	}
	restoreCursor(CursorBuffer);			   // not strictly necessary as display will be closed
	vgDestroyImage(CursorBuffer);			   // tidy up memory
	finish();					   // Graphics cleanup
	exit(0);
}
Beispiel #27
0
int main() {
	int width, height;
	char s[3];
	char hello1[] = {'H','e','j',',',' ','v', 0xc3, 0xa4,'r' , 'l','d' ,'e','n',0};
	char hello2[] = {'H','e','l','l',0xc3,0xb3,' ', 'V', 'i', 'l', 0xc3,0xa1,'g',0};
	char hello3[] = {'A','h','o','j',' ','s','v',0xc4,0x95,'t','e',0};
	init(&width, &height);				   // Graphics initialization

	Start(width, height);				   // Start the picture
	Background(0, 0, 0);				   // Black background
	Fill(44, 77, 232, 1);				   // Big blue marble
	Circle(width / 2, 0, width);			   // The "world"
	Fill(255, 255, 255, 1);				   // White text
	TextMid(width / 2, (height * 0.7), "hello, world", SerifTypeface, width / 15);	// Greetings 
	TextMid(width / 2, (height * 0.5), hello1 , SerifTypeface, width / 15);
	TextMid(width / 2, (height * 0.3), hello2 , SerifTypeface, width / 15);
	TextMid(width / 2, (height * 0.1), hello3 , SerifTypeface, width / 15);
	End();						   // End the picture

	fgets(s, 2, stdin);				   // look at the pic, end with [RETURN]
	finish();					   // Graphics cleanup
	exit(0);
}
void main()
{
   int i;
   G();
   Intro();
   Background();
   DrawBoard();
   Marble(320,220,0);
   board[3][3]=0;
   Init();
   setcolor(0);
   for(i=0;i<=220;i++)
   {
   rectangle(0+i,0+i,640-i,480-i);
   delay(10);
   }
   for(i=0;i<=220;i++)
   {
   rectangle(100+i,100,540-i,380);
   delay(8);
   }
   closegraph();
   getch();
}
Beispiel #29
0
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
	// Defines PI
	const float PI = 3.14159f;

    // Create the window of the application
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Pong");

    // Load the sounds used in the game
    sf::SoundBuffer BallSoundBuffer;
    if (!BallSoundBuffer.LoadFromFile("datas/pong/ball.wav"))
    {
        return EXIT_FAILURE;
    }
    sf::Sound BallSound(BallSoundBuffer);

    // Load the images used in the game
    sf::Image BackgroundImage, LeftPaddleImage, RightPaddleImage, BallImage;
    if (!BackgroundImage.LoadFromFile("datas/pong/background.jpg")    ||
        !LeftPaddleImage.LoadFromFile("datas/pong/paddle_left.png")   ||
        !RightPaddleImage.LoadFromFile("datas/pong/paddle_right.png") ||
        !BallImage.LoadFromFile("datas/pong/ball.png"))
    {
        return EXIT_FAILURE;
    }

    // Load the text font
    sf::Font Cheeseburger;
    if (!Cheeseburger.LoadFromFile("datas/post-fx/cheeseburger.ttf"))
        return EXIT_FAILURE;

	// Initialize the end text
	sf::String End;
    End.SetFont(Cheeseburger);
	End.SetSize(60.f);
    End.Move(150.f, 200.f);
    End.SetColor(sf::Color(50, 50, 250));

    // Create the sprites of the background, the paddles and the ball
    sf::Sprite Background(BackgroundImage);
    sf::Sprite LeftPaddle(LeftPaddleImage);
    sf::Sprite RightPaddle(RightPaddleImage);
    sf::Sprite Ball(BallImage);

    LeftPaddle.Move(10, (App.GetView().GetRect().GetHeight() - LeftPaddle.GetSize().y) / 2);
    RightPaddle.Move(App.GetView().GetRect().GetWidth() - RightPaddle.GetSize().x - 10, (App.GetView().GetRect().GetHeight() - RightPaddle.GetSize().y) / 2);
    Ball.Move((App.GetView().GetRect().GetWidth() - Ball.GetSize().x) / 2, (App.GetView().GetRect().GetHeight() - Ball.GetSize().y) / 2);

    // Define the paddles properties
    sf::Clock AITimer;
	const float AITime     = 0.1f;
    float LeftPaddleSpeed  = 400.f;
    float RightPaddleSpeed = 400.f;

    // Define the ball properties
    float BallSpeed = 400.f;
    float BallAngle;
    do
    {
        // Make sure the ball initial angle is not too much vertical
        BallAngle = sf::Randomizer::Random(0.f, 2 * PI);
    } while (std::abs(std::cos(BallAngle)) < 0.7f);

	bool IsPlaying = true;
    while (App.IsOpened())
    {
        // Handle events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Window closed or escape key pressed : exit
            if ((Event.Type == sf::Event::Closed) || 
               ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)))
            {
                App.Close();
                break;
            }
        }

        if (IsPlaying)
		{
			// Move the player's paddle
            if (App.GetInput().IsKeyDown(sf::Key::Up) && (LeftPaddle.GetPosition().y > 5.f))
				LeftPaddle.Move(0.f, -LeftPaddleSpeed * App.GetFrameTime());
            if (App.GetInput().IsKeyDown(sf::Key::Down) && (LeftPaddle.GetPosition().y < App.GetView().GetRect().GetHeight() - LeftPaddle.GetSize().y - 5.f))
				LeftPaddle.Move(0.f, LeftPaddleSpeed * App.GetFrameTime());

			// Move the computer's paddle
            if (((RightPaddleSpeed < 0.f) && (RightPaddle.GetPosition().y > 5.f)) ||
                ((RightPaddleSpeed > 0.f) && (RightPaddle.GetPosition().y < App.GetView().GetRect().GetHeight() - RightPaddle.GetSize().y - 5.f)))
            {
                RightPaddle.Move(0.f, RightPaddleSpeed * App.GetFrameTime());
            }

            // Update the computer's paddle direction according to the ball position
            if (AITimer.GetElapsedTime() > AITime)
            {
                AITimer.Reset();
                if ((RightPaddleSpeed < 0) && (Ball.GetPosition().y + Ball.GetSize().y > RightPaddle.GetPosition().y + RightPaddle.GetSize().y))
                    RightPaddleSpeed = -RightPaddleSpeed;
                if ((RightPaddleSpeed > 0) && (Ball.GetPosition().y < RightPaddle.GetPosition().y))
                    RightPaddleSpeed = -RightPaddleSpeed;
            }

			// Move the ball
			float Factor = BallSpeed * App.GetFrameTime();
            Ball.Move(std::cos(BallAngle) * Factor, std::sin(BallAngle) * Factor);

			// Check collisions between the ball and the screen
			if (Ball.GetPosition().x < 0.f)
			{
				IsPlaying = false;
				End.SetText("You lost !\n(press escape to exit)");
			}
			if (Ball.GetPosition().x + Ball.GetSize().x > App.GetView().GetRect().GetWidth())
			{
				IsPlaying = false;
				End.SetText("You won !\n(press escape to exit)");
			}
			if (Ball.GetPosition().y < 0.f)
			{
				BallSound.Play();
				BallAngle = -BallAngle;
				Ball.SetY(0.1f);
			}
			if (Ball.GetPosition().y + Ball.GetSize().y > App.GetView().GetRect().GetHeight())
			{
				BallSound.Play();
				BallAngle = -BallAngle;
				Ball.SetY(App.GetView().GetRect().GetHeight() - Ball.GetSize().y - 0.1f);
			}

			// Check the collisions between the ball and the paddles
			// Left Paddle
			if (Ball.GetPosition().x < LeftPaddle.GetPosition().x + LeftPaddle.GetSize().x && 
				Ball.GetPosition().x > LeftPaddle.GetPosition().x + (LeftPaddle.GetSize().x / 2.0f) &&
				Ball.GetPosition().y + Ball.GetSize().y >= LeftPaddle.GetPosition().y &&
				Ball.GetPosition().y <= LeftPaddle.GetPosition().y + LeftPaddle.GetSize().y)
			{
				BallSound.Play();
				BallAngle = PI - BallAngle;
				Ball.SetX(LeftPaddle.GetPosition().x + LeftPaddle.GetSize().x + 0.1f);
			}

			// Right Paddle
			if (Ball.GetPosition().x + Ball.GetSize().x > RightPaddle.GetPosition().x &&
				Ball.GetPosition().x + Ball.GetSize().x < RightPaddle.GetPosition().x + (RightPaddle.GetSize().x / 2.0f) &&
				Ball.GetPosition().y + Ball.GetSize().y >= RightPaddle.GetPosition().y &&
				Ball.GetPosition().y <= RightPaddle.GetPosition().y + RightPaddle.GetSize().y)
			{
				BallSound.Play();
				BallAngle = PI - BallAngle;
				Ball.SetX(RightPaddle.GetPosition().x - Ball.GetSize().x - 0.1f);
			}
		}

        // Clear the window
        App.Clear();

        // Draw the background, paddles and ball sprites
        App.Draw(Background);
        App.Draw(LeftPaddle);
        App.Draw(RightPaddle);
        App.Draw(Ball);

        // If the game is over, display the end message
        if (!IsPlaying)
            App.Draw(End);

        // Display things on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}
Beispiel #30
0
void HCI_Wait_For_Response(void)
{
  Background();
  
  return;
}