forums

TNT Basic Forums > Programming Q&A
searching arrays
< Last Thread     Next Thread >
Author
Thread        Post A Reply

10-28-2003 21:44

Posted by:
mark_667

Location:
England

Click Here to Email mark_667   Find more posts by mark_667

Hi,
Is it possible to find the name of an array entity or variable holding a corresonding value? The code I have is:

int current_x=sprite x (6) 'Gets current sprite position
int current_y=sprite y (6)

'this next part is some of the input system where you tap in the location of the square they want to move to - don't worry about this I just kept it in to help the next part make more sense

if pressed(n)
int new_rank=pressed(n)
end if
if pressed(n)
int new_square_no=pressed(n) 'Stores rank & square to move to in a variable
end if

sprite 6,new_rank,new_square_no 'Moves sprite to new co-ords
draw frame
'Verification bit:
'Need to find the pixel co-ords of the new square to find angle between old and new points of the sprite moving there
'if the angle is not 45 deg than disallow, move back to old co-ords.

now, in my game, all the square locations are stored in an array, each with two entities, one for the x, the other for the y.
example:
locations_Array[A1]=518
locations_array[A12]=218
and so on. Is the same true if I declared them as integers instead?
Global int A1=518, A12=218
thanks for any feedback you can offer on this
Mark_667

10-28-2003 22:58

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

...huh?

Sorry, I don't understand what you want to know.

10-29-2003 11:10

Posted by:
mark_667

Location:
England

Click Here to Email mark_667   Find more posts by mark_667

Sorry, I basically want to find the angle between an old and new location of a sprite. To do this, I get the current position variables and use that as point 1 (start), but as the user types in the location of the square it wants to move to (which are then stored in two new variables and make point 2) I need to know how to get the pixel co-ords for that second location. But all the square locations in my game are stored in an array:
locations_Array[A1]=518
locations_array[A12]=218
so the user doesn't type in the pixel co-ordinates, just the square ID they want to move to. This works OK, but how can I use it to get the pixel co-ords from what the user typed in (in order to make point 2) and see if the move is valid?
thanks,
Mark_667

10-29-2003 16:32

Posted by:
mark_667

Location:
England

Click Here to Email mark_667   Find more posts by mark_667

Think I've figured it out the code is included below. I got round it by moving the sprite whrever the user wanted it, then getting the pixel co-odiates for the new position finding the angle between the new and old position. if the move is invalid it moves the sprite back to the old position using the current_x and current_y variables recorded before the sprite is moved. What do you think?

'Gets current sprite position
int current_x=sprite x (6)
int current_y=sprite y (6)

if pressed(n)
int new_rank=pressed(n)
end if
if pressed(n) 'Stores square to move to in a variable
int new_square_no=pressed(n)
end if

sprite 6,new_rank,new_square_no 'Moves sprite to new co-ords input by user
draw frame
new_rank=sprite x(6) 'Allow move at first in order to get pixel co-ords to validate it
new_square_no=sprite y(6)

' Calculates angle
int a=current_y-new_square_no
int b=current_x-new_rank
int c=sqrt((a*a)+(b*b))

if current_y>=new_square_no 'old y => new y
int angle=invsin(b/c)+90
else
angle=270-invsin(b/c)
end if

if angle=45
sprite 6,new_square_no,new_rank 'Allow move
draw frame
else
beep 'This move is disallowed
sprite 6,current_x,current_y
draw frame
end if

10-30-2003 05:31

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

If you already have the coordinates to move the sprite to, why not just use those instead of moving the sprite to the point and getting its coordinates?

10-30-2003 14:05

Posted by:
mark_667

Location:
England

Click Here to Email mark_667   Find more posts by mark_667

The code would be too long and difficult. It'd just cause me more errors and confusion than it's worth, thanks for the suggestion tho.

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.