WAGGL von Windows nach Linux portieren

D

djtraumwelt

Foren As
Hallo!

Ich habe unter Windows ein Spiel geschrieben Namens WAGGL (läuft unter wine) und möchte das jetzt auch für Linux schreiben. Das wird dann meine erste Linux-Anwendung die ich schreibe und von daher habe ich noch ziemlich wenig Ahnung. Was ich bis jetzt habe: CODE. Als nächstes bräuchte ich den Hintergrund schwarz und weiß nicht wie man das macht

Vielen Dank für eure Hilfe
 
Wuerde ich einfach mit gtk_style_set_background() machen. Installiere dir mal devhelp und die zugehoerige GTK-Referenz und besorg dir mal ganz dringend ein Buch zur GTK-Programmierung. :)
 
also ich will dir ja jetzt nix dreinreden aber ich wuerde das waggel so wie du das gemacht hast mit der xlib realisieren... ist denk ich schoener als mit gtk... tja is meine meinung!

mfg hazelnoot
 
Schoener geht immer. ;) Noch schoener wirds mit SDL oder OpenGL. :D
 
ich hab ja noch so gut wie nix geschafft und könnte von daher auch gerne SDL verwenden. aber ich hab so überhaupt keine ahnung. kann mir jemand das fenster mit schwarzem hintergrund in SDL schreiben. ich weiß das ist viel verlangt aber ich kriegs alleine wirklich nicht hin und wenn ich den fertigen code erst mal sehe dann kann ich davon lernen.
 
Ich wuerde ja zu OpenGL tendieren, allerdings nur weil ich in meinem Studium damit etwas Erfahrung gesammelt habe :D !

OpenGL ist natuerlich recht maechtig weil man an jedem Parameter drehen kann aber somit auch recht low-level. Ausserdem behandelt es nur Grafik und Eingabegeraete, eine Funktion zum Abspielen von Sound fehlt. SDL waere da vielleicht besser.

Falls du dich doch dazu entscheiden solltest OpenGL zu nehmen, ich hab hier noch ein paar Beispiele-Programme aus der GDV (Graphische Datenverarbeitung)-Vorlesung rumfliegen die ich dir geben kann.

Gruss,
Philip
 
#include <stdlib.h>
#include <SDL/SDL.h>

SDL_Event event;
int quit = 0;
int xbox = 400;
int ybox = 300;
int radbox = 120;
int xxbox = 50;
int yybox = 50;

int main()
{
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
fprintf(stderr, "SDL konnte nicht initialisiert werden: %s\n",
SDL_GetError());
exit(1);
}

SDL_Surface *display;
SDL_Surface *image;

SDL_Rect drect;
SDL_Rect srect;

display = SDL_SetVideoMode( 800, 600, 16, SDL_SWSURFACE );
if ( display == NULL )
{
fprintf(stderr, "Konnte kein Fenster 800x600px oeffnen: %s\n",
SDL_GetError());
exit(1);
}

image = SDL_LoadBMP("sperr.bmp");
if (image == NULL)
{
fprintf(stderr, "Das Bild konnte nicht geladen werden: %s\n",
SDL_GetError());
exit(-1);
}

srect.x = 0;
srect.y = 0;
srect.w = 10;
srect.h = 10;

drect.x = xxbox - 35;
drect.y = yybox - 35;
drect.w = 70;
drect.h = 70;
SDL_FillRect(display, &drect, SDL_MapRGB(display->format, 0, 50, 127));

drect.w = 10;
drect.h = 10;
for( drect.x = xbox - radbox; drect.x <= xbox + radbox; drect.x = drect.x + 10) {
drect.y = ybox - radbox;
SDL_BlitSurface(image, &srect, display, &drect);
SDL_UpdateRects(display,1,&drect);
drect.y = ybox + radbox;
SDL_BlitSurface(image, &srect, display, &drect);
}
for( drect.y = ybox - radbox; drect.y <= ybox + radbox; drect.y = drect.y + 10) {
drect.x = xbox - radbox;
SDL_BlitSurface(image, &srect, display, &drect);
SDL_UpdateRects(display,1,&drect);
drect.x = xbox + radbox;
SDL_BlitSurface(image, &srect, display, &drect);
}

