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 / DNG - Space Invaders

Author
Message
AJAtom
15
Years of Service
User Offline
Joined: 25th Feb 2009
Location:
Posted: 16th Oct 2010 00:55
I dont have time to code on weekdays.....so no, I dont really have progress. I've just been writing down code on paper

BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 16th Oct 2010 00:59
Alright, fair enough. Just wanted to keep up to date on things.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 20th Oct 2010 20:00
Progress report! Daygamer, Aj, where are you guys currently. Any progress in the last week?

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Daygamer
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: United States
Posted: 20th Oct 2010 22:36
I'll get that menu code worked out any day now. I've got internet finally!

yrotate when you can spin?
God Bless!
AJAtom
15
Years of Service
User Offline
Joined: 25th Feb 2009
Location:
Posted: 20th Oct 2010 22:55
Yes there is progress, but im choosing not y=to post it right this second

BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 21st Oct 2010 00:43
Thats cool guys, just hadn't heard from you guys in a while. Try to post with updates every week or so that way I can know that this hasn't died.

Personally time has been short, but the menus for switching out key-binds are ready and the high score table is there.

@Old_School
If you are interested, I have a job for you.

You mentioned being into doing music/sound. We currently need some. As far as the sound goes, just find one of the ones that comes with and sounds appropriate for explosions, shooting lasers, etc.

Music is needed as well. It doesn't need to be something really AMAZING, but just some nice background music.

Let me know if you want the job.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 22nd Oct 2010 07:02
@OldSchool
If you do take on the music it would be great if it was inspired by the original space invaders music. I just mean the dropping tones it doesn't have to sound 8-bit.


Do oranges know what colour they are?
Daygamer
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: United States
Posted: 24th Oct 2010 18:51 Edited at: 24th Oct 2010 18:53
FINALLY! I apologize for my slowness on this. There's no reason it should have taken this long. Even now I was kinda hurrying through it, so let me know if I've missed something you wanted me to do in your comments. Thanks for your patience.



EDIT: and if you still want me to attach sprites to my player movement code I'd be happy too.

yrotate when you can spin?
God Bless!
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Oct 2010 20:46 Edited at: 24th Oct 2010 21:47
Good job Daygamer, I'm going over your code now.

You don't need to update newmouse and oldmouse in every statement, just stick it in the main loop.


When you write conditional statements, you need to be sure of what is conditional and what isn't. Here's an example from your code.

Your first condition checks if the mouse is on the button; does this effect whether the button is drawn or the text printed? No, so these can be placed outside the statement. The clue is that you have put these commands on both sides of the condition.
The box command is not actually a duplicate because you have specified an ink colour as part of its parameters. We can choose to separate the ink and move the box out of the condition, or leave them as one inside the condition, whichever works best for our needs.
I think I'll leave the box as it is and as a little touch I'll make it expand when the mouse is on it.


Note how short my comments are. I appreciate you trying to explain your code but you want to avoid comments that are too wordy.
For big if statements it's helpful to have a comment above that tells the reader the context of the condition, e.g.

Here I've explained in very few words that the code below is executed only if the mouse is over the button. You only need to tell the reader what a true condition means, false is obviously the opposite.

To compare here is one of your comments.

I don't think this actually needs a comment at all. Game_started is a very good variable name and it's clear that game_started=1 means a game has been created.
A habit that you want to get out of is describing what will happen after the condition; you are just describing the condition here, if elements inside the condition need further explanation they can be commented individually. This way you don't pile information onto the reader all at once, and it makes editing easier because if you move things around you probably wont have to edit your comments at all!


Do oranges know what colour they are?
Eminent
13
Years of Service
User Offline
Joined: 15th Jul 2010
Location:
Posted: 24th Oct 2010 20:54
I'm still here if you need me. I've got animation down(at least in 3d) and I get how it works in 2d.


BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 24th Oct 2010 21:35
Awesome, thanks daygamer.

