moving pixel drawings

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

moving pixel drawings

Post by Quicky »

Hi again,

i am having trouble with moving graphics on the screen with my commands and the AI response ot my commands here is
an example without using graphics instead a 0

Code: Select all

attackrow = 12
attackcolumn = 40
row = 12
column = 10
DO
DO
keyed$ = INKEY$
LOOP UNTIL keyed$ <LOCATE> 1) THEN 
row = row - 1
end if
IF (keyed$ = CHR$(0) + CHR$(80)) AND (row <23> 1) THEN 
column = column - 1
end if
IF (keyed$ = CHR$(0) + CHR$(77)) AND (column < 80) THEN 
column = column + 1
end if
IF keyed$ = "e" THEN END
LOCATE row, column
COLOR 10
PRINT "0"

'AI
LOCATE attackrow, attackcolumn
PRINT " "
IF row <attackrow> attackrow THEN 
attackrow = attackrow + 1
end if
IF column <attackcolumn> attackcolumn THEN 
attackcolumn = attackcolumn + 1
end if
LOCATE attackrow, attackcolumn
COLOR 5
PRINT "0"
LOOP


And using that code above but modified i want to move this graphic for player 1
cls
screen 7
xlength = 6
ylength = 6
FOR x = 1 TO xlength
FOR Y = 1 TO ylength
READ z
PSET (x, Y), z

DATA 04,04,04,04,04,04
DATA 04,04,04,04,04,04
DATA 04,04,04,04,04,04
DATA 04,04,04,04,04,04
DATA 04,04,04,04,04,04
DATA 04,04,04,04,04,04


NEXT
NEXT

and this one for the AI

cls
screen 7
xlength = 8
ylength = 8
FOR x = 1 to xlength - 1
FOR y = 1 to ylength - 1
READ z
PSET (x, y), z
DATA 00, 00, 00, 14, 14, 00, 00, 00
DATA 00, 00, 00, 14, 14, 00, 00, 00
DATA 00, 00, 00, 14, 14, 00, 00, 00
DATA 14, 14, 14, 14, 14, 14, 14, 14
DATA 14, 14, 14, 14, 14, 14, 14, 14
DATA 00, 00, 00, 14, 14, 00, 00, 00
DATA 00, 00, 00, 14, 14, 00, 00, 00
DATA 00, 00, 00, 14, 14, 00, 00, 00
NEXT
NEXT

And finally once i have those i can firgure out how to not let the player/AI go through lines. the lines are basic draw command ones
(line(x1,y1)-(x2,y2), color)

could someone please help me i need it very bad
Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

Post by Ralph »

Could you first fix this part of your code?

Code: Select all

LOOP UNTIL keyed$ <LOCATE> 1) THEN 
row = row - 1 
end if 
Also, please note that:
Arrow Up = 0H = 0+CHR$(72)
Arrow Down = 0P = 0+CHR$(80)
Arrow Left = 0K = 0+CHR$(75)
Arrow Right = 0M = 0+CHR$(77)
You have some changes to make in your code!
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish
Quicky
Coder
Posts: 20
Joined: Wed Jun 13, 2007 10:51 am

fixed

Post by Quicky »

Code: Select all

DO' fixed player1
DO
keyed$ = INKEY$
LOOP UNTIL keyed$ <LOCATE> 1) THEN 
row = row - 1
end if
IF (keyed$ = CHR$(0) + CHR$(80)) AND (row <23> 1) THEN 
column = column - 1
end if
IF (keyed$ = CHR$(0) + CHR$(77)) AND (column < 80) THEN 
column = column + 1
end if
IF keyed$ = "e" THEN END
LOCATE row, column
COLOR 10
PRINT "0"

'fixed AI
LOCATE attackrow, attackcolumn
PRINT " "
IF row <attackrow> attackrow THEN attackrow = attackrow + 1
IF column <attackcolumn> attackcolumn THEN attackcolumn = attackcolumn + 1
LOCATE attackrow, attackcolumn
COLOR 5
PRINT "0"
LOOP

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

umm

Post by Quicky »

okay well it was fixed on preview but then it got messed up
Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

Post by Ralph »

Your present code has some basic lack of knowledge problems...

First, you ignored my post and copied from your old code.

Did you, perhaps, copy all the code from someone else? If you are trying to learn, I would recommend that you be humble about it, and ask one question at a time, where you either don't understand the code, or where you want to do something, but just don't know how to go about it.

Also, I would recomment that you read and understand all the tutorials that you can, and practice your QuickBASIC.
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish
Post Reply