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.

DarkBASIC Discussion / DarkNOOBS Project 1

Author
Message
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 6th Aug 2008 20:29 Edited at: 7th Aug 2008 10:31
Hey guys! We are relocating all discussion about our project to this thread. Anyway here is a quick rundown of what we have and what we need.

Have:
-Conceptual Idea of how the game will work

Need:
(C=concept T=tangible)
-(C)Storyline
-(C)How the mechanics will work (rules and such)
-(T)Engine
-(T)AI(assuming that we add in enemies)
-(T)Images
-(T)Music
-(T)Levels (sinister had a good idea for text files, I think we will do that)
-(T)File input and interpretation (to load the levels)

Ok I tried to be inclusive. If I missed anything let me know. So, our game plan is to hammer out all of the conceptual items and then we can get started on the actual coding.

Also, anyone interested in joining the team, check out the noobs wanted forum post to see details. We are all about trying to give noobs to programming a chance to learn with other like noobs.
Heres the link http://forum.thegamecreators.com/?m=forum_view&t=131352&b=10

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Irojo
15
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 9th Aug 2008 21:34 Edited at: 9th Aug 2008 21:35
Here's my first contribution:



I hope that's neat enough...

BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 9th Aug 2008 21:49
Not bad, could use some REM's though, so that we can know what everything does.

Also, I think we need to iron out exactly how it will work before we start coding. Since there will be falling rocks, we need to think about the timing for it. In the hamsterjam or whatever it was, the rocks would fall shortly after you step under them. However, I have played another variation called Mr. Matt in which they fall when you step out from under them (including down, which kills you).

Also, other than rocks and coins, what else will there be? Will there be enemies? In Mr. Matt, there were bins that could hold 3 or so rocks before disappearing, so that you could get rid of some rocks. Can Rocks be pushed? Can 2 rocks be pushed? Will the rocks simply stack in grid patters or will they be more offset(here is a pic)

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

VS

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

So we really need to figure out how this is going to work, which shouldn't take too long, before we jump in.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Irojo
15
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 9th Aug 2008 21:55
Hmmmmm okay. I don't know about rocks. I thought it should be one of those puzzles, that you have to do it in the right order to get through, or reset it. No enemies. Just a timer, and switches etc.

BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 9th Aug 2008 22:36
hmmm Wait, I thought we would be imitating hamster jam. So lets iron this out:

It is a puzzle game. (We agree)

The view I thought would be aerial, to avoid having physics.

The Goal is of course to beat the level. I thought that that would be done by collecting all of a certain item. You thought that it would be switches done in the right order.

So, whichever we do, there will also have to be some sort of obstacle. Be it rocks that can fall down and kill you/block paths, or something to stop you from flipping switches.

So, I guess we need to re-define what kind of game we are doing.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 10th Aug 2008 01:43
Hamster Jam looks like an old game I played when I was about 4,
the ground was "eaten" as you moved around trying to collect the diamonds, but if there was a space under a rock it would fall down, if you were underneath you got killed.

An aerial view is kind of impossible as this game is set in a subterranean world. This game actually has a lot of similarities with the cellular programs that I've written.
Physics aren't required, it's much simpler to make the world as a grid and check the squares below the rocks, moving the rock down if necessary.

TIPS: Store the world in an array, have different states for each cell: player, ground, empty or rock. Have a separate array that stores the positions of the rocks (the rocks are the only non-player entities that need to be analysed so it will be much quicker to keep an index of their positions rather than search the entire world for rocks).

What are the switches for?

It is far better to complete a 10 line program than to start a 10,000 line program.
Irojo
15
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 10th Aug 2008 01:47
You have to set off all the switches to advance the level. If you do the switches in a wrong order then it doesn't work, and you have to reset.

Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 10th Aug 2008 01:51
OK
I'm gonna have a go at making a small version myself and see if I come across anything that would be useful to you

It is far better to complete a 10 line program than to start a 10,000 line program.
Irojo
15
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 10th Aug 2008 02:50
Okay.
Nice to hear from you by the way.

