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.

Newcomers DBPro Corner / anyway to improve on this code? noob here

Author
Message
Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 20th Nov 2010 15:56 Edited at: 23rd Nov 2010 16:04
totally new to this, so hi to everyone, I hope to see more of you all, anyway I followed a great tutorial "http://forum.thegamecreators.com/?m=forum_view&t=153346&b=7" and done all of that, and then I expanded it by adding a menu and a few little things, is their anyway I could expand on this? or improve whats already here? because I want to learn to do this all properly



test edit

been making crap games using every little program I could find, now I want to do it properly using a proper language
Eminent
13
Years of Service
User Offline
Joined: 15th Jul 2010
Location:
Posted: 20th Nov 2010 18:14
"show mouse
set text size 55
set text font "papyrus""
Delete all that. Put it outside the loop just before the do because its just making your program slower. Showing the mouse is automatically enabled so delete that.


Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 20th Nov 2010 19:39
show mouse is used because after dying on the game you return to the main menu by pressing space, but the mouse is hidden while playing so it must be shown again otherwise it can't be seen when the main menu re-appears

been making crap games using every little program I could find, now I want to do it properly using a proper language
T4r4ntul4
14
Years of Service
User Offline
Joined: 1st Jan 2010
Location: close to my pc
Posted: 20th Nov 2010 19:58
before you get Grog Grueslayer in your topic, use gosub instead of goto
Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 20th Nov 2010 21:47
will do T4r4ntul4, but can you please tell me why?

been making crap games using every little program I could find, now I want to do it properly using a proper language
Eminent
13
Years of Service
User Offline
Joined: 15th Jul 2010
Location:
Posted: 20th Nov 2010 22:29
Well the two text commands can be left out of the loop.


T4r4ntul4
14
Years of Service
User Offline
Joined: 1st Jan 2010
Location: close to my pc
Posted: 20th Nov 2010 23:28
Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 21st Nov 2010 08:01
k thanks T4r4ntul4 and eminent, I'll remove the text from the loop and replace goto with gosub, just wondering though anything else I could do? and if not mind giving me another task to improve my skills?

been making crap games using every little program I could find, now I want to do it properly using a proper language
Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 21st Nov 2010 08:18
made a few small changes to the script, but nothing major, text removed from loop, slightly changed PlyrHlth# value and changed the scoring system, just wondering, wouldn't it improve my script if I removed the # after PlyrHlth? because I am not using decimal points only straight number, 50,30,10 ect

been making crap games using every little program I could find, now I want to do it properly using a proper language
Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 21st Nov 2010 08:20
oops just thought, don't think I posted the code, (because of delays in my message being posted) so here it is



been making crap games using every little program I could find, now I want to do it properly using a proper language
T4r4ntul4
14
Years of Service
User Offline
Joined: 1st Jan 2010
Location: close to my pc
Posted: 21st Nov 2010 18:02
if you use gosub

do it like this:



and maybe set your framerate to 60 or more/less because the game was ended before i could blink my eye...

your using from object nr 2 to 8 the same color, why not using an for loop for that?

why not indent your code? it makes it more readable. maybe use comments, becuase after a month you dont probably not know why you put the whatever code there.

if i press new game, ill get a object exist error, if you make a new game, delete existing objects ( with delete object ) before you create new objects.

that were some thoughts
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 21st Nov 2010 18:45
Yeah T4r4ntul4 is right... in fact you don't really need a GOSUB since you know how to do functions.



Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 21st Nov 2010 19:12
thanks grog, you used the old code I think, because it has a few problems that I got rid of but your mods seem sound, so thanks it'll help me a lot, any way I could add to the code to have more features,

I'd like to do credits & top 10 highscores (offline) next, could you help me with this as I don't know where to start.

highscores would need to be able to-

1.save 10 highscores
2. be able to sort the highscores from lowest 10 to highest 1, and be able to record name.

