I changed the topic to better show what this thread is all about...
Old --------------
I need ideas for games that are easy to program
I have programed Pong and a game where you had to save the earth from falling meteors. I made pong using DirectDraw and the meteor thing using BitBlt...
I thought about making a pacman clone but then I have to make up some kind of tileengine and I have no idea how to do that. Then I thoght about making a snake/nibbes kind of game but I dont know how to make the worm...
Any ideas are welcome
Last edited by McCain; May 7th, 2002 at 09:21 PM.
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
well it seems like you got the basic technical aspects so I would really start to learn how to make tile engines since they will open a lot of new possibilites to you!
I learned it at www.ur.co.nz it was kind of hard for me back than because I did not even know what API was but since you already know all of the Blitting and DirectX stuff it will take you about 5 mins to get it!
If you have any further questions on it just post again.
The only easy tutorial I found on the site you gave me was the pacman tutorial and it uses classes - is that what you guys use for tile engines?
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
no not at all...
well I guess you can but no need for it.. here the simple explanation:
you have an array that stores the map. Typically a 2 dimensional one.
Every number represents one tile
now you go like
Code:
for x = 0 to 10
for y = 0 to 10
Destinatio.Draw Tile(map(x,y)), x*width, y * with
next y
next x
of course this is pseudo code but it will give you a good idea what tile engines are all about... all you need is an array of sourceimages (the tiles) which one you will draw is stored in the map array. NOw you loop through every singe element and draw it.
but why don'T you check out the good explanations on this in the tutorials section on www.ur.co.nz?
alright that works and you got the basics but it has two things in it that I would change, it can be way easier than your attempt.
the first one is just to save some time and make things a little nicer.
Instead oj using a textfile to store the map youse a binary file. The textfile has the advantage that you don't need to program a map editor to create a map, but as easily as you can use notepad to create the map anyone will be able to alter the map. And it's also a waste of diskspace... (oh well) and it's also slower to laod it that way line by line.
Look into the get and put statements in the MSDN you can just save a whole array with one line like put 1,,Array
now the big one (actually it's too)
instead of looping through strings and than manipulating them again to the get current one just use a two dimensional array you can declare one like this
dim Map(0 to 10, 0 to 10)... now you got an array with two dimensions that has the width and height of 11.
that makes the code much easier instead of all the string cutting you just go like
Code:
for x = 0 to 10
for y = 0 to 10
map(x,y) 'gives you the content of the field you want... it's kind of the same with you strings, just faster and less code like this.
next y
next x
now you see all those case statements... It might be a way to do it but just imagine how huge your code will be when you have like 200 different tiles (if a game gets bigger that's nothing to special) well there must be some better way (it's also faster... of course )
instead of having a letter for each tile you assign a number... now you store the tiles in an array. (you can also store them in one file but it's way easier this way for now, you can easily move on after you accomplished that). When they are in an array they all got their index as their number to indentify them so now you can just go like:
draw Destination.hdc x*width,y*height,Tiles(map(x,y)).hdc
alright have a look at that..
instead of using the variable you called intX and intY I just use the x and y that where used in the foor next loop and take them times the width of the tiles.. will give you the same result 2 lines of code less and 2 variables less.
than instead of having those case statements I put what I marked Bold... the map(x,y) will return the number/index of the tile to be drawn that way one line will work for all the tiles....
I think that should help... (hey I nearly wrote a book)
Thanks a bunch for all the help! You have no idea how greatfull I am!
But I don't quite get the binary thing...
I know how to use the put and get statements and I can put and get simple variables but when it gets to 2d arrays I'm in a bit deep... Could you please explain that some more?
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
well do you have a problem understanding 2 dimensional arrays or just saving them?
VB Code:
'for loading
Open App.Path + "\Map1.map" For Binary As #1
Get 1, , Map
Close
'for saving
Open App.Path + "\Map1.map" For Binary As #1
Put #1, , map
Close #1
A two dimensional array is like a chess board...
you can set a variable for every element like you'd say b3 on a chess board = pawn... well now in your array the difference is that you use numbers instead of letters for both coordinates so the same thing would be map(x,y) = pawn... well now you don't want to set pawns but tiles.. we represent every tile by a number it has in its array so it would be map(x,y) = 3 (or whatever tile would represent a pawn)
I hope that made everything a little clearer if not I will try again tomorrow need to catch some Zzs now...
Ok, thanks again
I'll see what I can come up with...
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
I just saw something in your code..
well you do not have the 2d array implemented, yet. It will clean the code up even more... but you are getting ahead.
But you call the game loop after you are done drawing.
The drawing will be inside of the game later on that is why it needs to be fast becaue you redraw all the time.
(well in some cases you don't need to but most likely you will)
later on when you might implement scrolling or something you will need to redraw anyways or when you draw actors on it.
by the way what are you doing... a snake kind of game or something like that? Will it need scrolling?
well I guess I am gonna post some old code of mine if I can find it tomorrow...
Ok, I got it, I didn't realize I could just save the whole 2d array at once to the binary file, thought I could only save one row at a time...
My code is so much shorter now!
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
I dunno what I'm doing yet... I just thought I should get the basics of tiled game first...
Next logical step will probably be to get somekind of sprite to move around...
I have no idea how to do the collision detection so any pointers are very welcome...
Please don't post any code - just keep doing what you have done so far - give me pointers in the right direction or post psuedo code.
I feel I learn much more that way then if I just copy and paste code...
Thanks
Edit ----
If we assume that the sprite moves with 20 pixels (the width and hight of the tiles) at a time. And then divide the x and y by 20 we should get the tile we're on right now and then it's just a matter about checking to see if the tile we're about to step on is a wall or not...
The problem is that I can't get the sprite to move...
I've tried Form_KeyDown and KeyPress - neither of them worked at all. Then I tried GetAsyncKeyState but it executes the moving code to fast, by the time I release the button the sprite is long gone from the screen... And I haven't been able to figure out how to just execute the code once...
Last edited by McCain; May 5th, 2002 at 07:26 PM.
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
alright doens't the code look so much nicer now?
one more hint... normaly all tiles should be the same width so instead of saving the width for every tile just make it one constant in memory. That will save 2 longs pro tile-type.
After this you can remove the line with the
intChar = Map(x,y)
and just put map(x,y) instead of it in the drawing code.
You wont loose any time for the lookup because it will be only looked up one time so it's even faster and more memory efficient.
alright I just saw the edited part..
so: You are right about the collision thing.
You can still use form_key down but as you are in a tight loop events wont be executed unless you put a 'doevents' in the loop somewhere... you should always do so.
But still GetAsyncKeyState is the way to go (or just GetKeyState) as you saw it's very fast and it allows you to have more than one key pressed at a time.
Now what you need to do is build in something that only executes the movement code if enough time passed. For that you should look up the GetTickcount API it is really simple you just use it like
VB Code:
static LastT as long
if LastT < Gettickcount then
'your code for moving
LastT = GetTickCount+1000
endif
this code would wait one second until it can be executed again (1000ms = 1s)
As allways, thanks for the hints. I'll try the code when I get home from school. And I do have a DoEvents in my loop, but the keyDown still doesn't work...
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
maybe the focus is set to some object on the form that recieves the key down events... I can remember things like this happening to me when I started off, but I haven't used the key down event for anything serious in a long time so I really don't know
The GetKeyState will do a much better job anyways.
Well you seem to learn really quick so here one more hint:
for scrolling you just need two variables (well for pixelwise scrolling more but we will do this later on )
lets call them xScroll and yScroll
the drawline is going to change like this:
Draw destination.hdc, ....., Source(map(x+xScroll, y + yScroll) that's how easy it is.
Ok, a few questions that is more regular VB then tiling...
In the GetTickCount thing you used a "static" variable, what exactly is a static variable?
First when I moved my little sprite around it left a trail because I only drew the map once so I moved the code that draws the map into the gameloop but now it draws the map ontop of my little sprite so I can't see it at all... What should I do?
How should I shut down my program? As it is now when I press the litte X in the corner the program becomes invisible but it is still runnig so I have to press the stop button in the VB GUI...
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
In math we learned that x was from left to right and that y was from top to bottom... So I thought you wold declare that map as intMap(19, 9) because it has 20 cols (x) and 10 rows (y).
So to me it looks like intMap(9, 19) should have 10 cols and 20 rows... Please explain someone!
Last edited by McCain; May 7th, 2002 at 12:18 AM.
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
alright that seems wierd to me...
well one thing about the math.. it's a good way to keep it like you learned in school but it is not neccesary you could also store it like
map(y,x) but keep it map(x,y) so you don't all confused.
How did you determine your map looks like this? the Array wont have any more elements than you declared... so it might be the way of how you found out about it....
hm with the loop thing, the game should look something like this
initialisation
Main Loop containing:
pretty much all of the game for now that would be
the GetKey thing
the drawing of the Graphics..
and after the main loop the clean up /End...
for the drawing you should first draw the map
than maybe a second map onto it (for multiple layers kind of things) than the sprites and stuff, than the GUI (if you got one)
now one thing that I belief you aren't using yet is a backbuffer.
You do all the drawing to a picbox that is invisible and Autoredraw = true
afterwards when all the drawing's done just blit it to the visible picbox you used to draw to. This will prevent flickering! (Gets even more neccessary when using masks)
Later on you should replace the picbox by a DC but a picbox is good enough for now... after you got all the techniques you might as well redo it (in clean code) in DDraw, so you don't need any DCs anyways since you will be using surfaces then.
Ok, I'll post all code tha's relevant to the creation of the map...
I know I shouldn't use a txt file but I do so for now because I don't want to create a map editor...
VB Code:
Dim intMap(9, 19) As Integer
Private Sub Form_Load()
Dim intLen As Integer
Dim intX As Integer
Dim intChar As Integer
Dim intY As Integer
Dim strFileLine As String
Dim strFileArray(19) As String
Dim intMap2(9, 19) As Integer
Open "c:\MyFile.txt" For Input As #1
intY = 0
Do Until EOF(1)
Line Input #1, strFileLine
strFileArray(intY) = strFileLine
intY = intY + 1
Loop
Close #1
For intX = 0 To 19
intLen = Len(strFileArray(intX))
For intY = 1 To intLen
intChar = Mid$(strFileArray(intX), intY, 1)
intMap2(intX, intY - 1) = intChar
Next intY
Next intX
Open "BinaryFile" For Binary As #1
Put #1, , intMap2
Close #1
For intX = 0 To 9 ' ********This is where I see what the map look like...
I thinkg I know what's wrong with my gameloop...
I only draw my sprite when I click on a button (in the GetAsyncKeyState thingie)... I'll fix it when I get home so it draws the sprite all the time and just changes the X and Y coordinates when I click the buttons...
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
alright the code looks neat... since you already save your map as binary it will be no problem to switch to binary later...
alright.. I really can't see how this code gives you more than 20 elements in one line since even the code to show it only loops 20 times...
When you dynamically allocate the array using Redim, and Redim Preserve (which you are not doing, at the moment), When you write the array to a file as binary, it also stores some extra data. When it does this, it makes it more difficult to read the data in another language, So I usually loop through and write out the actual integer data, as well as the width and height when saving the map. Just some advice =).
well Zaie that is true, but I have experienced that putting the data with no loops actually saves a lot of time! So when not using more languages I would stick to saving the whole thing...
@McCain One more thing about the redim though. You probably used redim preserve before... it does not work on 2d arrays. It won't give you an error but it will just have the same effect as redim without preserve.
One way to get around this is using a one dimensional array and go like this arrayMap(x+y*line) while line would be the number of how many tiles you have in each line...
Hmmm, I dunno if you guys understood my question... (if you didn't it's probably b/c of my bad english... )
So here comes my question again formulated different...
2d Arrays are declared Dim array(x, y) As *whatever*, Right?
But sometimes it looks as if the computer reads them array(y, x) (the wrong way)
My map that looks like this:
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
But it's not square =)
The map is (supposed to be) 10 tiles high and 20 tiles long...
Last edited by McCain; May 7th, 2002 at 09:59 PM.
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
Ok, everything is working good now!
Let's move on, shall we?
I've increased the size of the map a bit - it's now 20 tiles high and 60 tiles long. I can scroll the map tile by tile using the keyboard but how should I do this with my sprite? Should I always try to keep the sprite in the middle or should I just scroll as the sprite gets close to the edges of the visible area?
What is the next logical step in the learnig curve?
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
I made a tile (Engine, basically)
150 tiles wide, 100 tall..
149 individual tiles, all together (Corner pieces, etc.)
many different types of terrain
it runs pretty fast(map editor), but it took me awhile to get it to it's current stage. of course, in-game, it'll run faster... because map editor has a lot of fail safes.
Full screen, 1024x768, I get around 50-60 FPS.
Start off small, trial and error, basically..
find the best ways to do things, and you'll learn as you go.
image (50% original quality, so i can upload)
Just remember: everybody starts small, it's easy to get discouraged.
Your first project may not get off the ground, but as you learn, you'll find what you're best at.
Originally posted by McCain Ok, everything is working good now!
Let's move on, shall we?
I've increased the size of the map a bit - it's now 20 tiles high and 60 tiles long. I can scroll the map tile by tile using the keyboard but how should I do this with my sprite? Should I always try to keep the sprite in the middle or should I just scroll as the sprite gets close to the edges of the visible area?
What is the next logical step in the learnig curve?
Depends on what type of game you want. Keeping it in the center will be harder, IMHO.
sorry for being unclear.
I am not talking about global declaration of the variable but that they should specify a global postion
this gets important when using scrolling let's say some sprite is at the point of (5,5).. right now you can just draw it where you draw sprite (5,5) but when you scroll away this guy is supposed to scroll away too...
so you can't just draw it like draw x*tilewidth,y*tilewidht but more like
draw (x-scrollx)*tilewidht, (y-scrolly)*tileheight
(that wouldn't be pixel accurate but tile accurate... we can work on that later depending on what you want to do)
for the snake thing and stuff... you learn pretty good from everything but I would recommend a all direction scrollable jump and run game since you get to do it all than!.. (snake will be more likely to be some fun game after you finished...)
... baiscally it's up to you every practise is good....
If your map is not square, it wont Blt square (unless you are using un-square tiles =).
As to scrolling, it depends on the type of game that you want. You can have a single character game, in which case, it is fine to keep that character in the center, or to scroll near the edges (you might also consider scrolling an entire screen, a la Original Zelda). If you are going to have a party oriented game, you might want to try a Baldur's Gate style, and detach the camera from the character completly. Also, You could center on the character, until you reach the edge of the map. At that point, the character moves off center until he reaches the edge of the map.
Ok, let's go for a jump 'n' run game
I'll keep the character in the middle of the screen until it reaches the edges. There the map will stop scrolling.
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
I prefer moving the map when the actor gets to close to the edge that way the map does not scroll around all the time when you are just moving back and forth for something... I don't know if it's just me but the other way I get a headache...
what Zaei said about the detached camera is something I think is were slick. You can program the camera totally free from the game action and than attach it the way you want for effects and all of this. (for example when you press a button and somewhere there is a door opening or something you could have a move over there and stuff) that way you would be able to have maximum flexibility and also it would ensure good code (it needs to be good otherwise it wouldn't work that way)
Originally posted by /\/\isanThr0p keeping the sprite in the center is not a problem at all the only thing you got to remember than is that if you want to let the sprite go to the outermost pieces of the map that you engine must be able to recognize that it's not drawing anymore stuff otherwise you will get an out of bounds error. You can easily get around this by putting a wall around each map that is was wide as half a screen... the on error resume next would work to but it slows down things to much,.
I think the harder way is to scroll when the sprite gets to close to the edge but it's also not to big of a problem.
When you do all of this you need to start using global x and y positions that you convert to the screen x and y when drawing, so your collision detection does not get screwed up.
The way mine does it, it wraps the map around...
once your character gets to the edge, it centers the screen on your character, thus letting your character move more.
This is a lot easier(and less error checking is needed) than keeping the guy in the center the whole time.
Ok, I've decided what kind of scrolling I want. I want the character to be centerd on the screen in the up/down direction and I want the map to scroll in the left/right direction when the character gets to 10 tiles from the edge of the viewable area of the map.
To do this you obviously need to know where the character is on the screen, and as my tileengine is now this is very easy - the character moves exactly 20 pixels every time (my tiles are 20x20 pixels big). But that is not how I want my character to move... I want it to be able to move in different speeds (walk and run) and I want it to move smoother then 20 pixels jump... So my guess is that we have to get in to pixel collision detection...
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
well the collision with the map still works the same. But now I would store the position of the character in an x and y variable that represent pixels... before you draw it you just go like
draw character.x-tilewidth*scrollx,....
I think that should be clear...?
than what do you think about letting the map scroll pixelwise? I think you need to do it otherwise everything will be jerking...
so for pixelwise scrolling, here a way I did it (I don't think it's the smartest way, but since it worked for me I never thought about altering it...)
so here it is, I added 2 more variables
sclX, sclY
and I draw like
draw tile.x*tilewidth+sclx ,....
alright now I add to the sclx (in pixels) whenever I want to scroll..
whenever sclx (same goes for the scly) is equal to (or bigger than) 20 (your tilewidth) I set it to 0 and increase the scrollx by one...
well of yourse you have to do the same for -20 for scrolling to the left...
alright I hope you understood if not just post... (I will be home all day, so I will be around)
I'm having major problems with the scrolling... I can get it to move but not as I want. And I can't get the collision detection to work at all... The scrolling works pretty good when I go right but when I go left the map doesn't update... just keeps tiling the same row again and again...
Here's some rellevant code...
VB Code:
If GetAsyncKeyState(vbKeyRight) <> 0 Then
If intMap(intTmpY, intTmpX + 1) = 0 And intMap(intTmpY2, intTmpX + 1) = 0 Then
intPX = intPX + 20
If intTmpX >= 20 + intScrollX Then
intScrX = intScrX + 20
If intSclX < 20 Then
intSclX = intSclX + 20
ElseIf intSclX >= 20 Then
intScrollX = intScrollX + 1
intSclX = 0
End If
End If
End If
End If
If GetAsyncKeyState(vbKeyLeft) <> 0 Then
If intMap(intTmpY, intTmpX - 1) = 0 And intMap(intTmpY2, intTmpX - 1) = 0 Then
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
you forgot to decrease the intScrollX when the intScrlX is getting smaller than -20 (you have 20 there which kind of confuses me this should cause your program to act all wierd)
Ohh, it's acting weird allright!
And I have 20 because if I try to move it like 5 or something (to make it look smoother) the collision detecting (the little I have) messes up totally...
This is driving me nuts, I can't for my life figure out what's wrong...
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer