Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
yagl freebasic port 0.0.7
#91
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...
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply
#92
yes the c++ version uses overloading instead of a seperate method identifier.
quote="NecrosIhsan"]
[Image: yagl1.png]
[/quote]
Reply
#93
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++?
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply
#94
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
quote="NecrosIhsan"]
[Image: yagl1.png]
[/quote]
Reply
#95
Everything I try crashes... Sad
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply
#96
gimme code Smile
quote="NecrosIhsan"]
[Image: yagl1.png]
[/quote]
Reply
#97
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 );

}
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply
#98
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.
quote="NecrosIhsan"]
[Image: yagl1.png]
[/quote]
Reply
#99
Quote: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:Confusedcore after the "Score: " in

::YaglGfxDevice_printAt( "Score: ", 16, 16, ::ColourRGB(255,255,255), font, 1.0 );
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply
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);
}
url=http://www.sloganizer.net/en/][Image: style4,TheDarkJay.png][/url]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)