Qbasicnews.com
February 25, 2020, 11:39:47 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2 3 4
  Print  
Author Topic: npc movement on tiles  (Read 10444 times)
Diroga
Been there, done that
*****
Posts: 1087


« on: August 24, 2003, 03:34:21 AM »

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.... Smiley
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #1 on: August 24, 2003, 08:24:13 AM »

That's "welcome"...

npc.x(n) = npc.x(n)-1
npc.y(n) = npc.y(n)+1
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Diroga
Been there, done that
*****
Posts: 1087


« Reply #2 on: August 24, 2003, 11:50:35 PM »

war is peace, 1984
Logged
Neo
Na_th_an
*****
Posts: 2150



« Reply #3 on: August 25, 2003, 08:36:18 AM »

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.
Logged
Diroga
Been there, done that
*****
Posts: 1087


« Reply #4 on: August 25, 2003, 02:39:06 PM »

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
Logged
barok
Na_th_an
*****
Posts: 1727


How about a tasty lead sandwich?


« Reply #5 on: August 25, 2003, 07:28:49 PM »

it's to make the code readable.
Logged

Jumping Jahoolipers!
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #6 on: August 25, 2003, 07:54:46 PM »

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.
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Diroga
Been there, done that
*****
Posts: 1087


« Reply #7 on: August 25, 2003, 08:34:12 PM »

can you just use ! # $ %
what's the difference?
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #8 on: August 25, 2003, 08:55:22 PM »

Agamemnus is always wrong when he talks about types, 'cause he hates'em LOL Cheesy j/k

Types are useful to pass a bunch of related variables to a function just with 1 parameter, for example.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Diroga
Been there, done that
*****
Posts: 1087


« Reply #9 on: August 25, 2003, 09:19:16 PM »

does it run faster?
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #10 on: August 25, 2003, 09:25:15 PM »

no.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Diroga
Been there, done that
*****
Posts: 1087


« Reply #11 on: August 26, 2003, 12:13:50 AM »

then i guess i wont use it.
Logged
Neo
Na_th_an
*****
Posts: 2150



« Reply #12 on: August 26, 2003, 07:16:36 AM »

It makes coding more readable and you'll have much less variables.
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #13 on: August 26, 2003, 08:22:02 AM »

No, you won't.

You'll have fewer code in your variable declaration, but not by much.

And you can't have two dots in types.
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #14 on: August 26, 2003, 08:35:37 AM »

Dots in variable names are bad practice, 'cause in every estructured language the dot is used to express a member of a data structure.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Pages: [1] 2 3 4
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!