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

Username:   Password: 
 RegisterRegister   
 A.I. for small game..
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Boarder16




PostPosted: Sat Jan 03, 2004 8:46 pm   Post subject: A.I. for small game..

Hey i am making a small game (spinoff of ratchet and clank), does anyone have any Artificial Intelligence or something like that that i could use as an example for my bad guys movements, so they can figure out which way isbetter to attack you.. its a topview game...liek the pokemons 4 gameboy... i realize i could use things like when ur charater is on a certain space they move, or other things like that but if anyone has any better ideas or ways...could you tell me....i'll post teh first level for my game soon ok... it'll be sweet...its in turing..
Sponsor
Sponsor
Sponsor
sponsor
DanShadow




PostPosted: Sat Jan 03, 2004 8:57 pm   Post subject: (No subject)

The absolute easiest one is the one ill place below. Just add in collision detection for the enemy. Pretty much, anything inside the black box is the enemies (red oval) sight line. If he is inside the box, he can see you, and will therefore chase you. If he isnt, he will just sit around. Use the arrow keys to move the guy around. I hope this helps.
code:

var playerx, playery, enemyx, enemyy : int := 200
enemyx := 300
enemyy := 300
var key : string (1) := ""


loop
    setscreen ("offscreenonly")
    View.Update
    Draw.FillBox (0, 0, maxx, maxy, 2)
    Draw.FillBox (playerx - 10, playery - 10, playerx + 10, playery + 10, 1)
    Draw.FillOval (enemyx, enemyy, 10, 10, 12)
    Draw.Box (playerx - 100, playery - 100, playerx + 100, playery + 100, 255)
    if hasch then
        getch (key)
    end if
    if key = (KEY_RIGHT_ARROW) then
        playerx := playerx + 5
    elsif key = (KEY_LEFT_ARROW) then
        playerx := playerx - 5
    elsif key = (KEY_UP_ARROW) then
        playery := playery + 5
    elsif key = (KEY_DOWN_ARROW) then
        playery := playery - 5
    end if
    if (playerx > enemyx - 100 and playerx < enemyx + 100) and (playery > enemyy - 100) and (playery < enemyy + 100) then
        if enemyx < playerx then
            enemyx := enemyx + 2
        elsif enemyx > playerx then
            enemyx := enemyx - 2
        end if
        if enemyy < playery then
            enemyy := enemyy + 2
        elsif enemyy > playery then
            enemyy := enemyy - 2
        end if
    end if
end loop
Tony




PostPosted: Sat Jan 03, 2004 10:14 pm   Post subject: (No subject)

posts in [source code] are for sharing your code, not for asking others... that's what [turing help] is for Rolling Eyes

moved
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Boarder16




PostPosted: Sat Jan 03, 2004 11:03 pm   Post subject: (No subject)

thanks dan shadow.... this will help and sorry tony.. but i was originally goin to post my game aswell as this but i realized i need to zip it all...won't happen again. 8) lol
Boarder16




PostPosted: Sat Jan 03, 2004 11:12 pm   Post subject: (No subject)

hey dan teh thing is..weird.. one arrow key hit..sends it flyin across teh screen.. i can't see teh guy chasin me either.... any better isntrctions lol
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  [ 5 Posts ]
Jump to:   


Style:  
Search: