Map [solved]

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Map [solved]

Post by SpiritWebb »

So I have this area, a huge map and I want to click a direction to change the image of the map. (This is for a pbbg) I don't want the player to walk around the map, just an image. For example, if you look at Zombie Pandemic on Facebook, it has what I am looking for...

Another example: Image on main screen. North, South, East, West, NW, SW, NE, SE are my options. I click North, image changes to show a new location. Down below a description of the area appears, so on and so fourth. So lost here...


Unless I am not finding it, can someone point me in the right direction? Otherwise, how would I go about this?
Image

Image
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Map

Post by Chris »

Will there be a character walking around at all, or do you just click and investigate stuff?

Shouldn't be that difficult. Just make a database that holds x, y axes of the map areas and player position.
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Map

Post by SpiritWebb »

No, no walking at all, changing of the image would be the "walking"
Image

Image
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Map

Post by Chris »

This make any sense? Sorry for the messiness, I hate making shit like this neat, takes all the fun out of it.
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Map

Post by SpiritWebb »

I understand, kinda...its setting it up in the code where I am confused on. Never done anything like this before...used to using Unity.
Image

Image
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Map

Post by Chris »

PHP example.

Code: Select all

<h1>Map/thing test</h1>
<?php

mysql_connect('localhost', 'root');
mysql_select_db('test_game');

$userQuery = mysql_query("SELECT * FROM `users` WHERE `id` = 1"); // username = test
$userArray = mysql_fetch_assoc($userQuery);


function tileExists($x,$y)
{
    $query = mysql_query("SELECT `id` FROM `map` WHERE `x` = $x AND `y` = $y");
    if( mysql_num_rows($query) == 1 )
    {
        return true;
    }
    return false;
}

function setUserAxes($x,$y)
{
    return mysql_query("UPDATE `users` SET `x` = $x, `y` = $y WHERE `id` = 1");
}

function movePlayer($x,$y)
{
    if( tileExists($x,$y) )
    {
        setUserAxes($x,$y);
        return true;
    }
    return false;
}

if( empty($_GET['move']) === false  )
{
    switch( $_GET['move'] )
    {
        case 1 :
            if( movePlayer( $userArray['x'], ($userArray['y']+1) ) )
            {
                echo 'Moved north';
            }
        break;
        case 2 :
            if( movePlayer( ($userArray['x']+1), ($userArray['y']+1) ) )
            {
                echo 'Moved north-east';
            }
        break;
        case 3 :
            if( movePlayer( ($userArray['x']+1), $userArray['y'] ) )
            {
                echo 'Moved east';
            }
        break;
        case 4 :
            if( movePlayer( ($userArray['x']+1), ($userArray['y']-1) ) )
            {
                echo 'Moved south-east';
            }
        break;
        case 5 :
            if( movePlayer( $userArray['x'], ($userArray['y']-1) ) )
            {
                echo 'Moved south';
            }
        break;
        case 6 :
            if( movePlayer( ($userArray['x']-1), ($userArray['y']-1) ) )
            {
                echo 'Moved south-west';
            }
        break;
        case 7 :
            if( movePlayer( ($userArray['x']-1), $userArray['y'] ) )
            {
                echo 'Moved west';
            }
        break;
        case 8 :
            if( movePlayer( ($userArray['x']-1), ($userArray['y']+1) ) )
            {
                echo 'Moved north-west';
            }
        break;
    }
}

$userQuery = mysql_query("SELECT * FROM `users` WHERE `id` = 1"); // username = test
$userArray = mysql_fetch_assoc($userQuery);

$mapQuery = mysql_query("SELECT * FROM `map` WHERE `x` = {$userArray['x']} AND `y` = {$userArray['y']}");
$mapArray = mysql_fetch_assoc($mapQuery);

echo '<h2>User info</h2>';
print_r($userArray);

echo '<h2>Map info</h2>';
print_r($mapArray);

