Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Reading Specific Data

Author
Message
MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 10th Feb 2004 22:54
Hey. I was wondeing how to read one tile in my DATA statement. The tile is 50x50. My map(DATA) is 14,10 The closest I could get was:

for x = 1 to 14
for y = 1 to 10
read map(4,4)
next x
next y

...

i know that this reads this:

DATA 1,1,1,1
DATA 1,0,0,0
DATA 1,0,0,0
DATA 1,0,0,0

but i want it to read just this:
DATA -,-,-,-
DATA -,-,-,-
DATA -,-,-,-
DATA -,-,-,4 <---just that

...the dashes indicate that i don't want it to be read. Does anyone know how to do this?
Thanks!

.....
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 11th Feb 2004 00:02 Edited at: 11th Feb 2004 00:05
This is how you do it.

You can use a label with MyMap:
Then restore MYMap
This would just restore that part of the data, so you could restore something that happens after another set of Data.




MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 11th Feb 2004 00:23
Thanks Pincho.
What I'm trying to do is make it so if a sprite that I can move around on my map hits tile 1 then it stops. Here's what I have so far:


If you know a way I an solve this please help!
Thanks a lot!

.....
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 11th Feb 2004 00:34 Edited at: 11th Feb 2004 00:35
dim map(14,10)......You haven't even used this yet!!!

rem reads the map

for x = 1 to 14
for y = 1 to 10

read map

Map(x,y) = map ................Use it here!!!
if map=1 then paste image 1,x*50,y*50,1
if map=0 then paste image 3,x*50,y*50,1

if upkey()=1 and move=true then guyy=guyy-5 ......here you need to add a map position for your man!
if downkey()=1 and move=true then guyy=guyy+5
if leftkey()=1 and move=true then guyx=guyx-5
if rightkey()=1 and move=true then guyx=guyx+5

Now that you have stored your map in an array you can look inside it to see if your man is touching a wall. But to look inside it in blocks of 14,10 you need to find out which square your man is standing inside. So as your man walks around the screen, you need to wait for him to walk 50 pixels, and then make a map position for your man, and see if it is a wall.

sprite 2,guyx,guyy,2

MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 11th Feb 2004 01:17
Thanks again Pincho.
I tried using this in my main loop:

for x=1 to 14
for y=1 to 10
map(guyx/50,guyy/50)=map
read map
if map=1 then move=false
next x
next y

...it still doesn't work. Do you know why?
Thanks again!

.....
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 11th Feb 2004 01:31 Edited at: 11th Feb 2004 01:32
map(guyx/50,guyy/50)=map


Just use..........map(x,y)=map

MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 11th Feb 2004 01:38
ok thanks. Now how do i check the guy's position so if he hits a wall he stops?

thanks!

.....
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 11th Feb 2004 01:55 Edited at: 11th Feb 2004 02:01
Well lets take a look at whet you have stored in your map.

Map(1,1) = 1
Map(2,1) = 1
Map(3,1) = 1.......etc

Map(2,2) = 0
Map(2,3) = 0.......etc

data 1,1,1,1,1,1,1,1,1,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,1,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,1,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,1,0,0,0,0,1
data 1,0,0,0,1,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,1,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,1,1,1,1,1,1,1,1,1

If your man starts the game at 150,150 he is standing on Map(2,2)


data 1,1,1,1,1,1,1,1,1,1
data 1,0,0,0,0,0,0,0,0,1....Your man is here!
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,1,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,1,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,1,0,0,0,0,1
data 1,0,0,0,1,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,1,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,1,1,1,1,1,1,1,1,1

So

ManposX = 2 : ManposY = 2

If map(ManposX,ManPosY) = 1 then he has hit a wall!

Now if he walks left/right/up/down you have to count how many pixels he moves, because you need to track his movements. when he crosses into the next tile you need to look in the map(Manposx,manposy) to see if it is a 1 or a 0. If it is a 1, you don't allow him to walk anymore, and you put him back where he moved from.

You dec ManposX if the man walks around 50 pixels left. You inc ManposX if your man walks 50 pixels right, plus his width.

MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 11th Feb 2004 02:20
Thanks again.
This is what I have now:

It still doesn't work..but I'm understanding it a lot more. Do you know what's wrong with my code?
Thanks so much!

.....
MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 11th Feb 2004 05:06
well i figured some more out. Here's all my code now.


my problem is that it is reading map(posx,posy) and posx=2, posy=2, but at (2,2) on my data there is grass(0). I think it is reading:
DATA 1,1
DATA 1,0
...since there are 3 ones there, then move=false. how do i get it to just read:
DATA -,-
DATA -,0<---just that
....that's what I want it to do. Is there a way to do this?
Thanks so much Pilchard...you've taught me so much about Programming, I really appreciate it.

.....
MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 11th Feb 2004 05:07
i spelled ur name wrong..sorry...pilchard is the name of another guy that wrote a Q-Basic tutorial that I read last night..haha..sorry

.....
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 11th Feb 2004 11:35 Edited at: 11th Feb 2004 11:43
Quote: "...since there are 3 ones there, then move=false. how do i get it to just read:
DATA -,-
DATA -,0<---just that"


That is Map(2,2)...2 across, 2 down. That's how Your Map works, by just reading one piece of data at a time.

map(x,y)=map
read map

you have these the wrong way around should be.....

read map
map(x,y)=map...........All the Data has been put inside here...

The data has been stored so..You don't need to read the map twice.....so you can remove this line.

read map(posx,posy)

MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 12th Feb 2004 05:35
thanks again.
I almost have it. For some reason, it stops at 3,3...heres my code:


i've tested it and it changes posx and posy when it changes tiles. But I just cant figure out how to get my sub col to work. Please help. Thanks a lot.

.....
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 12th Feb 2004 10:21
Well you haven't changed any of the things that I already told you about.

MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 12th Feb 2004 23:14
Ok. Now I got it to work. I just don't know what to do to make my guy stop moving when he hits a wall. Thanks.

.....
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 13th Feb 2004 02:17
You move him back to his last position before he hit the wall. he will always try to move towards the wall, but will always be put back where he started from.

Pincho.

Code Stealer
20
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 13th Feb 2004 14:12
Please paste up the code that works, so I can look at it(Im learning)

GIve me more power!
MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 13th Feb 2004 22:15
here it is


.....

Login to post a reply

Server time is: 2024-05-13 17:44:38
Your offset time is: 2024-05-13 17:44:38