Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - Quentin

#62
wühle mich zur Zeit ein wenig durch DDgui, um damit eine Spielsteuerung hinzubekommen. Bei einem Dialog, der lediglich einige Strings anzeigen soll, ist das Ergebnis etwas seltsam. Zwischen dem ersten und zweiten String klafft eine recht große Lücke.



hier der Code dazu:
Habe es mit und ohne Spacer probiert, mit und ohne nachfolgende Leerzeichen. Immer das gleiche Ergebnis. Wenn ich den ersten Spacer setze, werden die Strings zwar zusammenhängend dargestellt, noch oben ist jedoch ein ziemlich großer Bereich dann frei.

Kleiner Hinweis vielleicht, was ich hier falsch mache?

Code (glbasic) Select
// ------------------------------------------------------------- //
// -=#  DIA_CONTROL  #=-
// ------------------------------------------------------------- //
FUNCTION dia_control:

  SETFONT 2
  DDgui_pushdialog(100, 100, 500, 300)
  DDgui_set("MOVEABLE", TRUE)
  DDgui_set("TEXT", "Steuerung")

  //DDgui_spacer(1000, 0)    
  DDgui_widget("", "Cursor oben   --> Beschleunigen     ", 0, 0)
  //DDgui_spacer(1000, 0)
  DDgui_widget("", "Cursor unten  --> Bremsen           ", 0, 0)
  //DDgui_spacer(1000, 0)
  DDgui_widget("", "Cursor links  --> nach links drehen ", 0, 0)
  //DDgui_spacer(1000, 0)
  DDgui_widget("", "Cursor rechts --> nach rechts drehen", 0, 0)
  //DDgui_spacer(1000, 0)
  DDgui_widget("", "Leertaste     --> Laser feuern      ", 0, 0)
  //DDgui_spacer(1000, 0)
  DDgui_widget("", "L             --> Laser wechseln    ", 0, 0)
  //DDgui_spacer(1000, 0)
  DDgui_widget("", "ESC           --> Menue/Pause       ", 0, 0)
  //DDgui_spacer(1000, 0)
                                               
  DDgui_spacer(200, 50)
  DDgui_button("bt_ok", " Zurueck", 100, 25)
 
  WHILE TRUE
    DDgui_show(FALSE)
    IF DDgui_get("bt_okCLICKED")
      BREAK
    ENDIF
    SHOWSCREEN
    HIBERNATE
  WEND
 
  DDgui_popdialog()

ENDFUNCTION // DIA_CONTROL
#63
bei Verwendung von PLAYMUSIC ist mir jetzt häufiger aufgefallen, daß am Ende des Stückes das Spiel kurz stockt. Kann man das evlt. umgehen? Oder muss man damit leben?
#64
Besteht prinzipiell die Möglichkeit GL auch auf einem USB-Stick zu installieren? Oder sind heir bestimmte Registry-Einträge zwingend erforderlich?

Ist der USB-Stick am Rechner angeschlossen, von dem die Installation ausgeführt wurde, klappts, auf anderen Rechnern dann nicht.

Meldung:
"Diese Anwendung konnte nicht gestartet werden, weil die Anwendungskonfiguration nicht korekt ist."
#65
versuche mich gerade an einem Sudoku-Generator in GL. Das Spielfeld hab ich auch soweit. Nur ist mir nicht so ganz klar, wie die Schwierigkeitsgrade einzustellen sind. Erst dachte ich, bei leicht decke ich von vornherein mehr Zahlen auf. Schaue ich mir aber die Sudokus z.B. in Zeitungen an, sind bei den leichten nicht unbedingt mehr Zahlen aufgedeckt als bei den schweren.

Weiß vielleicht jemand, worauf es hier zu achten gilt?
#66
Sometimes it would be useful to let decide the "customer" in which screen resolution she or he wants to play your game. Currently GLBasic offers no support for this. In fact it's possible to set different screen resolutions with the SETSCREEN command but however one can not be sure if this resolution is working on every graphic card.

