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 / how do I do "wait" without halting the program?

Author
Message
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 26th Oct 2011 19:05
The backdrop is used in 3D games, so since you are going 2D, there is no need for it. You could easily change the color of the screen by using CLS rgb(red,green,blue) where red, green and blue equal the color values you want. It does change things with regard to SYNCing when you use the backdrop.

It makes sense to me to use variable names that I can relate to. If it works for you to name several things with MM, that's fine, you can do whatever you think; to me it is confusing and I would avoid doing that. It is only a suggestion.

Quote: "I grabbed the text as an image because only sprites work with my fadeIn function, which when the player died, just text appearing on the screen is boring, I wanted it to fade in."

I understand what you are doing and that makes sense. I did notice that you were not grabbing the entire image.

Quote: "I offsetted the images because they were appearing on the top left (or bottom right, I dont remember) of the screen lol."


Just letting you know that it was not working. The sprites were in the upper left corner, yet when I moved the mouse in the center of the main menu graphic, it was like I was over them. There are a couple of reasons for offsetting a sprite, but what you were doing was not taking care of the problem.

Quote: "I know I do some things in some bad ways, everyone probally has at some point, But most of the things you asked were for a point, the goto's though. I know not to use them. I was being an idiot. This is for learning, I dont plan on selling it for $60 at gamestop or anything. Its not very serious to me, but thanks for the advice."


Please understand I am not down on you in any way here. We all were new at some point. The code you had posted had some significant flaws and I have given you suggestions/ provided code on how you might go about fixing them.

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 26th Oct 2011 21:45 Edited at: 27th Oct 2011 01:04
What!?!? You can use rgb after cls lol

