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 / Made this while doing TDK's tut's.

Author
Message
Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 11th Apr 2008 23:09 Edited at: 11th Apr 2008 23:14
Nothing special, just a number guesser. However, it is the computer this time.

Made it when the tut explained the commands, and this is a pretty decent thing I made that is fun to mess with for about 5 mins.

I got weird results. First time, it took 206 guesses to get it, and the second took 6 times, to get the same number.



I know I used Goto, and it is not a good command, but for a small program, I see no harm in using it. If it is large, then I will not.

Woops, forgot something, this is better.

Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 12th Apr 2008 00:33 Edited at: 12th Apr 2008 03:00
Here is another code. Sorry for the double post, but I think it is worth looking at. I was reading TDK's tut on the elementary commands, and it mentioned that the code will go faster if put the color value in instead of the RGB value, so I made this nifty little windowed program that you enter the RGB value in, and it converts it to the color value. I made it windowed so you can have DarkEdit open, enter the values, and type it into DarkEdit, ultimately speeding up the program, if you enter allot of RGB values. Tell me what you think.



**Edit**
Now, you can select either a light value, or a dark value. So you can read any color, instead of having to only select light values to read it.


***EDIT***
Instead of triple posting I shall post my latest here. This is a basic program the will draw and X through the screen using the Dot Drawing feature, and will basically point the middle of the screen, this was mainly a test to see if I could do it, and it is almost dead on. I cannot get it 100% accurate due the the fact the that when I was calculating the Y movement, I divided 640/480 (Defualt screen Res) and I got 1.3333333333 which is 1/3. I may attempt to make it more accurate by implementing 480/640, which is .75 or 3/4, which the ratio for the screen, so that should work better.



Eh, cannot get it dead on, but this seems to be more accurate.



The accuracy attached. The Vertical and Horizontal lines pin point the center of the screen, so the X is almost exact.

Attachments

Login to view attachments
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 12th Apr 2008 03:35
nice programs!
your first program only needed a goto because the structure was bad.
the later programs have much improved structure

your last program is the best because it shows you are starting to think like a true coder
i had a glance at the code and it is confusing
the way it jumps about is hard to follow, but i see how you combated the x:y ratio.
There is a much simpler way of doing so which i will test and post soon...

keep up the good work and keep writing little progs like these.
It's better to complete a 10 line program than to begin a 10,000 line one. That is becoming a catchphrase for me :p

Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 12th Apr 2008 03:43
Lol. After I start to get the hang of programing a bit better, I am going to try and teach myself to compress the coding a bit more. Such as lines like "If Y=3 then BlahBlahBlah" instead of writing it fully out like I do right now. The reason why I am not attempting to compress my coding, is that I am afraid I will start doing that, making me type less, making me lazier, my goal is to make it so that I will not be to lazy to full program something.

I am slowly learning how to apply the coding. I am working on coding as I learn new commands through TDK's tutorials. So far, I think I am doing pretty good..

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 12th Apr 2008 04:15 Edited at: 13th Apr 2008 01:06
I have returned! [fanfare sounds] :p
I knew there was a much quicker way to do the line program because x and y had such a strong relationship. That's something you'll pick up with experience, but basically: the stronger the relationship, the less code is needed.
Now here's the code:


hope that's helpful to show how code can be broken-down and optimized.

Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 12th Apr 2008 04:54
Ran it, seems pretty good, but one flaw. The cross is supposed to be in the center of the screen. I ran yours, and it was further down then half.

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 12th Apr 2008 16:20
really?
that's odd
could you post a screenie, i don't have db at the mo
thanks

KISTech
17
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 12th Apr 2008 18:11
One tip, if I understood you correctly a couple of posts up.

It's not a bad practice to continue writing,



Instead of,



In a long program when you are trying to debug something it's easier to trace if similar structures are structured the same. Also don't be to concerned about using blank lines to separate things out to make it easier to read. It might make your source file bigger, but the compiled program wont be any bigger because the compiler ignores REM statements and blank lines. Which brings to mind another good practice. Always try and at least put a rem statement at the beginning of a block of code that has a particular function. It makes it easier to follow for you, and anyone else that might end up reading your code.

If you already knew these things, then hopefully it will help someone else down the road.

Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 12th Apr 2008 21:22 Edited at: 12th Apr 2008 21:42
Yeah, I know those tips. But really simple programs like these should nearly be like a book to more fine tuned, better programmers. If you noticed, I put a few REM's on the color values. (`'s instead of REM) I just put it there, because I felt like messing around with it. I am now going to modify those programs to save some information, like the number guessing, I am going to make it save your best and worst guesses.

Oh, and Obese, the center is where the tip of the mouse is. Here is your program. I did not move the mouse, on a 640, 480 program, the mouse starts in the center. It is hard to see, lemme make the lie color white.

Also, further examination of your code, it should be width/hieght, to get the 3:4 ratio. And, the "for x= 0 to sw" Should be "For x= 0 to sw-1," otherwise it will be a never ending loop. Seeing as the resolution for 640, 480 has pixels 0-639, 0-479, and not the actual number. From what I have seen, DB does not draw dot out of the resolution. Hm, I am trying to get your code, same size (one added ink command) but work fully.I am getting a "cannot divide by zero" error, but logic would tell you it is dividing by .75...

Ok, I got it to work.


That works like it is supposed to.

It will not work for wide screen though.

Attachments

Login to view attachments
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 13th Apr 2008 00:50 Edited at: 13th Apr 2008 01:10
@Maindric
that doesn't make any sense because 640/480 IS 1.333
maybe it was a strange syntax thing.

sorry if I patronised you but I don't really know how experienced you are.