Sinani201
17
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 10th Aug 2008 03:01
Should the order of the switches be shown?


Irojo
15
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 10th Aug 2008 03:17
What do you mean?

Sinani201
17
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 10th Aug 2008 03:57
Nevermind...


Irojo
15
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 10th Aug 2008 04:01
Okay.

BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 10th Aug 2008 09:22
Wait, when did the switches come into this? That seems like it would be kinda easy to win. I am thinking we should stick to hamster jam. It is already made so we can reference that. Switches would be more of a zelda type puzzle (next project maybe?). Anyway, I am going to make an executive decision here and say we stick with collecting coins.

@Obese
Good tips, I had been thinking of storing the whole world as an array myself. Didn't even think of the array for rock positions though.

@All team members
Check out the game Mr. Matt (google it, its a free downloadable game). It is almost identical to hamster jam, but doesn't have enemies or random death spots (or I just played a really weird version of hamster jam).

So here is the way it will work:

The terrain consists of rocks,ground,coins(or whatever), and (maybe) walls. Rocks fall when you step out from under them and can be pushed if there is only one. Two cannot be pushed. Rocks can't be pushed into ground, only cleared ground.

The goal is to collect all of the coins. If you die, you start over.

As you move, the ground is changed from ground to cleared ground.

Walls (if used) are fixed and only there to present added challenge and structure. For all intents and purposes, they are essentially ground that can't be cleared.

Later concepts: Rocks fall down and then so the side if the hit an obstacle, so that instead of:

*
*
you get:

**

I say later because that will require a bit of physics work.

The map will be a 400x400 with tiles that are 10x10.

Initially, all spaces will be ground. Rocks cannot move through ground only cleared ground.

Ok, that should do it.

What we need:

-Tile based motion-Irojo can take this because he has already started
-Tile control system (controlling the ground->cleared ground and coins)-Up for grabs as soon as first assignment is finished and approved.
-Rock control (includes falling and being pushed)-Sinani I want you to take this one

I will take on the physics and see what I can come up with.

I want all sections to be posted and approved by me or obese, just to make sure we are all going in the same direction. Sinister can also approve if he wants too, he has helped out. ALL code needs to be COMMENTED. While every line would be nice, that might be a bit much. I mainly want to be able to know EXACTLY what each section does and HOW it works.

So, thats it, lets get crackin.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
darkvee
18
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 10th Aug 2008 11:38
Hi this Vee
I figured, I would show you a game I made, its a racing game.
The object of the game is to dodge the boxs.



Vee
sinisterstuf
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location: Namibia, Southern Africa
Posted: 10th Aug 2008 12:51
Shall I make images for the tiles or has someone already done that?

over and out
Sinani201
17
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 10th Aug 2008 20:39 Edited at: 10th Aug 2008 20:42
errrrr... ok. I'll try to make a simple demo of the rocks falling.
There's one thing I'm still not sure about-- what should the game be called? Maybe we should focus on that later. Anyways, I'll get started.


BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 10th Aug 2008 20:44
yeah, story and name come later. About the demo, try to either keep it in functions (don't go overboard) or make it easy to copy and paste what is needed.

@sinister
That would be awesome, thanks!

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Irojo
15
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 10th Aug 2008 22:15 Edited at: 10th Aug 2008 22:22
Okay I have some family members over today. I'll start tomorrow. Should we make the code possible to essentially import? Like

1= ground
2= rock

etc.

?

+

I'll just make the boxes, which can later easily be textured.

-----

[Edit]

Let's try to make it so it works for any screen resolution. For example, instead of center text 320,240,"Text" we could do center text screen width()/2,screen height()/2,"Text"
Which would work the exact same, but no matter the resolution, it would be in the middle of the screen.

Sinani201
17
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 10th Aug 2008 22:25
If it works with every display mode, then maybe we should use TDK's Display Mode Function!


sinisterstuf
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location: Namibia, Southern Africa
Posted: 10th Aug 2008 22:51 Edited at: 10th Aug 2008 22:54
And the terrain tile images are 32x32 so they should fit on any standard screen resolution without getting cut at the edge of the screen.

over and out
Irojo
15
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 10th Aug 2008 23:19 Edited at: 11th Aug 2008 00:25
and/or we could use this wonderful function...








[EDIT]

How's this size?








[New Edit!!!]


I thought I'd give a progress report. It can check what row and column your on right now. I'm going to add how to determine the sprite's number. This is to determine what sprite is there. Which will soon be how to determine which sprite to hide, or delete.




sinisterstuf
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location: Namibia, Southern Africa
Posted: 11th Aug 2008 00:29 Edited at: 11th Aug 2008 00:32
There aren't any comments or indents in your code. So I don't know what it does and I can't test it. But it is short so from reading it it looks like you save 120 identical white squares and then fill a 510x272 pixel space with them? Is that correct?

If yes then here are some questions:
1)Why is the size of the image larger than the size of the drawing? i.e. Box size 33x33 pixels and get image size 41x41 pixels? Shouldn't the get image size also be 33x33 pixels? And why 33?
2)Why is the increment a different size aswell? Are you putting spaces inbetween the squares?
3)If this is to show the size of a map
Quote: "How's this size?"
then (I can't test it but 120/15=8 , 15*34=510 and 8*34=272 so 510x272, I think?) is an odd size. Is this going to be the screen size?
4)If all the squares are identical then why do you save 120 of them instead of having only 1 and pasting it 120 times?
5)I don't think you need CLS because I think the get image removes that part from the screen anyway.
6)Just an idea:



if that code doesn't work then it's because I wrote it on my phone and I can't test it but it should be fine and like I say, it's just a suggestion

Keep up the good work
cheers
sinisterstuf

over and out
Sinani201
17
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 11th Aug 2008 00:30 Edited at: 11th Aug 2008 00:31
I think I should do my job (making the boulders fall) after the entire game is finished, because then I can easily get where the boulders are, what tiles it should go under, etc. It's hard to make a demo when I ave almost no code to work on, aside from Irojo's little demo. But I'm afraid to say that the demo isn't enough to work on.

So when a basic demo comes with an example level that has boulders, I'll be able to do my job.


sinisterstuf
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location: Namibia, Southern Africa
Posted: 11th Aug 2008 00:42 Edited at: 11th Aug 2008 00:43
I think you should start now and write functions for the boulders that will apply to any situation so that Irojo can easily add the boulder "physics" to the game. You know, just think about what has to be done, surely it can't be too hard; If the player's x position is 1 tile less than that of a boulder and his y position is the same as the boulder then if he moves right then move the boulder right then check for empty spaces under the boulder and if yes then it moves down and checks again until not, when it stays still and the same for moving left. The part where the boulder checks for ground underneath it is then also used to see if the player has opened a space underneath it for it to fall, so just the same but without the first (player pushes the rock) part. Then all you need to do is animate the falling boulder with the move sprite command.

sorry, this is your job, so I'll stop now goodluck

over and out
Irojo
15
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 11th Aug 2008 00:44
@Sinister
1) When I was figuring out the sizes, I forgot to change that. Thanks for pointing it out
2) I am putting increments between the squares for the time being.
3) It is an odd size... I'll change that.
4) So if the sprite is collided into, it can be removed.
5) Perhaps not, but I'd put that there when I was doing some testing.

@Sinani

I agree with you.

sinisterstuf
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location: Namibia, Southern Africa
Posted: 11th Aug 2008 00:54 Edited at: 11th Aug 2008 01:02
Ok, re: question (4) then why don't you have 1 image and 120 sprites? I can't remember the parameters for SPRITE command off the top of my head but:



should do, right?
Then you can just delete the sprites when the player collides with them. Although you could obviously do it by using player positions with the images, with the sprites you can use collision / hit check commands to see when to delete them or perform whatever function. And if sinani has not made the boulder functions then how will the player interact with your boulders? I understand he may not know all game parameters and variables and so forth but I think you should be working at the same time, with each other, you know?
The tiles which I made are intended not to have spaces inbetween so as to look like solid ground and the boulders and coins have spaces on the images themselves.

over and out
Irojo
15
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 11th Aug 2008 01:04
OH DUH! I'm an idiot! Good point!

Ya Sinani can still work on it.

sinisterstuf
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location: Namibia, Southern Africa
Posted: 11th Aug 2008 01:14
lol, you're not idiot, don't be silly

well, I'm having a bit of a lack of inspiration/creativity for music (and lack of computer) but hopefully I will find some soon. And get it to sound really cool.

over and out
Sinani201
17
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 11th Aug 2008 01:30
Fine, I'll work on it.


I'm Sinani201, and I approve of this message.
sinisterstuf
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location: Namibia, Southern Africa
Posted: 11th Aug 2008 01:37
That' the spirit!

over and out
Sinani201
17
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 11th Aug 2008 02:20 Edited at: 11th Aug 2008 02:21
Alright! Here it is! Basically you would call checkBoulder subroutine in the main loop.


These are the variables and arrays that should be declared at the beginning of the main program:

Tile array: The tiles array. If the tile is equal to 1, then that means it is an open space.

Boulder array: holds x and y position of a boulder.

boudlerAmount: The amount of boulders in the level (should this be global?)


I'm Sinani201, and I approve of this message.
Irojo
15
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 11th Aug 2008 05:13 Edited at: 11th Aug 2008 05:44
[EDIT]
Forget the question. I solved my number one problem!!!! Here it is. It needs a TON of work, but it will be alot easier from now on. I'll fix the sizes of the blocks, the multiple image problem, and other problems. But here it is!!!




Sinani201
17
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 11th Aug 2008 05:27
I think there is a command, but I think it's in 3D... not sure, though.


I'm Sinani201, and I approve of this message.
Irojo
15
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 11th Aug 2008 05:43 Edited at: 11th Aug 2008 05:51
Okay. What do you think about the code? (I edited it so you probably didn't see it)
[EDIT]
!New problem solved!

I was having a little trouble with replacing the blocks, but it worked in the end! I'm going to make the code look nice, rem it up, and make it fit screen resolutions.





Sinani201
17
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 11th Aug 2008 05:54 Edited at: 11th Aug 2008 06:05
I'll try to edit that code so that it will support boundries.
[EDIT]: Now it supports boundries! No hard feelings, but Irojo, you should've known that boundries can be set with two simple lines of code. (not including the comment)



So just place that at the bottom of the main loop, right before the debugging text, and it should work fine.


I'm Sinani201, and I approve of this message.
Irojo
15
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 11th Aug 2008 05:59 Edited at: 11th Aug 2008 06:13
Eh. That'll be easy. I was going to do that next to last. Go for it though.


[EDIT]
Letting the player set the screen resolution is extremely difficult... I'm thinking of leaving it at one res.

BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 11th Aug 2008 07:07 Edited at: 11th Aug 2008 07:12
Wow, I am gone for a day and there are like 15 unread posts, impressive, but here are a few things I wanted to say:

1.COMMENT THE FREAKIN CODE! I don't want to re-create your train of thought. It is easy, just hit the ` key (next to 1) and type.
/rant

2.I want to put a couple things in stone here. The tile size is good at 32x32. The screen size WILL be 640x480, and the tile count will be square for now, 14x14. Here are the arrays to use: map-contains all information about map tiles. 0 means it is cleared ground. 1 means uncleared ground. 2 means rock. The other big array is rocks-contains locations for each rock 2 sub areas, so that it is:



3. Here is just an idea I want some feedback on. Rather than spending resources (which I admit we won't be using too much of anyway) making hundreds of sprites, why not make one and use the paste sprite. Then we just call a redraw function that will check what the value is in the map array for every tile and paste the appropriate sprite there. That way we can also use text on top of it.

Sorry for kinda jumping in late and possibly messing up what you guys have done, just wanted to throw out some of this stuff.

For sinani and irojo, not bad work so far. Remember to keep it organized, indented and commented. If you guys want any info for universal variables (like arrays and such) ask, and we will define them.

For sprite numbers, if we use paste sprite, then we will simply do whatever the code is for the tile (nothing for clear,1 for ground etc). If not, then the player will be 65535.Then, we will do a sprite for each tile and change the image used (so that there really IS no changing of tiles, just their pics).

Btw, I will make the redraw code, just focus on getting functions thrown together. And sinani, what sinister said was right, you don't need a working demo. Just make your own and put it into functions. You don't even need a character just a little bit of template stuff (arrays and such).

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 11th Aug 2008 08:12 Edited at: 11th Aug 2008 09:24
Allright, I know I am double posting, but I am because this is totally unrelated to my last post and because this is already at the top, so it isn't a bump.

I finished the function for the falling direction. Use it so that when the rock is falling and hits something other than ground, it will fall down and to the side, if necessary. It favors the right side (if both spots are open, it goes to the right) and is written to use the paste sprite method mentioned above.



also made the refresh function, using the paste sprite stuff. If we aren't going to go with that method, don't worry about it, it took me like 30 seconds to do.


Ok, so yeah, that stuff is done. Noticed that I commented the direction function (almost) to death. That is what I am looking for.

Alright, within the next day, irojo and sinani, I want you guys to post what you have got, just so that I can see where you are. Currently, what needs doing is:

-Tile control
-rock control
-map setup(read the files by bytes use x for ground, use o for coin/whatever,r for rock, s for the start point, and z for a wall)

just for fun, lets use a .map format for the files (essentially a txt file, just with a different extension)

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
sinisterstuf
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location: Namibia, Southern Africa
Posted: 11th Aug 2008 08:55 Edited at: 11th Aug 2008 08:58
@BN2 Productions
for your point number 2.
I read it a few times and I think you said there will be 2 arrays of terrain data and rock position data, if yes then why?
Also, for the numbers
0=cleared
1=uncleared
2=rock
what about walls and coins.
And I didn't know you could paste sprites... I guess that's a good idea. Except you won't be using sprite collision anymorw but instead checking the player's tile position and seeing what's there, right?
Well done for making those functions

@Sinojo & Irani
Well done, it looks like you guys stayed up quite late doing that... Unless there's a huge time difference... I'll have to check it out this afternoon.

over and out
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 11th Aug 2008 09:06
Quote: "Except you won't be using sprite collision anymorw but instead checking the player's tile position and seeing what's there, right?"


Yeah thats right.

Don't have any numbers for coins and walls yet, so 3=coin and 4=wall

the 2 arrays are for referencing different pieces of data. The map one for the terrain simply tells the refresh function (or whatever) what is in each tile, a rock, a wall, a coin, etc. The rock position array is to so that you can track each rocks position and control it. You can reference each rock and manipulate it. They are closely related, but both are necessary.

Here is how they can work together



For pasting sprites, the catch is that it can't be moved, just erased with cls. So it is good and bad. In a tile based system, that works fine, though, as there isn't a whole lot to worry about.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Irojo
15
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 11th Aug 2008 17:16 Edited at: 11th Aug 2008 17:20
I really don't get arrays. Even after I read TDK's tutorial. And I don't know if this is a bad habit, but I don't comment code until I know that piece of code is going to be kept.

Quote: "Alright, within the next day, irojo and sinani, I want you guys to post what you have got"


Just so you are aware, I'm not always able to be coding.

Quote: "Sinojo & Irani"




BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 11th Aug 2008 19:43 Edited at: 11th Aug 2008 19:44
I know you aren't. I don't expect it to be done, I just want to know where everyone is at so far so that I can plan accordingly.

About the commenting, I can understand that. But sometimes, commenting a little will help you formulate your ideas so that if it doesn't work, you can walk through the english (the comments) and see if the code does what it is supposed to.

Ok, I will try my hand at explaining arrays.

What they are:

Arrays are essentially variables that can hold more than a single number. They are referenced through a coordinate like numbers.

A good way to think of arrays are like filing cabinets. First you have the variable name, which is the unit itself. It can be, just like a variable, an integer, a float (containing decimals), or a string (words). The number of drawers is the first number (so dim checkdata(3) would have 3 drawers). From there, you can sub-divide each drawer with folders, for arrays, it would simply be the next number, signifying how many "folders" for each drawer.

So:
dim apples(3,2) would, to keep up the analogy, a filing cabinet with 3 drawers, and 2 folders in them (just to throw this out there, you CAN use and store data to apples(3,0) but that should only be used if it makes the code easier to read (don't go out of your way if you don't have to).

Now, since this is a computer, you can subdivide every drawer infinitely (to a point, but you will probably run out of memory before you hit the extents) as well as every folder. Inside each folder, though, is a piece of paper, which simply has a number or string (depending on the type) printed on it. This is what the value of that folder is.

How they are used:
You reference them just like variables, with code that looks like:
rocks(32,2)=6

In this case, it is saying (once again, to reuse the same example) go to the filing cabinet labeled "rocks", open drawer 32, and change what is in folder 2 so that it is 6 (pull out the old piece of paper and put in a new one with the number 6 on it).

Tricks that make arrays useful:

Here are two examples:
Example one, with no array-


That is ugly and a waste of space and time. Sections of code with many ifs should really be looked at to see if they can be condensed with loops and arrays.

Here is the second example with arrays:


Ok, so now, lets look at how arrays can be used to help us on our current project:

1 array can store the entire map, and that way it can easily be referenced in loops.
map(3,3) could be used for a 3tilex3tile map. Then you can reference it with x and y values. So if there is a rock at 3,1 then the check could read:


Think about how you would do this without arrays. There would have to be 9 different variables and 9 different checks, which could be done with 1 array and 2 for-next loops like:



So, what could have been 18 lines of tedious and messy code (and remember, the more lines you have the more mistakes you can make) can be done in 5.

Hopefully, this has helped you out. I remember I didn't get arrays when I first started either, then one day I read it and it clicked and suddenly they helped me out. I did go overboard at first and make EVERYTHING an array in my programs...don't do that, it doesn't always help.

A few tips and tricks I have learned:
-you can't inc or dec arrays. You either have to do it the old fashioned way (rocks(rock,2)=rocks(rock,2)+1) or set a variable equal to it, inc the variable, and set the array to the variable.

-you CAN re-define an array (using dim 2 times with the same name but different numbers). Data is only lost if it doesn't exist anymore so:

Will work perfectly (it should, anyway). This really should only be done if necessary, and even then try not to, but it is nice to know the rules so that you can bend them later .

I will let you in on more as I think of them. Let me know if this helps, I "stole" the filing cabinet example from a book I read a while back, it helped me understand arrays so I figured maybe it would help you too.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
sinisterstuf
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location: Namibia, Southern Africa
Posted: 11th Aug 2008 20:38
@BN2
I might be missing something but why can't there be just 1 array if the 1st one already says which tiles are rocks,ground,walls or coins then it already tells you the position of rocks and rocks shouldn't be sharing tiles with other stuff right? And are the rocks still sprites? Because otherwise there is a lower chance of sinani bothering to make falling and sliding animations?

over and out
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 11th Aug 2008 20:47
Essentially they are ways to look at similar information starting with different pieces

the first requires a coordinate and returns whats there. The other requires a number and returns a coordinate.

No, I was thinking that the rocks could be pasted as well. By animations, do you mean different pictures? As long as you call redraw and sync correctly, you can still show it being slid, or you could even use a sprite for sliding, then move the sprite offscreen and paste it where the sprite ended. The reason for pasting is that it uses fewer resources and If necessary we can put some Text over it, an impossibility with sprites.

I don't know, the pasting idea was just a suggestion, not a mandate, so I was expecting some sort of feedback, rather than everyone just going with it.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
sinisterstuf
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location: Namibia, Southern Africa
Posted: 11th Aug 2008 21:00 Edited at: 11th Aug 2008 21:02
I would have done it with one array. Why do you have the other one there? For speed? Or I guess you are just approaching the problem from a different angle. I would have had one array. Then before the loop which updates the screen there would be a loop that scans the array for rocks and when it finds one it checks if there is space below or next to it and updates the array before moving onto the next rock. Does this make sense? I don't think it would slow the game down either because there are so few items stored in the array.

Well for animation I just meant the movement of the rocks, i.e. move sprite command, which , with pasted stuff would have to be done with some sort of "slightly increment the position, cls, redraw, repeat" algorythm. Unless I'm mistaken? I'd rather do sprites and make any text that is to be displayed be sprites too that solves the hidden text problem.

over and out
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 11th Aug 2008 21:09
Why sprites rather than pasted sprites? Just curious.

I am a little confused, how would you move the rocks if there is no way to know where they are with only the one variable? If you would want to know where rock 2 is, how would you find out?

Anyway, I am working on my own version of this, so that I can help answer questions during development on how to make it work. I used the two array method and it does work. I am not saying yours doesn't, I just am a little confused as to how to make it work.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Irojo
15
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 11th Aug 2008 21:55 Edited at: 11th Aug 2008 21:58
I think I understand what arrays do.

It's like this
dim a(4)
a(1)=4
a(2)=3
a(3)=2
a(4)=7
------
or

dim a(2,2)
a(1,1)=2
a(1,2)=3
a(2,1)=5
a(2,2)=6
------

So basically, an array is storing the numbers into to sections, or branches?
Like In the example above:
Under branch 1, there is 1 and 2 which are essentially 1-1, 1-2
Under branch 2, there is again, but a different, 1 and 2, which are essentially 2-1,2-2.

Is this correct? If so, thanks very much for you example. If not, thanks anyways!


So I working example of array use:




sinisterstuf
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location: Namibia, Southern Africa
Posted: 11th Aug 2008 22:29 Edited at: 11th Aug 2008 23:07
@Irojo
yes, that's pretty much all there is to it

I found the help files example on how useful arrays are particularly useful.

@BN2
I'm not sure, I think you can just do a lot more with sprites. Or am I wrong?
Quote: "I am a little confused, how would you move the rocks if there was no way to know where they are with only the one variable? If you would want to know where rock 2 is, how would you find out?"

I don't really understand what you mean with there is no way to know where they are. The array contains all the information of the map, so it know where all the rocks are. And if you wanted to find rock 2... you wouldn't, why would you look for rock 2 in the first place, the loop before the draw refresh loop checks all rocks and makes any updates necessary. There is never a time when you would want to know the position of rock 2. Ofcourse if code has already been written that requires you to find rock 2, for whatever reason (still don't know why you would ) then I suppose you could use types to give each item an ID and then search array1 (the only array) for a rock with rock.ID value of 2 and get it to return the position of it. But why, when you could just have something like:



or wouldn't that work?
I just typed it on my phone now, so sorry for any spelling mistakes. Does my theory still not make sense? ...maybe it doesn't work... it should though... I certainly don't see anything wrong with it what more should I explain? lol

over and out
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 11th Aug 2008 23:25 Edited at: 11th Aug 2008 23:27
@Irojo
Yep, thats pretty much it. Glad I could help

@sinister
Ok, I see what you are saying. To be honest, that was what I was thinking of originally, till obese posted and suggested using two:
Quote: "TIPS: Store the world in an array, have different states for each cell: player, ground, empty or rock. Have a separate array that stores the positions of the rocks (the rocks are the only non-player entities that need to be analysed so it will be much quicker to keep an index of their positions rather than search the entire world for rocks).
"


It made sense so I figured go with it.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?

Login to post a reply

Server time is: 2024-04-20 09:57:29
Your offset time is: 2024-04-20 09:57:29