Qbasicnews.com
July 21, 2019, 12:05:30 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 ... 6 7 [8]
  Print  
Author Topic: yagl freebasic port 0.0.7  (Read 31368 times)
TheDarkJay
I hold this place together
*****
Posts: 913



WWW
« Reply #105 on: February 11, 2006, 03:50:24 PM »

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
Logged

url=http://www.sloganizer.net/en/][/url]
Pages: 1 ... 6 7 [8]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!