Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
yagl freebasic port 0.0.7
well you could use stl string

#include <string>

stl:Confusedtring text;
text = "Score: ";
text += itoa( 123123 );

YaglGfxDevice_printAt( text.c_str(), ... )
quote="NecrosIhsan"]
[Image: yagl1.png]
[/quote]
Reply
Quote:well you could use stl string

#include <string>

stl:Confusedtring text;
text = "Score: ";
text += itoa( 123123 );

YaglGfxDevice_printAt( text.c_str(), ... )

Damn...a few minutes earlier and I wouldn't had rewritten it...Oh well, If i put in an FPS counter and remove the 50 fps cap in the new one we can really see how fast Yagl is Big Grin

Edit

well, that didn't work... I got some Invalid conversions...

Oh well, i'll try to figure it out later...
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply
sorry i wrote it from the top of my head, itoa might need aditional parameters afair. maybe post the compiler output so i can help a bit more.
quote="NecrosIhsan"]
[Image: yagl1.png]
[/quote]
Reply
Forget it. I'll just do some googling and stuff and figure it out. Besides, the thing runs fast until...well about 15000 squares in... Big Grin
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply
hehe ok good look. check out strstream ( string stream ) keyword stl stringstream
quote="NecrosIhsan"]
[Image: yagl1.png]
[/quote]
Reply
I've got it...sort of

Code:
#include <yaglwrapper.h>
#include <time.h>
#include <iostream>
#include <strings.h>

const int MaxNoOfBoxes = 1000;
int ScreenX = 0;
int ScreenY = 0;
int ScreenBit = 0;
bool ScreenMode = 0;

bool Yagl_Screen(int Width, int height, int depth, bool mode);
int ColourRGB(int R, int G, int B);
int IntRnd(int min, int max);

struct Location{int x;int y;};

class Box{
      public:
      Box();
      void Manage();
      
      protected:
      Location location;
      int size;
      int speed;
      int Xadj;
      int Yadj;
      
      void BoxDraw(void)
      {
      YaglGfxDevice_solidBox( location.x, location.y, location.x+size,location.y+size , ::ColourRGB(255,0,100),  1.0 );
      YaglGfxDevice_box( location.x, location.y, location.x+size,location.y+size , ::ColourRGB(0,0,0),  0.75 );
      YaglGfxDevice_box( location.x+1, location.y+1, location.x+(size-1),location.y+(size-1), ::ColourRGB(0,0,0),  0.5 );
      YaglGfxDevice_box( location.x+2, location.y+2, location.x+(size-2),location.y+(size-2), ::ColourRGB(0,0,0),  0.25 );
      }
      
      };          

int main() {
srand(time(NULL));
    
if ( !Yagl_Screen(800,600,32,0) )
{
     if ( !Yagl_Screen(800,600,24,0) ) { return 0; }
}
YaglGfxDevice_setWindowTitle ( " Yagl Mouse And Basic Drawing Demo " );

unsigned int NoOfBoxes = 1;
if (NoOfBoxes > MaxNoOfBoxes) NoOfBoxes = MaxNoOfBoxes;
Box Player[MaxNoOfBoxes];

unsigned int UpdateTimer = clock();
YaglGfxDevice_clear(ColourRGB(100,100,100));

for (int i = 0; i < NoOfBoxes; i++) {Player[i].Manage();}

long Timer = 0;
long fps = 0;
long fpc = 0;
long LastFps = 0;

fpc = clock()+1000;

char sz_FpsCount[10];

while ( (!YaglGfxDevice_wasWindowCloseButtonPressed()) && (!YaglKeyboard_isKeyPressed( YAGL_KEY_ESCAPE )) )
{
Timer = clock();

if(clock() >= UpdateTimer + (1000/50)){
fps++;
UpdateTimer = clock();
YaglGfxDevice_clear(ColourRGB(100,100,100));
for (int i = 0; i < NoOfBoxes; i++) {Player[i].Manage();}
if ( (YaglKeyboard_isKeyPressed(YAGL_KEY_UP)) && (NoOfBoxes < MaxNoOfBoxes) ) NoOfBoxes++;
if ( (YaglKeyboard_isKeyPressed(YAGL_KEY_DOWN)) && (NoOfBoxes > 0) ) NoOfBoxes--;
YaglGfxDevice_swapBuffers( );
}
if (clock() >= fpc){
        fpc = clock()+1000;
        if ((fps <= 50) && (fps)){itoa(fps, sz_FpsCount, 10);YaglGfxDevice_setWindowTitle ( strcat(sz_FpsCount, "/50 FPS") );}
        LastFps = fps;
        fps = 0;
    }
    else{
if ((LastFps <= 50) && (LastFps)) {itoa(LastFps, sz_FpsCount, 10);YaglGfxDevice_setWindowTitle ( strcat(sz_FpsCount, "/50 FPS") );}
}

}
   return 0;
}