[edit]
just had a thought what might've been wrong.
There's a funny syntax for getting a float from a division, so I changed the denominator (sh) to a float (sh#)
Could you try the code again for me (it's edited)
thanks.

Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 13th Apr 2008 01:11
I know, I thinking off.

I now realize that 4/3 is correct, 1.333, but when it was ran with the formula in DBC, it did not do it right. My math was off, that's all. I needa go back to school, Spring break is killing me. Eh, but Algebra sucks now. We are doing Cubed roots, 4th roots, etc. Anyways, I was thinking wrong. =P

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 13th Apr 2008 01:13
@Maindric
see my edited post above
you weren't wrong

Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 13th Apr 2008 01:18
Ok, it works now. I was thinking about doing that when I was posting my previous post. Ah well, I was wrong in my post by saying this.
Quote: "but logic would tell you it is dividing by .75"


I was right IF you reversed to 3/4, so I am right saying I am wrong.

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 13th Apr 2008 01:22
oh right missed the .75 bit
cool so it works now?

Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 13th Apr 2008 01:39 Edited at: 13th Apr 2008 04:18
Yes, it does, and smoothly, a bit dark though.

Currently I am making a number guessing program that saves your best/worst scores, and number of games played. I am making the saving and loading functions, to practice functions.

I may also do a Hi-Scores chart in it to get more practice. Honestly, this is the first challenge I am giving myself that I may actually be able to do. On the high scores, I may save them as Arrays, which I have not read yet, but will soon when it comes around to it.

I shall post what I got when I get a cleaned up version of it. Currently it just saves and loads the data, but not number guessing yet.

I finished it without a highscore chart. I MAY add one, I doubt. This was mainly a test of a few things for me.
Arrays
Functions
File Access

Here is the code. (In order to use the save, you need to save the file, or else it may or may not work.)


Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 13th Apr 2008 20:11
Quick question. This is more of an annoying thing than anything else, but when I run this code, and move the ^, Sometimes it jumps, how can I prevent that?



TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 14th Apr 2008 06:26 Edited at: 14th Apr 2008 06:37
First of all, it's nice to see someone actually putting into practice some of the layout suggestions I put in the tutorials. I'm sure you'll agree that a) your programs look a lot neater and b) they are a lot easier to follow, debug and add to. Well done!

On to your problems...

First of all, colons ( : ) are for two things:

1. Combining more than one statement or line of code (multi-statement lines)
2. Defining labels

You therefore shouldn't use them at the end of a Gosub call as in effect you are defining the label twice. It doesn't actually matter that much in DBC as it assumes a multi-line statement where the following line is blank and still works.

However, it's confusing - and bad practice - so it should be avoided.

Have you read my 2D shooting tutorial? If you've based your program on the code snippets in that, you need to realise that the examples are very un-refined and intended only to demonstrate the basic principles.

The 'jumping' issue is a combination of how busy the program is doing other things at the point the point the spaceship is being drawn, and the fact that text mode isn't ideal for doing this sort of thing. There are a couple things you can do to improve things:

1. Try setting the sync rate to 0. If the speed of the ship is too fast, change the PosX=PosX-5 part to a lower value. Try something like Inc PosX,2 and Dec PosX,2.

This however still has one major flaw - it will run at varying speeds on different computers. For example, on your computer, it might take say 8 seconds for the ship to move from the left edge to the right edge of the screen. On mine, it might take 14 seconds or even 5 seconds - depending on the specs of the machine it is run on. Timers are the only way around this.

2. Use a timer for both the ship and bullet movement.

I've adapted the code snippet from the 2D Shooting tutorial rather than your program just in case you haven't seen it and are planning to do so. It then makes the tutorial explanations relevant and keeps it a little less confusing...

At the end of the day though, doing this sort of thing in text mode isn't ideal. You would be much, much better using sprites. But anyway, here's a little example for you to look at. Check the shooting tutorial for more info if there's anything you aren't sure about.



And, to show you the difference, roughly the same thing with sprites. See if it's any smoother for you than using text:



TDK_Man

Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 14th Apr 2008 14:18 Edited at: 15th Apr 2008 03:09
Ok, I shall look into this later. Thanks for the reply. I thought that the fact I was using text might have caused it, but was not 100% sure. I was attempting to make a medialess style'd game.

Quote: "Have you read my 2D shooting tutorial?"


Hm.. Not at the time I made that code. I purely made that code, then read the tutorial in comparison. I usually learn better that way. I honestly did not expect to be a able to make it WORKING, so I did not expect it to be perfect.

Quote: "
2. Use a timer for both the ship and bullet movement. "


Working with the timer I see, I shall do that.

Quote: "
And, to show you the difference, roughly the same thing with sprites. See if it's any smoother for you than using text:"


I ran both of them, and I see what you mean. I shall work on that when I come home from school. I gotta get ready soon. >.>


Thanks for your response TDK. I shall look into what you said later, I read it and made a quick reply, but I may have missed something, so I am going to look more into what you said when I come home.

Ok, I am working on the sprites, and I just made the ship. (Sorry if any typos, no spell check and odd keyboard, I am over at a friend's place who also has DBC [Convinced them to get it=P]) Here is the ship:



I made it a GoSub code just to implement into DBC easier. Whatcha think?



There is the bullet, mainly put it here to implement when I get home.



Yay! Here it is so far, I haven't put in the timer to keep speed steady, but I put in the sprites and steadied the fire rate. One question though, why does it look like 2 bullets get fired after a while?

Login to post a reply

Server time is: 2025-06-07 17:17:34
Your offset time is: 2025-06-07 17:17:34