Can I use normal C++ libraries in my g4c application?
Yes, you can use code from C++ libraries, like files, rand( ), strings,... except any code related to the console (cin, cout, getch( ),.....
My program behaves erroneously if I call wait( ) with a large number, like wait(2000) or wait(5000)
There is a problem with the wait function; to wait for a long time you can wait for a short time many times; for example instead of calling wait(2000) you can call wait(50) forty times. Tip: you can create a function to do that for you.
How to clear the screen?
How can I convert a string to a char* in order to use it with text_out?
Learn from this example:
string s = "Hello";
char *c = (char *) s.c_str();
text_out(c, 20, 20);
How can I convert a char * (that I got by using the input( ) function) to a string?
Learn from this example:
char *c = input("Enter your name:", 30, 30);
string s = c;
Yes, you can use code from C++ libraries, like files, rand( ), strings,... except any code related to the console (cin, cout, getch( ),.....
My program behaves erroneously if I call wait( ) with a large number, like wait(2000) or wait(5000)
There is a problem with the wait function; to wait for a long time you can wait for a short time many times; for example instead of calling wait(2000) you can call wait(50) forty times. Tip: you can create a function to do that for you.
س: ازاي اتغلب على مشكلة الحد الأقصى بتاع 30 sprite؟
ج1: استخدم ذكاءك؛ كل الألعاب القديمة (غزاة الفضاء، باكمان، ماريو...) احتاجت لعدد قليل من الsprites. لاحظ ان رقم 30 هو حد أقصى للأشكال الظاهرة على الشاشة في لحظة معينة
ج2: لو عايز ترسم صورة من غير ما تحركها، ممكن تستخدم copy_sprite_image بدلاً من put_sprite، ودي مالهاش حد أقصى (لكن ما تسمحش بتحريك الصورة اللي رسمتها أو التصادم)
ج2: لو عايز ترسم صورة من غير ما تحركها، ممكن تستخدم copy_sprite_image بدلاً من put_sprite، ودي مالهاش حد أقصى (لكن ما تسمحش بتحريك الصورة اللي رسمتها أو التصادم)
How to clear the screen?
- Use fill_rect to draw over normal graphics
- To hide sprites, use hide_sprite (give any numbers as the x, y parameters; they're not important)
س: (سؤال متقدم) اللعبة بتاعتي بتهنج لو شغلتها من mouse_proc
ج: شغلها من main، لأنه لو الmouse_proc قعدت تشتغل بلا توقف حتعطل الـmessage loop بتاع البرنامج والمستخدم مش حيقدر يعمل فيه أي حاجة ثانية
س: بس أنا عايز اشغل اللعبة لما المستخدم يدوس بالماوس على مكان معين
ج: لو عايز main تفضل منتظرة حدث معين اعمل متغير بـfalse، خلي الmain شغالة في loop مادام المتغير ده لسة خطأ، وخليه true في الmouse_proc لما تحب اللعبة تشتغل.
ملاحظة: لو ما مريتش بالموقف اللي السؤال ده بيتكلم عنه، تجاهل السؤال والإجابة.
How can I convert a string to a char* in order to use it with text_out?
Learn from this example:
string s = "Hello";
char *c = (char *) s.c_str();
text_out(c, 20, 20);
How can I convert a char * (that I got by using the input( ) function) to a string?
Learn from this example:
char *c = input("Enter your name:", 30, 30);
string s = c;
ملاحظة: لو عايز تقرأ أكثر من قيمة نصية باستخدام دالة input وتحافظ عليهم، لازم تعمل نسخة من كل حاجة تقرأها قبل ما تقرأ اللي بعدها، لأن دالة input دايماً بتقرأ في نفس المكان في الذاكرة، وبالتالي لو ما عملتش نسخ حتلاقي ان كل حاجة قرأتها بقى لها نفس القيمة.
لو قرأت القيمة وحولتها لرقم فكدة تبقى حافظت عليها، لأن الرقم سوف يخزن في مكان مختلف في الذاكرة
لو قرأت القيمة في صورة char * وحولتها لـstring، تبقى حافظت عليها لأن الـstring حيعمل لنفسه نسخة
لو قرأتها char * ومش عايز تحولها لـstring، استخدم strcpy كما في المثال الآتي:
char *c = input("Enter your name:", 30, 30);
char s2[100]; // make sure it's of sufficient size
strcpy(s2, c);
// now use s2
للأسف طريقة انك تعمل array of char بحجم ثابت كبير عشان تشيل فيه نص غير معروف حجمه هي طريقة سيئة، كان ممكن الـg4c تخبرك بعدد الchar التي قد تم قراءتها وتعمل انت dynamic allocation بالحجم ده. يمكن أحل المشكلة دي في إصدارة قادمة.
ليست هناك تعليقات:
إرسال تعليق