bool Yagl_Screen(int Width, int height, int depth, bool mode) {
   ScreenX = Width;
   ScreenY = height;
   ScreenMode = mode;
    
   if (depth == 0) { depth = 24; }
   ScreenBit = depth;
    return YaglGfxDevice_setScreenMode(Width, height, depth, mode);
                                          
}

// Thanks to Netman for this:
int ColourRGB(int R, int G, int B)
{
  return (int)((R*65536)+(G*256)+B);
} // End Thanks :D

void Box::Manage()
{

location.x += Xadj;
location.y += Yadj;

int MouseX = ::YaglMouse_getX();
int MouseY = ::YaglMouse_getY();

if (location.y <= 0 ) Yadj = speed;
if (location.y + size >= ::ScreenY ) Yadj = -speed;
if (location.x + size >= ::ScreenX ) Xadj = -speed;
if (location.x <= 0 ) Xadj = speed;

if ((MouseY >= location.y - size) && (MouseY <= location.y + size) && (MouseX >= location.x - size) && (MouseX <= location.x + size) && (YaglMouse_isLeftButtonPressed()))
{
speed += 1;

if (::IntRnd(1,2) == 1){
Xadj = (::IntRnd(1,speed));
}else{Xadj = -(::IntRnd(1,speed));}

if (::IntRnd(1,2) == 1){
Yadj = -(::IntRnd(1,speed));
}else{Yadj = (::IntRnd(1,speed));}

if ((Xadj < speed) && (Yadj < speed)){
if (::IntRnd(1,2) == 1) {Xadj = speed;}else{Yadj = speed;}
}

location.x = ::IntRnd(size, ::ScreenX-size);
location.y = ::IntRnd(size, ::ScreenY-size);            
}

BoxDraw();
}

Box::Box()
{
size = 20;
speed = 1;

if (::IntRnd(1,2) == 1){
Xadj = (::IntRnd(1,speed));
}else{Xadj = -(::IntRnd(1,speed));}

if (::IntRnd(1,2) == 1){
Yadj = -(::IntRnd(1,speed));
}else{Yadj = (::IntRnd(1,speed));}

if ((Xadj < speed) && (Yadj < speed)){
if (::IntRnd(1,2) == 1) {Xadj = speed;}else{Yadj = speed;}
}

location.x = ::IntRnd(size, ::ScreenX-size);
location.y = ::IntRnd(size, ::ScreenY-size);
}

int IntRnd(int min, int max)
{
return (int)((rand()%max)+min);
}

It'll count the FPS in the window.

EDIT: Downloads

Get The Binaries Here (the .exe and binaries) NOTE: This one is set to start of with 10000 boxes on-screen
Download CPP-Mouse-Click.cpp.zip

Get The Binaries Here (the .exe and binaries) NOTE: This one is set to start of with 0 boxes on-screen
Download Cpp-Mouse-Click.zip
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)