Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 help with walking restrictions
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
shoobyman




PostPosted: Fri Oct 13, 2006 4:37 pm   Post subject: help with walking restrictions

The code is supposed to create walking restrictions for my character, and it does, but then my character gets stuck in the barriers that I have set up.

i set it so that if colour=yellow then it is walkable but if he goes inside black (which is unwalkable) then he can't move any furthur. However, when my character goes inside black, he gets stuck! WHAT THE HELL?????? Evil or Very Mad Evil or Very Mad Evil or Very Mad

plz help

prog attached



walkrestriction.zip
 Description:

Download
 Filename:  walkrestriction.zip
 Filesize:  15.75 KB
 Downloaded:  66 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Oct 13, 2006 5:37 pm   Post subject: (No subject)

without looking at all of that code, the most common problem is that your object moves further then where the check happens. For example, if you check for the colour one step ahead, but your unit is moving fast and travels 2 steps at a time, there's a chance to _jump_ over the barrier and get stuck
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
neufelni




PostPosted: Fri Oct 13, 2006 5:40 pm   Post subject: (No subject)

The program is doing exactly what you programmed it to do, to get stuck when it gets into black. You need to make it so that your character can go rigth up to the black, but not actually go into the black. You do this by simply adding a bit to your whatdotcolors.
code:
if key (KEY_LEFT_ARROW) and x > 10 and whatdotcolor (x - 5, y) = yellow then
        x -= 1
    elsif key (KEY_RIGHT_ARROW) and x > 10 and whatdotcolor (x + 5, y) = yellow then
        x += 1
    elsif key (KEY_DOWN_ARROW) and x > 10 and whatdotcolor (x, y - 5) = yellow then
        y -= 1
    elsif key (KEY_UP_ARROW) and x > 10 and whatdotcolor (x, y + 5) = yellow then
        y += 1
    end if
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: