Skip to content

Instantly share code, notes, and snippets.

@ramainen
Created February 21, 2012 20:27
Show Gist options
  • Save ramainen/1878700 to your computer and use it in GitHub Desktop.
Save ramainen/1878700 to your computer and use it in GitHub Desktop.
ПРимер PHP
<?
$globalx=10;
$globaly=10;
$scx=array();
for($i=1;$i<=9;$i++)
{
$scx[$i]=0;
}
$srckub['x']=0;
$srckub['y']=0;
$srckub['w']=50;
$srckub['h']=50;
$minikub['h']=220;
$minikub['w']=220;
$scrollrect['y']=0;
$scrollrect['h']=240;
function display_bmp()
{
global $globalx,$globaly,$fon,$screen,$fonrect,$srckub,$domik, $minikub,$scroll,$scx,$screencopy,$scrollrect, $curship,$ship;
$minikub['x']=$globalx;
$minikub['y']=$globaly;
$curship++;
if($curship==6)$curship=0;
SDL_BlitSurface($fon,null,$screencopy, null);
for($i=9;$i>=1;$i--){
SDL_BlitSurface($scroll[$i], array('w'=>320,'h'=>240,'x'=>$scx[$i],'y'=>0),$screencopy, null);
}
//SDL_BlitSurface($domik, $srckub,$screencopy, $minikub);
SDL_BlitSurface($ship[$curship], null,$screencopy, $minikub);
SDL_BlitSurface($screencopy, null,$screen, null);
SDL_Flip($screen);
}
$keypress =0;
$h=0;
$flag=0;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK ) ;
$joy= SDL_JoystickOpen(0);
if(function_exists('getgsensorposz'))
{
if (!($screen = SDL_SetVideoMode(320, 240, 16, SDL_HWSURFACE | SDL_FULLSCREEN/* | SDL_DOUBLEBUF | SDL_HWACCEL | SDL_FULLSCREEN */)))
SDL_Quit();
}else{
if (!($screen = SDL_SetVideoMode(320, 240, 16, SDL_HWSURFACE /* | SDL_DOUBLEBUF | SDL_HWACCEL | SDL_FULLSCREEN */)))
SDL_Quit();
}
$domik = SDL_DisplayFormat(SDL_LoadBMP("ship.bmp"));
$domik= SDL_ConvertSurface($domik, $domik['format'], SDL_SRCCOLORKEY | SDL_HWSURFACE);
SDL_SetColorKey($domik,SDL_SRCCOLORKEY,SDL_MapRGB($screen['format'],255,0,128));
$shipall = SDL_DisplayFormat(SDL_LoadBMP("ship.bmp"));
SDL_SetColorKey($shipall,SDL_SRCCOLORKEY,SDL_MapRGB($shipall['format'],255,0,128));
// $shipall= SDL_ConvertSurface($shipall, $shipall['format'], SDL_SRCCOLORKEY | SDL_HWSURFACE);
$ship=array();
for($i=0;$i<=5;$i++)
{
$ship[$i]= SDL_DisplayFormat(SDL_LoadBMP("shipdummy.bmp"));
$ship[$i]= SDL_ConvertSurface($ship[$i], $ship[$i]['format'], SDL_SRCCOLORKEY | SDL_HWSURFACE);
SDL_SetColorKey($ship[$i],SDL_SRCCOLORKEY,SDL_MapRGB($ship[$i]['format'],255,0,128));
SDL_BlitSurface( $shipall,array('w'=>32,'h'=>32,'x'=>$i*32+ $i,'y'=>0),$ship[$i], null);
}
$curship=0;
$fon=SDL_DisplayFormat(SDL_LoadBMP("back.bmp"));
$screencopy=SDL_DisplayFormat(SDL_LoadBMP("back.bmp"));
$scroll=array();
for($i=1;$i<=9;$i++){
$scroll[$i]= SDL_DisplayFormat(SDL_LoadBMP("scroll".(10-$i).".bmp"));
SDL_SetColorKey($scroll[$i],SDL_SRCCOLORKEY,SDL_MapRGB($screen['format'],255,0,128));
}
$fonrect['w']=320;
$fonrect['h']=240;
$fonrect['x']=0;
$fonrect['y']=0;
display_bmp();
$flag=1;
while( $keypress==0)
{
if($flag==1)
{
display_bmp();
/* $scx[1]++;
if($scx[1]>1680)$scx[1]=0;
for($i=2;$i<=9;$i++){
if($scx[1]/$i==round($scx[1]/$i))
{$scx[$i]++;
if($scx[$i]>1680)$scx[$i]=0;
}
*/
for($i=1;$i<=9;$i++){
$scx[$i]+=(10-$i);
if($scx[$i]>1680)$scx[$i]=0;
}
}
while(SDL_PollEvent(&$event))
{
switch ($event['type'])
{
case SDL_QUIT:
$keypress = 1;
break;
case SDL_KEYDOWN:
if($event['key']['keysym']['sym']==SDLK_DOWN)
{
$globaly+=5;
if($globaly>200)$globaly=10;
}
if($event['key']['keysym']['sym']==SDLK_UP)
{
$globaly-=5;
if($globaly<10)$globaly=200;
}
if($event['key']['keysym']['sym']==SDLK_RIGHT)
{
$globalx+=5;
if($globalx>300)$globaly=10;
}
if($event['key']['keysym']['sym']==SDLK_LEFT)
{
$globalx-=5;
if($globalx<10)$globalx=300;
}
if($event['key']['keysym']['sym']==SDLK_Q)
{
$keypress = 1;
}
//display_bmp();
break;
case SDL_KEYUP:
if($event['key']['keysym']['sym']==SDLK_DOWN)
{
$flag=1;
}
//display_bmp();
break;
case SDL_JOYBUTTONDOWN:
if($event['jbutton']['button']==1)
{
$globaly+=5;
if($globaly>200)$globaly=10;
}
if($event['jbutton']['button']==3)
{
$globaly-=5;
if($globaly<10)$globaly=200;
}
if($event['jbutton']['button']==2)
{
$globalx+=5;
if($globalx>300)$globaly=10;
}
if($event['jbutton']['button']==0)
{
$globalx-=5;
if($globalx<10)$globalx=300;
}
if($event['jbutton']['button']==8)
{
$keypress = 1;
}
//display_bmp();
break;
case SDL_JOYBUTTONUP:
$flag=1;
//display_bmp();
break;
case SDL_JOYAXISMOTION:
if($event['jaxis']['axis']==0){
$globalx=round( ($event['jaxis']['value']+32000)/64000*280+5);
}
if($event['jaxis']['axis']==1){
$globaly=round( ($event['jaxis']['value']+32000)/64000*180+5);
}
//display_bmp();
break;
}
}
}
SDL_Quit();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment