Qbasicnews.com
July 20, 2019, 11:27:15 PM *
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 ... 5 6 [7] 8
  Print  
Author Topic: yagl freebasic port 0.0.7  (Read 31366 times)
TheDarkJay
I hold this place together
*****
Posts: 913



WWW
« Reply #90 on: February 09, 2006, 06:31:07 PM »

I understand...

Didn't you (marzecTM) originally overload the Blitting functions with this 'ranging'???

I also understand Tinting now...I posted, then saw a pot on the Yagl forums that sort of clarified it, then couldn't be bothered to change the post.

Thanks for taking the time to post Z!re though, sorry about my laziness...with the sleeping and the snoozing and the forgetting to eat...
Logged

url=http://www.sloganizer.net/en/][/url]
marzecTM
Ancient Guru
****
Posts: 688


« Reply #91 on: February 09, 2006, 06:56:37 PM »

yes the c++ version uses overloading instead of a seperate method identifier.
Logged

quote="NecrosIhsan"]

[/quote]
TheDarkJay
I hold this place together
*****
Posts: 913



WWW
« Reply #92 on: February 10, 2006, 05:51:25 PM »

I'm almost finished porting the Mouse Click example to C++, I just need a bit of help. In FB I used str() to display the score as a string. Is they anything like that in C++?
Logged

url=http://www.sloganizer.net/en/][/url]
marzecTM
Ancient Guru
****
Posts: 688


« Reply #93 on: February 10, 2006, 06:00:04 PM »

do you use the yagl c wrapper in c++ or in c? if you use c++ you could use string streams and get the char* pointer via c_str, if you just want to output a number as a char* string then you can use itoa http://www.cplusplus.com/ref/cstdlib/itoa.html which you can directly pass to YaglGfxDevice_printAt
Logged

quote="NecrosIhsan"]

[/quote]
TheDarkJay
I hold this place together
*****
Posts: 913



WWW
« Reply #94 on: February 11, 2006, 06:56:02 AM »

Everything I try crashes... Sad
Logged

url=http://www.sloganizer.net/en/][/url]
marzecTM
Ancient Guru
****
Posts: 688


« Reply #95 on: February 11, 2006, 09:02:51 AM »

gimme code Smiley
Logged

quote="NecrosIhsan"]

[/quote]
TheDarkJay
I hold this place together
*****
Posts: 913



WWW
« Reply #96 on: February 11, 2006, 09:06:48 AM »

Code:
#include <yaglwrapper.h>
#include <time.h>
#include <stdlib.h>

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);

struct Location{int x;int y;};

class Box{
      public:
      Box();
      void Manage();
     
      protected:
      Location location;
      int size;
      int score;
      int speed;
      int Xadj;
      int Yadj;
      YaglGfxFont font;
      char* ScoreString;
     
      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() {
   
if ( !Yagl_Screen(640,400,32,0) )
{
     if ( !Yagl_Screen(640,400,24,0) ) { return 0; }
}
YaglGfxDevice_setWindowTitle ( " Yagl Mouse And Basic Drawing Demo " );

Box Player;
unsigned int UpdateTimer = clock();
YaglGfxDevice_clear(ColourRGB(100,100,100));
Player.Manage();

while ( (!YaglGfxDevice_wasWindowCloseButtonPressed()) && (!YaglKeyboard_isKeyPressed( YAGL_KEY_ESCAPE )) )
{
if(clock() >= UpdateTimer + (1000/50)){
UpdateTimer = clock();
YaglGfxDevice_clear(ColourRGB(100,100,100));
Player.Manage();
}
YaglGfxDevice_swapBuffers( );
}
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 - size <= 0 ) Yadj = speed;
if (location.y + size >= ::ScreenY ) Yadj = -speed;
if (location.x + size >= ::ScreenX ) Xadj = -speed;
if (location.x - size <= 0 ) Xadj = speed;

if ((MouseY >= location.y - size) && (MouseY <= location.y + size) && (MouseX >= location.x - size) && (MouseX <= location.x + size) && (YaglMouse_isLeftButtonPressed()))
{
score += 1;
speed = score;
Xadj = -speed;
Yadj = -speed;
location.x = (ScreenX/2);
location.y = (ScreenY/2);            
}

::YaglGfxDevice_printAt( "Score: ", 16, 16, ::ColourRGB(255,255,255), font, 1.0 );
BoxDraw();
}

