Nevyn
16-07-2006, 05:48 PM
Hi, Im currently trying to learn the Delphi headers for SDL.
Im not that good with general delphi programming allthough, I know enough i'd say. Now here is the thing. Im wondering if its possible to create a particle flow without using opengl? Sure there is no problem using opengl and if you know how implant it into the code im gonna post underneath i'd appriciate it.
uses SDL, SDL_Image, SDL_Mixer, smpeg, SysUtils;
Var screen,image,sprite: PSDL_surface;
rect1 : TSDL_rect;
event: TSDL_Event;
keys: PKeyStateArr;
music: PMix_Music;
//Game Variable Settings
title: PAnsiChar;
Resolution_x: integer;
Resolution_y: integer;
song: string;
color_depth : integer;
background: string;
Character: string;
//End of the game variable section
//Section for Video and Sound
begin
//Checks if everything works and if it does not, then it exits.
if ((SDL_Init(SDL_INIT_VIDEO OR SDL_INIT_AUDIO)=-1)) then
begin
exit;
end;
//Sets the sound channel quality.
if (Mix_OpenAudio(44100, AUDIO_U8, 1, 4048) < 0) then // Loads the sound channel
begin
exit;
end;
//Check end, If it reaches here, everything is good
//Loads our Game variable settings.
title:=('Kwaoeoaooewo');
Resolution_x := (800);
Resolution_y := (600);
color_depth := (32);
song := ('cerror-nobodandi.xm');
background := ('Background.jpg');
Character := ('Sprite.bmp');
//End of loaded game variable settings.
//Window title section..
WriteLn('/////// Loading Window Params \\\\\\\');
SDL_WM_SetCaption(title,nil); //Titeln p?• f??nstret
WriteLn('Title set to '+title);
////Sets the resolution mode on the window.
screen:=SDL_SetVideoMode(Resolution_x,Resolution_y ,color_depth,SDL_HWSURFACE);
WriteLn('Resolution: '+IntToStr(Resolution_x)+' x '+IntToStr(Resolution_y)+' set');
//Load Images
image:=IMG_Load(PCHAR(background)); //Loads the Background
WriteLn('Image: '+Background+' Loaded');
sprite:=IMG_Load(PCHAR(Character)); //Loads the Character
WriteLn('Image: '+Character+' Loaded');
sprite:=SDL_DisplayFormat(sprite);
SDL_BlitSurface(image,nil,screen, nil); //Puts out the background onto the window.
rect1.x:=700;
rect1.y:=500;
rect1.w:=400;
rect1.h:=240;
SDL_SetColorKey(sprite,SDL_SRCCOLORKEY OR SDL_RLEACCEL,SDL_MapRGB(sprite.format,255,255,255) );
SDL_BlitSurface(sprite,nil,screen,@rect1); //Loads the character onto the screen
SDL_UpdateRect(screen,0,0,0,0); //Updates the character sprite
SDL_ShowCursor(1); //Show mouse cursor 1=ja 0=nej
//Audio section
WriteLn('//////// Initializing Audio \\\\\\\\\');
WriteLn('Loading song: '+song);
music := Mix_LoadMUS( PChar(song) ); //Song to play.
WriteLn('Song loaded...');
WriteLn('Song playing: '+song);
WriteLn('//////// Section Audio end \\\\\\\\\\');
Repeat
while (SDL_PollEvent(@Event) > 0) do
begin
case Event.type_ of
SDL_QuitEv:
begin
Exit;
end;
end;
end;
keys:=PKeyStateArr(SDL_GetKeyState(nil));
if (keys[SDLK_UP]=SDL_PRESSED) and (rect1.y>0) then //Move the character up
begin
SDL_BlitSurface(image,@rect1,screen, @rect1); //Loads the character sprite onto the background
dec(rect1.y);
SDL_BlitSurface(sprite,nil,screen, @rect1); //Loads the character sprite again
SDL_UpdateRect(screen,0,0,0,0); //update the character.
end;
if (keys[SDLK_DOWN]=SDL_PRESSED) and (rect1.y<580) then //Move the character down
begin
SDL_BlitSurface(image,@rect1,screen,@rect1); //Loads the character
inc(rect1.y);
SDL_BlitSurface(sprite,nil,screen,@rect1); //Loads the character sprite again
SDL_UpdateRect(screen,0,0,0,0); //update the character.
end;
if (keys[SDLK_LEFT]=SDL_PRESSED) and (rect1.x>0) then //Flytta gubbe n?•t v?§nster
begin
SDL_BlitSurface(image,@rect1,screen,@rect1); //Laddar om gubben
dec(rect1.x);
SDL_BlitSurface(sprite,nil,screen, @rect1); //Kopierar gubben
SDL_UpdateRect(screen,0,0,0,0); //updaterar gubben
end;
if (keys[SDLK_RIGHT]=SDL_PRESSED) and (rect1.x<780) then //flyttar gubbe ?•t h??ger
begin
SDL_BlitSurface(image,@rect1,screen, @rect1); //Laddar om gubben
inc(rect1.x);
SDL_BlitSurface(sprite,nil,screen,@rect1); //Kopierar gubben
SDL_UpdateRect(screen,0,0,0,0); //updaterar gubben
end;
if (not (Mix_PlayingMusic=1)) then //If the music aint playing, play it again
begin
Mix_PlayMusic(music,0);
end;
Until (keys[SDLK_SPACE]=SDL_PRESSED); //If the spacekey is down then this will happend
Mix_CloseAudio(); //Audio channel exits
SDL_ShowCursor(1); //The Mouse curous is shown, if already isnt
SDL_Quit; //Application is ended.
end.
And sorry for the swedish you see on the char movement, I was to lazy to translate that too.
You might notice this is from the Delphi SDL example. And thats because it is :>
Im not that good with general delphi programming allthough, I know enough i'd say. Now here is the thing. Im wondering if its possible to create a particle flow without using opengl? Sure there is no problem using opengl and if you know how implant it into the code im gonna post underneath i'd appriciate it.
uses SDL, SDL_Image, SDL_Mixer, smpeg, SysUtils;
Var screen,image,sprite: PSDL_surface;
rect1 : TSDL_rect;
event: TSDL_Event;
keys: PKeyStateArr;
music: PMix_Music;
//Game Variable Settings
title: PAnsiChar;
Resolution_x: integer;
Resolution_y: integer;
song: string;
color_depth : integer;
background: string;
Character: string;
//End of the game variable section
//Section for Video and Sound
begin
//Checks if everything works and if it does not, then it exits.
if ((SDL_Init(SDL_INIT_VIDEO OR SDL_INIT_AUDIO)=-1)) then
begin
exit;
end;
//Sets the sound channel quality.
if (Mix_OpenAudio(44100, AUDIO_U8, 1, 4048) < 0) then // Loads the sound channel
begin
exit;
end;
//Check end, If it reaches here, everything is good
//Loads our Game variable settings.
title:=('Kwaoeoaooewo');
Resolution_x := (800);
Resolution_y := (600);
color_depth := (32);
song := ('cerror-nobodandi.xm');
background := ('Background.jpg');
Character := ('Sprite.bmp');
//End of loaded game variable settings.
//Window title section..
WriteLn('/////// Loading Window Params \\\\\\\');
SDL_WM_SetCaption(title,nil); //Titeln p?• f??nstret
WriteLn('Title set to '+title);
////Sets the resolution mode on the window.
screen:=SDL_SetVideoMode(Resolution_x,Resolution_y ,color_depth,SDL_HWSURFACE);
WriteLn('Resolution: '+IntToStr(Resolution_x)+' x '+IntToStr(Resolution_y)+' set');
//Load Images
image:=IMG_Load(PCHAR(background)); //Loads the Background
WriteLn('Image: '+Background+' Loaded');
sprite:=IMG_Load(PCHAR(Character)); //Loads the Character
WriteLn('Image: '+Character+' Loaded');
sprite:=SDL_DisplayFormat(sprite);
SDL_BlitSurface(image,nil,screen, nil); //Puts out the background onto the window.
rect1.x:=700;
rect1.y:=500;
rect1.w:=400;
rect1.h:=240;
SDL_SetColorKey(sprite,SDL_SRCCOLORKEY OR SDL_RLEACCEL,SDL_MapRGB(sprite.format,255,255,255) );
SDL_BlitSurface(sprite,nil,screen,@rect1); //Loads the character onto the screen
SDL_UpdateRect(screen,0,0,0,0); //Updates the character sprite
SDL_ShowCursor(1); //Show mouse cursor 1=ja 0=nej
//Audio section
WriteLn('//////// Initializing Audio \\\\\\\\\');
WriteLn('Loading song: '+song);
music := Mix_LoadMUS( PChar(song) ); //Song to play.
WriteLn('Song loaded...');
WriteLn('Song playing: '+song);
WriteLn('//////// Section Audio end \\\\\\\\\\');
Repeat
while (SDL_PollEvent(@Event) > 0) do
begin
case Event.type_ of
SDL_QuitEv:
begin
Exit;
end;
end;
end;
keys:=PKeyStateArr(SDL_GetKeyState(nil));
if (keys[SDLK_UP]=SDL_PRESSED) and (rect1.y>0) then //Move the character up
begin
SDL_BlitSurface(image,@rect1,screen, @rect1); //Loads the character sprite onto the background
dec(rect1.y);
SDL_BlitSurface(sprite,nil,screen, @rect1); //Loads the character sprite again
SDL_UpdateRect(screen,0,0,0,0); //update the character.
end;
if (keys[SDLK_DOWN]=SDL_PRESSED) and (rect1.y<580) then //Move the character down
begin
SDL_BlitSurface(image,@rect1,screen,@rect1); //Loads the character
inc(rect1.y);
SDL_BlitSurface(sprite,nil,screen,@rect1); //Loads the character sprite again
SDL_UpdateRect(screen,0,0,0,0); //update the character.
end;
if (keys[SDLK_LEFT]=SDL_PRESSED) and (rect1.x>0) then //Flytta gubbe n?•t v?§nster
begin
SDL_BlitSurface(image,@rect1,screen,@rect1); //Laddar om gubben
dec(rect1.x);
SDL_BlitSurface(sprite,nil,screen, @rect1); //Kopierar gubben
SDL_UpdateRect(screen,0,0,0,0); //updaterar gubben
end;
if (keys[SDLK_RIGHT]=SDL_PRESSED) and (rect1.x<780) then //flyttar gubbe ?•t h??ger
begin
SDL_BlitSurface(image,@rect1,screen, @rect1); //Laddar om gubben
inc(rect1.x);
SDL_BlitSurface(sprite,nil,screen,@rect1); //Kopierar gubben
SDL_UpdateRect(screen,0,0,0,0); //updaterar gubben
end;
if (not (Mix_PlayingMusic=1)) then //If the music aint playing, play it again
begin
Mix_PlayMusic(music,0);
end;
Until (keys[SDLK_SPACE]=SDL_PRESSED); //If the spacekey is down then this will happend
Mix_CloseAudio(); //Audio channel exits
SDL_ShowCursor(1); //The Mouse curous is shown, if already isnt
SDL_Quit; //Application is ended.
end.
And sorry for the swedish you see on the char movement, I was to lazy to translate that too.
You might notice this is from the Delphi SDL example. And thats because it is :>