drect.x = 0;
drect.y = 0;
drect.w = 800;
drect.h = 600;
SDL_UpdateRects(display,1,&drect);

while( quit == 0 )
{
while( SDL_PollEvent( &event ) )
{
switch( event.type )
{
case SDL_QUIT:
quit = 1;
break;
case SDL_MOUSEBUTTONDOWN:
if (event.x >= xbox - radbox && event.x <= xbox + radbox && event.y >= ybox - radbox && event.y <= ybox + radbox) quit = 1;
/* er kennt kein event.x und kein event.y */
break;
}
}
}

SDL_FreeSurface(image);
atexit(SDL_Quit);
}

das hab ich bis jetzt und komm nicht weiter. was hab ich falsch gemacht?
 
Ganz einfach SDL_Event kennt die Elemente x und y nicht.
Code:
error: union has no member named `x'
Siehe dazu auch die Definition von von SDL_Event (man sdl_event):
Code:
STRUCTURE DEFINITION
       typedef union{
         Uint8 type;
         SDL_ActiveEvent active;
         SDL_KeyboardEvent key;
         SDL_MouseMotionEvent motion;
         SDL_MouseButtonEvent button;
         SDL_JoyAxisEvent jaxis;
         SDL_JoyBallEvent jball;
         SDL_JoyHatEvent jhat;
         SDL_JoyButtonEvent jbutton;
         SDL_ResizeEvent resize;
         SDL_ExposeEvent expose;
         SDL_QuitEvent quit;
         SDL_UserEvent user;
         SDL_SywWMEvent syswm;
       } SDL_Event;

Nachtrag: Im uebrigen waere es der Lesbarkeit des Codes sehr zutraeglich, wenn du ihn hier im Board in einen
Code:
-Block packen wuerdest.
 
ich hab ja versucht das in einen code-block zu packen, aber hab schnell antwort erwischt und da war kein code-block in der formatierung. naja das nächste mal.

ich weiß, dass SDL_Event kein x und kein y kennt. Aber wer kennt das? Ich muss doch die position der Maus überprüfen ob sie innerhalb des Kästchens ist.
 
Ich hab's jetzt:
Code:
  while( quit == 0 )
  {
   while( SDL_PollEvent( &event ) )
   {
    switch( event.type )
    {
      case SDL_QUIT:
        quit = 1;
      break;
      case SDL_MOUSEBUTTONDOWN:
        if (event.button.x >= xbox - radbox && event.button.x <= xbox + radbox && event.button.y >= ybox - radbox && event.button.y <= ybox + radbox) quit = 1;
      break;
    }
   }
  }
 
was brauch ich alles um eine ganzzahlige zufallszahl zu bekommen?
 
man random

Und nimm dir verdammt nochmal endlich eine C-Doku und die Dokus zu den Libs, die du benutzt. Da koenntest du solche Fragen ganz allein beantworten.
 
Du solltest mal die Uhr deines Rechners bzw. Servers richtig stellen :)
Code:
theton@BigTAPS:~/Documents> tar -xzf game.tar.gz
tar: game/waggl: time stamp 2006-10-02 09:19:52 is 75862 s in the future
tar: game/waggl.c: time stamp 2006-10-02 09:19:49 is 75859 s in the future
tar: game: time stamp 2006-10-02 09:23:24 is 76074 s in the future
Und aus einigen der 'if' kann man locker 'else if' machen. Ausserdem solltest du mal schauen, ob man diese Unmengen globalen Variablen irgendwie vermeiden kann. Und du solltest dir angewoehnen mit -Wall zu kompilieren:
Code:
waggl.c: In function `main':
waggl.c:207: warning: unreachable code at beginning of switch statement
waggl.c:219: warning: control reaches end of non-void function