?>

    <div style="width: 610px;">
        <a style="height: 40px; width: 200px; border: #CCC 1px solid; display: block; float: left" href="?move=8">NW</a>
        <a style="height: 40px; width: 200px; border: #CCC 1px solid; display: block; float: left" href="?move=1">N</a>
        <a style="height: 40px; width: 200px; border: #CCC 1px solid; display: block; float: left" href="?move=2">NE</a>
    </div>

    <div style="width: 610px;">
        <a style="height: 400px; width: 100px; border: #CCC 1px solid; display: block; float: left" href="?move=7">W</a>
        <img src="<?php echo $mapArray['image']; ?>" alt="" style="height: 400px; width: 400px; float: left" />
        <a style="height: 400px; width: 100px; border: #CCC 1px solid; display: block; float: left" href="?move=3">E</a>
    </div>

    <div style="width: 610px;">
        <a style="height: 40px; width: 200px; border: #CCC 1px solid; display: block; float: left" href="?move=6">SW</a>
        <a style="height: 40px; width: 200px; border: #CCC 1px solid; display: block; float: left" href="?move=5">S</a>
        <a style="height: 40px; width: 200px; border: #CCC 1px solid; display: block; float: left" href="?move=4">SE</a>
    </div>
SQL:

Code: Select all


-- phpMyAdmin SQL Dump
-- version 3.4.9
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Feb 14, 2012 at 11:55 PM
-- Server version: 5.5.20
-- PHP Version: 5.3.9

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `test_game`
--

-- --------------------------------------------------------

--
-- Table structure for table `map`
--

CREATE TABLE IF NOT EXISTS `map` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `zone` int(11) NOT NULL,
  `x` int(11) NOT NULL,
  `y` int(11) NOT NULL,
  `image` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;

--
-- Dumping data for table `map`
--

INSERT INTO `map` (`id`, `zone`, `x`, `y`, `image`) VALUES
(1, 1, 1, 1, 'http://www2.skoftenmedia.com/images/picdump/218/02.jpg'),
(2, 1, 1, 2, 'http://www2.skoftenmedia.com/images/picdump/218/03.jpg'),
(3, 1, 1, 3, 'http://www2.skoftenmedia.com/images/picdump/218/17.jpg'),
(4, 1, 1, 4, 'http://www2.skoftenmedia.com/images/picdump/218/32.jpg'),
(5, 0, 2, 1, 'http://www2.skoftenmedia.com/images/wtfpics/12/01.jpg'),
(6, 0, 3, 1, 'http://www2.skoftenmedia.com/images/wtfpics/12/02.jpg');

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(25) NOT NULL,
  `x` int(11) NOT NULL,
  `y` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `username`, `x`, `y`) VALUES
(1, 'test', 2, 1);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Map

Post by SpiritWebb »

Will put this together soon...thanks guys!!!
Image

Image
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Map

Post by SpiritWebb »

Have it working...thanks again!!
Image

Image
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Map

Post by SpiritWebb »

Apparently I am having issues. It is stating Undefined variable username on line 69 which is in the setUserAxis function. I don't understand why as its been defined and/or called up top, but when reaching this point it says its not. Please help...

Code: Select all

<?php
include 'scripts/connect.php';
session_start();
if(isset($_SESSION['username'])){
  
  $username = $_SESSION['username'];

  $sql = mysql_query("SELECT * FROM players WHERE username='$username'");
  $info = mysql_fetch_array($sql);

$hpoints = $info['hpoints'];
$defense = $info['defense'];
$exper = $info['exper'];
$strength = $info['strength'];
$level = $info['level'];
$cash = $info['cash'];
$profilepic = $info['profilepic'];
$x = $info['x'];
$y = $info['y'];

} else {
   $msgToUser = "You are not logged in, please log in.<br><br><a href='login.php'>Log In Here</a>";
   include_once "msgToUser.php";
   exit();
}

$mapSQL = mysql_query("SELECT * FROM conwaymap");
$mapINFO = mysql_fetch_array($mapSQL);

$zonename = $mapINFO['zone_name'];
$description = $mapINFO['description'];

if($profilepic == ""){
	$profilepic = "Choose Character";
}
else if($profilepic == "option1"){
	$profilepic = "<img src='images/chars/thumbs/option1_sm.png'>";
}
else if($profilepic == "option2"){
	$profilepic = "<img src='images/chars/thumbs/option2_sm.png'>";
}
else if($profilepic == "option3"){
	$profilepic = "<img src='images/chars/thumbs/option3_sm.png'>";
}
else if($profilepic == "option4"){
	$profilepic = "<img src='images/chars/thumbs/option4_sm.png'>";
}
else if($profilepic == "option5"){
	$profilepic = "<img src='images/chars/thumbs/option5_sm.png'>";
}

    $userQuery = mysql_query("SELECT * FROM players WHERE username='$username'");
    $userArray = mysql_fetch_assoc($userQuery);


    function tileExists($x,$y)
    {
        $query = mysql_query("SELECT zone_id FROM conwaymap WHERE x='$x' AND y='$y'");
        if( mysql_num_rows($query) == 1 )
        {
            return true;
        }
        return false;
    }

    function setUserAxes($x,$y)
    {
        return mysql_query("UPDATE players SET x='$x', y='$y' WHERE username='$username'");  <!-- ERROR OCCURRING HERE -->
    }

    function movePlayer($x,$y)
    {
        if( tileExists($x,$y) )
        {
            setUserAxes($x,$y);
            return true;
        }
        return false;
    }

    if( empty($_GET['move']) === false  )
    {
        switch( $_GET['move'] )
        {
            case 1 :
                if( movePlayer( $userArray['x'], ($userArray['y']-1) ) )
                {
                    echo 'Moved north';
                }
            break;
            case 2 :
                if( movePlayer( ($userArray['x']-1), ($userArray['y']-1) ) )
                {
                    echo 'Moved north-east';
                }
            break;
            case 3 :
                if( movePlayer( ($userArray['x']-1), $userArray['y'] ) )
                {
                    echo 'Moved east';
                }
            break;
            case 4 :
                if( movePlayer( ($userArray['x']-1), ($userArray['y']+1) ) )
                {
                    echo 'Moved south-east';
                }
            break;
            case 5 :
                if( movePlayer( $userArray['x'], ($userArray['y']+1) ) )
                {
                    echo 'Moved south';
                }
            break;
            case 6 :
                if( movePlayer( ($userArray['x']+1), ($userArray['y']+1) ) )
                {
                    echo 'Moved south-west';
                }
            break;
            case 7 :
                if( movePlayer( ($userArray['x']+1), $userArray['y'] ) )
                {
                    echo 'Moved west';
                }
            break;
            case 8 :
                if( movePlayer( ($userArray['x']+1), ($userArray['y']-1) ) )
                {
                    echo 'Moved north-west';
                }
            break;
        }
    }

    $userQuery = mysql_query("SELECT * FROM players WHERE username='$username'");
    $userArray = mysql_fetch_assoc($userQuery);

    $mapQuery = mysql_query("SELECT * FROM conwaymap WHERE x='{$userArray['x']}' AND y='{$userArray['y']}'");
    $mapArray = mysql_fetch_assoc($mapQuery);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The Re-Awaken</title>
