|
Post by piegopher on Feb 19, 2002 6:46:24 GMT
I use simple x, y coordinates, a variable each, to keep track of all of the sprites on screen, but it starts to get confusing as I add more- Is there a simpler way to deal with the placement on screen?
This is how I use it: x = 90 y = 10 a = 100 b = 10 circle(x,y), (5) circle(a,b), (5) x = x + yedda yedda yedda...
|
|
|
Post by Hendrix70 on Mar 17, 2002 17:47:02 GMT
to recognize everyone of the sprites use a '. Example:
This is how I use it: x = 90 y = 10 a = 100 b = 10 circle(x,y), (5)' circle number 1 circle(a,b), (5)' circle number 2 x = x + yedda yedda yedda...
if this doesn't answer your question did everything possible in order that does it
|
|
MikeTR2000@hotmail.com
Guest
|
Post by MikeTR2000@hotmail.com on Apr 18, 2002 21:28:10 GMT
There are a couple of ways
The easiest for just 2 sprites would be to include the name of the sprite in the x/y variables, remember you don't have to keep your variables one letter. ex:
BadGuy_x = 90 BadGuy_y = 10 GoodGuy_x = 100 GoodGuy_x = 10
circle(BadGuy_x, BadGuy_y), (5)' circle number 1 circle(GoodGuy_x, GoodGuy_y), (5)' circle number 2
Badguy_x = BadGuy_x + yedda yedda yedda...
Another way if your are using a bunch of them would to be using arrays. ex:
dim sprite_x(n), sprite_y(n) 'n= # of sprites dim xmovement(n), ymovement(n) sprite_x(1)=10 sprite_y(1)=50 sprite_x(2)=98 sprite_y(2)=7
FOR temp=1 to n 'again, n=# of sprites circle(sprite_x(temp), sprite_y(temp)), (5) sprite_x(temp)=sprite_x(temp)+xmovement(temp) sprite_y(temp)=sprite_y(temp)+ymovement(temp) NEXT
hope that helps
**Warning** I did not check the code, so it may not be exactly right, but it should give you an idea
|
|
|
Post by piegopher on May 7, 2002 3:48:06 GMT
Wow... you can do variable(#) ? This revolutionizes my programming! MY GOD! I KNOW NO BOUNDS! Except 20... it cant seem to get past variable(20)... is that normal?
|
|
|
Post by Clark-O on Jun 6, 2002 21:48:13 GMT
i might be wrong, but is'nt variable(20) an array. if it is an array, then if you leave it at varaiable() it will automaticlly leave 20 available array spaces for use (21 including 0). maybe trying to assign the default array spaces to an array freaks it out or something?
|
|
|
Post by brisray on Jun 6, 2002 22:36:58 GMT
Quite right Clark-O
Try this
FOR Count = 1 TO 30 MyArray(Count) = Count PRINT Count NEXT Count
QBasic v1.1 will only let you assign 10 elements to an unDIM'd array. The code will above will give an error.
Adding
DIM MyArray(30)
to the start of the program will give 30 elements, and so the program runs properly.
Ray
|
|
|
Post by brisray on Jun 6, 2002 22:51:07 GMT
I've just been re-reading the previous posts.
Something else you can do in the arrays is to define them as multi-dimensioned. An array with 2 dimensions acts like a table or grid.
Suppose you want to keep track of your sprites x and y position, it's offensive and defensive capabilities and it's speed. You can define an array to keep track of all of these by using :-
DIM sprite(30, 5) AS INTEGER
'1 = x, 2 = y, 3 = offense, 4 = defence, 5 = speed
sprite(1, 1) = 50 sprite(1, 2) = 30 sprite(1, 3) = 4 sprite(1, 4) = 6 sprite(1, 5) = 8
sprite(2, 1) = 60 sprite(2, 2) = 20 sprite(2, 3) = 5 sprite(2, 4) = 7 sprite(2, 5) = 12
Multi-dimensioned arrays can only keep data of one type in them. If you want to keep both numeric and string data in them you have to use the TYPE command to define your own data types.
Ray
|
|