X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pages%2FSDL-Tutorial-LunarLander.html-inc;h=3d8d77e7bfbfdebfdfd7482fa6a6ad51f90ee5ea;hb=1f5d808215c3e475e7d752ba28a3f2c3d6f468ad;hp=a20a1fda0e7998bf598602cc172fcb9031f558ae;hpb=60f74f6f8f641636a03bd789ede09bebe208108b;p=sdlgit%2FSDL-Site.git diff --git a/pages/SDL-Tutorial-LunarLander.html-inc b/pages/SDL-Tutorial-LunarLander.html-inc index a20a1fd..3d8d77e 100644 --- a/pages/SDL-Tutorial-LunarLander.html-inc +++ b/pages/SDL-Tutorial-LunarLander.html-inc @@ -214,10 +214,12 @@ this tutorial; Save these images in a subdirectory called "images":

First step: use the required libraries:

 

-
    use SDL; #needed to get all constants
-    use SDL::App;
-    use SDL::Surface;
-    use SDL::Rect;
+
	use SDL; #needed to get all constants
+	use SDL::Video;
+	use SDL::App;
+	use SDL::Surface;
+	use SDL::Rect;
+	use SDL::Image;
 
 

 

@@ -234,44 +236,41 @@ this tutorial; Save these images in a subdirectory called "images":

 

Third step: load the images and create the necessary "rectangles":

 

-
    my $background = SDL::Surface->new( -name => 'images/background.jpg', );
-    my $ship       = SDL::Surface->new( -name => 'images/ship.png', );
+
	my $background = SDL::Image::load('images/background.jpg');
+	my $ship       = SDL::Image::load('images/ship.jpg');
 
-    my $background_rect = SDL::Rect->new(
-        -height => $background->height(),
-        -width  => $background->width(),
-    );
+	my $background_rect = SDL::Rect->new(0,0,
+	    $background->w,
+	    $background->h,
+	);
 
-    my $ship_rect = SDL::Rect->new(
-        -height => $ship->height(),
-        -width  => $ship->width(),
-    );
+	my $ship_rect = SDL::Rect->new(0,0,
+	    $ship->w,
+	    $ship->h,
+	);
 
 

 

Fourth step: create a sub to draw the spaceship and background:

 

-
    sub draw {
-        my ( $x, $y ) = @_; # spaceship position
+
	sub draw {
+	    my ( $x, $y ) = @_; # spaceship position
 
-        # fix $y for screen resolution
-        $y = 450 * ( 1000 - $y ) / 1000;
+	    # fix $y for screen resolution
+	    $y = 450 * ( 1000 - $y ) / 1000;
 
-        # background
-        $background->blit( $background_rect, $app, $background_rect );
+	    # background
+	    SDL::Video::blit_surface($background, $background_rect, $app, $background_rect );
 
-        # ship
-        my $ship_dest_rect = SDL::Rect->new(
-            -height => $ship->height(),
-            -width  => $ship->width(),
-            -x      => $x,
-            -y      => $y,
-        );
+	    # ship
+	    my $ship_dest_rect = SDL::Rect->new(
+		$x, $y, $ship->w, $ship->h,
+	    );
 
-        $ship->blit( $ship_rect, $app, $ship_dest_rect );
+	    SDL::Video::blit_surface($ship, $ship_rect, $app, $ship_dest_rect );
 
-        $app->update($background_rect);
-    }
+	    SDL::Video::update_rects($app, $background_rect);
+	}