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// ------------------------------------------------------------- //
// -=# 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
// --------------------------------- //
// 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.// --------------------------------- //
// 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. // --------------------------------- //
// 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
PLAYMUSIC "nightflyer.mp3"
Init_Game()
//Intro()
WHILE TRUE
Update()
SHOWSCREEN
WEND
STOPMUSIC
END
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.// --------------------------------- //
// 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