<link href="styles/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php
include_once "header.php";
?>
<table width="100%" border="1" align="center" cellpadding="12">
  <tr>
    <td width="11%" height="56">Location: <?php echo $x; ?>, <?php echo $y; ?><br /><?php echo $zonename; ?></td>
    <td width="69%"><center><img src="images/health.png"> = <?php echo $hpoints; ?>  | <img src="images/xpLevel.png"> = <?php echo $exper; ?>% | <img src="images/strength.png"> = <?php echo $strength; ?></center></td>
    <td width="9%" rowspan="3" valign="top">
    Level: <?php echo $level; ?><br>
    Cash: <?php echo $cash; ?><br><br>

    <a href="#"><img src="images/searcharea_noHover.png" onmouseover="this.src='images/searcharea_Hover.png';" onmouseout="this.src='images/searcharea_noHover.png';" /></a><br />
    <a href="#"><img src="images/leavecity_noHover.png" onmouseover="this.src='images/leavecity_Hover.png';" onmouseout="this.src='images/leavecity_noHover.png';" /></a><br />
    <br /><br /><br />
    <a href="#" target="_blank"><img src="images/forums_noHover.png" onmouseover="this.src='images/forums_Hover.png';" onmouseout="this.src='images/forums_noHover.png';" /></a></td>
    <td width="11%" rowspan="3" valign="top">Advertise here</td>
  </tr>
  <tr>
    <td height="333" valign="top"><center><?php echo $profilepic; ?><br />
    <?php echo $username ?></center><br /><br /><br /><br />
    <a href="#"><img src="images/location_noHover.png" onmouseover="this.src='images/location_Hover.png';" onmouseout="this.src='images/location_noHover.png';" /></a><br />
    <a href="#"><img src="images/character_noHover.png" onmouseover="this.src='images/character_Hover.png';" onmouseout="this.src='images/character_noHover.png';" /></a><br />
    <a href="#"><img src="images/map_noHover.png" onmouseover="this.src='images/map_Hover.png';" onmouseout="this.src='images/map_noHover.png';" /></a><br />
    <a href="#"><img src="images/clan_noHover.png" onmouseover="this.src='images/clan_Hover.png';" onmouseout="this.src='images/clan_noHover.png';" /></a><br />
    <a href="#"><img src="images/shop_noHover.png" onmouseover="this.src='images/shop_Hover.png';" onmouseout="this.src='images/shop_noHover.png';" /></a><br />
    <a href="#"><img src="images/help_noHover.png" onmouseover="this.src='images/help_Hover.png';" onmouseout="this.src='images/help_noHover.png';" /></a><br />
    <a href="settings.php"><img src="images/settings_noHover.png" onmouseover="this.src='images/settings_Hover.png';" onmouseout="this.src='images/settings_noHover.png';" /></a><br />
    <a href="#"><img src="images/messages_noHover.png" onmouseover="this.src='images/messages_Hover.png';" onmouseout="this.src='images/messages_noHover.png';" /></a><br />
    <a href="logout.php"><img src="images/logout_noHover.png" onmouseover="this.src='images/logout_Hover.png';" onmouseout="this.src='images/logout_noHover.png';" /></a><br /></td>
    <td><table width="100%" border="0" align="center" cellpadding="12">
      <tr>
        <td width="7%"><a href="?move=2"><img src="images/directions/gone.png"></a></td>
        <td width="86%"><center><a href="?move=1"><img src="images/directions/gonorth.png"></a></center></td>
        <td width="7%"><a href="?move=8"><img src="images/directions/gonw.png"></a></td>
      </tr>
      <tr>
        <td height="334"><a href="?move=3"><img src="images/directions/goeast.png"></a></td>
        <td><center>
          <img src="<?php echo $mapArray['zone_picture']; ?>" width="600" height="600" alt="" />
        </center></td>
        <td><a href="?move=7"><img src="images/directions/gowest.png"></a></td>
      </tr>
      <tr>
        <td><a href="?move=4"><img src="images/directions/gose.png"></a></td>
        <td><center><a href="?move=5"><img src="images/directions/gosouth.png"></a></center></td>
        <td><a href="?move=6"><img src="images/directions/gosw.png"></a></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td>Site News</td>
    <td><?php echo $description; ?></td>
  </tr>
</table>
<?php
include_once "footer.php";
?>
</body>
</html>


Image

Image
User avatar
Ark
Posts: 427
Joined: Wed Jun 01, 2011 10:25 pm

Re: Map

Post by Ark »

Well actually it's not defined 'In' the function.

change it to:

Code: Select all

function setUserAxes($x,$y,$username)
    {
        return mysql_query("UPDATE players SET x='$x', y='$y' WHERE username='$username'"); 
    } 
Orgullo Catracho
Post Reply

Return to “Advanced Help and Support”