Points of nitpicking here:

line 42 reads "If game_started"

While this will work, since it is checking if the variable equals one, its a bit clearer to just put the =1 after it.

line 38 reads "if newmouse > oldmouse then return `not really sure what should go here"

My questions is what exactly were you trying to do with this one? If its start the game then that one is a pretty simple tweak. Just like you are controlling the maps (with a variable for the different instances and corresponding subroutines) we will be controlling the main program. So, to continue the game, you will set a variable called "Game". You will want to set it to 1 to begin playing. To resume should be 2 (would need to try it out to make sure).

@eminent
Glad to hear from you, kinda thought you had moved on to other things. I will look over where we're at and see what needs doing and I will get back to you soon.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Oct 2010 21:52 Edited at: 24th Oct 2010 21:55
Quote: "
line 38 reads "if newmouse > oldmouse then return `not really sure what should go here"

My questions is what exactly were you trying to do with this one? If its start the game then that one is a pretty simple tweak. Just like you are controlling the maps (with a variable for the different instances and corresponding subroutines) we will be controlling the main program. So, to continue the game, you will set a variable called "Game". You will want to set it to 1 to begin playing. To resume should be 2 (would need to try it out to make sure).
"

I've answered this in my post. Well I just put "then game_started=1" so the full game would need to be more advanced and have a condition to setup a new game if one didn't already exist.

Quote: "
line 42 reads "If game_started"

While this will work, since it is checking if the variable equals one, its a bit clearer to just put the =1 after it.
"

I actually prefer omitting the =1, I think it reads better. I guess it's just personal preference.


Do oranges know what colour they are?
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Oct 2010 22:25
I've had a neat idea for a website that would be useful for collaborative coding.

Explanation of my ascii entities:
[button] is a button
[option1|*option2*] is a row of tabs with option2 selected.
_________________
01 line 1
02 line 2
03 line 3
_________________ is a scrollable box that can be expanded to any height.


So here's my idea.

Quote: "
[*Original Code*|Ammendment 1]

Original Code by Daygamer
______________________________
01 print "hello world"
02 wait 1000
03 end
______________________________
[Copy][Ammend]

Comments

{OBese87}
- Nice job.

{BN2 Productions}
- That's impressive! I've made a small ammendment.
"


We now click on the Ammendment 1 tab to look at BN2's ammendment. BN2 could also have put a link to it in his comment.
Quote: "
[Original Code|*Ammendment 1*]

Ammendment 1 by BN2 Productions
______________________________
01 print "hello world"
02 wait key
03 end
______________________________
[Copy][Ammend]

Comments

{BN2 Productions}
- This way the user controls when the program ends.

{Daygamer}
- Ah, that's cool.
"



Do oranges know what colour they are?
Daygamer
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: United States
Posted: 25th Oct 2010 07:00
@Obese, So, I'm a little confused after all these posts. Is there anything you're waiting for me to do, or did you make the changes you wanted to my code?

yrotate when you can spin?
God Bless!
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 26th Oct 2010 21:21
@Eminent

I have been thinking and I have a job for you. We need HUD display code. This includes things that will visually depict lives, score, maybe level. Etc. To give you a challenge, though, work this out: I want the score to always be displayed with the same number of digits (I will say 8-10 for now, we will see how that looks). That means you will need code that will generate the correct number of leading 0's.

Also, the font for the score should be using bitmaps for each number (you will only need 10 pics: 0-9, and try to make em snazzy with a gradient or something). What I specifically want from you is a function that accepts the arguments of: a string (that will become the output), location (to place the images), and the image offset number (so that we can arrange the image numbers of the number pictures without changing the function), and a bitmap number to use (since I haven't charted through the code to see which ones aren't being used).

And for the real game changer: It must all be done (the entire HUD) using NO MORE THAN ONE sprite.