Box::Box()
{
location.x = (int)(ScreenX/2);
location.y = (int)(ScreenY/2);
size = 15;
score = 0;
speed = 1;
Xadj = speed;
Yadj = speed;
font = ::YaglGfxDevice_createFont();
::YaglGfxFont_loadFont( font, "font.ttf" );
::YaglGfxFont_setSize( font, 16 );

}
Logged

url=http://www.sloganizer.net/en/][/url]
marzecTM
Ancient Guru
****
Posts: 688


« Reply #97 on: February 11, 2006, 10:20:34 AM »

doesn't crash for me. well it did at first as i did not have font.ttf in the directory of the exe file. but after i placed that file there it worked without a problem.
Logged

quote="NecrosIhsan"]

[/quote]
TheDarkJay
I hold this place together
*****
Posts: 913



WWW
« Reply #98 on: February 11, 2006, 10:40:20 AM »

Quote from: "marzecTM"
doesn't crash for me. well it did at first as i did not have font.ttf in the directory of the exe file. but after i placed that file there it worked without a problem.


Odd...what did you do?

EDIT: Oh right, i forgot to put the bit that caused it to crash back in...it runs fine if you just copy THAT source code and compile it.

I need it to display the integer Box::score after  the "Score: " in

::YaglGfxDevice_printAt( "Score: ", 16, 16, ::ColourRGB(255,255,255), font, 1.0 );
Logged

url=http://www.sloganizer.net/en/][/url]
TheDarkJay
I hold this place together
*****
Posts: 913



WWW
« Reply #99 on: February 11, 2006, 11:28:05 AM »

Never Mind. I've rewritten it so it doesn't use Scores. Also you can control how many boxes are on the screen (up to 1000) and stuff.

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

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 = 0;
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();}

while ( (!YaglGfxDevice_wasWindowCloseButtonPressed()) && (!YaglKeyboard_isKeyPressed( YAGL_KEY_ESCAPE )) )
{
if(clock() >= UpdateTimer + (1000/50)){
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( );
}
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 = 15;
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);
}
 
Logged

url=http://www.sloganizer.net/en/][/url]
marzecTM
Ancient Guru
****
Posts: 688


« Reply #100 on: February 11, 2006, 11:29:30 AM »

well you could use stl string

#include <string>

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

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

quote="NecrosIhsan"]

[/quote]
TheDarkJay
I hold this place together
*****
Posts: 913



WWW
« Reply #101 on: February 11, 2006, 11:34:27 AM »

Quote from: "marzecTM"
well you could use stl string

#include <string>

stl::string 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 Cheesy

Edit

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

Oh well, i'll try to figure it out later...
Logged

url=http://www.sloganizer.net/en/][/url]
marzecTM
Ancient Guru
****
Posts: 688


« Reply #102 on: February 11, 2006, 01:09:10 PM »

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.
Logged

quote="NecrosIhsan"]

[/quote]
TheDarkJay
I hold this place together
*****
Posts: 913



WWW
« Reply #103 on: February 11, 2006, 01:19:01 PM »

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... Cheesy
Logged

url=http://www.sloganizer.net/en/][/url]
marzecTM
Ancient Guru
****
Posts: 688


« Reply #104 on: February 11, 2006, 01:46:20 PM »

hehe ok good look. check out strstream ( string stream ) keyword stl stringstream
Logged

quote="NecrosIhsan"]

[/quote]
Pages: 1 ... 5 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!