ai help please

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Quicky
Coder
Posts: 20
Joined: Wed Jun 13, 2007 10:51 am

ai help please

Post by Quicky »

for some reason i cannot get my ai to move can someone help please

Code: Select all

SCREEN 13
x = 50
 y = 50
 
 DO
 typed$ = INKEY$
WAIT &H3DA, 8
 LINE (x - 8, y - 8)-(x + 8, y + 8), 0, BF
 CIRCLE (x, y), 2
 PAINT (x, y), 4, 15
 IF typed$ = "w" THEN y = y - 1
IF typed$ = "s" THEN y = y + 1
 IF typed$ = "d" THEN x = x + 1
 IF typed$ = "a" THEN x = x - 1



aix = 12
aiy = 15
WAIT &H3DA, 8
LINE (aix - 8, aiy - 8)-(aix + 8, aiy + 8), 0, BF
CIRCLE (aix, aiy), 2
PAINT (aix, aiy), 5, 15
IF x <aix> aix THEN attackrow = aix + 1
IF y <aiy> aiy THEN aiy = aiy + 1


LOOP
Mac
Veteran
Posts: 151
Joined: Mon Aug 06, 2007 2:00 pm

Re: ai help please

Post by Mac »

Quicky wrote:for some reason i cannot get my ai to move can someone help please
Here. (I slowed down the enemy so it didn't win immediately)

Mac

Code: Select all

SCREEN 13
x = 50
y = 50
aix = 12
aiy = 15
DO
  typed$ = INKEY$
  IF typed$ = CHR$(27) THEN SYSTEM
  WAIT &H3DA, 8
  LINE (x - 8, y - 8)-(x + 8, y + 8), 0, BF
  CIRCLE (x, y), 2
  PAINT (x, y), 4, 15
  IF typed$ = "w" THEN y = y - 1
  IF typed$ = "s" THEN y = y + 1
  IF typed$ = "d" THEN x = x + 1
  IF typed$ = "a" THEN x = x - 1
  WAIT &H3DA, 8
  LINE (aix - 8, aiy - 8)-(aix + 8, aiy + 8), 0, BF
  CIRCLE (aix, aiy), 2
  PAINT (aix, aiy), 5, 15
  IF aix > x THEN aix = aix - .1
  IF aix <x> y THEN aiy = aiy - .1
  IF aiy < y THEN aiy = aiy + .1
LOOP
Quicky
Coder
Posts: 20
Joined: Wed Jun 13, 2007 10:51 am

thanks

Post by Quicky »

but why wont the side to side work now
Anonymous

Post by Anonymous »

Two ifs were left out I think, this code has not been tested.

Code: Select all

SCREEN 13
x = 50
y = 50
aix = 12
aiy = 15
DO
  typed$ = INKEY$
  IF typed$ = CHR$(27) THEN SYSTEM
  WAIT &H3DA, 8
  LINE (x - 8, y - 8)-(x + 8, y + 8), 0, BF
  CIRCLE (x, y), 2
  PAINT (x, y), 4, 15
  IF typed$ = "w" THEN y = y - 1
  IF typed$ = "s" THEN y = y + 1
  IF typed$ = "d" THEN x = x + 1
  IF typed$ = "a" THEN x = x - 1
  WAIT &H3DA, 8
  LINE (aix - 8, aiy - 8)-(aix + 8, aiy + 8), 0, BF
  CIRCLE (aix, aiy), 2
  PAINT (aix, aiy), 5, 15
  IF aix > x THEN aix = aix - .1
  IF aix <x> y THEN aiy = aiy - .1
  IF aiy < y THEN aiy = aiy + .1
  'Missing these two ifs I think
  IF x <aix> aix THEN attackrow = aix + 1
  IF y <aiy> aiy THEN aiy = aiy + 1 
LOOP
Mac
Veteran
Posts: 151
Joined: Mon Aug 06, 2007 2:00 pm

HTML problem

Post by Mac »

Dang! It's the old "I forgot to turn off HTML problem"

I noticed everybody else has the same problem in this thread. When you post code, you must remember to turn HTML off or else the less-than-sign is interpreted as an attempt to give an HTML command to the browser. Many slip through as illegal and stay unchanged, but some, like this post, get messed up.

Actually, it wouldn't hurt for me to preview the code, but if I could remember that, I could remember to turn HTML off. LOL.

Anyway, here is the code again. Since I am posting again, I altered the code to keep the player on the screen.

Code tested.

Mac

Code: Select all

SCREEN 13
x = 50
y = 50
aix = 12
aiy = 15
DO
  typed$ = INKEY$
  IF typed$ = CHR$(27) THEN SYSTEM
  WAIT &H3DA, 8
  LINE (x - 8, y - 8)-(x + 8, y + 8), 0, BF
  CIRCLE (x, y), 2
  PAINT (x, y), 4, 15
  IF typed$ = "w" THEN IF y > 3 THEN y = y - 1
  IF typed$ = "s" THEN IF y < 197 THEN y = y + 1
  IF typed$ = "d" THEN IF x < 315 THEN x = x + 1
  IF typed$ = "a" THEN IF x > 2 THEN x = x - 1
  WAIT &H3DA, 8
  LINE (aix - 8, aiy - 8)-(aix + 8, aiy + 8), 0, BF
  CIRCLE (aix, aiy), 2
  PAINT (aix, aiy), 5, 15
  IF aix > x THEN aix = aix - .1
  IF aix < x THEN aix = aix + .1
  IF aiy > y THEN aiy = aiy - .1
  IF aiy < y THEN aiy = aiy + .1
LOOP
iamdenteddisk
Veteran
Posts: 185
Joined: Mon Jun 30, 2008 4:10 pm

Post by iamdenteddisk »

it all apears correct, the ai seems stationary because it is the reference point in the code read thru a few times you'll see it


as to getting code to show up in there just put it between tags like this

<code>
code goes in here.

</code>
Post Reply