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! / 2d help

Author
Message
lukeman
21
Years of Service
User Offline
Joined: 16th Feb 2004
Location:
Posted: 16th Feb 2004 20:56
Hello! I am 17 yrs old and am pretty much completely new to programming, dark basic or other wise. I have read through the principles, turtorials, etc... and, from that knowledge, created a very simple "game"
Anyways, I have a huge desire to create a side-scrolling, 2-dimensional shoot-em-up, but I have no knowledge of how to do this. I would like to create my own graphics for my game, but do not know of a good (particulary free) program to do it with. Also, I have no idea how to implement these much needed images into my game. (This includes, background images, characters, weapons, etc...) Also, I do not know how to make the camera scroll across the image (considering I got the image into my program), and many other things that I will not mention. I would really like to do this, but just don't know where to start. Please help. Thanks!
comando 300
21
Years of Service
User Offline
Joined: 23rd Nov 2003
Location:
Posted: 16th Feb 2004 21:00
you downloaded the trial version of DarkBASIC?

CURRENT PROJECT: RETRO PAC-MAN
lukeman
21
Years of Service
User Offline
Joined: 16th Feb 2004
Location:
Posted: 16th Feb 2004 21:15
yes what does that matter?
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 16th Feb 2004 21:37
You need a free 2D art package, I can't think of any but there are some posted on these pages. You could use Anim8or for the graphics as well...WWW.Anim8or.com. It's a 3D modeller that can render 2D graphics with a light source. They end up looking like real metal, or rock, so it makes your graphics look better. It's good for buildings too, in the background, and machinery like cannons, or anything mechanical. You could even use 3D graphics to make your 2D game, it makes scrolling the screen easier because you can just move the camera.

To scroll a screen in 2D you use 2 screens..Bitmap 1 and Bitmap 0.

Bitmap 1 should be a long picture. You can load a long picture, or you can make the long picture from tiles, called a tile map. You are supposed to build the picture whilst the screen is scrolling, but this technique takes some getting used to.

You use

do
Copy Bitmap 1,x1,y1,x2,y2,0,0,0,screenwidth,screenheight

inc x1,3.......scroll speed = 3
inc x2,3.......scroll speed = 3...can be whatever you want.
Loop

Pincho.

lukeman
21
Years of Service
User Offline
Joined: 16th Feb 2004
Location:
Posted: 16th Feb 2004 22:22
thanks for the info on scrolling in 2d, but could you tell me what bitmap 2 represents? Also, you think making a 2d sidescroller game with 3d graphics would be easier? thanks again.
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 16th Feb 2004 22:44
The second bitmap is used to create the scroll effect in 2D. It's used for pasting images onto.

2D/3D about the same for this project.

Pincho.

Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 17th Feb 2004 12:52
Try using the paint program that comes with windows. Its ok for doing simple sprites with. Set the colour of the page to black and then draw away!

When you save the picture, its saved as a bitmap(.bmp) file, which is the main one that DB uses. Draw your spaceship, then a couple of baddies and you will have something to start learning how to get in game.

Next you have to learn about loading images and displaying them on screen. Use the load image command and the sprite command. Load your ship like this

load image "myimage.bmp",1

then draw it on screen like this

sprite 1,100,100,1

this will draw it on the screen 100pixels from the left and 100pixels down. Try this as your first exarcise, it is quite quick...
this pice of code will draw the sprite and move it every time you ress any key! Remeber to press the escape key to exit the program!

GIve me more power!
Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 17th Feb 2004 12:54
load image "myship.bmp",1
x=100
y=100

do
sprite 1,x,y,1
wait key
x=x+10
y=y+10
loop

GIve me more power!
lukeman
21
Years of Service
User Offline
Joined: 16th Feb 2004
Location:
Posted: 17th Feb 2004 19:35
Thanks lot for the info, that last message helped a lot, but i still have a question- If I set my background to black like you said and draw on it, then how do I get all of that other background to go away once I load it into my game as a sprite? by the way, what does the second "1" do in this piece of code, i know the first one is the image number but I don't know what the second one is:

"this will draw it on the screen 100pixels from the left and 100pixels down. Try this as your first exarcise, it is quite quick... thanks!"^^

