Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Graphics problem
#1
hey, im just starting top learn 2d graphics, anyway, i got this down from qbn.com (this site)'s tutorial and i played around with it, how would i get the sprite "moveobj" to move with the inkey$?

Code:
DIM flrtile1(10, 10), flrtile2(10, 10), wall(10, 10), moveobj(10, 10)
DIM map(21, 15)
SCREEN 13
FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
PSET (x, y), clr
NEXT: NEXT
GET (1, 1)-(10, 10), flrtile1

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
PSET (x, y), clr
NEXT: NEXT
GET (1, 1)-(10, 10), flrtile2

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
PSET (x, y), clr
NEXT: NEXT
GET (1, 1)-(10, 10), wall

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
PSET (x, y), clr
NEXT: NEXT
GET (1, 1)-(10, 10), moveobj


CLS
FOR y = 1 TO 15
FOR x = 1 TO 21
READ map(x, y)
NEXT: NEXT

FOR y = 1 TO 15
FOR x = 1 TO 21
IF map(x, y) = 1 THEN PUT (x * 10 - 10, y * 10 - 10), flrtile1
IF map(x, y) = 2 THEN PUT (x * 10 - 10, y * 10 - 10), flrtile2
IF map(x, y) = 3 THEN PUT (x * 10 - 10, y * 10 - 10), wall
IF map(x, y) = 4 THEN PUT (x * 10 - 10, y * 10 - 10), moveobj

NEXT
NEXT
SLEEP

'flrtile1
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0

' flrtile2
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,15

'wall
DATA 0,8,8,8,8,8,8,8,8,0
DATA 8,7,7,7,7,7,7,7,7,8
DATA 8,7,7,7,7,7,7,7,7,8
DATA 8,7,7,7,7,7,7,7,7,8
DATA 8,7,7,7,7,7,7,7,7,8
DATA 8,7,7,7,7,7,7,7,7,8
DATA 8,7,7,7,7,7,7,7,7,8
DATA 8,7,7,7,7,7,7,7,7,8
DATA 8,7,7,7,7,7,7,7,7,8
DATA 0,8,8,8,8,8,8,8,8,0

'moveobj
DATA 0,8,8,8,8,8,8,8,8,0
DATA 8,7,7,7,7,7,7,7,7,8
DATA 8,7,7,7,7,7,7,7,7,8
DATA 8,7,7,7,3,7,7,7,7,8
DATA 8,7,7,3,3,3,7,7,7,8
DATA 8,7,7,7,3,7,7,7,7,8
DATA 8,7,7,7,7,7,7,7,7,8
DATA 8,7,7,7,7,7,7,7,7,8
DATA 8,7,7,7,7,7,7,7,7,8
DATA 0,8,8,8,8,8,8,8,8,0



'map
DATA 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
DATA 3,2,1,2,1,2,1,2,1,2,3,2,1,2,1,2,1,2,1,2,3
DATA 3,1,2,1,2,1,2,1,2,1,3,1,2,1,2,1,2,1,2,1,3
DATA 3,2,1,2,1,2,1,2,1,2,3,2,1,2,1,2,1,2,1,2,3
DATA 3,4,2,1,2,1,2,1,2,1,3,1,2,1,2,1,2,1,2,1,3
DATA 3,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,3
DATA 3,1,2,1,2,1,2,1,2,1,3,3,3,3,3,3,3,3,3,3,3
DATA 3,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,3
DATA 3,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,3
DATA 3,3,3,3,3,2,3,3,3,3,3,3,3,3,3,3,1,3,3,3,3
DATA 3,1,2,1,2,1,2,1,3,1,2,1,2,1,2,1,2,1,2,1,3
DATA 3,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,3
DATA 3,1,2,1,2,1,2,1,3,1,2,1,2,1,2,1,2,1,2,1,3
DATA 3,2,1,2,1,2,1,2,3,2,1,2,1,2,1,2,1,2,1,2,3
DATA 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
unning a panasonic toughbook, cf-25 Smile
Reply
#2
Code:
DO
kbd$ = RIGHT$(INKEY$, 1)

  IF  kbd$ = "H" then
    'Move up
  elseif kbd$ = "P" then
     'Move down
  elseif kbd$ = "M" then
     'Move left
  elseif kbd$ = "K" then
     'Move right
  end if

loop

Left and right may be mixed up .....just going from the top of my head.....

usually, if u go up, y = y-1 , and down, visa-versa
left is x = x-1, and right visa-versa

:wink:

Oz~
Reply
#3
For the arrow keys, you can you CHR$

CHR$(0) + CHR$(77)
CHR$(0) + CHR$(75)

etcetera
Reply
#4
thx, when i have time ill give it a shot, anyway, i havent spent much time looking at the code you guys posted but eill l8er today, but where do i put this in the program? im asuming aft i declare all the sprites? :???:
unning a panasonic toughbook, cf-25 Smile
Reply
#5
Code:
DIM flrtile1(10, 10), flrtile2(10, 10), wall(10, 10), moveobj(10, 10)
DIM map(21, 15)
SCREEN 13
FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
PSET (x, y), clr
NEXT: NEXT
GET (1, 1)-(10, 10), flrtile1

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
PSET (x, y), clr
NEXT: NEXT
GET (1, 1)-(10, 10), flrtile2

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
PSET (x, y), clr
NEXT: NEXT
GET (1, 1)-(10, 10), wall

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
PSET (x, y), clr
NEXT: NEXT
GET (1, 1)-(10, 10), moveobj


CLS
FOR y = 1 TO 15
FOR x = 1 TO 21
READ map(x, y)
NEXT: NEXT

FOR y = 1 TO 15
FOR x = 1 TO 21
IF map(x, y) = 1 THEN PUT (x * 10 - 10, y * 10 - 10), flrtile1
IF map(x, y) = 2 THEN PUT (x * 10 - 10, y * 10 - 10), flrtile2
IF map(x, y) = 3 THEN PUT (x * 10 - 10, y * 10 - 10), wall
IF map(x, y) = 4 THEN PUT (x * 10 - 10, y * 10 - 10), moveobj

NEXT
NEXT


DIM x, y

x = 320 \ 2
y = 200 \ 2

DO

kbd$ = INKEY$

IF  kbd$ = "H" then
    y = y-1
  elseif kbd$ = "P" then
    y = y+ 1
  elseif kbd$ = "M" then
    x = x-1
  elseif kbd$ = "K" then
     x = x+1
  end if

PUT (x, y), **THE SPRITE**

LOOP until kbd$ = CHR$(27)   'Code for Esc

END

'flrtile1
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0

' flrtile2
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,15
DATA 15,15,15,15,15,15,15,15,15,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,1,2,1,2,1,2,1,2,1,2,3
DATA 3,1,2,1,2,1,2,1,3,1,2,1,2,1,2,1,2,1,2,1,3
DATA 3,2,1,2,1,2,1,2,3,2,1,2,1,2,1,2,1,2,1,2,3
DATA 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
Reply
#6
hey oz, it has an error when i run it, so i took out the
Code:
dim x, y
and it ran but it had a flickering box where you placed it but it didnt move at all. anyway, arnt you suppoed to do
[/code]
y = *****
x = *****

not

x = *****
y = *****
Code:
just wondering :roll:
unning a panasonic toughbook, cf-25 Smile
Reply
#7
shouldn't make a difference.....

it should work, tho....

hmmmm........i'll test it later
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)