This is a seemingly easy task but I tried to throw in some little challenges for you. They shouldn't be TOO difficult if you are familiar with the help files and your 2D graphics commands. If it is, thats what we're here for

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Eminent
13
Years of Service
User Offline
Joined: 15th Jul 2010
Location:
Posted: 26th Oct 2010 23:24
What display setting will this be on?


BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 27th Oct 2010 00:14
Ideally 640x480, but the user will be able to change it. Rather than create multiple versions, arrange the parts such it will scale itself to the screen size (so position things based off of the edges).

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Eminent
13
Years of Service
User Offline
Joined: 15th Jul 2010
Location:
Posted: 27th Oct 2010 23:40
1 sprite? Seriously? I'm gonna have to make a whole bunch of photoshop images.....


BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 28th Oct 2010 00:03 Edited at: 28th Oct 2010 00:03
That's the point of the challenge! Using a bunch of sprites can get VERY burdensome on the system ESPECIALLY when we have 1 for every alien, 1 for the player, 1 for each barrier, etc. Then imagine a bunch for a static (mostly) hud. It all adds up.

Here is a quick one word hint: "bitmaps"

Also for the numbers, you can put them all on ONE picture, then in the program load it as a bitmap, use GET IMAGE, to grab the different numbers separately from the picture.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 30th Oct 2010 12:42 Edited at: 1st Nov 2010 07:53
@Daygamer
Quote: "Since all these buttons function the same I will describe just one in detail."

You didn't realise quite how insightful that comment of yours was; since all the buttons work the same way we only need to define one, and the way we do that is to write a function.
Here's few general pointers on the rest of your code before I get back to explaining how to write our button function:

You put CLS in the menu routine, this is fine but I recommend placing SYNC and CLS in the main loop because they control the screen buffer. Having a quick visual of when the buffer is flushed and wiped helps the reader to follow the flow of the program.

All subroutines should be called from the main loop. Calling subroutines from within subroutines is counter-productive; if we have long branches of routines, snaking away from the main loop in all directions, we may as well be using GOTOs because it will make the program just as hard to follow.

Now, on with writing this function.
We start writing a function by thinking about what properties we want to be constant (shared by all buttons generated), and what we want to be variable (unique to each button). Let's make two lists:
Constants – height (integer), width (integer), colour (integer), horizontal position (integer).
Variables – text (string), vertical position (integer), colour (integer).
By just looking at the constants we can imagine the character of our buttons: they will have a uniform shape, they'll line up vertically and they'll use the same colours. You probably think I've made a mistake by putting colour in both lists; that's because we want the colour of the buttons to change when highlighted (variable), but we want all buttons to use the same colour schemes for the two states (constant). This is our first big decision, how do we treat colour in our function?

To tell the truth, my first solution to this problem was awful. My idea was to hard-code the colours into the function and use a boolean parameter to select the colour to use, like this:

This seems like a logical solution, it saves us having to supply a colour every time we call the function. The problem is that it makes the function really inflexible. If we wanted to change the colours used we'd have to edit the function. If we wanted to add a third colour for when the button is clicked we'd have to edit the function. We could go one step further and put the mouse over button check inside the function; why is this a bad idea? Because then we could ONLY EVER use the mouse to select the buttons. Sorry for the diversion into bad coding but this is a good example of recognising your own mistakes and accepting them. You see, bad code is like weeds, you might have to sacrifice a few flowers if you spray them, but if you leave them they will take over your whole garden! You have to be comfortable with deleting huge chunks of your program if you find a major flaw in your method. Now let's get out of this horrible garden metaphor and back on the right path.

Now we're ready to write the first line of our function, we simply list the parameters, which are all the items in our variable list: function draw_btn(btn$,y,fg,bg) The parameters are button text (btn$), vertical position (y), foreground colour (fg) and background colour (bg).
We can go ahead and write the full function:


Here's the function being used:


I don't have DB at the moment, so there's a chance this wont work. If it doesn't work then take it as a challenge to get my code working.
Even if it works, this is just the icing on top of our menu system cake. We can now display as many buttons as we want very easily and in under 50 lines of code, but we don't have a functioning menu. The inner workings of the menu system are separate, it's good practise to keep processing and output separate.
To find out how to make the inner workings keep an eye out for my modularization tutorial, I've already posted the first half on the DBC board in its own thread called "What is Modularization?", I'm using menus as an example so you should be able to create your own system from reading that.

I'm only really getting to grips with modularization myself so if I'm going too fast for you just say and we settle on a less flexible system that is easier to write, but it's good practice to start thinking in modules.


Do oranges know what colour they are?
Daygamer
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: United States
Posted: 31st Oct 2010 08:20 Edited at: 31st Oct 2010 08:21
Yeah, great comments, thanks, but it is getting just a little over my head.

Your code didn't quite work on my computer. I attempted to fix it quickly, but it looks like I'll have to look into it further tomorrow.

EDIT:

yrotate when you can spin?
God Bless!
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 31st Oct 2010 13:13
I forgot to put SYNC:CLS is there, does it work now?
What part is going over your head? If you're having trouble with functions in general have a look at Grand Master TDK's explanation http://forum.thegamecreators.com/?m=forum_view&t=96075&b=7


Do oranges know what colour they are?
Daygamer
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: United States
Posted: 1st Nov 2010 05:35
Okay, I reviewed you message again, and I understood it a lot better. It's just a lot of text to absorb the first time.

I've been unable to get your code to work on my computer. It is supposed to standalone right? I can't blame you though. It's pretty hard to code without DB.

Also I actually never code with functions. I've personally found it easier to use just subs. But I'd be happy to work with them in this project if you want me too. Maybe I'll be converted one of these days.

But that made it a little hard for me to correct your code. Even if I understand functions, it's hard to work on them when I don't have any experience with them.

Also I noticed on line 10:


Should that be

possibly?

One more thing, I'm having trouble with


I guess I just don't understand the data command. I looked it up, I'm still struggling with it in this code. thanks!

yrotate when you can spin?
God Bless!
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 1st Nov 2010 07:08 Edited at: 2nd Nov 2010 08:19
Functions took me ages to grasp but they are probably the most useful thing you will ever learn in DB. You'll feel like you weren't really using your computer before.

If code could talk: plain code would ask "What?", subroutines "When?" and functions "How?".

Imagine, if you will, a virtual kitchen made from DB code. In this kitchen the taps (faucets if you like) are made from subroutines; you turn them on and off as required and they give you water, but only ever water and nothing else.
The oven is made from a function; the oven applies the same process, in this case heat, to whatever is put inside it and produces cooked meals of infinite variety.
(I was trying to sound like Carl Sagan on that one )

And for my final metaphor that literally illustrates (oxymoron?) the benefits of functions...
If we think of code as geometry it might look like this:

Plain code flows from one end of the line to the other (if you use GOTO this becomes a squiggly line ).
With the subroutines square, imagine that the bottom line is the main program and the top line is a subroutine. As we travel along the main program we can call the subroutine at any point by drawing a vertical line that connects the bottom to the top.
We call the function in the same way, by connecting the function at the top of the cube with a vertical line from any point along the program line. We can also draw the line at different depths, supplying the function with different parameters and thus adjusting its output.

I like making metaphors about this sort of thing so humour me.


When you say my code doesn't work, does it crash or just not display the buttons properly? Have you tried it with that dim in place? Good spot by the way.


Do oranges know what colour they are?
Daygamer
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: United States
Posted: 1st Nov 2010 21:23
Okay, I'm starting to see the advantages of functions better. Thank you very much for providing all the details (and metaphors. haha)

I worked a little more on the code, and got past a few more problems. On line 12,


The error was "Compilation Failed. Could not determine parameter type of 'New Game' at line 12." I retyped line 12, and it works fine. (For some reason DB wasn't recognizing that data command's values when I pasted it into my editor)