Also, the bullet system doesn't work (Probally because I don't have an image for it lol, but if its a coding problem, please tell me), neither does the enemies, for some reason the sprite numbers override so only one enemy is ever one the screen, and after the delay, it moves rather than spawning another one. (Plus they don't move, there going to be like zombies (Actually, they will be zombies) So pretty much they just move straight down at you.)



EDIT TWO: Never mind, ignore this post (Probally too late for that) I fixed it, making the image for the bullet right now.

EDIT THREE: Ok, this isnt really a problem, its just a weird bug I encountered, after I added this timer check (To make sure the zombie doesnt just massively drain your health when touching you, and can only hurt you every second for like 5 damage or something) it made the collision box on the zombies just span almost the whole x coord of the screen and its weird. (Just looking for a fix, ill be fine with just deleting it and coming up with a better system)



zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 27th Oct 2011 03:15 Edited at: 27th Oct 2011 03:42
Quote: "I know I do some things in some bad ways, everyone probally has at some point, But most of the things you asked were for a point, the goto's though. I know not to use them. I was being an idiot. This is just for learning, but thanks for the advice."


I know I am going to get thrashed for saying this....

But, Goto's: [IMHO] As much as anyone who has been around programming knows that GOTO's have been demonized by structured programming - and with it - better methods to control program flow. But, they are NOT AS EVIL as we are all conditioned to think they are. And Yes, I too have been indoctrinated into the "KILL THE EVIL GOTOs" movement, and still find myself advocating the philosophy from time to time. I'm still trying to reconcile with the command that shall not be mentioned.

Seriously though, I'm not saying that they should be used all over the place, willy-nilly like. But, during development, and sometimes even in release... as long as you understand and document what you are doing, and especially if you are coding a solo project, I see nothing wrong with using a goto to easily bypass code or perform a jump. Let's face it, sometimes it's just easier when you are trying out things to use a goto. Perhaps when you have things nailed down a bit, you can edit the code to remove the reliance on them. But I see no point in making things difficult on yourself when you are experimenting.

It's not like the days of line numbers, and interpreted BASIC, where you could really code yourself into a corner. Like if you had to renumber large blocks of code because you didn't leave a big enough gap. If you didn't already develop a renumber utility that could cross referenc your GOTO's it could have a problem on your hands. And if you used GOTO's without reservation, you could wind up with spaghetti and no meatball. But used wisely it can be a powerful aid/tool. And while any code can be written to eliminate the need for a GOTO, I see no need to throw it completely out of the toolbox.

Ask an assembly programmer how he feels about any of the variations of jmp instruction. Sure you can push an pop from the stack or a register, but not if you don't need to. It's done all the time in assembly. And that's essentially what a GOSUB is, a jump back to a marker. So while GOTO puts more responsibility on the programmer.... the way I see it,, if you are willing to take on that responsibility than GO inTO that toolbox and pull out the GOTO. It doesn't make you a newb programmer to do so. In fact, when done with intent, purpose, and discretion... just the opposite could be said.

While the the advice to not use them is hard to debate at times. I think it's worse for someone to get hung up and frustrated trying to make their code pretty and neat and coder approved, than it is to get your ideas out and have something that works with a GOTO in it. After you get things working, you can make the time to eliminate them (if it bother you), but I personally wouldn't get that worked up about it,, if it helped you work through a tough piece of code, or... It just simply was the BEST solution. [Yes, I said Best]

I can't count the number of times that my code wound up looking more obfuscated just because I was trying to make it all nicey-nice. When, in fact, using the GOTO was the perfect tool for the job.

Now I need to find a sturdy pot to put over my head to protect myself........

Your signature has been erased by a mod please reduce it to 600 x 120.
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 27th Oct 2011 04:45
I already knew that, I just think, if your randomly using GOTO's, youre gonna get screwed, but if you have a system for it, and you understand it, your fine.

(I need help with my question from up there too)

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 30th Oct 2011 00:14 Edited at: 30th Oct 2011 00:16
Gah! I've tried everything, only one enemy appears on-screen at a time, even though it should have 6 at one time, either enemy sprites arent showing up, or the collision on the enemies spans almost the whole x coord of the screen, and bullets still dont work. I really need help. I have been working hard trying to fix it, I fixed it a little bit. But the bug is still there.



LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 30th Oct 2011 01:28
Some thoughts:
1. You have assigned your entity x and y values as floats, yet this is a 2D game; the x and y for a 2D game are integers. For example, you will not move to position 21.3,45.9 on the screen, you'll move to 21,45. I would assign them as integers and move them accordingly.
NOTE: integers are the default for TYPE variables and you can combine several on the same line.
2. You did not seed the random generator; typically, this is done as RANDOMIZE timer(). This will keep your game from being the same every time.
3. Suggest using a subroutine / function to setup the enemies.

Something like this:


Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 30th Oct 2011 01:38 Edited at: 30th Oct 2011 01:49
Oh ok, I used te floats because I wanted the zombies to move really slow, and 1 was going too fast, so I set it to 0.30, but if that was the problem, Im fine with changing it.

EDIT: ...I got the .dll error again... (Guess Ill just put it in the folder)

EDIT TWO: Ok, well they spawn randomly everywhere, and all at once. At least it works though, Ill fix that.

Also a question, does abs stand for absolute value? Never used it before so im not sure what it means or how it works.

EDIT THREE: Ok, sorry for all the edits, but after about 30 seconds of playing the fps drops to like 3 and im not sure why.

LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 30th Oct 2011 01:11 Edited at: 30th Oct 2011 01:12
Quote: "Oh ok, I used te floats because I wanted the zombies to move really slow, and 1 was going too fast, so I set it to 0.30, but if that was the problem, Im fine with changing it."


You could always slow it down by making it go through extra game loop iterations before going to the MoveEnemies() function. One way you could do that is from within your main game loop, like this:

This way, it only goes there after three iterations.

Quote: "Also a question, does abs stand for absolute value? Never used it before so im not sure what it means or how it works."

yes, it calculates the absolute value of the expression.
In this



code, for example, all we care about is that the difference between the player.x and enemy(b).x is more than 4. The player might be more than 4 pixels beyond the enemy or the enemy might be 4 pixels beyond the player - either way, we know we can increment / decrement the enemy's x coordinate. This code was put in to keep the enemies from jiggling back and forth as it approaches the player.

Quote: "EDIT THREE: Ok, sorry for all the edits, but after about 30 seconds of playing the fps drops to like 3 and im not sure why."


I made a mistake by using the variable, EnemyDelay as you had already used it. Change mine to EDelay instead.

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 30th Oct 2011 01:18
Well thanks, this was all really helpful, now all I have to do is working shooting (Which I still have no idea why it isnt working)
and do enemy collision when I figure out your code lol (So they don't go inside each other, thats really annoying)

Login to post a reply

Server time is: 2024-11-22 12:29:33
Your offset time is: 2024-11-22 12:29:33