To find a remedy we can use a function of the Windows API which will deliver all possible resolutions of a graphic card. The following example program will show how to use this function in own programs.

From this place once more "special thanks to Gernot" for the help to find the right way calling this function.

The core is the function GetScreenModes() which can be called in two ways.

GetScreenModes(0)    
--> will deliver all resolutions which were supported by the graphic car. Some resolutions are shown several times as many resolutions could be used with differnt color depth and frequency. Color depth and frequency are not important for GLBasic at the time as they could not be affected with the normal commands like SETSCREEN (but who knows what future brings)

GetScreenModes(1)
--> will deliver all resolutions too but double entries will be deleted from the list.

Code (glbasic) Select
// --------------------------------- //
// Project: ScreenModes
// Start: Thursday, July 05, 2007
// IDE Version: 4.237

// this structure is needed to use function GetScreenModes()
TYPE tScreenMode
  width
  height
  bits
  frequency
ENDTYPE
GLOBAL ScreenMode[] AS tScreenMode
GLOBAL scrmode AS tScreenMode


// test program part 1
LOADFONT "arial.bmp", 0     // <-- here please enter an own font !!!!!!
GETFONTSIZE fontx, fonty
GetScreenModes(0)
PRINT "All possible resolutions:", 0, 0
y = 2 * fonty
FOREACH scrmode IN ScreenMode[]
  PRINT scrmode.width + " x " + scrmode.height + " Color depth: "+scrmode.bits+" Bits " + "Frequency: "+scrmode.frequency, 0, y
  INC y, fonty
NEXT
SHOWSCREEN
KEYWAIT

// test program part 2
GetScreenModes(1)
PRINT "Distinct resolutions:", 0, 0
y = 2 * fonty
FOREACH scrmode IN ScreenMode[]
  PRINT scrmode.width + " x " + scrmode.height, 0, y
  INC y, fonty
NEXT
SHOWSCREEN
KEYWAIT

// test program part 3
LOCAL maxres = BOUNDS(ScreenMode[], 0) - 1
SETSCREEN ScreenMode[maxres].width, ScreenMode[maxres].height, 1
PRINT "This is the highest resolution possible in fullscreen mode", 0, 0
y = 2 * fonty
FOREACH scrmode IN ScreenMode[]
  PRINT scrmode.width + " x " + scrmode.height, 0, y
  INC y, fonty
NEXT
SHOWSCREEN
KEYWAIT

END

FUNCTION WeNeedOne:
ENDFUNCTION

// In __GLBASIC__ namespace, outside of functions make a pointer to a function
INLINE
    DECLARE_ALIAS(    user32_EnumDisplaySettings, "user32.dll", \
                    "EnumDisplaySettingsA", (const char*, unsigned int, void*), \
                    int);
ENDINLINE

FUNCTION EnumDisplaySettings: disp$, num

    LOCAL retcode

    INLINE
        struct DEVMODE {
              char dmDeviceName[32];
              short dmSpecVersion;
              short dmDriverVersion;
              short dmSize;
              short dmDriverExtra;
              long  dmFields;
              short dmOrientation;
              short dmPaperSize;
              short dmPaperLength;
              short dmPaperWidth;
              short dmScale;
              short dmCopies;
              short dmDefaultSource;
              short dmPrintQuality;
              short dmColor;
              short dmDuplex;
              short dmYResolution;
              short dmTTOption;
              short dmCollate;
              char dmFormName[32];
              short dmUnusedPadding;
              long dmBitsPerPel;
              long dmPelsWidth;
              long dmPelsHeight;
              long dmDisplayFlags;
              long dmDisplayFrequency;
        };
        DEVMODE devmode;
        devmode.dmSize = sizeof(DEVMODE);
        // if disp$ = "", pass NULL instead!
        if (user32_EnumDisplaySettings(LEN(disp_Str) ? disp_Str.c_str() : NULL, num, &devmode))
        {
        scrmode.width = devmode.dmPelsWidth;
        scrmode.height = devmode.dmPelsHeight;
        scrmode.bits = devmode.dmBitsPerPel;
        scrmode.frequency = devmode.dmDisplayFrequency;
        retcode = 1;
        }
        else
        {
        retcode = 0;
        }
    ENDINLINE

    RETURN retcode