One line 23,


I figured you meant to REM this:


Now I'm stuck on line 35,


The error message is "Compilation Failed. User function 'draw_btn' must return a value if used in an expression at line 35."

Probably a simple fix, but I haven't been able to get it right.

Here's the full code I'm working with:




yrotate when you can spin?
God Bless!
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 2nd Nov 2010 08:03
I think the problem with this line

is the b=focus; this is a boolean equivalence check, it will return 1 if b=focus or 0 if b!=focus (b not equal to focus). It might look new to you but you've been using it all along: if b=focus... would simply be using the value of b=focus as a condition for the if statement.

I have never tried using a boolean value to directly feed a function, so that was probably foolish given I can't test it

How about this?


Maybe just putting parentheses around the boolean will solve it



Do oranges know what colour they are?
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 2nd Nov 2010 17:50 Edited at: 2nd Nov 2010 17:57
@Eminent any luck on that task BN2 gave you?

@Daygamer
The first time I saw the DATA command it I thought, "What is the point in that?", and never used it for ages until I realised it was actually quite useful.

DATA is like having a small file stitched into your program. The really useful thing about DATA is the way it's read; every time you use the READ command it takes one item from the data list and stores it in whatever variable you assigned to READ. Here's an example of how that helps us: if we were writing an adventure game and wanted several monsters to fight we might do it like this if we didn't know about DATA.

Gah all of those lines are starting to look ugly and very similar, and as the fourth sacred tenet of computer programming states: Endeavour to merge similar code. If we use a FOR loop to load the array we'll only need one line, this is where DATA comes in because there's no way to generate the data we want to fill the array with; I've yet to see a mathematical formula that takes 10 as an input and outputs "Insano Blob", and takes 3 and outputs "Extra Death". So we write all the data in ourselves and read it off one by one into the array.

Voila, much neater and less typing. Another good thing about DATA is that you can put it absolutely anywhere in your program, as far as I know it is completely ignored by the program cursor (the thing that reads the commands to execute). Most people stick DATA at the bottom of the program to keep it out of the way.

You can use DATA to store any data type, so strings and numbers can be in the same line, which can be very useful. If you enter the DBC challenges (which I recommend you do), you'll use DATA a lot because external files aren't allowed.

If you're wondering about the Sacred Tenets of Computer Programming, they are ancient codes of conduct that have been upheld by all noble coders since about two hours ago. Yes I just made them up in a crazy attempt to create some sort of chivalric code and go around calling everyone "my liege!", but here they are anyway.

Quote: "
== The Six Sacred Tenets of Computer Programming ==

1. Maintain clear presentation in all of your programs.

2. Tackle your own problems before seeking help.

3. Acknowledge those who have aided you.

4. Endeavour to merge similar code.

5. Pass on your knowledge.

6. Master your language.
"

Have you noticed that each tenet has one less word than the last? This was completely by chance after I re-wrote three of them.

[edit]
Oh I forgot to tell you about RESTORE. That command sets the data reading cursor back to a label you specify; the label is the same kind you use for subroutines. If you have lots of labels you can separate sections of data for reading at different times. I'm not sure if you can use RESTORE without specifying a label, that might take it back to the first piece of data in the program but you'd have to check the help file.


Do oranges know what colour they are?
Daygamer
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: United States
Posted: 3rd Nov 2010 00:15
The code ran fine, but the cursor would stay on the "New Game" button and flashing down to the "Continue" if you pressed the downkey, and then popping back up to the "New Game" button.

I wasn't able to figure out a fix quickly, so I'll have to look into when I get a little more time, unless you've got something for me to try. We're getting there.

And I can now see the advantage of DATA. Not only is DATA my favorite character in Star Trek (see my Avatar), it's also a great way to store values. I'm officially a convert.

And I think your Six Sacred Tenets of Computer Programming are worthy of being sacred by the way.