Hier mal die Version mit bereinigten Warnungen:
Code:
#include <stdlib.h>
#include <SDL/SDL.h>

SDL_Event event;
SDL_TimerID timer;
SDL_Surface *display;
SDL_Surface *image;
SDL_Rect drect;
SDL_Rect srect;
int quit = 0;
int xbox = 400;
int ybox = 300;
int rbox = 0;
int ubox = 0;
int speed = 1;
int level = 1;
int radbox = 120;
int xxbox = 50;
int yybox = 50;
int rrbox = 1;
int uubox = 1;
double punkte = 0;
int zufall;

Uint32 haupt_funk (Uint32 intervall, void *parameter)
{
    if (xxbox <= 35) rrbox = 1;
    if (xxbox >= 765) rrbox = -1;
    if (yybox <= 35) uubox = 1;
    if (yybox >= 565) uubox = -1;

    xxbox = xxbox + rrbox;
    yybox = yybox + uubox;

    zufall = 1+(int) (25.0*rand()/(RAND_MAX+1.0));
    if (zufall >= 20 && zufall <= 24) rbox = -1;
    if (zufall >= 5 && zufall <= 9) rbox = 1;
    if (zufall >= 10 && zufall <= 14) ubox = -1;
    if (zufall >= 15 && zufall <= 19) ubox = 1;

    if (xbox <= radbox) rbox = 1;
    if (xbox >= 800 - radbox) rbox = -1;
    if (ybox <= radbox) ubox = 1;
    if (ybox >= 600 - radbox) ubox = -1;

    xbox = xbox + (rbox * speed);
    ybox = ybox + (ubox * speed);

    punkte = punkte + 0.01;
    if (punkte >= 150) {
        radbox = 100;
        speed = 2;
        punkte = punkte + 0.02;
        level = 2;
    } else if (punkte >= 400) {
        radbox = 90;
        speed = 3;
        punkte = punkte + 0.03;
        level = 3;
    } else if (punkte >= 700) {
        radbox = 80;
        speed = 3;
        punkte = punkte + 0.04;
        level = 4;
    } else if (punkte >= 1300) {
        radbox = 70;
        speed = 4;
        punkte = punkte + 0.05;
        level = 5;
    } else {
        radbox = 60;
        speed = 5;
        punkte = punkte + 0.06;
        level = 6;
    }

    srect.x = 0;
    srect.y = 0;
    srect.w = 10;
    srect.h = 10;

    drect.x = 0;
    drect.y = 0;
    drect.w = 800;
    drect.h = 600;
    SDL_FillRect(display, &drect, SDL_MapRGB(display->format, 0, 0, 0));

    drect.x = xxbox - 35;
    drect.y = yybox - 35;
    drect.w = 70;
    drect.h = 70;
    SDL_FillRect(display, &drect, SDL_MapRGB(display->format, 0, 50, 127));

    drect.w = 10;
    drect.h = 10;
    for( drect.x = xbox - radbox; drect.x < xbox + radbox; drect.x = drect.x + 10) {
        drect.y = ybox - radbox;
        SDL_BlitSurface(image, &srect, display, &drect);
        SDL_UpdateRects(display,1,&drect);
        drect.y = ybox + radbox - 10;
        SDL_BlitSurface(image, &srect, display, &drect);
    }
    for( drect.y = ybox - radbox; drect.y < ybox + radbox; drect.y = drect.y + 10) {
        drect.x = xbox - radbox;
        SDL_BlitSurface(image, &srect, display, &drect);
        SDL_UpdateRects(display,1,&drect);
        drect.x = xbox + radbox - 10;
        SDL_BlitSurface(image, &srect, display, &drect);
    }

    drect.x = 0;
    drect.y = 0;
    drect.w = 800;
    drect.h = 600;
    SDL_UpdateRects(display,1,&drect);
    return intervall;
}

