/    Sign up×
Community /Pin to ProfileBookmark

How do I code a special condition for this?

First of all, I should point out that I’m new to php. But, I’m trying my best to learn it. The only way I can learn something is by doing it, so I gotta work via useful example. :S

That said, I’m working on modifying a php script for a game. In the game, I’m wanting to set a condition where a character is not allowed to move to a specfic adjacent space. With what little I’ve learned in Visual BASIC, I’m thinking this involves some sort of php versioned if statement. But I’m not sure how to set it up.

Here’s the code that controls character.

[code=php]
$latitude = $userrow[“latitude”];
$longitude = $userrow[“longitude”];
if (isset($_POST[“north”])) { $latitude++; if ($latitude > $controlrow[“gamesize”]) { $latitude = $controlrow[“gamesize”]; } }
if (isset($_POST[“south”])) { $latitude–; if ($latitude < ($controlrow[“gamesize”]*-1)) { $latitude = ($controlrow[“gamesize”]*-1); } }
if (isset($_POST[“east”])) { $longitude++; if ($longitude > $controlrow[“gamesize”]) { $longitude = $controlrow[“gamesize”]; } }
if (isset($_POST[“west”])) { $longitude–; if ($longitude < ($controlrow[“gamesize”]*-1)) { $longitude = ($controlrow[“gamesize”]*-1); } }
[/code]

Say there’s an uncrossable mountain range in an area.. or the user comes to an ocean or lake shore? How do I tell it not to let the character move there. I should probably have it display a special “Character can’t go any further this way.” message when the user encounters such instances too.

Is there a patient person out there who can teach me how to do this one?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceMar 02.2005 — OK, so the code shown already determines if the new, calculated position is within the game boundaries. So, basically, you just need to next determine if the new position is an allowed position. If not, then you display a message and don't move the character. I can't tell you how to determine if the new position is an allowed position without knowing how you store the layout of the game area.
×

Success!

Help @penguine spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...