ENDFUNCTION


// ------------------------------------------------------------- //
// -=#  SCREENMODES  #=-
// ------------------------------------------------------------- //
FUNCTION GetScreenModes: restrict

  LOCAL found = TRUE
  LOCAL mode = 0
  LOCAL notsorted = TRUE
  LOCAL count, i
  LOCAL swapmode AS tScreenMode

  // get all resolutions possible. If the function returns a "0" or a "1"
  // as frequency then Windows is not sure about the frequency so
  // we will ignore this one as a precaution
  WHILE found
    IF EnumDisplaySettings("", mode)
      IF scrmode.frequency > 1
        DIMPUSH ScreenMode[], scrmode
      ENDIF
    ELSE
      found = FALSE
    ENDIF
    INC mode, 1
  WEND

  // sort the list ascending by the resolution
  // a simple bubble sort should be fast enough
  count = BOUNDS(ScreenMode[], 0)
  WHILE notsorted
    notsorted = FALSE
    FOR i = 0 TO count - 2
      IF ScreenMode[i].width > ScreenMode[i+1].width AND _
         ScreenMode[i].height > ScreenMode[i+1].height
        swapmode = ScreenMode[i]
        ScreenMode[i] = ScreenMode[i+1]
        ScreenMode[i+1] = swapmode
        notsorted = TRUE
      ENDIF
    NEXT
  WEND
 
  // if wanted delete all double entries
  IF restrict = 1
    swapmode.width = 0
    swapmode.height = 0
    FOREACH scrmode IN ScreenMode[]
      IF scrmode.width = swapmode.width AND scrmode.height = swapmode.height
        DELETE scrmode
      ENDIF
      swapmode = scrmode
    NEXT  
  ENDIF
 
ENDFUNCTION // SCREENMODES
To use this functionallity in your own programs just copy the coding to your own one and delete the parts of the test programs.
If someone find this useful, have fun!
#67
Bei einigen Spielen kann es sinnvoll sein, wenn man seinen "Kunden" die Wahl lässt, in welchen Bildschirmauflösungen sie/er das Spiel spielen will. GLBasic bietet zur Zeit hier noch keine Hilfestellung. Man kann zwar mit dem Befehl SETSCREEN diverse Auflösungen einstellen, kann sich dabei aber nicht wirklich sicher sein, daß diese auch auf allen möglichen Computern laufen.

Abhilfe schafft hier das Einbinden einer Funktion der Window-API, die die möglichen Auflösungen der Grafikkarte zurückliefert. Das folgende Beispielprogramm demonstriert die Verwendung dieser Funktion.

An dieser Stelle nochmal "special thanks to Gernot" für die Hilfe beim Aufruf der Funktion

Herzstück ist die Funktion GetScreenModes(), die auf zwei Arten aufgerufen werden kann.

GetScreenModes(0)    
--> liefert alle Auflösungen zurück, die von der Grafikkarte unterstützt werden. Hierbei können sich einzelne Auflösungen häufig wiederholen, da viele Auflösungen mit unterschiedlicher Farbtiefe und Bildwiederholfrequenz möglich sind (je nach Grafikkarte). Farbtiefe und Frequenz spielen für GLBasic noch keine Rolle, da sie mit den Standardbefehlen z.B. SETSCREEN nicht beeinflusst werden können (aber was nicht ist, kann ja noch kommen)

GetScreenModes(1)
--> liefert alle möglichen Auflösungen zurück, wobei doppelte Einträge bezüglich der Auflösung aus der Liste entfernt werden.

