Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
yagl freebasic port 0.0.7
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


Messages In This Thread
yagl freebasic port 0.0.7 - by marzecTM - 12-26-2005, 01:09 PM
yagl freebasic port 0.0.7 - by Deleter - 12-26-2005, 01:27 PM
yagl freebasic port 0.0.7 - by marzecTM - 12-26-2005, 01:37 PM
yagl freebasic port 0.0.7 - by SBM Productions - 12-26-2005, 07:29 PM
yagl freebasic port 0.0.7 - by marzecTM - 12-26-2005, 07:50 PM
yagl freebasic port 0.0.7 - by SBM Productions - 12-27-2005, 08:27 PM
yagl freebasic port 0.0.7 - by marzecTM - 12-27-2005, 08:46 PM
yagl freebasic port 0.0.7 - by SBM Productions - 12-27-2005, 11:22 PM
yagl freebasic port 0.0.7 - by marzecTM - 12-27-2005, 11:53 PM
yagl freebasic port 0.0.7 - by SBM Productions - 12-28-2005, 10:49 AM
yagl freebasic port 0.0.7 - by marzecTM - 12-28-2005, 03:33 PM
yagl freebasic port 0.0.7 - by marzecTM - 01-04-2006, 08:11 AM
yagl freebasic port 0.0.7 - by marzecTM - 01-06-2006, 10:58 AM
yagl freebasic port 0.0.7 - by NecrosIhsan - 01-07-2006, 08:11 PM
Good stuff, man! ^-^ - by Adigun A. Polack - 01-08-2006, 02:45 AM
yagl freebasic port 0.0.7 - by marzecTM - 01-08-2006, 05:47 AM
yagl freebasic port 0.0.7 - by marzecTM - 01-08-2006, 05:59 AM
yagl freebasic port 0.0.7 - by marzecTM - 01-09-2006, 03:07 AM
yagl freebasic port 0.0.7 - by na_th_an - 01-09-2006, 02:00 PM
yagl freebasic port 0.0.7 - by Z!re - 01-09-2006, 03:10 PM
yagl freebasic port 0.0.7 - by marzecTM - 01-09-2006, 03:45 PM
yagl freebasic port 0.0.7 - by na_th_an - 01-09-2006, 04:14 PM
yagl freebasic port 0.0.7 - by marzecTM - 01-09-2006, 04:32 PM
yagl freebasic port 0.0.7 - by na_th_an - 01-09-2006, 04:42 PM
yagl freebasic port 0.0.7 - by marzecTM - 01-09-2006, 05:23 PM
yagl freebasic port 0.0.7 - by na_th_an - 01-09-2006, 05:58 PM
yagl freebasic port 0.0.7 - by marzecTM - 01-09-2006, 06:28 PM
yagl freebasic port 0.0.7 - by NecrosIhsan - 01-09-2006, 07:42 PM
yagl freebasic port 0.0.7 - by marzecTM - 01-09-2006, 07:53 PM
yagl freebasic port 0.0.7 - by marzecTM - 01-09-2006, 08:09 PM
yagl freebasic port 0.0.7 - by NecrosIhsan - 01-09-2006, 08:17 PM
yagl freebasic port 0.0.7 - by Z!re - 01-09-2006, 08:27 PM
yagl freebasic port 0.0.7 - by Z!re - 01-09-2006, 08:33 PM
yagl freebasic port 0.0.7 - by NecrosIhsan - 01-09-2006, 08:33 PM
yagl freebasic port 0.0.7 - by marzecTM - 01-09-2006, 09:04 PM
yagl freebasic port 0.0.7 - by NecrosIhsan - 01-09-2006, 09:55 PM
yagl freebasic port 0.0.7 - by marzecTM - 01-09-2006, 10:20 PM
yagl freebasic port 0.0.7 - by Z!re - 01-10-2006, 01:31 AM
yagl freebasic port 0.0.7 - by marzecTM - 01-10-2006, 08:20 PM
yagl freebasic port 0.0.7 - by Z!re - 01-11-2006, 08:54 PM
yagl freebasic port 0.0.7 - by Deleter - 01-12-2006, 01:38 AM
yagl freebasic port 0.0.7 - by marzecTM - 01-12-2006, 02:18 AM
yagl freebasic port 0.0.7 - by marzecTM - 01-14-2006, 08:56 AM
yagl freebasic port 0.0.7 - by marzecTM - 01-14-2006, 10:03 PM
yagl freebasic port 0.0.7 - by TheDarkJay - 01-15-2006, 01:14 AM
yagl freebasic port 0.0.7 - by marzecTM - 01-15-2006, 03:23 AM
yagl freebasic port 0.0.7 - by marzecTM - 01-15-2006, 08:10 AM
yagl freebasic port 0.0.7 - by TheDarkJay - 01-15-2006, 02:35 PM
yagl freebasic port 0.0.7 - by TheDarkJay - 01-15-2006, 05:26 PM
yagl freebasic port 0.0.7 - by marzecTM - 01-15-2006, 09:16 PM
yagl freebasic port 0.0.7 - by marzecTM - 01-16-2006, 05:04 PM
yagl freebasic port 0.0.7 - by TheDarkJay - 01-16-2006, 10:04 PM
yagl freebasic port 0.0.7 - by Z!re - 01-16-2006, 11:16 PM
yagl freebasic port 0.0.7 - by na_th_an - 01-16-2006, 11:48 PM
yagl freebasic port 0.0.7 - by TheDarkJay - 01-17-2006, 01:33 AM
yagl freebasic port 0.0.7 - by na_th_an - 01-17-2006, 01:19 PM
yagl freebasic port 0.0.7 - by TheDarkJay - 01-19-2006, 09:55 PM
yagl freebasic port 0.0.7 - by marzecTM - 01-19-2006, 10:19 PM
yagl freebasic port 0.0.7 - by TheDarkJay - 01-19-2006, 10:32 PM
yagl freebasic port 0.0.7 - by Deleter - 01-20-2006, 12:58 AM
yagl freebasic port 0.0.7 - by marzecTM - 01-20-2006, 01:34 AM
yagl freebasic port 0.0.7 - by TheDarkJay - 01-20-2006, 02:11 AM
yagl freebasic port 0.0.7 - by marzecTM - 01-20-2006, 03:58 AM
yagl freebasic port 0.0.7 - by marzecTM - 01-21-2006, 10:10 AM
yagl freebasic port 0.0.7 - by marzecTM - 01-23-2006, 02:43 PM
yagl freebasic port 0.0.7 - by marzecTM - 01-24-2006, 07:32 AM
yagl freebasic port 0.0.7 - by marzecTM - 01-26-2006, 10:53 PM
yagl freebasic port 0.0.7 - by marzecTM - 01-27-2006, 06:57 AM
yagl freebasic port 0.0.7 - by SBM Productions - 01-31-2006, 04:04 PM
yagl freebasic port 0.0.7 - by marzecTM - 01-31-2006, 05:06 PM
yagl freebasic port 0.0.7 - by Z!re - 01-31-2006, 06:02 PM
yagl freebasic port 0.0.7 - by SBM Productions - 01-31-2006, 07:39 PM
yagl freebasic port 0.0.7 - by Z!re - 01-31-2006, 07:59 PM
yagl freebasic port 0.0.7 - by SBM Productions - 01-31-2006, 08:02 PM
yagl freebasic port 0.0.7 - by marzecTM - 01-31-2006, 08:30 PM
yagl freebasic port 0.0.7 - by DrV - 02-01-2006, 10:28 AM
yagl freebasic port 0.0.7 - by marzecTM - 02-02-2006, 12:05 PM
yagl freebasic port 0.0.7 - by marzecTM - 02-05-2006, 12:14 PM
yagl freebasic port 0.0.7 - by marzecTM - 02-06-2006, 10:47 PM
yagl freebasic port 0.0.7 - by marzecTM - 02-07-2006, 06:05 AM
yagl freebasic port 0.0.7 - by SBM Productions - 02-07-2006, 04:21 PM
yagl freebasic port 0.0.7 - by marzecTM - 02-07-2006, 05:08 PM
yagl freebasic port 0.0.7 - by marzecTM - 02-08-2006, 09:18 PM
yagl freebasic port 0.0.7 - by marzecTM - 02-09-2006, 05:57 PM
yagl freebasic port 0.0.7 - by Z!re - 02-09-2006, 06:22 PM
yagl freebasic port 0.0.7 - by TheDarkJay - 02-10-2006, 01:09 AM
yagl freebasic port 0.0.7 - by Z!re - 02-10-2006, 01:32 AM
yagl freebasic port 0.0.7 - by marzecTM - 02-10-2006, 01:57 AM
yagl freebasic port 0.0.7 - by TheDarkJay - 02-10-2006, 02:31 AM
yagl freebasic port 0.0.7 - by marzecTM - 02-10-2006, 02:56 AM
yagl freebasic port 0.0.7 - by TheDarkJay - 02-11-2006, 01:51 AM
yagl freebasic port 0.0.7 - by marzecTM - 02-11-2006, 02:00 AM
yagl freebasic port 0.0.7 - by TheDarkJay - 02-11-2006, 02:56 PM
yagl freebasic port 0.0.7 - by marzecTM - 02-11-2006, 05:02 PM
yagl freebasic port 0.0.7 - by TheDarkJay - 02-11-2006, 05:06 PM
yagl freebasic port 0.0.7 - by marzecTM - 02-11-2006, 06:20 PM
yagl freebasic port 0.0.7 - by TheDarkJay - 02-11-2006, 06:40 PM
yagl freebasic port 0.0.7 - by TheDarkJay - 02-11-2006, 07:28 PM
yagl freebasic port 0.0.7 - by marzecTM - 02-11-2006, 07:29 PM
yagl freebasic port 0.0.7 - by TheDarkJay - 02-11-2006, 07:34 PM
yagl freebasic port 0.0.7 - by marzecTM - 02-11-2006, 09:09 PM
yagl freebasic port 0.0.7 - by TheDarkJay - 02-11-2006, 09:19 PM
yagl freebasic port 0.0.7 - by marzecTM - 02-11-2006, 09:46 PM
yagl freebasic port 0.0.7 - by TheDarkJay - 02-11-2006, 11:50 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)