credits would be text scrolling up, with a star background (think I know how to do the last bit....

I don't want ready code, I just need a hand knowing how to go about doing what I need, thanks to you all

been making crap games using every little program I could find, now I want to do it properly using a proper language
Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 22nd Nov 2010 16:36


latest code, got very basic credits sorted (after many trial and major errors lol) sorted everything (basically) except 1 major thing, after playing 1 game when you go back to the main menu you still see the game board and background instead of it showing the proper main menu, any advice?

been making crap games using every little program I could find, now I want to do it properly using a proper language
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 22nd Nov 2010 17:07 Edited at: 22nd Nov 2010 17:09
Np.

For a high score table the easiest way is using an array to store the scores and use the commands LOAD ARRAY() and SAVE ARRAY(). Sorting the score is not really needed if you make code to check each number in the array to see if the current players score is high enough to make the list. When the players score is higher than the next element in the array the remaining scores are moved down the array and the new score is added.

For credits you can just use PASTE IMAGE to show the background and use the TEXT commands to write the credits. Since TEXT allows you to use exact x and y coordinates you can slowly decrease the y coordinate of the TEXT to appear to be scrolling up. I would use an array to store all the credits and use a FOR/NEXT loop to write all the TEXT in the array. Also if you use CENTER TEXT it'll be less painful to center it on the screen.

Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 22nd Nov 2010 18:27
may sound like a dumb question but I want to load an image as the background of the main menu, how would I go about this? I have looked around and a few things came close but nothing that worked for me, menu code is above

been making crap games using every little program I could find, now I want to do it properly using a proper language
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 23rd Nov 2010 01:13 Edited at: 23rd Nov 2010 07:10
You can texture the backdrop to put an image there all the time. However, it still shows up in the menus. I made a few edits that hopefully will be helpful to you. You were using PlyScr# to track the player's score (same idea with the health variable), but you only use integer values. The # on the end tells DBPro that you are using a float. Not a really big deal, but I only use # when I actually need float precision and consider it a better programming practice. Anyway, I removed the # on them.

I also put things into subroutines so it is a little more comprehensible. It is worth noting that a subroutine label requires a colon after the name and not a semicolon. A backdrop texture is made in the code just to show you how it can be easily done. I reset the placement of the text in the menu, because it was mostly off the screen. I also edited your collision check code to make it more efficient. You don't want repetitious code calculating any more than it has to. An example is the screen width() and screen height() calculations. You can see where I changed this so the computer doesn't have to calculate these values.

It would be better to handle the object speeds via an array, or using type variables (more advanced topic) instead of manually coding the amount they move like that.

I hope this is helpful. If you need a hand with arrays or types, let us know.

** EDIT: The Get window width and height in the original code use Ian M's Matrix1Util plugin: It is a free plugin for DBPro that I highly recommend you get. Here is a link to thread where it is located:
http://forum.thegamecreators.com/?m=forum_view&t=85209&b=18

In the meantime, this code should run okay for you (I have also added some comments to it to help with understanding):


It is worth noting that one of the lines for the credits is too long to fit on the screen.

Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 23rd Nov 2010 06:17
k thanks I'll get back to you on this after school, but for now I'm just wondering what screen resolution you used, because for me the text never went off screen, is there anything else that could cause the text to be placed wrong on ytour computer?

been making crap games using every little program I could find, now I want to do it properly using a proper language
Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 23rd Nov 2010 06:39
a few little problem,


doesn't work, I tried changing window to screen but still never worked. is it because get isn't a command? or is it the wrong syntax?

also can you please give me a sample code of how to make a background for just main_menu? I couldn't get the code you gave me last to work fully because I didn't understand everything sorry

been making crap games using every little program I could find, now I want to do it properly using a proper language
Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 23rd Nov 2010 14:03
I changed that part of the code when it never worked anyway, but thanks for putting so much effort to helping me

been making crap games using every little program I could find, now I want to do it properly using a proper language
Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 23rd Nov 2010 14:40
my latest code, everything working (maybe not perfect code, but it works)



thanks for the help up to now, the next thing I want (after working out the main menu background properly) is a high score system, I'll start working on that now

been making crap games using every little program I could find, now I want to do it properly using a proper language
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 23rd Nov 2010 14:56
You will notice that I revised the code in my first post here. Did you try it? If so, and it errored, what was the error? Are you using DBPro v 7.5?

Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 23rd Nov 2010 19:56
loaded a great music track (not trying to blow my own horn lol) sped up the game, at least partially finished credits, game working glitch free ( to the best of my knowledge) but I'm stuck again, I'd like to have the option to turn the music off, because I personally hate to play games without that option and I'm sure others are the same, can anyone help me with this? I don't even know where to start for this thing

been making crap games using every little program I could find, now I want to do it properly using a proper language
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 24th Nov 2010 08:19
You can check the KEYSTATE() of a key like the S button to toggle sound on/off which is just a variable switch. In the following code snip when the S key is hit it checks to see if the switch is off (Music=0) and if it is it turns it on (Music=1) and if the music is on it'll turn it off. Making it a standard toggle switch. The TIMER() is there to make sure the toggle doesn't happen too fast. With timers 1000 = 1 second so in the code snip it waits 300 milliseconds between each music switch toggle.



baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Nov 2010 10:50 Edited at: 24th Nov 2010 10:50
A handy way to toggle "music" between 1 and 0 is this (Adapting grogs code):


Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 24th Nov 2010 14:26
cool thanks guys, It might not be a good time, but would you's help me if I try to code a simple rpg or racing game?

2d rpg, with simple concept, chests ect.
racing game, sort of like gran turismo 2

been making crap games using every little program I could find, now I want to do it properly using a proper language
Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 24th Nov 2010 14:36
I'll keep trying to work it out, but where would I put the loop so it works?

been making crap games using every little program I could find, now I want to do it properly using a proper language
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Nov 2010 17:20
Quote: "but would you's help me if I try to code a simple rpg or racing game?"

I'm sure if you get stuck people will help you out... just post the problem.

Quote: "I'll keep trying to work it out, but where would I put the loop so it works?"

Not sure what you mean? The "do / loop"? It looks to be in the right place to me...

Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 24th Nov 2010 17:21
@ baxslash:

Much better.


@ Shadow Legacy:

Yeah it's probably not a good idea to start anything big until you learn more about programming in Darkbasic Pro. Consider the DO/LOOP in our code snips to be the same as the DO/LOOP in your own code (meaning whatever is in ours you copy into yours minus the DO/LOOP since you should already have one).

Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 24th Nov 2010 18:07 Edited at: 26th Nov 2010 16:04
thanks grog, I like that explanation I think I understand 100% now, just to put it into practice now lol.

if all life can be generated even in todays games,
then what hope is their for us? for we are obsolete
Skype = Shadow-Legacy
Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 24th Nov 2010 19:11 Edited at: 26th Nov 2010 16:13
Deleted

if all life can be generated even in todays games,
then what hope is their for us? for we are obsolete
Skype = Shadow-Legacy
Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 24th Nov 2010 21:15
just had a great thought, I'd like to play 3 different tracks, they'd need to start in a random order though,m because the game isn't long, so how would I go about that?

something like

music$ = rnd(3)
if music$ = 1 then play music 1
if music$ = 2 then play music 2
if music$ = 3 then play music 3

something like that? or would it need to be more complicated?

another thought I had is an exit screen, a picture that shows for 5 seconds when you press the exit button on the main menu, I have tried a few things to implement this but nothing thats worked up to now,

I've tried coding along the lines of

remove picture 1
paste picture 1,0,0
suspend till keypress
exit

but I just got a frozen screen until I pressed a key at which point it exits as normal.

just going to bed now, so try to collaborate on this better tomorrow

if all life can be generated even in todays games,
then what hope is their for us? for we are obsolete
Skype = Shadow-Legacy
Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 26th Nov 2010 16:08
ok, focusing on the music thing, I want to play 1 of 2 music tracks when the game starts.

like this (in... em pseudo code)

music$ = rnd(2)
if music$ = 1 then loop music 1
if music$ = 2 then loop music 2

gonna try it when I have access to dbpro

if all life can be generated even in todays games,
then what hope is their for us? for we are obsolete
Skype = Shadow-Legacy
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 26th Nov 2010 22:41
Drop the $ to make Music a variable and it'll work.

Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 27th Nov 2010 12:43
ok thanks again grog, I got past that part but hit another snag,

I keep hitting a Function declaration mid-game ( when I press new game button on menu) and it exits me from the game, I know the problem but not how to fix it, I'll keep messing around with it until I get a reply



DBPro noob here
Skype = Shadow-Legacy
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 27th Nov 2010 16:14
Any time it errors out with "You have hit a FUNCTION declaration mid-program!" it's because the normal program flow actually got down to your function. Functions are called but are not suppose to be actually seen.

In this snip there is no END to stop the program from hitting the function and thus produces an error.



For your program you just need a RETURN before the function.

Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 27th Nov 2010 16:19
thanks didn't think it would be that simple, thanks again grog

DBPro noob here
Skype = Shadow-Legacy
Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 27th Nov 2010 16:28
ok I'm getting no error messages now but I can't start a new game, it just closes the program, am I missing something? the code it still the same as before by the way just fixed the function error

DBPro noob here
Skype = Shadow-Legacy
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 28th Nov 2010 01:28
One of the problems is you were GOSUBing to the MainMenu when it's better to let the normal program flow go there naturally because when you RETURNed you would of gone there normally anyway. Always remember when you GOSUB you'll eventually have to RETURN to the line under the GOSUB... too many GOSUBs and you'll produce stacking errors.

Instead of making the main menu a REPEAT/UNTIL loop I made it a DO/LOOP with a GOSUB MainGame when the user hits New Game. The check for the spacebar at the end of MainGame is a RETURN instead of another GOSUB to MainMenu.



Shadow Legacy
13
Years of Service
User Offline
Joined: 20th Nov 2010
Location: Infront of my computer
Posted: 28th Nov 2010 08:42
thanks as usual works perfectly now

DBPro noob here
Skype = Shadow-Legacy

Login to post a reply

Server time is: 2024-05-27 20:56:13
Your offset time is: 2024-05-27 20:56:13