Code (glbasic) Select
// --------------------------------- //
// Project: ScreenModes
// Start: Thursday, July 05, 2007
// IDE Version: 4.237

// diese Struktur wird immer benötigt, wenn man die Funktion GetScreenModes() nutzen will
TYPE tScreenMode
  width
  height
  bits
  frequency
ENDTYPE
GLOBAL ScreenMode[] AS tScreenMode
GLOBAL scrmode AS tScreenMode


// Testprogramm Teil 1
LOADFONT "arial.bmp", 0     // <-- hier bitte eigenen Font einsetzen !!!!!!
GETFONTSIZE fontx, fonty
GetScreenModes(0)
PRINT "Alle möglichen Auflösungen:", 0, 0
y = 2 * fonty
FOREACH scrmode IN ScreenMode[]
  PRINT scrmode.width + " x " + scrmode.height + " Farbtiefe: "+scrmode.bits+" Bits " + "Frequenz: "+scrmode.frequency, 0, y
  INC y, fonty
NEXT
SHOWSCREEN
KEYWAIT

// Testprogramm Teil 2
GetScreenModes(1)
PRINT "Auflösungen ohne Doppelnennungen:", 0, 0
y = 2 * fonty
FOREACH scrmode IN ScreenMode[]
  PRINT scrmode.width + " x " + scrmode.height, 0, y
  INC y, fonty
NEXT
SHOWSCREEN
KEYWAIT

// Testprogramm Teil 3
LOCAL maxres = BOUNDS(ScreenMode[], 0) - 1
SETSCREEN ScreenMode[maxres].width, ScreenMode[maxres].height, 1
PRINT "Das ist die höchstmögliche Auflösung im Vollbildmodus", 0, 0
y = 2 * fonty
FOREACH scrmode IN ScreenMode[]
  PRINT scrmode.width + " x " + scrmode.height, 0, y
  INC y, fonty
NEXT
SHOWSCREEN
KEYWAIT

END

FUNCTION WeNeedOne:
ENDFUNCTION

// In __GLBASIC__ namespace, outside of functions make a pointer to a function
INLINE
    DECLARE_ALIAS(    user32_EnumDisplaySettings, "user32.dll", \
                    "EnumDisplaySettingsA", (const char*, unsigned int, void*), \
                    int);
ENDINLINE

FUNCTION EnumDisplaySettings: disp$, num

    LOCAL retcode

    INLINE
        struct DEVMODE {
              char dmDeviceName[32];
              short dmSpecVersion;
              short dmDriverVersion;
              short dmSize;
              short dmDriverExtra;
              long  dmFields;
              short dmOrientation;
              short dmPaperSize;
              short dmPaperLength;
              short dmPaperWidth;
              short dmScale;
              short dmCopies;
              short dmDefaultSource;
              short dmPrintQuality;
              short dmColor;
              short dmDuplex;
              short dmYResolution;
              short dmTTOption;
              short dmCollate;
              char dmFormName[32];
              short dmUnusedPadding;
              long dmBitsPerPel;
              long dmPelsWidth;
              long dmPelsHeight;
              long dmDisplayFlags;
              long dmDisplayFrequency;
        };
        DEVMODE devmode;
        devmode.dmSize = sizeof(DEVMODE);
        // if disp$ = "", pass NULL instead!
        if (user32_EnumDisplaySettings(LEN(disp_Str) ? disp_Str.c_str() : NULL, num, &devmode))
        {
        scrmode.width = devmode.dmPelsWidth;
        scrmode.height = devmode.dmPelsHeight;
        scrmode.bits = devmode.dmBitsPerPel;
        scrmode.frequency = devmode.dmDisplayFrequency;
        retcode = 1;
        }
        else
        {
        retcode = 0;
        }
    ENDINLINE

    RETURN retcode

ENDFUNCTION


