• 12Nov

    Here is a tutorial with a remake of the game my friend made. Note, this is not his source code. I made it right on the spot. Also, my mic was off the first time, so this is a voice over.
    This three-part tutorial goes over using arrays, loops and sessions to create a simple grid based game. There is no true object to the game other than to move around and hit your head on the boundaries (the edges of the grid).
    You need flash to play this tutorial.
    This tutorial goes over the following goals:
    Here is my tutorial of the game my friend made.
    Note, This is not his source code,
    but I made it right on the spot.
    Also, my mic was off the first time,
    so this is a voice over.
    You can find this tutorial video on youtube here.


    The Game Part 2You need flash to play this tutorial.
    This tutorial goes over the following goals:
    Here is my tutorial of the game my friend made.
    Note, This is not his source code,
    but I made it right on the spot.
    Also, my mic was off the first time,
    so this is a voice over.
    You can find this tutorial video on youtube here.

    The Game Part 3You need flash to play this tutorial.
    This tutorial goes over the following goals:
    Here is my tutorial of the game my friend made.
    Note, This is not his source code,
    but I made it right on the spot.
    Also, my mic was off the first time,
    so this is a voice over.
    You can find this tutorial video on youtube here.

    Here are the sources used in this tutorial:
    tut025.php
    <?php
    session_start();
    $grid = array();
    $width = 20;
    $height = 10;
    for ($x = 0; $x < $width; $x++) {
        for ($y = 0; $y < $height; $y++) {
            $grid[$x][] = "_";
        }
    }
    if (!isset($_SESSION['x'])) {
        $_SESSION['x'] = (int)($width / 2);
    }
    if (!isset($_SESSION['y'])) {
        $_SESSION['y'] = (int)($height / 2);
    }
    //Determine new location based on relative location and given direction
    if (isset($_REQUEST['d'])) {
        //they gave us a direction so now we will process it.
        if ($_REQUEST['d'] == "l" && $_SESSION['x'] > 0) {
            $_SESSION['x'] -= 1;
        }
        if ($_REQUEST['d'] == "r" && $_SESSION['x'] < $width - 1) {
            $_SESSION['x'] += 1;
        }
        if ($_REQUEST['d'] == "d" && $_SESSION['y'] < $height - 1) {
            $_SESSION['y'] += 1;
        }
        if ($_REQUEST['d'] == "u" && $_SESSION['y'] > 0) {
            $_SESSION['y'] -= 1;
        } 
    
        //the opposite
        $error = "you bonked your head, therefore you are dead.(not really.)";
        if ($_REQUEST['d'] == "l" && $_SESSION['x'] <= 0) {
            echo $error;
        }
        if ($_REQUEST['d'] == "r" && $_SESSION['x'] >= $width - 1) {
            echo $error;
        }
        if ($_REQUEST['d'] == "d" && $_SESSION['y'] >= $height - 1) {
            echo $error;
        }
        if ($_REQUEST['d'] == "u" && $_SESSION['y'] <= 0) {
            echo $error;
        } 
    
    }
    ?><html><head><title><?php
    echo "You are at: (".$_SESSION['x'].",".$_SESSION['y'].")";
    ?></title></head><body><?php
    //PHP Tutorial 025 -- The Game! 
    
    $grid[$_SESSION['x']][$_SESSION['y']] = "X"; 
    
    echo '<table border="1">' . "\n";
    for ($y = 0; $y < $height; $y++) {
        echo '<tr>';
        for ($x = 0; $x < $width; $x++) {
            echo '<td>' . $grid[$x][$y] . '</td>';
        }
        echo '</tr>' . "\n";
    }
    echo '</table>';
    ?><a href="?d=l">Left</a> <a href="?d=r">Right</a> <a href="?d=u">Up</a> <a href="?d=d">Down</a></body></html>

    Here are all the php functions used in this tutorial:

    Posted by Kloplop321 @ 8:16 pm

One Response

WP_Orange_Techno

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.