
-----------------------------------
Paper*Mate
Wed May 25, 2005 11:07 am

AI----WELL NOT REALLY AI
-----------------------------------
Well i'm alsmost done my paintball game..just gotta get my guy shooting. I'm getting really frustrated because i can't get by blue guy moving and shooting randomly at me (red guy).I'm trying to make him as a computer player...i don want just a 2 player game!!!!!!

setscreen ("offscreenonly") 
var x, y : int 
x := 100 
y := 100 

var chars : array char of boolean 

loop 

    drawfillbox (50, 110, 40, 280, black)
    drawfillbox (590, 110, 600, 280, black)
    drawfillbox (490, 0, 500, 25, black)
    drawfillbox (490, 375, 500, maxy, black)
    drawfillbox (125, 375, 135, maxy, black)
    drawfillbox (125, 0, 135, 25, black)
    drawfilloval (320, 190, 50, 50, black)
     drawfilloval(520,98,6,6,blue) %%%MY BLUE GUY--WANT HIM TO SHOOT AND MOVE RANDOMLY AT THE RED GUY

    Input.KeyDown (chars) 

    if chars (KEY_UP_ARROW) then 
        if whatdotcolor (x, y + 9) = 0 
                then 
            y := y + 5 
        end if 
    end if 
    if chars (KEY_RIGHT_ARROW) then 
        if whatdotcolor (x + 9 , y) = 0 then 
            x := x + 5 
        end if 
    end if 
    if chars (KEY_LEFT_ARROW) then 
        if whatdotcolor (x - 9, y) = 0 then 
            x := x - 5 
        end if 
    end if 
    if chars (KEY_DOWN_ARROW) then 
        if whatdotcolor (x, y - 9) = 0 then 
            y := y - 5 
        end if 
    end if 

    drawfilloval (x, y, 6, 6, 12) %%MY RED GUY
   
    View.Update 
    delay (7) 
    cls 
    
end loop

-----------------------------------
Delos
Wed May 25, 2005 11:20 am


-----------------------------------
Please use 
 drawfilloval(520,98,6,6,blue) 


Instead of '520' and '98', use variables as you have with your red piece.  Now, you can dynamically change the position of the piece.
You'll have to deal with how it's going to move - it would not be useful to have it moving randomly with every execution of the loop.  My suggestion would be thus:
- you know that the piece will only move in the x-direction (left/right).  So, you assign a random value to a variable, between the numbers 0 and {maximum x-value possible}.
- for each execution of the loop, add or subtract a constant from the piece's x-value, and subtract the same from your 'counter' variable.
- stop when either the counter variable reaches 0 or your piece does
What would this look like?


variable x_p                variable counter
50 (starting value)          random number -> 10
---choose to *add* 1 each loop
51                              9
52                              8
...                              ...
60                              0 (has reached 0, time to choose another number)
60                              random number -> 14
---choose to *subtract* 1 each loop
...


Get the idea?  You can vary the value being added or subtracted to make it seem like the piece is moving quickly or slowly.  Repost your code when you're done.