// ------------------------------------------------------------- //
// -=#  SCREENMODES  #=-
// ------------------------------------------------------------- //
FUNCTION GetScreenModes: restrict

  LOCAL found = TRUE
  LOCAL mode = 0
  LOCAL notsorted = TRUE
  LOCAL count, i
  LOCAL swapmode AS tScreenMode

  // alle möglichen Auflösungen ermitteln. Wenn die Funktion als
  // Wiederholfrequenz eine "0" oder eine "1" zurückliefert, kann
  // Windows nicht genau feststellen, um welche Frequenz es sich handelt.
  // Sicherheitshalber bleibt dieser Modus dann unberücksichtigt.
  WHILE found
    IF EnumDisplaySettings("", mode)
      IF scrmode.frequency > 1
        DIMPUSH ScreenMode[], scrmode
      ENDIF
    ELSE
      found = FALSE
    ENDIF
    INC mode, 1
  WEND

  // Liste sortieren nach der Auflösung
  // Ein einfacher Bubble-Sort ist hier schnell genug
  count = BOUNDS(ScreenMode[], 0)
  WHILE notsorted
    notsorted = FALSE
    FOR i = 0 TO count - 2
      IF ScreenMode[i].width > ScreenMode[i+1].width AND _
         ScreenMode[i].height > ScreenMode[i+1].height
        swapmode = ScreenMode[i]
        ScreenMode[i] = ScreenMode[i+1]
        ScreenMode[i+1] = swapmode
        notsorted = TRUE
      ENDIF
    NEXT
  WEND
 
  // wenn gewünscht, werden alle doppelten Einträge entfernt
  IF restrict = 1
    swapmode.width = 0
    swapmode.height = 0
    FOREACH scrmode IN ScreenMode[]
      IF scrmode.width = swapmode.width AND scrmode.height = swapmode.height
        DELETE scrmode
      ENDIF
      swapmode = scrmode
    NEXT  
  ENDIF
 
ENDFUNCTION // SCREENMODES
Um diese Funktionalität in den eigenen Programmen zu nutzen, einfach das Coding in das eigene einbinden und die Testblöcke löschen.
Wer es gebrauchen kann, viel Spaß damit.
#68
ist mir beim Beispiel für die Chat-Queue aufgefallen.

Lese ich über INKEY$() Zeichen ein und drücke die linke SHIFT-Taste, kommt nicht der entsprechende Großbuchstabe, sondern z.B. ein "(" für ein "H". Habe ich CAPS-Lock aktiviert, werden Großbuchstaben korrekt geliefert !?!? Auch mit der rechten Umschalttaste arbeitet das Teil korrekt. Umlaute werden gar nicht angenommen.

Glaube nicht, daß es am Font liegt. Habe neben smallfont noch diverse selbsterstellt ausprobiert.

Kann das irgend jemand bestätigen? Oder habe ich in dem Beispiel Mist gebaut oder einfach nur einen Sch... Rechner?

P.S.
gleiches gilt für den INPUT-Befehl, gleiches Verhalten, daher schließe ich Mistbauen meinerseits erst einmal aus ;)
#69
Frage:
Ist 1024 * 768 das absolute Maximum? Zumindest bei den Projekteinstellungen finden sich keine höheren Werte. Versuche mit SETSCREEN und höheren Auflösungen scheitern.
Wenn ja, ist geplant, daran noch etwas zu ändern?
#70
Um mit GL warm zu werden, hab ich mich an einer etwas abgewandelten Variante von Asteroids versucht. Das vorläufige Ergebnis findet sich hier

//

Aufgabe: Klar Asteroiden abschießen. Diese fliegen kreuz und quer durch das All. Zusammenstöße mit dem Schiff kosten Lebensenergie. Bei 50 Abschüssen hat man erst mal gewonnen. Die nach einem Abschuss umherfliegenden Trümmer richten keinen Schaden an. Ein Radarbildschirm gibt einen Überblick wo sich die Asteroiden befinden.
#71
Versuche mich gerade an Explosionen mit umherfliegenden Trümmerteilen. Das folgende habe ich dabei zusammengeschustert. Klick auf linke Maustaste erzeugt an der aktuellen Mausposition eine Explosion. Die Anzahl der umherfliegenden Trümmer wird links oben angezeigt. Bei mehr als 5.000 Trümmerteilen ging mein Rechner allerdings schwer in die Knie. Wer bietet mehr? ;)

Mit den hier eingesetzten Werten komme ich jedoch auch bei gedrückt gehaltener Maustaste auf max. 1.100 Trümmerteile

Code (glbasic) Select
// --------------------------------- //
// Project: Explosion
// Start: Tuesday, June 26, 2007
// IDE Version: 4.225


// Typebeschreibung für die Explosionen
TYPE tExplosion
  picture           // ID für die Grafik
  x                 // horizontale Position auf dem Bildschirm
  y                 // vertikale Position auf dem Bildschirm
  direction         // Bewegungsrichtung (Winkel)
  rotation          // Rotationsgeschwindigkeit
  speed             // Geschwindigkeit der Partikel
  size              // aktuelle Größe der Partikel
  delay             // Pause bis zur nächsten Berechnung geht sonst zu schnell
ENDTYPE
GLOBAL Explosion[] AS tExplosion
GLOBAL newExplosion AS tExplosion

// lokale Variablen für Mausabfrage und Grafikerstellung
LOCAL mx, my, b1, b2, i, sx, sy


// erst mal ein paar Grafiken für die Partikel in
// unterschiedlicher Größe erstellen
// sieht mit richtigen Grafiken natürlich besser aus
FOR i = 0 TO 9
  FILLRECT 0, 0, 10+i, 10+i, RGB(255, RND(255), RND(128))
  GRABSPRITE i, 0, 0, 10+i, 10+i
NEXT

// Hauptschleife
SYSTEMPOINTER TRUE   // Mauscursor sichtbar machen
WHILE TRUE
  // mit Klick auf die linke Maustaste wird an der aktuellen
  // Mausposition eine Explosion erzeugt
  MOUSESTATE mx, my, b1, b2
  IF b1
    Make_Explosion(mx, my, RND(100) + 50, RND(100) + 50)
  ENDIF
  // und hier werden die Explosionen dargestellt
  Update_Explosions()
  SHOWSCREEN
WEND


// ------------------------------------------------------------- //
// -=#  MAKE_EXPLOSION  #=-
// ------------------------------------------------------------- //
FUNCTION Make_Explosion: x, y, width, height

  LOCAL wx, wy, pic

  // zufällig eine Partikelgrafik auswählen und deren Größe festhalten
  pic = RND(9)
  GETSPRITESIZE pic, wx, wy

  // die Anzahl der Partikel pro Explosion errechnet sich aus der
  // Größe des Explosionsbereiches, der mit den Parameters Breite (width)
  // und Höhe (height) angegeben wird. Hintergrund ist, daß eine
  // Explosion ja normalerweise dann erfolgt, wenn ein Objekt zerstört
  // wurde. Als width und height sollten dann die Breite und Höhe
  // der Objektgrafik mitgegeben werden. Je größer ein Objekt ist
  // desto mehr Partikel werden für die Explosion erzeugt
  count = width / wx + height / wx

  // nun werden die einzelnen Partikel der Explosion erzeugt
  FOR i = 1 TO count
    newExplosion.picture = pic          // zufällig ausgewählte Grafik
    newExplosion.x = x                  // Position übergeben
    newExplosion.y = y
    newExplosion.size = 1               // zu Begin ist die Größe noch normal
    newExplosion.rotation = RND(2)      // Rotationsgeschwindigkeit
    newExplosion.direction = RND(360)   // zufällige Bewegungsrichtung
    newExplosion.speed = RND(5) + 5     // und Geschwindigkeit (soll aber nicht zuuuu
                                        // langsam sein, sonst steht der Partikel dumm
                                        // in der Gegend rum
    DIMPUSH Explosion[], newExplosion   // und einfügen
  NEXT

ENDFUNCTION // MAKE_EXPLOSION


// ------------------------------------------------------------- //
// -=#  UPDATE_EXPLOSIONS  #=-
// ------------------------------------------------------------- //
FUNCTION Update_Explosions:

  // zur Info geben wir die Anzahl der Partikel aus
  PRINT BOUNDS(Explosion[], 0), 0, 0

  FOREACH ex IN Explosion[]
    // Partikel darstellen
    ROTOZOOMSPRITE ex.picture, ex.x, ex.y, ex.direction, ex.size
    IF GETTIMERALL() > ex.delay                 // Timer abwarten, da sonst die Darstellung zu schnell ist
      DEC ex.x, SIN(ex.direction) * ex.speed    // neue Position in Abhängigkeit von der
      DEC ex.y, COS(ex.direction) * ex.speed    // Bewegungsrichtung errechnen
      INC ex.direction, ex.rotation             // Rotation hinzufügen
      DEC ex.size, 0.03                         // Größe des Partikel verringern
                                                // je größer man diesen Wert wählt, umso schneller
                                                // verschwinden die Partikel wieder
      ex.delay = GETTIMERALL() + RND(50) + 10   // Verzögerung setzen, auch ein bißchen zufällig
      IF ex.size <= 0 THEN DELETE ex            // ist der Partikel nicht mehr sichtbar, dann
                                                // können wir ihn entfernen
    ENDIF
  NEXT

ENDFUNCTION // UPDATE_EXPLOSIONS
#72
ein etwas seltsames Phänomen

spiele in einem Programm mit PLAYMUSIC eine MP3 ab. Im Spiel wird dann der Mauscursor als Eieruhr angezeigt. SYSTEMPOINTER FALSE hat keinen Einfluß. SYSTEMPOINTER TRUE zeigt wie erwartet den normalen Pfeil-Cursor. Ohne PLAYMUSIC läuft alles normal ab ohne Mauscursor.


Code (glbasic) Select
PLAYMUSIC "nightflyer.mp3"
Init_Game()
//Intro()

WHILE TRUE
  Update()
  SHOWSCREEN
WEND

STOPMUSIC
END
#73
Schranz0r hatte beim Schneegestöber empholen, den Hintergrund der angezeigten Grafik mit der Transparenzfarbe RGB(255, 0, 128) zu hinterlegen.

Code (glbasic) Select
 FILLRECT 0,0,10,10, RGB(0xff, 0x00, 0x80)
  DRAWLINE 0, 5, 10, 5, RGB(RND(255), 255, 255)
  GRABSPRITE 0, 0, 0, 10, 10
Nun habe ich jedoch das Problem, wenn ich das Sprite anzeigen will, die Transparenzfarbe alles andere als transparent ist. In einem Beispiel von Gernot hab ich mal gesehen, daß er die Grafik dann erst als BMP speichert und gleich wieder lädt.

Gehört das so? Warum funzt das nicht gleich mit GRABSPRITE?
Oder habe ich etwas Grundlegendes übersehen?
#74
I just started in programming in GLBasic and I'm surprised how easy it is to create nice effects. This simple example shows a snow flurry which should be more or less realistic ;-)))

Code (glbasic) Select
// --------------------------------- //
// Project: schnee
// Start: Friday, June 15, 2007
// IDE Version: 4.218

// a simple snow flurry

// TYPE declaration for a snowflake
TYPE tSnowFlake
  x            // X - position
  y            // Y - position
  size         // size of a snowflake
  speed        // speed with which the flakes fall to to ground
  rotate       // flag if a flake will rotate while falling
  angle        // value for the libration of the snowflakes
ENDTYPE

