Qbasicnews.com

Full Version: npc movement on tiles
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6
me again. i need to move a npc on tile. i figure just array out some (x,y)'s the flag if user is close to npc....um.....your code is very welcom.... Smile
That's "welcome"...

npc.x(n) = npc.x(n)-1
npc.y(n) = npc.y(n)+1
war is peace, 1984
Define a Type for all your npc's like this one:

Code:
TYPE NPCtype
   X AS SINGLE
   Y AS SINGLE
   vX AS SINGLE
   vY AS SINGLE
   Text AS STRING * 32
   iD AS INTEGER
   wid AS INTEGER
   hei AS INTEGER
END TYPE

Then define your npc like:
Code:
DIM npc AS NPCtype
And you're ready to use your npc type.

And by messing and comparing with the x and y values of both the user and the npc you can find out if the user if close to the npc.
could you explain the type thing. i get what it does. is just for Convenience? this is what i'm using to move the guy around. it's nnot good but it's all i can think of
Code:
FOR enemyx = 5 TO 11
PUT (enemyx * 15 - 15, enemyy * 13 - 13), enemysh, AND
PUT (enemyx * 15 - 15, enemyy * 13 - 13), enemy, OR
oldx = enemyx
FOR i = 1 TO 100000: NEXT
PUT (oldx * 15 - 15, enemyy * 13 - 13), tile2, PSET
NEXT

FOR enemyy = 5 TO 7
PUT (enemyx * 15 - 15, enemyy * 13 - 13), enemysh, AND
PUT (enemyx * 15 - 15, enemyy * 13 - 13), enemy, OR
oldy = enemyy
FOR i = 1 TO 100000: NEXT
PUT (enemyx * 15 - 15, oldy * 13 - 13), tile2, PSET
NEXT

FOR enemyx = 11 TO 5 STEP -1
PUT (enemyx * 15 - 15, enemyy * 13 - 13), enemysh, AND
PUT (enemyx * 15 - 15, enemyy * 13 - 13), enemy, OR
oldx = enemyx
FOR i = 1 TO 100000: NEXT
PUT (oldx * 15 - 15, enemyy * 13 - 13), tile2, PSET
NEXT

FOR enemyy = 7 TO 5 STEP -1
PUT (enemyx * 15 - 15, enemyy * 13 - 13), enemysh, AND
PUT (enemyx * 15 - 15, enemyy * 13 - 13), enemy, OR
oldy = enemyy
FOR i = 1 TO 100000: NEXT
PUT (enemyx * 15 - 15, oldy * 13 - 13), tile2, PSET
NEXT
it's to make the code readable.
In qb, TYPEs serve no real purpose. TYPEs are like the XP-type search mechanism: search for images, documents, music files? What was the color of that file? Did it have a cupcake in it...?

TYPEs try to enforce some sort of order on your variables. If you don't have that order in your head in the first place though, types won't help. But they WILL hurt, as type variable arrays are invoked differently than real arrays, and they have limitations when real arrays with the same name are used.
can you just use ! # $ %
what's the difference?
Agamemnus is always wrong when he talks about types, 'cause he hates'em LOL Big Grin j/k

Types are useful to pass a bunch of related variables to a function just with 1 parameter, for example.
does it run faster?
Pages: 1 2 3 4 5 6