Anyways, what if I dont want my background to be black in ms paint and what about the black lines for the outline of my object/s? I thought I heard that you could create a "masking color" or something that you could take away once you put your image into your program, but I'm not sure how to do it or how it works. Well, thanks again for all the great support!
MakcKid
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 17th Feb 2004 20:18
You can use DATA to create your background. Here's an example:

rem load images
load image "grass.bmp",1
load image "wall.bmp",2

rem dim map
dim map(10,10)

rem create map (where it says x*50 and y*50, change the 50 to the rem size of your tile
for x=1 to 10
for y=1 to 10
read map(x,y)
if map(x,y)=0 then paste image 1,x*50,y*50,1
if map(x,y)=1 then paste image 2,x*50,y*50,2
next x
next y

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,0,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,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,0,0,0,0,0,1
data 1,1,1,1,1,1,1,1,1,1
............
this should work. I am a noobie too so I'm not completely sure if it'll work.
Good Luck!

.....
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 17th Feb 2004 22:24
For background graphics you don't really want any trasparency, unless you are doing a parrallax effect. So best to turn off transparency completely.

Pincho.

Prep
21
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 17th Feb 2004 22:31
Just something I have been wondering for a while (and I don't mean to hijack this thread, and its somewhat relevent).

Why use data statements, I build all my maps in arrays completely and have never used data, I just ask the reason to?

Is it more for just quick example areas on forums or do people really make whole areas out of data statements?

To be no more, sad cure.
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 18th Feb 2004 00:49
Well you could read a file directly into an array, but then you could not show an example on Apollo.

Pincho.

lukeman
21
Years of Service
User Offline
Joined: 16th Feb 2004
Location:
Posted: 18th Feb 2004 04:32
hey macckid, do you think you could better explain your method for creating a background? I dont really get all of the
part. If you could just explain excatly what this is doing then that would be great. Also, does anyone know of a tutorial that involves creating a 2-d sidescroller or for individual things like geting images onto your background? Thanks!
lukeman
21
Years of Service
User Offline
Joined: 16th Feb 2004
Location:
Posted: 18th Feb 2004 04:37
Like I have probably said before, I am completely new to the whole idea of programming, I have never really touched on it before February 13 of 2004, so hopefully that gives you an idea of how much I understand of all of this. I am currently working through the Monster Hunt 3D Tutorial and I am on about section 2.0 and am having problems. So if anyone could reccomend any other ways/tutorials to grasp the concepts/commands/etc... of programming then that would be of great help. Keep in minding I STARTED (FOR THE FIRST TIME) programming about 3 days ago.
Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 18th Feb 2004 11:50
Ok, lukeman, when you draw a picture to use as a sprite, darkbasic automatically makes any black you have on the picture invisible when you disply it as a sprite. You know how the tv shows the colours? As red, green and blue particles that make up each pixel. If you set the clour of a pixel to 0 red 0 green and 0 blue than it is black(obviously!) but if you set it to 10red, 10 green and 10 blue, it still LOOKS black, but wont be recognised by dark basic as black. So any part of an image that is used to make a sprite that is set to rgb 000pure black) wont be drawn!

In the sprite command, the first 1 is the sprite number, the second 2 numbers are the position and the fourth numer is the image you want the sprite to show. When it says load image"myship.bmp", 1 this is setting myship to be image number one. Then Image number 1 is put into sprite number 1. You could draw another image(a baddie or missile or something) and load it into image number 2 like this
load image"baddie01.bmp",2

then put it into a sprite, called sprite 3, like this

sprite 3,x+200,y+200,2

try putting those lines in the right place in the simple program I gave you!

GIve me more power!
Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 18th Feb 2004 11:52
Personally, I never use black in anything I paint or draw anyway, always use dark blue or dark green or brown!

GIve me more power!
Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 18th Feb 2004 12:32
The guys above are talking about ways to get a background to the game running, not background colours on the pictures you draw in whatever program you draw in! They are talking about how to get backgrounds working using tiles that repeat(grass, trees, walls, rivers eyc).

An array is a sequence of numbers. Data is nubers your program can read off using the data commands. A command is like sprite, load, stuff like that.

GIve me more power!
MakcKid
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 18th Feb 2004 19:04
Quote: "Why use data statements, I build all my maps in arrays completely and have never used data, I just ask the reason to?
"

Hey Prep, could you please explain how to do this. The reason I use data statments is because that's the only way I know how to make maps. So learning another method would be great. Thanks a lot!

.....
MakcKid
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 18th Feb 2004 19:18
Ok. Now here's my explination to lukeman. These...

data 1,1,1,1,1,1,1,1,1,1
data 1,0,0,0,0,0,0,0,0,1
...etc...are just a bunch of numbers that are being used to represent different tiles that are being used on the map. This...

for x=1 to 10 'you change the 10 to the width of your data
for y=1 to 10 'you change the 10 to the length of your data
read map 'this reads your data
if map=0 then paste image 1,x*tilewidth,y*tileheight,1
if map=1 then paste image 2,x*tilewidth,y*tileheight,2
next x: next y

...now to explain the "if map=0 then".....
here its saying that if the data it's reading is a 0, then put image 1 there. The read map reads every number in you data stamements seprately...if your image is 64x64 you would change tilewidth and tileheight to 64, etc. I hope this helped. Good Luck!

.....
Tersaken
21
Years of Service
User Offline
Joined: 15th Dec 2003
Location: France ( Rennes )
Posted: 18th Feb 2004 20:36
if Map(x,y) <> 0
paste image map(x,y),x*tilewidth,y*tileheight,1
endif

More Fast !

Athlon 1700+ ; 256 Mo DDR ; GeForce Fx 5600 128 Mo.
Prep
21
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 18th Feb 2004 22:21 Edited at: 18th Feb 2004 22:32
Well firstly make sure your clear that I am in no way an expert, I think I have been programming in DBp (and any form of for that matter) for 3ish months.

Basically what I do is make an array. (the following is a very small basic example of what an array is, if you already know skip this).

An array is basically a table of varibles. If you dimension (dim) an array 2,2 you send up with 9 (you also get a 0 column row) "data spots" (My word!).

Heres my attempt at a diagram (theres a good link in the newcomers forum to matedits website which has some pretty easy to understand information about arrays, and a lot of other things worth reading).



When I make games (well... I call them games , and these tend to be top down / birds eye veiw style) I make my maps as arrays.

I use sprites for my whole background (made up of a couple of hundred tiles), because in my experiance its far faster then using bitmaps and copy pasting, but that might be something for another day. I'm going to ignore scrolling for now.

Lets say we want to make 640x480 screen made up of tiles. (again this is from a top down veiw, but the same principles are used). I have 2 different types of terrain, grass and water, I load these into image 1 and 2. I dimension an array 16,12 (you could do it with 15,11 and it wouldn't require as much memory but generally I ignore the 0,0 columns for readability, and in this case the difference is totally unnoticable).



My tiles are 40x40 pixels meaning I should get 16x12 tiles on my screen. By looping through my array, working out the image the number inside it represents I can build my screen.



The reason for the +1 is because I loaded the images in 1 and 2, you can't load an image to 0.

In theory the screen should be completely covered in the grass tiles I loaded into image 1. This is because when you make an array it has no data.

To add water tiles I can just do

Map(3,6)=1

and then tile 3x6 will be a water one when I load the screen. Of course when you have lots of tiles and are wanting to make whole areas you can't (well you can but probably wouldn't want to) go through setting all the tiles up in the array like that.

For my games, after I have the very bases of an engine, I begin work on a level editor. The following is a quick snippet from the editor I wrote for my current project. The intention is to give you an idea of how you can go about building your maps using arrays. (mX and mY is the mouse position the worldx worldy are because it scrolls, and thats some good grammer ).



If you have DBpro (I have no idea what the earlier DBs are capable of as I have never used them) theres simple functions for saving and loading arrays (surprisingly called "save array" and the apt "load array").

If your not using pro and what you are using can't save arrays like that then the following code should work (I would imagine)



I hope thats not too confusing to read, i'm not the greatest teacher in the world, but if you have questions I will try and clarify.

To be no more, sad cure.
MakcKid
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 19th Feb 2004 05:31
Thanks a lot for the explination. I completely understand it. But I was wondering...isn't it easier to use data? Here's an example why:



Note thearray code doesn't completely work. I don't know how to put the right side and the bottom walls in.

Also, do you know how to do collision using arrays?
Thanks a lot. Your explanation was a big help!

.....
MakcKid
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 19th Feb 2004 06:28
Hey. I'm trying to start a very simple game using arrays now that I've learned how to use them. Here's what I have so far:


I marked where I needed help with collision. Does anyone know how to make it so the guy stops when he hits a wall? Thanks a lot!

PS you were right Prep, arrays aren't very hard.

.....
Prep
21
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 19th Feb 2004 22:05 Edited at: 19th Feb 2004 22:08
Edit - Didn't notice you had already started working with array collison when I wrote this post, you appear to learn fast.

A very simple way of stopping people moving through walls is to use array collision, its not pixel perfect, its fine for the type of games I tend to make, and probably will be for what your doing.

Dim Map(10,10,1)

Right basically that means every X,Y sector has 2 values; it adds "depth" to your array.

Lets say 0= passable 1= blocked.

Map(1,1)=1(a wall) - if you don't put a Z coord in an array its 0 (x,y,z)
Map(1,1,1)=1 (impassable)

Now in your control code you simply check if where the player will be is passable or not and don't allow them to move if it isn't.

You can work out such off 2d arrays using a select statement (best wraped in a function), it probably uses less memory but is more work and needs constent updating as new tiles are added.



Hope thats helped.

To be no more, sad cure.
Izzy545
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location:
Posted: 19th Feb 2004 22:43
Hey, I set up an array map and I even went so far as to make myself a (crappy)editor so I can make very simple levels. I'm checking to see if the position that the player wants to move to is collision free and if it is then it allows the player to move. I used some of MakCKids code to help me along in my ways and I have it working... Sort of. Basically what happens is this:

If the player is walking along a wall, trying to go diagonally and comes to a doorway like so: __ __ then the player will enter the wall on the other side of the ^=Door doorway O_O How do I fix this? Any ideas? I'll post the collision code...

Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 19th Feb 2004 23:02
Just ignore the diagonal button press for doors.

MakcKid
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 19th Feb 2004 23:22
Thanks again for the help Prep. I kind of figured out how to do collision and it works a little bit on the right side wall. Here's my code:


Am I doing anything wrong? Thanks again!

.....
Izzy545
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location:
Posted: 19th Feb 2004 23:34
Quote: " Just ignore the diagonal button press for doors."


By diagonal I mean pressing two arrow keys at once.
Prep
21
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 21st Feb 2004 00:04
Makc, you may find it easier to do collisions like Izzy is, by checking it before the player moves there and not allowing them to move at all.

Izzy, On the doors, I don't really understand what your saying, the player ends up on the wrong side?

To be no more, sad cure.
Izzy545
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location:
Posted: 21st Feb 2004 00:10 Edited at: 21st Feb 2004 00:11
Okay... Lemmee see if I can draw a diagram type thingy.

P = Player, _ = wall and the open space is a door. -- = the way the player is going.

___ ___
------P

Now, say the player is pressing up and left at the same time, then the character will be moving to the left. Now then, when the player hits here:

___ ___
----P

And is still presseng left and up then the player will fall into the wall here:

__P ___

That happens any time. I can move diagonally into the corners of any walls, or bodies of water. Only the corners though. I'm thinking that the reason is that it's only checking if it's collision free above and to the left of the player, so when he hits that doorway and is trying to go diagonally then there is no collision up or to the left, so it allows the player to go diagonally.

How do I fix this?

Hope I explained that well enough.
Prep
21
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 21st Feb 2004 00:36
Hmm..., well you could always try doing your controls something like.



I don't seem to suffer such problems, i'm not sure why yours does, because really if you have left and down, it should still do the left check and then the down check (or whichever order your ifs are in) even if it gives the appearance of going diagonally.

To be no more, sad cure.
MakcKid
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 21st Feb 2004 02:41
Hey Izzy I tried your collision method and it works.
Quote: "if map(posX, posY-1)=0
"


Where it added or subtracted numbers to posx and posy I had to change the numbers. Can you explain why you used these numbers? Thanks a lot. Also, I think this collision only works for a border around the map, I might bve wrong.
Thanks for your help.

.....
Prep
21
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 21st Feb 2004 03:45
Yes i'm not to sure what Izzy was doing there, I just assumed it was some form of very unique control. Heres what my movement code looks like at the moment. (there are a few things I have kept out as its totally irelevent and unhelpful to readers)



I'm feeling generous, so i'll post my current tilemap code, I think its pretty decent and should give you fellows a good idea on how to do sprite map scrolling. (which in my experiance is far faster the bitmap)

Basically I fire off this function whenever a player moves, a tile is updated, an object appears etc. I should probably use Fors but i'm just stuck in the habit of using whiles.



I have also managed to reproduce Izzys problem of getting into the corners of array blocked areas, i'm going to fix that tomorrow probably so i'll post what I do if anyones interested.

In the control code, theres quite a lot of pieces that arn't finshed / will be wrapped in functions and such, so my apoligies it looks a bit of a mess.

To be no more, sad cure.
MakcKid
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 21st Feb 2004 19:08
I'm using Izzy's method for collision in this "game", but some walls don't work for collision. I don't understand the posy+1, posy+2, etc. Can you explain this. Here's my program:
[/code]

set display mode 800,600,32

load image "c:\sprites\grass.bmp",1
load image "c:\sprites\wall.bmp",2
load image "c:\sprites\sprite2.bmp",3

sync on

dim map(10,10)

guyx=250
guyy=250

posx=5
posy=5

movedx=0
movedy=0

do

sync

gosub makemap
gosub moveguy
gosub guypos

loop

REM MAKEMAP

makemap:

For Y=0 to 9
For X=0 to 9
Map(X,Y)=1
Next X
Next Y

For Y=1 to 10
For X=1 to 10
if X=1 or Y=1 or X=10 or Y=10 Then Map(X,Y)=2
if map(x,y)=2 then paste image 2,x*50-50,y*50-50,2
Next X
Next Y

For Y=0 to 9
For X=0 to 9
If Map(X,Y)=1 then paste image 1,X*50-50,Y*50-50,1
Next X
Next Y

return

REM MOVEGUY

moveguy:

if upkey()=1
if map(posx,posy-1)=1
guyy=guyy-5
movedy=movedy-5
endif
endif

if downkey()=1
if map(posx,posy+2)=1
guyy=guyy+5
movedy=movedy+5
endif
endif

if leftkey()=1
if map(posx,posy)=1
guyx=guyx-5
movedx=movedx-5
endif
endif

if rightkey()=1
if map(posx+2,posy)=1
guyx=guyx+5
movedx=movedx+5
endif
endif

sprite 3,guyx,guyy,3

return

REM GUYPOS

guypos:

if movedx>=oldmovedx+50
oldposx=posx
posx=posx+1
movedx=0
print "x ", posx
endif

if movedx<=oldmovedx-50
oldposx=posx
posx=posx-1
movedx=0
print "x ", posx
endif

if movedy>=oldmovedy+50
oldposy=posy
posy=posy+1
movedy=0
print "y ", posy
endif

if movedy<=oldmovedy-50
oldposy=posy
posy=posy-1
movedy=0
print "y ",posy
endif

return
[code]

If you know how some collision is working and others aren't, please tell me. Thanks.

.....
Prep
21
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 21st Feb 2004 19:35
A few things.

Firstly its probably not a good idea to update your map every loop, but rather at any time it needs updating, such as the player moving.

Secondly, i'm not sure why your using the "guy position" code, as generally scrolling games tend to scroll from the middle, the player never moving until they are at the edge of an area. If your character isn't moving a whole tile at a time, I would advise you make him untill your a bit more experianced. Its a lot easier that way. (although with large tiles it might be somewhat jerky looking)

Thirdly, i'm not particulary sure why sometimes you check +1 on the players positions and other times +2? This could be the problem with your collison checks.

Try making your loop end up just like

Do
gosub controls ` personnally I would use a function
Loop

And fire you updating of the map as the player moves, theres no point in drawing the same image over and over again, several times a second. (that I can think of anyway)

To be no more, sad cure.
MakcKid
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 21st Feb 2004 20:05
Thanks for the help.
Quote: "i'm not sure why your using the "guy position" code, as generally scrolling games tend to scroll from the middle, the player never moving until they are at the edge of an area"

I'm using this because I need to check when the guy moves over 50(the length of a tile). I need to do this to check for collision.
if map(posx,posy)...posx=the x tile the guy is on...etc.
And for right now I'm not doing a scrolling game, I'll try to do this once I figure out collision. Thanks again.

.....
Izzy545
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location:
Posted: 21st Feb 2004 20:39
The +1 +2 thing is because for some strange and unknown reason I have to put that otherwise it screws up everything. Basically, I put plus 1 or minuse 1 there because if I don't then you can move onto tiles. It's like there's a ghost image of the tiles set up and to the left if I don't put +1 and +2 and all that. I hope you understand what I mean.
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 21st Feb 2004 20:54
You could always make your man walk 50 pixels at a time. It's the same in Pacman. He walks 16 pixels at a time in lo-res, or 32 pixels at a time in 800*600. How does this work? Well it's a delay from when you push the joystick/keyboard, till the time that he stops moving. One quick press of a button and a sequence of movements is started. If you had a walk animation which worked exactly 50 pixels at a time, you could run the whole thing, which would always update your map.

Prep
21
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 21st Feb 2004 21:54
Exactly, moving your character a tile each time is far easier, collision becomes incredably simple. 50pixels maybe a little large though, I used 40 and it sometimes looks jerky, 20/20 looks pretty nice, but its quite a lot of effort to do.

To be no more, sad cure.
MakcKid
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 22nd Feb 2004 06:29
I'm moving the guy 50 pixels at a time now, but collision still wont work. Does anyone have a 2D program similar to mine that has collision that works. Thanks again guys.

.....
GameMaker Jason
21
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 3rd Mar 2004 22:24
i use data statements for my maps and i was wondering how to checks for collision using data statements coz theres only a array map example above?

Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 4th Mar 2004 01:27
Data is used in an array, there is no real difference apart from the Data statement.

Use........

For y = 1 to 2
for x = 1 to 8
read tile

map(x,y) = tile

next x
next y

Data 0,0,0,0,1,1,1,1
Data 0,0,0,0,1,1,1,1

GameMaker Jason
21
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 4th Mar 2004 09:58
what exactly will that do and how do i move a player about on tiles?

Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 4th Mar 2004 10:49
That puts all of the data into an array.

map(X,Y) = Map(1,1) = this is your first tile.

Map(2,1) = This is your second tile.

Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1

0 = walkable area
1 = wall

***************************
a = map(1,1)

Print a

result = 1
***************************

***************************
a = map(2,1)

Print a

result = 0
***************************

If your tiles are 32*32 you make a loop to paste them down like this..
********************************************
For y = 0 to HeightOfFirstScreenMap
for x = 0 to WidthOfFirstScreenMap


Paste image map(x,y),x*TileSize,y*TileSize

next x
next y

********************************************

The collision is just a check that you perform when your character has walked 32 pixels, or the width of your tiles. So you wait for him to walk that far, then your map(x,y) needs to have its x or y position changed because your character has walked onto the next tile. x = x + 1, or y = y + 1 depending on whether your character has walked sideways, or upwards. Now......

If map(x,y) = 1...Your character has hit a wall
If Map(x,y) = 0...Your character hasn't hit anything.

That's it!

GameMaker Jason
21
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 4th Mar 2004 18:47
i get collision but how do i make him move and update the array as he do it?

GameMaker Jason
21
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 4th Mar 2004 19:44
this code doen't work



It shows the images randomly place like in this screenshot



this is not what it is meant to be please help

Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 5th Mar 2004 00:18
You got your first x y backwards. I haven't tested this code because I didnt have a tile handy.




GameMaker Jason
21
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 5th Mar 2004 00:33
great thanks could you explain movin' the pacman how to update the array when he moves?

Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 5th Mar 2004 15:52
If he walks left 32 pixels it's Map(Xpos,???) xpos = xpos - 1
If he walks right 32 pixels it's Map(Xpos,???) xpos = xpos + 1
If he walks up 32 pixels it's Map(???,Ypos) ypos = ypos - 1
If he walks Down 32 pixels it's Map(???,Ypos) ypos = ypos + 1

Pincho.

Login to post a reply

Server time is: 2025-08-09 02:12:06
Your offset time is: 2025-08-09 02:12:06