GLOBAL SnowFlakes[] AS tSnowFlake   // an array for our snowflakes
GLOBAL newFlake AS tSnowFlake       // a single flake to insert into the array

GLOBAL screen_width, screen_height  // current screen size

// Konstanten
MAX_SNOWFLAKES = 1000               // maximum count of the flakes


// Hauptprogramm
Init_Snow()                         // initialisation
WHILE TRUE
  Update_Snow()                     // show the snow flurry
  SHOWSCREEN
WEND




// ------------------------------------------------------------- //
// -=#  INIT_SNOW  #=-
// ------------------------------------------------------------- //
FUNCTION Init_Snow:

  LOCAL i

  // draw the snow flake
  DRAWLINE 0, 5, 10, 5, RGB(RND(255), 255, 255)
  DRAWLINE 5, 0, 5, 10, RGB(RND(255), 255, 255)
  DRAWLINE 1, 1, 9, 9, RGB(RND(255), 255, 255)
  DRAWLINE 9, 1, 1, 9, RGB(RND(255), 255, 255)

  // store the "artwork" in a sprite
  GRABSPRITE 0, 0, 0, 10, 10

  // get the current screen size
  GETSCREENSIZE screen_width, screen_height

  // now draw the snow flakes
  // - the position is randomized all over the screen
  // - the falling speed should be 0.1 to 1.5 pixels per cycle
  //   in case the RND() function returns a Null we will set
  //   the speed to 0.5
  // - the size should be 0.1 to 1 of the original sprite
  // - the field "rotate" will tell us if a snowflake will rotate or not
  //   function RND(1) will return a 0 = not rotate or 1 = rotate
  // - for the libration of the flakes we will use the SIN() function
  //   see function Update_Snow()
  // - last we store the new snowflake the the array SnowFlakes[]
  FOR i = 1 TO MAX_SNOWFLAKES
    newFlake.x = RND(screen_width)
    newFlake.y = RND(screen_height)
    newFlake.speed = RND(150) / 100
    IF newFlake.speed = 0
      newFlake.speed = 0.5
    ENDIF
    newFlake.size = RND(10) / 10
    newFlake.rotate = RND(1)
    newFlake.angle = RND(360)
    DIMPUSH SnowFlakes[], newFlake
  NEXT

ENDFUNCTION // INIT_SNOW


// ------------------------------------------------------------- //
// -=#  UPDATE_SNOW  #=-
// ------------------------------------------------------------- //
FUNCTION Update_Snow:

  LOCAL lsnow AS tSnowFlake

  FOREACH lsnow IN SnowFlakes[]

    // rotate or not?
    IF lsnow.rotate
      // if rotate then increase the rotation for the next cycle by one
      ROTOZOOMSPRITE 0, lsnow.x, lsnow.y, lsnow.rotate, lsnow.size
      INC lsnow.rotate, 1
    ELSE
      // otherwise only display the flake in the given size
      ZOOMSPRITE 0, lsnow.x, lsnow.y, lsnow.size, lsnow.size
    ENDIF

    INC lsnow.y, lsnow.speed         // calculate new Y position
    INC lsnow.angle, 2               // increase value for libration
    INC lsnow.x, SIN(lsnow.angle)    // and add it to the X position
    IF lsnow.y > screen_height       // if a flake will disappear on the ground of the screen
      lsnow.y = 0                    // then we show it again at the top
      lsnow.x = RND(screen_width)
    ENDIF

  NEXT

ENDFUNCTION // UPDATE_SNOW
#75
Neuauflage: Die meisten Beiträge sind leider leer :(
#76
Gehe ich recht in der Annahme, daß die RND()-Funktion immer nur Ganzzahlen zurückliefert? Oder habe ich irgend etwas übersehen?

Ich kann mir zwar behelfen, indem ich statt "RND(3)" mit "RND(30) / 10" rechne, hätte es aber trotzdem gerne bestätigt.

Merci beaucoup