Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #16 from ericguirbal/fix_pod

Fix pod errors and warnings.
  • Loading branch information...
commit 4610b6eb1ff20402cb4b4bd3eadeed90c1b474fc 2 parents a0e6d72 + 357dbf7
@FROGGS FROGGS authored
View
5 src/03-events.pod
@@ -15,7 +15,7 @@ C<SDL::Event> object represents this queue in Perl, allowing you to add and
remove events constantly:
=begin programlisting
-
+
use strict;
use warnings;
use SDL;
@@ -124,7 +124,7 @@ For more information look at:
perldoc SDL::Event
-=end
+=end for
=head1 Quitting with Grace
@@ -284,6 +284,7 @@ initialization rules apply.
=head2 Mouse
Handling mouse events is almost as straightforward as keyboard events:
+
=begin programlisting
# track the drawing status
View
22 src/05-pong.pod
@@ -57,7 +57,7 @@ C<SDLx::App> constructor. This represents the length, in seconds, of a movement
step as managed by an C<SDLx::Controller> object. Because the C<SDLx::App>
object is also an C<SDLx::Controller> object, it can handle C<SDL_QUIT> events.
-=for sidebar
+=begin sidebar
B<Game Loop Granularity>
@@ -70,7 +70,7 @@ What is important to remember is that the C<dt> granularity must never be set so
it fails to capture collisions and interaction between moving objects. This can especially
happen with fast moving objects such as bullets, but the principle applies to many situation.
On the other hand having a too fine granularity taxes the CPU resources.
-
+
=end sidebar
=head1 Game Objects
@@ -715,11 +715,15 @@ things:
=over 4
-=item 1 Every time a player scores, the ball goes back to the middle but
+=item 1
+
+Every time a player scores, the ball goes back to the middle but
has the same sense and direction as before. See if you can make it restart
at a random direction instead.
-=item 2 Red is boring. How about a psychedelic Pong? Pick three different
+=item 2
+
+Red is boring. How about a psychedelic Pong? Pick three different
colors and make each paddle oscillate between them every time the ball hits it.
=back
@@ -728,7 +732,9 @@ colors and make each paddle oscillate between them every time the ball hits it.
=over 4
-=item 1 To make the ball restart at a random direction, update C<reset_game()>
+=item 1
+
+To make the ball restart at a random direction, update C<reset_game()>
function to set the ball's C<v_x> and C<v_y> to a random value between.
Anything between positive 1.5 and 2.5 works well:
@@ -744,7 +750,9 @@ Anything between positive 1.5 and 2.5 works well:
=end programlisting
-=item 2 Start by representing the available colors. You could use separate
+=item 2
+
+Start by representing the available colors. You could use separate
colors or hues for each player, but for simplicity this code uses a single
group of colors. Each player's hash will contain the index into this array:
@@ -819,6 +827,8 @@ C<color>, instead of the previously hardcoded value:
=end programlisting
+=back
+
=head1 Author
This chapter's content graciously provided by Breno G. de Oliveira (C<garu>).
View
14 src/07-puzz.pod
@@ -72,9 +72,9 @@ We want the image to be 400x400, and C<SDL::GFX::Rotozoom> makes this possible.
$zoomed_src = SDL::GFX::Rotozoom::surface_xy($src, $angle, $x_zoom, $y_zoom, $smoothing)
The zoom values are the multiplier for that component, or for both components at once as with C<$zoom>. C<$angle> is an angle of rotation in degrees. C<$smoothing> should be C<SMOOTHING_ON> or C<SMOOTHING_OFF> (which can be exported by C<SDL::GFX::Rotozoom>) or just 1 or 0.
-
+
Once the image is zoomed, it is added to the image array. The current image is then set to a random value of the array.
-
+
=head1 Handling Events
The next part I like to write is the events. We're going to make Escape quit, and left click will move the pieces around. We C<use SDL::Events> for the constants.
@@ -97,7 +97,7 @@ The next part I like to write is the events. We're going to make Escape quit, an
$App->run;
=head1 Filling the Grid
-
+
Once we have something like this, it's a good time to put some C<warn> messages in to make sure the inputs are working correctly. Once they are, it's time to fill it in.
my $x = int($e->button_x / 100);
@@ -144,7 +144,7 @@ Next we will write the move handler. All it needs to do is move any moving piece
}
}
}
-
+
30 has been arbitrarily chosen as the speed of the move, as it felt the best after a little playing and tweaking. Always remember to multiply things like this by the step value in C<$_[0]> so that the animation moves in correct time with the updating.
Once the offset is 100 or more, the grid place that the piece is moving to is set to the value of the piece, and the piece is set to the blank value. The move is then finished, so C<%Move> is deleted.
@@ -162,7 +162,7 @@ Now that we have all the functionality we need it's finally time to see the game
}
$App->flip;
}
-
+
We start the show handler by drawing a black rect over the entire app. Entire surface and black are the defaults of C<draw_rect>, so letting it use the defaults is good. Next we iterate through a C<y> and C<x> of 0 to 3 so that we can go through each piece of the grid. At the end of the handler we update the app with a call to C<flip>.
next unless my $val = $Grid[$y][$x];
@@ -196,7 +196,7 @@ When the code is run with all 3 handlers, we have a fully working game. The piec
@Grid = map { [@new[ $_*4..$_*4+3 ]] } 0..3;
$CurrentImg = $Img[rand @Img];
}
-
+
We will replace the grid initialising we did with this sub. First it shffles the numbers 0 through 15 with C<List::Util::shuffle>. This array is then arranged into a 2D grid with a C<map> and put in to @Grid. Setting the current image is also put into this sub.
sub won {
@@ -211,7 +211,7 @@ We will replace the grid initialising we did with this sub. First it shffles the
}
This sub returns whether the grid is in the winning configuration, that is, all piece values are in order from 0 to 15.
-
+
Now we put a call to C<new_grid> to replace the grid initialisation we had before. We put C<won> into the event handler to make click call C<new_grid> if you have won. Finally, C<won> is put into the show handler to show the blank piece if you have won.
=head1 Complete Code
View
6 src/08-music_and_sound.pod
@@ -99,7 +99,7 @@ To stop the music we can call C<halt_music>.
=begin sidebar
Controlling Volume can be as simple as:
-
+
#All channels indicated by the -1
SDL::Mixer::Channels::volume(-1,10);
@@ -579,7 +579,7 @@ A music effect reads stream data, then serializes it to share between threads:
The program's single command-line option governs the number of lines to display
in the visualizer. The default is 50.
-
+
my $lines = $ARGV[0] || 50;
The drawing callback for the C<SDLx::App> runs while a song plays. It reads
@@ -677,7 +677,7 @@ C<$play_next_song_callback> callback to switch to the next song gracefully:
};
A move handler is attached to detect if music is playing or not:
-
+
$app->add_move_handler(
sub {
my $music_playing = SDL::Mixer::Music::playing_music();
View
4 src/12-PDL_OpenGL.pod
@@ -20,7 +20,7 @@ This example will do the following:
=head2 Make the application
Let's start an application to use with PDL. Make sure you do C<use PDL>.
-
+
+ use strict;
+ use warnings;
+ use SDL;
@@ -199,7 +199,7 @@ Next we will make a C<OpenGL> perspective with the C<$app>'s dimensions:
glTranslatef( 0,0,-20);
Additionally we will be initializing C<glut>, but just to draw something quick.
-
+
#Using glut to draw something interesting really quick
glutInit();
Please sign in to comment.
Something went wrong with that request. Please try again.