yrotate when you can spin?
God Bless!
Daygamer
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: United States
Posted: 7th Nov 2010 07:19 Edited at: 7th Nov 2010 17:11
Got some time this weekend and fix this code.



The problem was in the following section of the old code:


In the old code the "focus" moves down or up when newin > oldin or newin < oldin. Let's say the player presses the downkey.

The --process-- does its job because for just one loop newin>oldin (1>0). This activates the following if then statement and moves the focus down 1 value.


Before the player releases the downkey it looks like this newin=oldin (1=1).

Then when the player releases the downkey, it will be newin<oldin (0<1). This activates the following if then statement deceasing "focus" by 1 and moving it right back where it started:


Hope I explained that okay. My best idea was to use a timer. So here ya go:


yrotate when you can spin?
God Bless!
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 7th Nov 2010 12:25
Well done Daygamer, that was kind of stupid of me lol.
Of course it was a test I planted in my code *ehem*

A simpler solution would be

Now only when a key is pressed will the focus change.

Can you make it so the focus wraps from one end of the menu to the other instead of stopping? Can you make it so the focus changes once on key press but scrolls when the key is held down?

You will need a timer for the second one, as a note it is usually better to use a "timer" that counts the number of loops the program has run rather than actual time. We don't know how long something will take to run and the speed may change depending on completely unrelated things. If the user opens up media player you don't want your program to act differently because the computer has slowed down.


Do oranges know what colour they are?
Daygamer
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: United States
Posted: 8th Nov 2010 03:45
Okay, Although not perfect, my solution works.


And Here's the full code




yrotate when you can spin?
God Bless!
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 8th Nov 2010 16:58 Edited at: 8th Nov 2010 23:18
By separating the newin/oldin comparison from the focus wrapping, you've improved the code but you missed the fact newin<oldin or newin>oldin can be simplified to newin<>oldin. My other change was to take the holdkey check out of the second condition, this just seemed more logical. Those are the only two real changes I made, good code.


This comment isn't needed:

You don't need to explain the command, you should instead explain what the operation means to the program. I changed this comment to "change menu focus".

Another comment that is too long:

You are talking about things that are going to happen somewhere else in the program, which can be confusing - if other parts of the program need explaining they can have their own comments. So we cut out the last bit: keep track of the time the player has held down the key, this is fine but still a bit too wordy for my liking and I would shorten it to something like key held for another loop. There is a slight difference in the style of my comment and yours; your comment describes the use of the holdkey variable, while mine explains what incrementing holdkey means in the context of the program.

I have been slowly learning C++ and the book I've been using has given a lot of good tips for general programming. It has changed the way I write comments. I will adapt a passage from the book to explain, it is specifically about while loops but the logic can be applied to any comment:


It can be hard to understand precisely what a particular while statement does. It's not too hard to see that the while statement above will print a number of rows depending on the value of r, but how can we be confident that we know exactly how many rows the program will write? For example, how do we know whether the number will be r, r-1, r+1 or something else entirely?
There is a useful technique for writing and understanding while statements that relies on two key ideas - one about the definition of a while statement, and the other about the behaviour of programs in general.
the first idea is that when a while finishes, its condition must be false - otherwise the while wouldn't have finished. so, for example, when the while in the above code snippet finishes, we know that x<>r is false and, therefore, x=r.
The second idea is that of a loop invariant, which is a property of the while that remains true each time we come to test its condition. Although the invariant is not part of the program text, it is a valuable intellectual tool for designing programs. Every useful while statement that we can imagine has an invariant associated with it. Stating the invariant in a comment can make a while much easier to understand.

To make this discussion concrete, we will look again at the while statement above. The comment immediately before the while describes the invariant: "We have written x rows so far".
To determine that this invariant is correct, we must verify that the invariant is true each time the while is about to test its condition. Doing so requires us to verify that the invariant will be true at two specific points in the program. The first point is just before the while tests its condition for the first time. It is easy to verify the invariant at this point in our example: because we have written 0 rows and x=0.
The second point is at the end of the while body. If the invariant is true here also, it will be true the next time the while tests the condtion. Therefore, the invariant will be true every loop.
In exchange for writing our program so that it meets these two requirements, we can be confident that the invariant is true not only each time the while tests the condition, but also after the while finishes. For example, when x=r and the while finishes, our invariant is still true - we have written x rows of output.

Heere is a summary of what we know about our program fragment in relation to the invariant:



Wow I didn't realise how wordy that passage was, I managed to cut out quite a lot of needless text from it . You see it's not just you, I even pick at a published author's writing .


Do oranges know what colour they are?
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 8th Nov 2010 17:11 Edited at: 8th Nov 2010 23:19
Anyone else have any updates/still alive?

[edit]
I am currently downloading DBP and will attempt to run it using Wine on Linux. If it works this will be fantastic and make things much easier.
Cross your fingers for me


Do oranges know what colour they are?
Daygamer
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: United States
Posted: 10th Nov 2010 05:15
Hey, just wanted to post to let you know I've haven't died on you.

Thanks for the tips. I'm having trouble staying awake, so I will re-read them, and maybe post something meaningful later. thanks

yrotate when you can spin?
God Bless!
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 10th Nov 2010 05:28
Sorry for going silent for so long, its been a rough couple weeks. Nothing major happened, just haven't had time to code or anything really between school and other things.

Most of my stuff is done, but I think aj might be MIA.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 14th Nov 2010 20:54
I hope to see this project finished eventually. I threw in a few codes on the display routine and a function to maybe help get this moving again.


Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 20th Nov 2010 02:22
I just got a new job (yay!) so I will probably be quite busy next week, I am also away next weekend.
I'll try and get on tomorrow and look at where we're at since not a lot has been getting done recently.


Do oranges know what colour they are?
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 29th Nov 2010 02:23
I am moving into my new house tomorrow!


Snobbery is a privilege of the ignorant.
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 29th Nov 2010 02:30
Congrats Obese!

@Everyone
Sorry I've been so absent lately. I'm entering Week 10 in college and then comes finals, so I have been studying like mad. I'll be monitoring but won't do a whole lot for the next couple weeks.

Sorry

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 30th Nov 2010 11:33
I've moved into the new house, my stuff is everywhere and I'm having to use the library for internet access atm.
Will update you as things change.


Snobbery is a privilege of the ignorant.
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 17th Dec 2010 20:21
Alright I'm back on my feet. Lets get this ball rolling again!

I will post back in a couple hours or so, I am going to look over what has been done and where we are to determine what still needs to be done.

Who is available to work?

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Daygamer
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: United States
Posted: 17th Dec 2010 20:56
Excellent,
I have started a project of my own recently, but I think I could find some time for some work. Count me in

yrotate when you can spin?
God Bless!
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 17th Dec 2010 21:32
Thanks BN2, I'm still committed to this but my internet isn't working yet so it's difficult to stay involved (I'm on my dad's computer).


Snobbery is a privilege of the ignorant.
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 17th Dec 2010 21:43
I totally understand Obese, that's why I'm here . I'm going to get it to a stable build before figuring out what needs to be done (working on integrating the menu code from daygamer right now)

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 17th Dec 2010 22:20
I'd like to be part of this project as well, count me in.

BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 17th Dec 2010 23:36
Excellent, glad you have you Ashingda.

@Obese
With DBPro I have found that we can store subroutines in separate files that are included in the project and we can still call them from the main source file. I was thinking it may help clean up the code a bit to separate different parts of the code into its own file (makes hunting for things a bit easier).

Don't want to make any major changes to things before I have your approval on this (it is still your project). I have tested the theory and it does work perfectly though.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 18th Dec 2010 00:34 Edited at: 18th Dec 2010 01:09
Not To Double Post but:

State of the Game:

I would place the game at 70-80% done. We're almost there. With the integration of the menu being completed you can now pause the game and resume it at will as well as start a new game.

Alien generation and User Interface is missing. The framework exists for customizing keybinds (which buttons do what), all that's missing are the menu's to do so.

Aliens move correctly and the player can destroy the aliens. Alien shots still cannot kill the player. Barriers are still missing.

That's it, I'm trying to be brief.

Job Postings:
0. We need a name for the game (unless we just want to go with Space Invaders)

1. User Interface
-We need a defined style. This isn't necessarily code, and most of this is defined by the hud, but things like common fonts, color schemes, etc are important and lacking.
-HUD. This needs to include the score (function to add leading 0's is already done). Score should be displayed at 8-10 digits (whatever looks good). Level should be displayed as well as wave numbers, lives and so on.
-The start menu needs a background of some sort. Be it animated or static, I don't care, it just needs to look good and have something to do with Space Invaders.

2. Highscore Table
-The structure is made and the file system is ready. Graphics for it need to be designed and implemented to finish it.

3. Menu Completion
-Options menu needs to be built
-Keybind control button/menu (I started on this already so I will finish it up just include a button for it)
-Video Options
-Gamma/Brightness control
-Set Display Mode (we default to 800x600)
-Sound Options
-Sound Effects On/Off
-Sound Volume Control
-Music On/Off
-Music Volume Control
4. Alien Bullets need to kill the player, nuff said.

5. Barrier Creation/Display/Destruction on collision with bullets (I know this was being worked on a while back but I couldn't find code for it so if its done, someone point it out to me).

Additionally sounds and music are required. If you have any non copy-written stuff, awesome. If its your own creation, that's even better. Worst case, DBC (dunno about DBP) came with a nice library of sound and music that we can pool from.

If you have a preference, say so, otherwise:

Job Assignments:

Daygamer: You started the menu, if you'd like to finish it, its yours. Its a larger task though, so if its too much we can break it down or you can have a smaller task.

Ashingda: User Interface stuff. That's graphics, and code to implement it. If possible, try to get the HUD into a single sprite. Don't forget to size it correctly (The player may change the screen resolution).

Anyone else who wants to help, now's the time to make your presence known.

Code (separated by function):
Main Stuff:


Menu Code:


Code for pre-game setup (initializes aliens and such)


Main Game Loop Subroutines:


Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Daygamer
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: United States
Posted: 18th Dec 2010 06:34
@BN2, I would like to give the menu a try.

Just so I don't put a bunch of effect in the wrong direction, you want me to work with the code under "Menu Code" for your post, and work on the tasks from "3. Menu Completion" on your list, correct?

I'm getting a little "unknown parameter" error at line 45 in the code from the post.

yrotate when you can spin?
God Bless!
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 18th Dec 2010 07:05 Edited at: 18th Dec 2010 07:10
Quote: " I'm getting a little "unknown parameter" error at line 45 in the code from the post."


Not sure where that is coming from (what line is it?)

I just cut up the main code to make it more manageable (rather than posting a HUGE source I broke it up) so each one might not compile correctly on its own.

Correct as to what you are doing. I already created a subroutine called Menu_Options for you to fill in. You will probably need an if then or some kind of branching subroutine so that, when the variable game=0 (which means the menu is active) it will go to the correct menu (remember no loops). Note the SELECT statement at the end of Main_Menu, the third one is for the options menu and right now it does nothing. Fill it in the same as the others are with whatever it needs to be to make the switch.

Here is the menu code in a format that you can run on its own.


Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Daygamer
14
Years of Service
User Offline
Joined: 16th Mar 2010
Location: United States
Posted: 18th Dec 2010 18:34
okay, this works fine now. I don't know what the problem was.

I may need some help on a few things. I'll attempt to work on this in the next few days, and I'll plan on giving you an update.

yrotate when you can spin?
God Bless!

Login to post a reply

Server time is: 2024-04-25 04:31:02
Your offset time is: 2024-04-25 04:31:02