int main()
{
    if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0 )
    {
        fprintf(stderr, "SDL konnte nicht initialisiert werden:  %s\n",
                SDL_GetError());
        exit(1);
    }

    display = SDL_SetVideoMode( 800, 600, 16, SDL_FULLSCREEN );
    if ( display == NULL )
    {
        fprintf(stderr, "Konnte kein Fenster 800x600px oeffnen: %s\n",
                SDL_GetError());
        exit(1);
    }

    image = SDL_LoadBMP("sperr.bmp");
    if (image == NULL)
    {
        fprintf(stderr, "Das Bild konnte nicht geladen werden: %s\n",
                SDL_GetError());
        exit(-1);
    }

    srect.x = 0;
    srect.y = 0;
    srect.w = 10;
    srect.h = 10;

    drect.x = 0;
    drect.y = 0;
    drect.w = 800;
    drect.h = 600;
    SDL_FillRect(display, &drect, SDL_MapRGB(display->format, 0, 0, 0));

    drect.x = xxbox - 35;
    drect.y = yybox - 35;
    drect.w = 70;
    drect.h = 70;
    SDL_FillRect(display, &drect, SDL_MapRGB(display->format, 0, 50, 127));

    drect.w = 10;
    drect.h = 10;
    for( drect.x = xbox - radbox; drect.x < xbox + radbox; drect.x = drect.x + 10) {
        drect.y = ybox - radbox;
        SDL_BlitSurface(image, &srect, display, &drect);
        SDL_UpdateRects(display,1,&drect);
        drect.y = ybox + radbox - 10;
        SDL_BlitSurface(image, &srect, display, &drect);
    }
    for( drect.y = ybox - radbox; drect.y < ybox + radbox; drect.y = drect.y + 10) {
        drect.x = xbox - radbox;
        SDL_BlitSurface(image, &srect, display, &drect);
        SDL_UpdateRects(display,1,&drect);
        drect.x = xbox + radbox - 10;
        SDL_BlitSurface(image, &srect, display, &drect);
    }

    drect.x = 0;
    drect.y = 0;
    drect.w = 800;
    drect.h = 600;
    SDL_UpdateRects(display,1,&drect);

    while( quit == 0 )
    {
        while( SDL_PollEvent( &event ) )
        {
            switch( event.type )
            {
                case SDL_MOUSEBUTTONDOWN:
                    if (event.button.x >= xbox - radbox && event.button.x <= xbox + radbox && event.button.y >= ybox - radbox && event.button.y <= ybox + radbox) {
                        timer = SDL_AddTimer (10, haupt_funk, NULL);
                        quit = 1;
                    }
                    break;
            }
        }
    }

    quit = 0;
    while( quit == 0 )
    {
        while( SDL_PollEvent( &event ) )
        {
            switch( event.type )
            {
                case SDL_MOUSEMOTION:
                    if (event.button.x <= xbox - radbox || event.button.x >= xbox + radbox || event.button.y <= ybox - radbox || event.button.y >= ybox + radbox) quit = 1;
                    break;
                case SDL_MOUSEBUTTONDOWN:
                    if (event.button.x >= xxbox - 35 && event.button.x <= xxbox + 35 && event.button.y >= yybox - 35 && event.button.y <= yybox + 35) punkte = punkte + (5*level);
            }
        }
    }
    fprintf(stderr, "%f punkte\n", punkte);
    SDL_FreeSurface(image);
    atexit(SDL_Quit);
    return 0;
}
 
Zuletzt bearbeitet:

Ähnliche Themen

Linux Mint 21 im Porträt: Eine Linux-Distribution für Windows-Umsteiger

Telefoninterview (Wie sich auf Bash-Shell-Fragen vorbereiten?)

Keine Zugriff von Windows 10 auf Sambafreigaben

[SOLVED]Linux/W7 Dualboot efi problem

Linux "vergisst" Dateisystem?

Zurück
Oben